Skip to content

Commit

Permalink
Move toggle logic out of view model
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Herdmann committed May 8, 2017
1 parent 3b0a835 commit 430c33a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
25 changes: 20 additions & 5 deletions app/script/calling/CallingRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ z.calling.CallingRepository = class CallingRepository {

/**
* Construct a new Calling repository.
*
* @param {CallService} call_service - CallService] Backend REST API call service implementation
* @param {CallingService} calling_service - Backend REST API calling service implementation
* @param {ClientRepository} client_repository - Repository for client interactions
Expand Down Expand Up @@ -172,6 +173,7 @@ z.calling.CallingRepository = class CallingRepository {

/**
* Join a call.
*
* @param {string} conversation_id - Conversation ID
* @param {boolean} video_send - Should video be send
* @returns {undefined} No return value
Expand Down Expand Up @@ -261,15 +263,28 @@ z.calling.CallingRepository = class CallingRepository {

/**
* User action to toggle the call state.
* @param {string} conversation_id - Conversation ID of call for which state will be toggled
*
* @param {boolean} video_send - Is this a video call
* @param {Conversation} conversation_et - Conversation for which state will be toggled
* @returns {undefined} No return value
*/
toggle_state(conversation_id, video_send) {
if (this._self_client_on_a_call() === conversation_id) {
return this.switch_call_center(z.calling.enum.CALL_ACTION.LEAVE, [conversation_id]);
toggle_state(video_send, conversation_et) {
if (!conversation_et) {
if (this.conversation_repository.active_conversation()) {
conversation_et = this.conversation_repository.active_conversation();
} else {
this.logger.info('No conversation selected to toggle call state in');
}
}

if (video_send && conversation_et.is_group()) {
amplify.publish(z.event.WebApp.WARNING.MODAL, z.ViewModel.ModalType.CALL_NO_VIDEO_IN_GROUP);
} else {
if (conversation_et.id === this._self_client_on_a_call()) {
return this.switch_call_center(z.calling.enum.CALL_ACTION.LEAVE, [conversation_et.id]);
}
this.join_call(conversation_et.id, video_send);
}
this.join_call(conversation_id, video_send);
}

/**
Expand Down
9 changes: 2 additions & 7 deletions app/script/view_model/ConversationTitlebarViewModel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ class z.ViewModel.ConversationTitlebarViewModel
amplify.unsubscribe z.event.WebApp.SHORTCUT.ADD_PEOPLE

click_on_call_button: =>
return if not @conversation_et()
amplify.publish z.event.WebApp.CALL.STATE.TOGGLE, @conversation_et().id, false
amplify.publish z.event.WebApp.CALL.STATE.TOGGLE, false

click_on_maximize: =>
@multitasking.auto_minimize false
Expand All @@ -84,11 +83,7 @@ class z.ViewModel.ConversationTitlebarViewModel
@show_participants()

click_on_video_button: =>
return if not @conversation_et()
if @conversation_et().is_group()
amplify.publish z.event.WebApp.WARNING.MODAL, z.ViewModel.ModalType.CALL_NO_VIDEO_IN_GROUP
else
amplify.publish z.event.WebApp.CALL.STATE.TOGGLE, @conversation_et().id, true
amplify.publish z.event.WebApp.CALL.STATE.TOGGLE, true

click_on_collection_button: ->
amplify.publish z.event.WebApp.CONTENT.SWITCH, z.ViewModel.content.CONTENT_STATE.COLLECTION
Expand Down
4 changes: 2 additions & 2 deletions app/script/view_model/list/StartUIViewModel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,13 @@ class z.ViewModel.list.StartUIViewModel
on_audio_call: =>
@on_submit_search (conversation_et) ->
window.setTimeout ->
amplify.publish z.event.WebApp.CALL.STATE.TOGGLE, conversation_et.id, false
amplify.publish z.event.WebApp.CALL.STATE.TOGGLE, false, conversation_et
, 500

on_video_call: =>
@on_submit_search (conversation_et) ->
window.setTimeout ->
amplify.publish z.event.WebApp.CALL.STATE.TOGGLE, conversation_et.id, true
amplify.publish z.event.WebApp.CALL.STATE.TOGGLE, true, conversation_et
, 500

on_photo: (images) =>
Expand Down

0 comments on commit 430c33a

Please sign in to comment.