21
21
<script>
22
22
import debounce from 'debounce'
23
23
import { provide } from 'vue'
24
+ import { mapGetters } from 'vuex'
24
25
25
26
import { getCurrentUser } from '@nextcloud/auth'
26
27
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
@@ -44,7 +45,7 @@ import { useDocumentTitle } from './composables/useDocumentTitle.ts'
44
45
import { useHashCheck } from './composables/useHashCheck.js'
45
46
import { useIsInCall } from './composables/useIsInCall.js'
46
47
import { useSessionIssueHandler } from './composables/useSessionIssueHandler.js'
47
- import { CONVERSATION, PARTICIPANT } from './constants.ts'
48
+ import { CONVERSATION, EVENTS, PARTICIPANT } from './constants.ts'
48
49
import Router from './router/router.ts'
49
50
import BrowserStorage from './services/BrowserStorage.js'
50
51
import { EventBus } from './services/EventBus.ts'
@@ -95,6 +96,30 @@ export default {
95
96
},
96
97
97
98
computed: {
99
+ // Computed properties for unread counts
100
+ getTotalUnreadMessages() {
101
+ if (!this.$store.state.conversationsStore?.conversations) {
102
+ return 0;
103
+ }
104
+ return Object.values(this.$store.state.conversationsStore.conversations).reduce((total, conv) => {
105
+ return total + (conv.unreadMessages || 0);
106
+ }, 0);
107
+ },
108
+
109
+ getTotalUnreadMentions() {
110
+ if (!this.$store.state.conversationsStore?.conversations) {
111
+ return 0;
112
+ }
113
+ return Object.values(this.$store.state.conversationsStore.conversations).filter(conv => conv.unreadMention).length;
114
+ },
115
+
116
+ getTotalUnreadMentionsDirect() {
117
+ if (!this.$store.state.conversationsStore?.conversations) {
118
+ return 0;
119
+ }
120
+ return Object.values(this.$store.state.conversationsStore.conversations).filter(conv => conv.unreadMentionDirect).length;
121
+ },
122
+
98
123
getUserId() {
99
124
return this.$store.getters.getUserId()
100
125
},
@@ -163,6 +188,17 @@ export default {
163
188
}
164
189
}
165
190
},
191
+
192
+ // Watch for changes in unread counters and emit events
193
+ getTotalUnreadMessages() {
194
+ this.emitUnreadCountUpdated()
195
+ },
196
+ getTotalUnreadMentions() {
197
+ this.emitUnreadCountUpdated()
198
+ },
199
+ getTotalUnreadMentionsDirect() {
200
+ this.emitUnreadCountUpdated()
201
+ },
166
202
},
167
203
168
204
beforeCreate() {
@@ -314,6 +350,9 @@ export default {
314
350
this.$store.dispatch('updateToken', '')
315
351
}
316
352
}
353
+
354
+ // Update unread counts after receiving conversations
355
+ this.emitUnreadCountUpdated()
317
356
})
318
357
319
358
EventBus.on('forbidden-route', (params) => {
@@ -409,6 +448,9 @@ export default {
409
448
})
410
449
}
411
450
451
+ // Initialize unread counts emission
452
+ this.emitUnreadCountUpdated()
453
+
412
454
subscribe('notifications:action:execute', this.interceptNotificationActions)
413
455
subscribe('notifications:notification:received', this.interceptNotificationReceived)
414
456
},
@@ -619,6 +661,19 @@ export default {
619
661
this.$router.push({ name: 'root' })
620
662
}
621
663
},
664
+
665
+ /**
666
+ * Emits the UNREAD_COUNT_UPDATED event with the current counter values
667
+ */
668
+ emitUnreadCountUpdated() {
669
+ const eventData = {
670
+ totalUnreadMessages: this.getTotalUnreadMessages,
671
+ totalUnreadMentions: this.getTotalUnreadMentions,
672
+ totalUnreadMentionsDirect: this.getTotalUnreadMentionsDirect
673
+ }
674
+
675
+ emit(EVENTS.UNREAD_COUNT_UPDATED, eventData)
676
+ },
622
677
},
623
678
}
624
679
</script>
0 commit comments