         success: =>
           @modal?.destroy()
           @handleCollaborationEndedForParticipant()
-
-
-  handleCollaborationEndedForParticipant: ->
-
-    # TODO: fix explicit state checks.
-    return  unless @stateMachine.state in ['Active', 'Ending']
-
-    # TODO: fix implicit emit.
-    @rtm.once 'RealtimeManagerWillDispose', =>
-      @chat.emit 'CollaborationEnded'
-      @chat.destroy()
-      @chat = null
-      @statusBar.emit 'CollaborationEnded'
-      @removeParticipant nick()
-      @removeMachineNode()
-
-    @rtm.once 'RealtimeManagerDidDispose', =>
-      kd.utils.defer @bound 'quit'
-
-    @cleanupCollaboration()
 
 
   endCollaborationForHost: (callbacks) ->

      @myWatchMap        = null
      @mySnapshot        = null

  registerCollaborationSessionId: ->

    realtimeHelpers.registerCollaborationSessionId @rtm, @participants

        callbacks.success()


  handleCollaborationEndedForParticipant: ->

    # TODO: fix explicit state checks.
    return  unless @stateMachine.state in ['Active', 'Ending']

    # TODO: fix implicit emit.
    @rtm.once 'RealtimeManagerWillDispose', =>
      @chat.emit 'CollaborationEnded'
      @chat.destroy()
      @chat = null
      @statusBar.emit 'CollaborationEnded'
      @removeParticipant nick()
      @removeMachineNode()

    @rtm.once 'RealtimeManagerDidDispose', =>
      kd.utils.defer @bound 'quit'

    @cleanupCollaboration()


  showChat: ->

    switch @stateMachine.state
