fix(category): fix category highlight calculation

Fixes #10313

There were a couple of small issues.
First, we didn't call the function to calculate the highlight on new messages.
Secondly, the calculation was bugged because the category wasn't saved correctly in the channelGroup update.
This commit is contained in:
Jonathan Rainville 2023-04-14 16:32:00 -04:00
parent ac9069aae6
commit 136635670e
4 changed files with 25 additions and 24 deletions

View File

@ -152,7 +152,7 @@ proc init*(self: Controller) =
(not self.isCommunitySection and chat.communityId != "")): (not self.isCommunitySection and chat.communityId != "")):
return return
self.chatService.updateUnreadMessagesAndMentions(args.chatId, args.allMessagesMarked, args.messagesCount, args.messagesWithMentionsCount) self.chatService.updateUnreadMessagesAndMentions(args.chatId, args.allMessagesMarked, args.messagesCount, args.messagesWithMentionsCount)
self.delegate.updateUnreadMessagesAndMentions(args.chatId) self.delegate.onMarkAllMessagesRead(chat)
self.events.on(chat_service.SIGNAL_CHAT_LEFT) do(e: Args): self.events.on(chat_service.SIGNAL_CHAT_LEFT) do(e: Args):
let args = chat_service.ChatArgs(e) let args = chat_service.ChatArgs(e)
@ -217,7 +217,7 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_COMMUNITY_CATEGORY_CREATED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_CATEGORY_CREATED) do(e:Args):
let args = CommunityCategoryArgs(e) let args = CommunityCategoryArgs(e)
if (args.communityId == self.sectionId): if (args.communityId == self.sectionId):
self.delegate.onCommunityCategoryCreated(args.category, args.chats) self.delegate.onCommunityCategoryCreated(args.category, args.chats, args.communityId)
self.events.on(SIGNAL_COMMUNITY_CATEGORY_DELETED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_CATEGORY_DELETED) do(e:Args):
let args = CommunityCategoryArgs(e) let args = CommunityCategoryArgs(e)

View File

@ -111,7 +111,7 @@ method onChatMuted*(self: AccessInterface, chatId: string) {.base.} =
method onChatUnmuted*(self: AccessInterface, chatId: string) {.base.} = method onChatUnmuted*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method updateUnreadMessagesAndMentions*(self: AccessInterface, chatId: string) {.base.} = method onMarkAllMessagesRead*(self: AccessInterface, chat: ChatDto) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method onContactAdded*(self: AccessInterface, publicKey: string) {.base.} = method onContactAdded*(self: AccessInterface, publicKey: string) {.base.} =
@ -147,7 +147,7 @@ method onReorderChat*(self: AccessInterface, chattId: string, position: int, new
method onReorderCategory*(self: AccessInterface, catId: string, position: int) {.base.} = method onReorderCategory*(self: AccessInterface, catId: string, position: int) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method onCommunityCategoryCreated*(self: AccessInterface, category: Category, chats: seq[ChatDto]) {.base.} = method onCommunityCategoryCreated*(self: AccessInterface, category: Category, chats: seq[ChatDto], communityId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method onCommunityCategoryDeleted*(self: AccessInterface, category: Category, chats: seq[ChatDto]) {.base.} = method onCommunityCategoryDeleted*(self: AccessInterface, category: Category, chats: seq[ChatDto]) {.base.} =

View File

@ -163,8 +163,9 @@ proc removeSubmodule(self: Module, chatId: string) =
self.chatContentModules.del(chatId) self.chatContentModules.del(chatId)
proc addCategoryItem(self: Module, category: Category, amIAdmin: bool) = proc addCategoryItem(self: Module, category: Category, amIAdmin: bool, communityId: string) =
let emptyChatItem = chat_item.initItem( let hasUnreadMessages = self.controller.chatsWithCategoryHaveUnreadMessages(communityId, category.id)
let categoryItem = chat_item.initItem(
id = category.id, id = category.id,
category.name, category.name,
icon = "", icon = "",
@ -174,7 +175,7 @@ proc addCategoryItem(self: Module, category: Category, amIAdmin: bool) =
`type` = chat_item.CATEGORY_TYPE, `type` = chat_item.CATEGORY_TYPE,
amIAdmin, amIAdmin,
lastMessageTimestamp = 0, lastMessageTimestamp = 0,
hasUnreadMessages = false, hasUnreadMessages,
notificationsCount = 0, notificationsCount = 0,
muted = false, muted = false,
blocked = false, blocked = false,
@ -183,7 +184,7 @@ proc addCategoryItem(self: Module, category: Category, amIAdmin: bool) =
category.id, category.id,
category.position, category.position,
) )
self.view.chatsModel().appendItem(emptyChatItem) self.view.chatsModel().appendItem(categoryItem)
proc buildChatSectionUI( proc buildChatSectionUI(
self: Module, self: Module,
@ -202,7 +203,7 @@ proc buildChatSectionUI(
for categoryDto in channelGroup.categories: for categoryDto in channelGroup.categories:
# Add items for the categories. We use a special type to identify categories # Add items for the categories. We use a special type to identify categories
self.addCategoryItem(categoryDto, channelGroup.admin) self.addCategoryItem(categoryDto, channelGroup.admin, channelGroup.id)
for chatDto in channelGroup.chats: for chatDto in channelGroup.chats:
var categoryPosition = -1 var categoryPosition = -1
@ -482,12 +483,17 @@ proc updateParentBadgeNotifications(self: Module) =
unviewedMentionsCount unviewedMentionsCount
) )
proc updateBadgeNotifications(self: Module, chatId: string, hasUnreadMessages: bool, unviewedMentionsCount: int) = proc updateBadgeNotifications(self: Module, chat: ChatDto, hasUnreadMessages: bool, unviewedMentionsCount: int) =
let chatId = chat.id
# update model of this module (appropriate chat from the chats list (chats model)) # update model of this module (appropriate chat from the chats list (chats model))
self.view.chatsModel().updateNotificationsForItemById(chatId, hasUnreadMessages, unviewedMentionsCount) self.view.chatsModel().updateNotificationsForItemById(chatId, hasUnreadMessages, unviewedMentionsCount)
# update child module # update child module
if (self.chatContentModules.contains(chatId)): if (self.chatContentModules.contains(chatId)):
self.chatContentModules[chatId].onNotificationsUpdated(hasUnreadMessages, unviewedMentionsCount) self.chatContentModules[chatId].onNotificationsUpdated(hasUnreadMessages, unviewedMentionsCount)
# Update category
if chat.categoryId != "":
let hasUnreadMessages = self.controller.chatsWithCategoryHaveUnreadMessages(chat.communityId, chat.categoryId)
self.view.chatsModel().setCategoryHasUnreadMessages(chat.categoryId, hasUnreadMessages)
# update parent module # update parent module
self.updateParentBadgeNotifications() self.updateParentBadgeNotifications()
@ -648,12 +654,12 @@ method onCommunityCategoryEdited*(self: Module, cat: Category, chats: seq[ChatDt
cat.position, cat.position,
) )
method onCommunityCategoryCreated*(self: Module, cat: Category, chats: seq[ChatDto]) = method onCommunityCategoryCreated*(self: Module, cat: Category, chats: seq[ChatDto], communityId: string) =
if (self.doesCatOrChatExist(cat.id)): if (self.doesCatOrChatExist(cat.id)):
return return
# TODO get admin status # TODO get admin status
self.addCategoryItem(cat, false) self.addCategoryItem(cat, false, communityId)
# Update chat items that now belong to that category # Update chat items that now belong to that category
self.view.chatsModel().updateItemsWithCategoryDetailsById( self.view.chatsModel().updateItemsWithCategoryDetailsById(
chats, chats,
@ -827,15 +833,8 @@ method onJoinedCommunity*(self: Module) =
method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: string) = method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: string) =
self.controller.requestToJoinCommunityAuthenticated(password) self.controller.requestToJoinCommunityAuthenticated(password)
method updateUnreadMessagesAndMentions*(self: Module, chatId: string) = method onMarkAllMessagesRead*(self: Module, chat: ChatDto) =
let chatDetails = self.controller.getChatDetails(chatId) self.updateBadgeNotifications(chat, hasUnreadMessages=false, unviewedMentionsCount=0)
self.updateBadgeNotifications(
chatId=chatId,
hasUnreadMessages=chatDetails.unviewedMessagesCount > 0,
unviewedMentionsCount=chatDetails.unviewedMentionsCount)
if chatDetails.categoryId != "":
let hasUnreadMessages = self.controller.chatsWithCategoryHaveUnreadMessages(chatDetails.communityId, chatDetails.categoryId)
self.view.chatsModel().setCategoryHasUnreadMessages(chatDetails.categoryId, hasUnreadMessages)
method markAllMessagesRead*(self: Module, chatId: string) = method markAllMessagesRead*(self: Module, chatId: string) =
self.controller.markAllMessagesRead(chatId) self.controller.markAllMessagesRead(chatId)
@ -1134,7 +1133,7 @@ proc addOrUpdateChat(self: Module,
var hasUnreadMessages = false var hasUnreadMessages = false
if not chat.muted: if not chat.muted:
hasUnreadMessages = chat.unviewedMessagesCount > 0 hasUnreadMessages = chat.unviewedMessagesCount > 0
self.updateBadgeNotifications(chat.id, hasUnreadMessages, chat.unviewedMentionsCount) self.updateBadgeNotifications(chat, hasUnreadMessages, chat.unviewedMentionsCount)
if not self.chatsLoaded: if not self.chatsLoaded:
return return

View File

@ -306,6 +306,8 @@ QtObject:
# status-go doesn't seem to preserve categoryIDs from chat # status-go doesn't seem to preserve categoryIDs from chat
# objects received via new messages. So we rely on what we # objects received via new messages. So we rely on what we
# have in memory. # have in memory.
if chat.id == "":
return
var categoryId = "" var categoryId = ""
if self.chats.hasKey(chat.id): if self.chats.hasKey(chat.id):
categoryId = self.chats[chat.id].categoryId categoryId = self.chats[chat.id].categoryId
@ -322,9 +324,9 @@ QtObject:
let index = self.getChatIndex(channelGroupId, chat.id) let index = self.getChatIndex(channelGroupId, chat.id)
if (index == -1): if (index == -1):
self.channelGroups[channelGroupId].chats.add(chat) self.channelGroups[channelGroupId].chats.add(self.chats[chat.id])
else: else:
self.channelGroups[channelGroupId].chats[index] = chat self.channelGroups[channelGroupId].chats[index] = self.chats[chat.id]
proc updateOrAddChannelGroup*(self: Service, channelGroup: ChannelGroupDto) = proc updateOrAddChannelGroup*(self: Service, channelGroup: ChannelGroupDto) =
self.channelGroups[channelGroup.id] = channelGroup self.channelGroups[channelGroup.id] = channelGroup