     if @amIHost
       @endCollaborationForHost
         success: =>
-          # TODO: move this into its own method.
-          @statusBar.emit 'CollaborationEnded'
-          sharedSuccessFn()
-          @cleanupCollaboration()
+          @modal?.destroy()
+          @handleCollaborationEndedForHost()
 
     else
       @endCollaborationForParticipant

    @rtm.once 'RealtimeManagerDidDispose', =>
      @rtm = null
      delete @stateMachine
      @prepareCollaboration  if @amIHost

    @rtm.dispose()


            callbacks.success()


  handleCollaborationEndedForHost: ->

    return  unless @stateMachine.state in ['Ending']

    @rtm.once 'RealtimeManagerWillDispose', =>
      @chat.emit 'CollaborationEnded'
      @chat.destroy()
      @chat = null
      @statusBar.emit 'CollaborationEnded'

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

    @cleanupCollaboration()


  endCollaborationForParticipant: (callbacks) ->

    @broadcastMessage { type: 'ParticipantWantsToLeave' }
