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..171e8e1d 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,14 @@ 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) { + 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') {