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 != "")):
return
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):
let args = chat_service.ChatArgs(e)
@ -217,7 +217,7 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_COMMUNITY_CATEGORY_CREATED) do(e:Args):
let args = CommunityCategoryArgs(e)
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):
let args = CommunityCategoryArgs(e)

View File

@ -111,7 +111,7 @@ method onChatMuted*(self: AccessInterface, chatId: string) {.base.} =
method onChatUnmuted*(self: AccessInterface, chatId: string) {.base.} =
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")
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.} =
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")
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)
proc addCategoryItem(self: Module, category: Category, amIAdmin: bool) =
let emptyChatItem = chat_item.initItem(
proc addCategoryItem(self: Module, category: Category, amIAdmin: bool, communityId: string) =
let hasUnreadMessages = self.controller.chatsWithCategoryHaveUnreadMessages(communityId, category.id)
let categoryItem = chat_item.initItem(
id = category.id,
category.name,
icon = "",
@ -174,7 +175,7 @@ proc addCategoryItem(self: Module, category: Category, amIAdmin: bool) =
`type` = chat_item.CATEGORY_TYPE,
amIAdmin,
lastMessageTimestamp = 0,
hasUnreadMessages = false,
hasUnreadMessages,
notificationsCount = 0,
muted = false,
blocked = false,
@ -183,7 +184,7 @@ proc addCategoryItem(self: Module, category: Category, amIAdmin: bool) =
category.id,
category.position,
)
self.view.chatsModel().appendItem(emptyChatItem)
self.view.chatsModel().appendItem(categoryItem)
proc buildChatSectionUI(
self: Module,
@ -202,7 +203,7 @@ proc buildChatSectionUI(
for categoryDto in channelGroup.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:
var categoryPosition = -1
@ -482,12 +483,17 @@ proc updateParentBadgeNotifications(self: Module) =
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))
self.view.chatsModel().updateNotificationsForItemById(chatId, hasUnreadMessages, unviewedMentionsCount)
# update child module
if (self.chatContentModules.contains(chatId)):
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
self.updateParentBadgeNotifications()
@ -648,12 +654,12 @@ method onCommunityCategoryEdited*(self: Module, cat: Category, chats: seq[ChatDt
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)):
return
# TODO get admin status
self.addCategoryItem(cat, false)
self.addCategoryItem(cat, false, communityId)
# Update chat items that now belong to that category
self.view.chatsModel().updateItemsWithCategoryDetailsById(
chats,
@ -827,15 +833,8 @@ method onJoinedCommunity*(self: Module) =
method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: string) =
self.controller.requestToJoinCommunityAuthenticated(password)
method updateUnreadMessagesAndMentions*(self: Module, chatId: string) =
let chatDetails = self.controller.getChatDetails(chatId)
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 onMarkAllMessagesRead*(self: Module, chat: ChatDto) =
self.updateBadgeNotifications(chat, hasUnreadMessages=false, unviewedMentionsCount=0)
method markAllMessagesRead*(self: Module, chatId: string) =
self.controller.markAllMessagesRead(chatId)
@ -1134,7 +1133,7 @@ proc addOrUpdateChat(self: Module,
var hasUnreadMessages = false
if not chat.muted:
hasUnreadMessages = chat.unviewedMessagesCount > 0
self.updateBadgeNotifications(chat.id, hasUnreadMessages, chat.unviewedMentionsCount)
self.updateBadgeNotifications(chat, hasUnreadMessages, chat.unviewedMentionsCount)
if not self.chatsLoaded:
return

View File

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