fix: chat reordering eventually not working

This commit is contained in:
Richard Ramos 2022-02-04 13:21:57 -04:00
parent 4cda8d8835
commit 04e1db6b56
3 changed files with 17 additions and 2 deletions

View File

@ -293,7 +293,7 @@ QtObject:
proc reorder*(self: Model, chatId, categoryId: string, position: int) = proc reorder*(self: Model, chatId, categoryId: string, position: int) =
let index = self.getItemIdxById(chatId) let index = self.getItemIdxById(chatId)
if(index == -1 or position == index): if(index == -1):
return return
let idx = self.createIndex(index, 0, nil) let idx = self.createIndex(index, 0, nil)

View File

@ -71,7 +71,8 @@ proc `$`*(self: ChatDto): string =
joined: {self.joined}, joined: {self.joined},
syncedTo: {self.syncedTo}, syncedTo: {self.syncedTo},
syncedFrom: {self.syncedFrom}, syncedFrom: {self.syncedFrom},
categoryId: {self.categoryId} categoryId: {self.categoryId},
position: {self.position}
)""" )"""
proc toChatMember(jsonObj: JsonNode): ChatMember = proc toChatMember(jsonObj: JsonNode): ChatMember =

View File

@ -543,6 +543,20 @@ QtObject:
if response.result.isNil or response.result.kind == JNull: if response.result.isNil or response.result.kind == JNull:
error "response is invalid", methodName="reorderCommunityChat" error "response is invalid", methodName="reorderCommunityChat"
if response.result != nil and response.result.kind != JNull:
let updatedCommunity = response.result["communities"][0].toCommunityDto()
for chat in updatedCommunity.chats:
let prev_chat_idx = findIndexById(chat.id, self.joinedCommunities[communityId].chats)
if prev_chat_idx > -1:
let fullChatId = communityId & chat.id
let prev_chat = self.joinedCommunities[communityId].chats[prev_chat_idx]
if(chat.position != prev_chat.position and chat.categoryId == categoryId):
var chatDetails = self.chatService.getChatById(fullChatId) # we are free to do this cause channel must be created before we add it to a category
self.joinedCommunities[communityId].chats[prev_chat_idx].position = chat.position
chatDetails.updateMissingFields(self.joinedCommunities[communityId].chats[prev_chat_idx])
self.chatService.updateOrAddChat(chatDetails) # we have to update chats stored in the chat service.
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: updatedCommunity.id, chatId: fullChatId, categoryId: chat.categoryId, position: chat.position))
except Exception as e: except Exception as e:
error "Error reordering community channel", msg = e.msg, communityId, chatId, position, methodName="reorderCommunityChat" error "Error reordering community channel", msg = e.msg, communityId, chatId, position, methodName="reorderCommunityChat"