Skip to content

Commit

Permalink
Merge pull request #6509 from nextcloud/backport/6507/stable23
Browse files Browse the repository at this point in the history
[stable23] Overwrite hasCall based on chat messages
  • Loading branch information
nickvergessen committed Nov 16, 2021
2 parents d1af05d + 947c92e commit 867ec3c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
11 changes: 3 additions & 8 deletions lib/Activity/Listener.php
Expand Up @@ -133,15 +133,10 @@ public function generateCallActivity(Room $room, bool $endForEveryone = false, ?
$numGuests = $this->participantService->getGuestCount($room, $activeSince);

$message = 'call_ended';
if ((\count($userIds) + $numGuests) === 1) {
if ($room->getType() !== Room::TYPE_ONE_TO_ONE) {
// Single user pinged or guests only => no summary/activity
$room->resetActiveSince();
return false;
}
$message = 'call_missed';
} elseif ($endForEveryone) {
if ($endForEveryone) {
$message = 'call_ended_everyone';
} elseif ($room->getType() === Room::TYPE_ONE_TO_ONE) {
$message = 'call_missed';
}

if (!$room->resetActiveSince()) {
Expand Down
16 changes: 10 additions & 6 deletions src/components/TopBar/CallButton.vue
Expand Up @@ -155,9 +155,13 @@ export default {
|| this.participantType === PARTICIPANT.TYPE.GUEST_MODERATOR)
},
hasCall() {
return this.conversation.hasCall || this.conversation.hasCallOverwrittenByChat
},
startCallButtonDisabled() {
return (!this.conversation.canStartCall
&& !this.conversation.hasCall)
&& !this.hasCall)
|| this.isInLobby
|| this.conversation.readOnly
|| this.isNextcloudTalkHashDirty
Expand All @@ -177,7 +181,7 @@ export default {
},
startCallLabel() {
if (this.conversation.hasCall && !this.isInLobby) {
if (this.hasCall && !this.isInLobby) {
return t('spreed', 'Join call')
}
Expand All @@ -193,7 +197,7 @@ export default {
return this.callButtonTooltipText
}
if (!this.conversation.canStartCall && !this.conversation.hasCall) {
if (!this.conversation.canStartCall && !this.hasCall) {
return t('spreed', 'You will be able to join the call only after a moderator starts it.')
}
Expand All @@ -205,7 +209,7 @@ export default {
return 'icon-loading-small'
}
if (this.conversation.hasCall && !this.isInLobby) {
if (this.hasCall && !this.isInLobby) {
return 'icon-incoming-call'
}
Expand All @@ -214,8 +218,8 @@ export default {
startCallButtonClasses() {
return {
primary: !this.conversation.hasCall && !this.isInLobby,
success: this.conversation.hasCall && !this.isInLobby,
primary: !this.hasCall && !this.isInLobby,
success: this.hasCall && !this.isInLobby,
}
},
Expand Down
12 changes: 12 additions & 0 deletions src/store/conversationsStore.js
Expand Up @@ -136,6 +136,14 @@ const mutations = {
}
},

overwriteHasCallByChat(state, { token, hasCall }) {
if (hasCall) {
Vue.set(state.conversations[token], 'hasCallOverwrittenByChat', hasCall)
} else {
Vue.delete(state.conversations[token], 'hasCallOverwrittenByChat')
}
},

setNotificationLevel(state, { token, notificationLevel }) {
Vue.set(state.conversations[token], 'notificationLevel', notificationLevel)
},
Expand Down Expand Up @@ -415,6 +423,10 @@ const actions = {
commit('updateConversationLastReadMessage', { token, lastReadMessage })
},

async overwriteHasCallByChat({ commit }, { token, hasCall }) {
commit('overwriteHasCallByChat', { token, hasCall })
},

async fetchConversation({ dispatch }, { token }) {
try {
dispatch('clearMaintenanceMode')
Expand Down
18 changes: 18 additions & 0 deletions src/store/messagesStore.js
Expand Up @@ -722,6 +722,24 @@ const actions = {
lastMessage = message
}

// Overwrite the conversation.hasCall property so people can join
// after seeing the message in the chat.
if (conversation && conversation.lastMessage && message.id > conversation.lastMessage.id) {
if (message.systemMessage === 'call_started') {
context.dispatch('overwriteHasCallByChat', {
token,
hasCall: true,
})
} else if (message.systemMessage === 'call_ended'
|| message.systemMessage === 'call_ended_everyone'
|| message.systemMessage === 'call_missed') {
context.dispatch('overwriteHasCallByChat', {
token,
hasCall: false,
})
}
}

// in case we encounter an already read message, reset the counter
// this is probably unlikely to happen unless one starts browsing from
// an earlier page and scrolls down
Expand Down

0 comments on commit 867ec3c

Please sign in to comment.