@@ -261,7 +261,9 @@ import {
261261 searchListedConversations ,
262262} from ' ../../services/conversationsService.js'
263263import { EventBus } from ' ../../services/EventBus.js'
264+ import { talkBroadcastChannel } from ' ../../services/talkBroadcastChannel.js'
264265import CancelableRequest from ' ../../utils/cancelableRequest.js'
266+ import { requestTabLeadership } from ' ../../utils/requestTabLeadership.js'
265267
266268export default {
267269
@@ -331,6 +333,8 @@ export default {
331333 preventFindingUnread: false ,
332334 roomListModifiedBefore: 0 ,
333335 forceFullRoomListRefreshAfterXLoops: 0 ,
336+ isFetchingConversations: false ,
337+ isCurrentTabLeader: false ,
334338 isFocused: false ,
335339 isFiltered: null ,
336340 }
@@ -414,17 +418,32 @@ export default {
414418 // before updated ones come from server
415419 this .restoreConversations ()
416420
417- this .fetchConversations ()
418- },
419-
420- mounted () {
421- // Refreshes the conversations every 30 seconds
422- this .refreshTimer = window .setInterval (() => {
423- if (! this .isFetchingConversations ) {
421+ requestTabLeadership ().then (() => {
422+ this .isCurrentTabLeader = true
423+ this .fetchConversations ()
424+ // Refreshes the conversations list every 30 seconds
425+ this .refreshTimer = window .setInterval (() => {
424426 this .fetchConversations ()
427+ }, 30000 )
428+ })
429+
430+ talkBroadcastChannel .addEventListener (' message' , (event ) => {
431+ if (this .isCurrentTabLeader ) {
432+ switch (event .data .message ) {
433+ case ' talk:reset-modified-before-count' : {
434+ this .roomListModifiedBefore = 0
435+ this .debounceFetchConversations ()
436+ break
437+ }
438+ default : {
439+ break
440+ }
441+ }
425442 }
426- }, 30000 )
443+ })
444+ },
427445
446+ mounted () {
428447 EventBus .$on (' should-refresh-conversations' , this .handleShouldRefreshConversations )
429448 EventBus .$once (' conversations-received' , this .handleUnreadMention )
430449 EventBus .$on (' route-change' , this .onRouteChange )
@@ -622,7 +641,13 @@ export default {
622641 */
623642 async handleShouldRefreshConversations (options ) {
624643 if (options? .all === true ) {
625- this .roomListModifiedBefore = 0
644+ if (this .isCurrentTabLeader ) {
645+ this .roomListModifiedBefore = 0
646+ } else {
647+ // Force leader tab to do a full fetch
648+ talkBroadcastChannel .postMessage ({ message: ' talk:reset-modified-before-count' })
649+ return
650+ }
626651 } else if (options? .token && options? .properties ) {
627652 await this .$store .dispatch (' setConversationProperties' , {
628653 token: options .token ,
0 commit comments