From ed69eacbe7b03ca6dcddea1520639a98f596eb76 Mon Sep 17 00:00:00 2001 From: Anurag Shivarathri Date: Wed, 4 Jan 2023 03:30:23 +0530 Subject: [PATCH] Count fix (#6926) --- app/database/models/server/my_channel.ts | 1 + app/queries/servers/channel.ts | 1 + app/screens/home/channel_list/servers/index.tsx | 2 +- .../servers/servers_list/server_item/server_item.tsx | 2 +- app/screens/home/tab_bar/home.tsx | 2 +- ios/Gekidou/Sources/Gekidou/Storage/Database+Mentions.swift | 3 ++- 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/database/models/server/my_channel.ts b/app/database/models/server/my_channel.ts index 21ad87db9c..ea01dfa3c2 100644 --- a/app/database/models/server/my_channel.ts +++ b/app/database/models/server/my_channel.ts @@ -23,6 +23,7 @@ export default class MyChannelModel extends Model implements MyChannelModelInter static associations: Associations = { [CHANNEL]: {type: 'belongs_to', key: 'id'}, [CATEGORY_CHANNEL]: {type: 'has_many', foreignKey: 'channel_id'}, + [MY_CHANNEL_SETTINGS]: {type: 'has_many', foreignKey: 'id'}, }; /** last_post_at : The timestamp for any last post on this channel */ diff --git a/app/queries/servers/channel.ts b/app/queries/servers/channel.ts index a10f5e689d..12e332dc68 100644 --- a/app/queries/servers/channel.ts +++ b/app/queries/servers/channel.ts @@ -465,6 +465,7 @@ export function observeMyChannelMentionCount(database: Database, teamId?: string Q.on(CHANNEL, Q.and( ...conditions, )), + Q.on(MY_CHANNEL_SETTINGS, Q.where('notify_props', Q.notLike('%"mark_unread":"mention"%'))), ). observeWithColumns(columns). pipe( diff --git a/app/screens/home/channel_list/servers/index.tsx b/app/screens/home/channel_list/servers/index.tsx index 6712fddd46..2a29d3ff53 100644 --- a/app/screens/home/channel_list/servers/index.tsx +++ b/app/screens/home/channel_list/servers/index.tsx @@ -63,7 +63,7 @@ const Servers = React.forwardRef((props, ref) => { let unread = Boolean(threadUnreads); for (const myChannel of myChannels) { const isMuted = settings?.[myChannel.id]?.mark_unread === 'mention'; - mentions += myChannel.mentionsCount; + mentions += isMuted ? 0 : myChannel.mentionsCount; unread = unread || (myChannel.isUnread && !isMuted); } diff --git a/app/screens/home/channel_list/servers/servers_list/server_item/server_item.tsx b/app/screens/home/channel_list/servers/servers_list/server_item/server_item.tsx index 30139a6f6c..687a0fe364 100644 --- a/app/screens/home/channel_list/servers/servers_list/server_item/server_item.tsx +++ b/app/screens/home/channel_list/servers/servers_list/server_item/server_item.tsx @@ -171,7 +171,7 @@ const ServerItem = ({ let isUnread = Boolean(threadUnreads); for (const myChannel of myChannels) { const isMuted = settings?.[myChannel.id]?.mark_unread === 'mention'; - mentions += myChannel.mentionsCount; + mentions += isMuted ? 0 : myChannel.mentionsCount; isUnread = isUnread || (myChannel.isUnread && !isMuted); } mentions += threadMentionCount; diff --git a/app/screens/home/tab_bar/home.tsx b/app/screens/home/tab_bar/home.tsx index c029a53e46..5ba2e5c506 100644 --- a/app/screens/home/tab_bar/home.tsx +++ b/app/screens/home/tab_bar/home.tsx @@ -71,7 +71,7 @@ const Home = ({isFocused, theme}: Props) => { let unread = false; for (const myChannel of myChannels) { const isMuted = settings?.[myChannel.id]?.mark_unread === 'mention'; - mentions += myChannel.mentionsCount; + mentions += isMuted ? 0 : myChannel.mentionsCount; unread = unread || (myChannel.isUnread && !isMuted); } diff --git a/ios/Gekidou/Sources/Gekidou/Storage/Database+Mentions.swift b/ios/Gekidou/Sources/Gekidou/Storage/Database+Mentions.swift index 1b5cd500c1..dc77d6b6f9 100644 --- a/ios/Gekidou/Sources/Gekidou/Storage/Database+Mentions.swift +++ b/ios/Gekidou/Sources/Gekidou/Storage/Database+Mentions.swift @@ -38,8 +38,9 @@ extension Database { let stmtString = """ SELECT SUM(my.mentions_count) \ FROM MyChannel my \ + INNER JOIN MyChannelSettings mys ON mys.id=my.id \ INNER JOIN Channel c ON c.id=my.id \ - WHERE c.delete_at = 0 + WHERE c.delete_at = 0 AND mys.notify_props NOT LIKE '%"mark_unread":"mention"%' """ let mentions = try? db.prepare(stmtString).scalar() as? Double return Int(mentions ?? 0)