fix(@community): List channel/Add channel/Remove channel from category

fixes #5801
This commit is contained in:
Anthony Laibe 2022-05-18 10:31:15 +02:00 committed by Anthony Laibe
parent 8c496e0505
commit ddb884fc37
4 changed files with 10 additions and 13 deletions

View File

@ -213,9 +213,8 @@ proc getCategories*(self: Controller, communityId: string): seq[Category] =
proc getChats*(self: Controller, communityId: string, categoryId: string): seq[ChatDto] =
return self.communityService.getChats(communityId, categoryId)
proc getChatDetails*(self: Controller, communityId, chatId: string): ChatDto =
let fullId = communityId & chatId
return self.chatService.getChatById(fullId)
proc getChatDetails*(self: Controller, chatId: string): ChatDto =
return self.chatService.getChatById(chatId)
proc getChatDetailsForChatTypes*(self: Controller, types: seq[ChatType]): seq[ChatDto] =
return self.chatService.getChatsOfChatTypes(types)

View File

@ -477,7 +477,7 @@ method onCommunityCategoryDeleted*(self: Module, cat: Category) =
for c in chats:
if (c.categoryId != cat.id or self.doesTopLevelChatExist(self.controller.getMySectionId() & c.id)):
continue
let chatDto = self.controller.getChatDetails(self.controller.getMySectionId(), c.id)
let chatDto = self.controller.getChatDetails(c.id)
let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0
let notificationsCount = chatDto.unviewedMentionsCount
let amIChatAdmin = self.controller.getMyCommunity().admin
@ -744,15 +744,14 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) =
let communityId = self.controller.getMySectionId()
let chats = self.controller.getChats(communityId, "")
for chat in chats:
let c = self.controller.getChatDetails(communityId, chat.id)
let c = self.controller.getChatDetails(chat.id)
let item = initItem(c.id, c.name, icon="", c.color, c.emoji, c.description,
c.chatType.int, amIChatAdmin=false, hasUnreadMessages=false, notificationsCount=0, c.muted,
blocked=false, active=false, c.position, categoryId="")
self.view.editCategoryChannelsModel().appendItem(item)
let catChats = self.controller.getChats(communityId, categoryId)
for chat in catChats:
let c = self.controller.getChatDetails(communityId, chat.id)
let c = self.controller.getChatDetails(chat.id)
let item = initItem(c.id, c.name, icon="", c.color, c.emoji, c.description,
c.chatType.int, amIChatAdmin=false, hasUnreadMessages=false, notificationsCount=0, c.muted,
blocked=false, active=false, c.position, categoryId)

View File

@ -236,7 +236,7 @@ QtObject:
if (showWarning):
warn "trying to get chat data for an unexisting chat id", chatId
return
return self.chats[chatId]
proc getOneToOneChatNameAndImage*(self: Service, chatId: string):

View File

@ -740,7 +740,6 @@ QtObject:
channels: seq[string]) =
try:
let response = status_go.createCommunityCategory(communityId, name, channels)
if response.error != nil:
let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "Error creating community category: " & error.message)
@ -748,12 +747,12 @@ QtObject:
if response.result != nil and response.result.kind != JNull:
var chats: seq[ChatDto] = @[]
for chatId, v in response.result["communityChanges"].getElems()[0]["chatsModified"].pairs():
let idx = findIndexById(chatId, self.joinedCommunities[communityId].chats)
let fullChatId = communityId & chatId
let idx = findIndexById(fullChatId, self.joinedCommunities[communityId].chats)
if idx > -1:
self.joinedCommunities[communityId].chats[idx].categoryId = v["CategoryModified"].getStr()
self.joinedCommunities[communityId].chats[idx].position = v["PositionModified"].getInt()
if self.joinedCommunities[communityId].chats[idx].categoryId.len > 0:
let fullChatId = communityId & chatId
var chatDetails = self.chatService.getChatById(fullChatId) # we are free to do this cause channel must be created before we add it to a category
chatDetails.updateMissingFields(self.joinedCommunities[communityId].chats[idx])
self.chatService.updateOrAddChat(chatDetails) # we have to update chats stored in the chat service.
@ -781,12 +780,12 @@ QtObject:
if response.result != nil and response.result.kind != JNull:
var chats: seq[ChatDto] = @[]
for chatId, v in response.result["communityChanges"].getElems()[0]["chatsModified"].pairs():
let idx = findIndexById(chatId, self.joinedCommunities[communityId].chats)
let fullChatId = communityId & chatId
let idx = findIndexById(fullChatId, self.joinedCommunities[communityId].chats)
if idx > -1:
self.joinedCommunities[communityId].chats[idx].categoryId = v["CategoryModified"].getStr()
self.joinedCommunities[communityId].chats[idx].position = v["PositionModified"].getInt()
let fullChatId = communityId & chatId
var chatDetails = self.chatService.getChatById(fullChatId) # we are free to do this cause channel must be created before we add it to a category
chatDetails.updateMissingFields(self.joinedCommunities[communityId].chats[idx])
self.chatService.updateOrAddChat(chatDetails) # we have to update chats stored in the chat service.