Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only display unread notification once in call
Only show one notification for unread messages, either for new messages
or for mentions.
When switching from "new messages" to "you have been mentionned",
discard the former notification.

Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 committed Jun 17, 2021
commit 9500c646a73977a88ee0a9a8334fcedb80cba4e1
33 changes: 28 additions & 5 deletions src/components/TopBar/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ export default {
},
},

data: () => {
return {
unreadNotificationHandle: null,
}
},

computed: {
isFullscreen() {
return this.$store.getters.isFullscreen()
Expand Down Expand Up @@ -319,8 +325,8 @@ export default {
}

// new messages arrived
if (newValue > 0 && oldValue === 0) {
showMessage(t('spreed', 'You have new unread messages in the chat.'))
if (newValue > 0 && oldValue === 0 && !this.hasUnreadMentions) {
this.notifyUnreadMessages(t('spreed', 'You have new unread messages in the chat.'))
}
},

Expand All @@ -329,9 +335,15 @@ export default {
return
}

// prevent duplicate notification caused by unreadMessagesCounter in case of mention
if (newValue && this.unreadMessagesCounter > 0) {
showMessage(t('spreed', 'You have been mentioned in the chat.'))
if (newValue) {
this.notifyUnreadMessages(t('spreed', 'You have been mentioned in the chat.'))
}
},

isInCall(newValue) {
if (!newValue) {
// discard notification if the call ends
this.notifyUnreadMessages(null)
}
},
},
Expand All @@ -344,13 +356,24 @@ export default {
},

beforeDestroy() {
this.notifyUnreadMessages(null)
document.removeEventListener('fullscreenchange', this.fullScreenChanged, false)
document.removeEventListener('mozfullscreenchange', this.fullScreenChanged, false)
document.removeEventListener('MSFullscreenChange', this.fullScreenChanged, false)
document.removeEventListener('webkitfullscreenchange', this.fullScreenChanged, false)
},

methods: {
notifyUnreadMessages(message) {
if (this.unreadNotificationHandle) {
this.unreadNotificationHandle.hideToast()
this.unreadNotificationHandle = null
}
if (message) {
this.unreadNotificationHandle = showMessage(message)
}
},

openSidebar() {
this.$store.dispatch('showSidebar')
BrowserStorage.setItem('sidebarOpen', 'true')
Expand Down