From 2888ab3cb2232b29a131eecee4aaa17de0d50d95 Mon Sep 17 00:00:00 2001 From: odkhang Date: Mon, 22 Jul 2024 08:51:07 +0700 Subject: [PATCH 1/2] Fix Chat Room Bugs When Changing Rooms and in Direct Messages --- server/venueless/live/modules/chat.py | 14 +++++++++++++- webapp/src/store/chat.js | 18 ++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/server/venueless/live/modules/chat.py b/server/venueless/live/modules/chat.py index 964ec861..46192a50 100644 --- a/server/venueless/live/modules/chat.py +++ b/server/venueless/live/modules/chat.py @@ -349,6 +349,18 @@ async def publish_unread_pointers(self, body): @event("notification") async def publish_notification(self, body): + event_id = body.get("data", {}).get("event", {}).get("event_id") + if event_id: + async with aredis() as redis: + read_pointer = await redis.hget(f"chat:read:{self.consumer.user.id}", body["data"]["event"]["channel"]) + read_pointer = int(read_pointer.decode()) if read_pointer else 0 + if read_pointer >= event_id: + if await self.service.remove_notifications(self.consumer.user.id, self.channel_id, read_pointer): + notification_counts = await database_sync_to_async( + self.service.get_notification_counts + )(self.consumer.user.id) + await self.consumer.send_json(["chat.notification_counts", notification_counts]) + return await self.consumer.send_json(["chat.notification", body.get("data")]) @command("send") @@ -638,7 +650,7 @@ async def publish_event(self, body): user_profiles_required |= extract_mentioned_user_ids( data["content"].get("body", "") ) - + user_profiles_required -= self.users_known_to_client data["users"] = {} diff --git a/webapp/src/store/chat.js b/webapp/src/store/chat.js index 71457ce4..41a61482 100644 --- a/webapp/src/store/chat.js +++ b/webapp/src/store/chat.js @@ -51,8 +51,8 @@ export default { }, channelName (state, getters, rootState) { return function (channel) { - if (this.isDirectMessageChannel(channel)) { - return this.directMessageChannelName(channel) + if (getters.isDirectMessageChannel(channel)) { + return getters.directMessageChannelName(channel) } else { return rootState.rooms.find(room => room.modules.some(m => m.channel_id === channel.id)).name } @@ -90,6 +90,7 @@ export default { state.usersLookup = members.reduce((acc, member) => { acc[member.id] = member; return acc }, {}) state.timeline = [] state.warnings = [] + state.fetchingMessages = null state.beforeCursor = beforeCursor state.config = config if (getters.activeJoinedChannel) { @@ -352,10 +353,19 @@ export default { }, async 'api::chat.notification' ({state, rootState, getters, dispatch}, data) { const channelId = data.event.channel - const channel = state.joinedChannels.find(c => c.id === channelId) || getters.automaticallyJoinedChannels.includes(channelId) ? {id: channelId} : null + const channel = state.joinedChannels.find(c => c.id === channelId) || (getters.automaticallyJoinedChannels.includes(channelId) ? {id: channelId} : null) + const eventId = data.event.event_id if (!channel) return // Increment notification count Vue.set(state.notificationCounts, channel.id, (state.notificationCounts[channel.id] || 0) + 1) + if (eventId > state.readPointers[channelId] && channelId === state.channel) { + // In volatile channels, markChannelRead does not advance the readPointer and does not send mark_read, unless + // notificationCounts is non-zero. + // However, if we receive a notification for the channel that is currently open, we do need to trigger a + // *after* we increased notificationCounts to make sure that other connected clients know that the notification + // has been read. + dispatch('markChannelRead') + } // TODO show desktop notification when window in focus but route is somewhere else? let body = i18n.t('DirectMessage:notification-unread:text') if (data.event.content.type === 'text') { @@ -393,4 +403,4 @@ export default { state.warnings.push(data) } } -} +} \ No newline at end of file From 7013839248336eb94e114ae5805dd5dd7b31a083 Mon Sep 17 00:00:00 2001 From: lcduong Date: Mon, 22 Jul 2024 15:34:08 +0700 Subject: [PATCH 2/2] remove unused comment, add line eof --- webapp/src/store/chat.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/webapp/src/store/chat.js b/webapp/src/store/chat.js index 41a61482..171e8e1d 100644 --- a/webapp/src/store/chat.js +++ b/webapp/src/store/chat.js @@ -359,11 +359,6 @@ export default { // Increment notification count Vue.set(state.notificationCounts, channel.id, (state.notificationCounts[channel.id] || 0) + 1) if (eventId > state.readPointers[channelId] && channelId === state.channel) { - // In volatile channels, markChannelRead does not advance the readPointer and does not send mark_read, unless - // notificationCounts is non-zero. - // However, if we receive a notification for the channel that is currently open, we do need to trigger a - // *after* we increased notificationCounts to make sure that other connected clients know that the notification - // has been read. dispatch('markChannelRead') } // TODO show desktop notification when window in focus but route is somewhere else? @@ -403,4 +398,4 @@ export default { state.warnings.push(data) } } -} \ No newline at end of file +}