issues adding category fixed

- chats list maintained in the chat service gets updated form the right places now
- redundant mapping `Chat` to `ChatDto` is removed, since we already get all
necessary data for the chat, no need for additional mapping which may just
introduce new inconsistencies
- `findIndexById` proc updated so in case if there is no the chat we're searching
for in the list, we're returning `-1` instead of last index in the list
- `DelegateChoice` on the qml side updated to match new type value `Constants.chatType.category`
This commit is contained in:
Sale Djenic 2022-01-28 13:05:17 +01:00
parent b67e97a05c
commit a05a821f51
5 changed files with 40 additions and 42 deletions

View File

@ -89,7 +89,6 @@ method init*(self: Controller) =
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args):
let args = CommunityChatArgs(e)
if (args.chat.communityId == self.sectionId):
self.chatService.updateOrAddChat(args.chat)
self.delegate.addNewChat(
args.chat,
true,
@ -110,17 +109,12 @@ method init*(self: Controller) =
self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args):
let args = CommunityChatArgs(e)
if (args.chat.communityId == self.sectionId):
self.chatService.updateOrAddChat(args.chat)
self.delegate.onCommunityChannelEdited(args.chat)
self.events.on(SIGNAL_COMMUNITY_CATEGORY_CREATED) do(e:Args):
let args = CommunityCategoryArgs(e)
if (args.communityId == self.sectionId):
var chats:seq[ChatDto] = @[]
for chat in args.chats:
self.chatService.updateOrAddChat(chat)
chats.add(chat)
self.delegate.onCommunityCategoryCreated(args.category, chats)
self.delegate.onCommunityCategoryCreated(args.category, args.chats)
self.events.on(SIGNAL_COMMUNITY_CHANNEL_REORDERED) do(e:Args):
let args = CommunityChatOrderArgs(e)

View File

@ -392,6 +392,11 @@ method onCommunityCategoryCreated*(self: Module, cat: Category, chats: seq[ChatD
let channelItem = initSubItem(chatDto.id, cat.id, chatDto.name, chatDto.identicon, false, chatDto.color,
chatDto.description, chatDto.chatType.int, true, hasNotification, notificationsCount, chatDto.muted,
false, chatDto.position)
# Important:
# Since we're just adding an already added community channel to a certain commuinity, there is no need to call
# `self.addSubmodule` here, since submodule (chat content module and modules beneath) were already added, so we're
# just updating the view from here, via model.
self.view.chatsModel().removeItemById(chatDto.id)
categoryChannels.add(channelItem)

View File

@ -112,19 +112,11 @@ QtObject:
self.joinedCommunities[membershipRequest.communityId] = community
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
proc mapChatToChatDto(chat: Chat, communityId: string): ChatDto =
result = ChatDto()
result.id = chat.id
result.communityId = communityId
result.name = chat.name
result.chatType = ChatType.CommunityChat
result.color = chat.color
result.emoji = chat.emoji
result.description = chat.description
result.canPost = chat.canPost
result.position = chat.position
result.categoryId = chat.categoryId
result.communityId = communityId
proc updateMissingFields(chatDto: var ChatDto, chat: Chat) =
# This proc sets fields of `chatDto` which are available only for comminity channels.
chatDto.position = chat.position
chatDto.canPost = chat.canPost
chatDto.categoryId = chat.categoryId
proc findChatById(id: string, chats: seq[ChatDto]): ChatDto =
for chat in chats:
@ -137,7 +129,7 @@ QtObject:
inc idx
if(chat.id == id):
return idx
return idx
return -1
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto]) =
let community = communities[0]
@ -153,13 +145,12 @@ QtObject:
if(community.chats.len > prev_community.chats.len):
for chat in community.chats:
if findIndexById(chat.id, prev_community.chats) == -1:
# update missing params
let updated_chat = findChatById(community.id&chat.id, updatedChats)
var chat_to_be_added = chat
chat_to_be_added.id = community.id&chat.id
chat_to_be_added.color = updated_chat.color
let chatFullId = community.id & chat.id
var createdChat = findChatById(chatFullId, updatedChats)
createdChat.updateMissingFields(chat)
self.chatService.updateOrAddChat(createdChat) # we have to update chats stored in the chat service.
let data = CommunityChatArgs(chat: mapChatToChatDto(chat_to_be_added, community.id))
let data = CommunityChatArgs(chat: createdChat)
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_CREATED, data)
# channel was removed
@ -187,14 +178,12 @@ QtObject:
# Handle name/description changes
if(chat.id == prev_chat.id and (chat.name != prev_chat.name or chat.description != prev_chat.description)):
# update missing params
let updated_chat = findChatById(community.id&chat.id, updatedChats)
var chat_to_be_edited = chat
chat_to_be_edited.id = community.id&chat.id
if(updated_chat.color != ""):
chat_to_be_edited.color = updated_chat.color
let data = CommunityChatArgs(chat: mapChatToChatDto(chat_to_be_edited, community.id))
let chatFullId = community.id & chat.id
var updatedChat = findChatById(chatFullId, updatedChats)
updatedChat.updateMissingFields(chat)
self.chatService.updateOrAddChat(updatedChat) # we have to update chats stored in the chat service.
let data = CommunityChatArgs(chat: updatedChat)
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, data)
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: communities))
@ -549,10 +538,12 @@ QtObject:
if idx > -1:
self.joinedCommunities[communityId].chats[idx].categoryId = v["CategoryModified"].getStr()
self.joinedCommunities[communityId].chats[idx].position = v["PositionModified"].getInt()
var c = mapChatToChatDto(self.joinedCommunities[communityId].chats[idx], communityId)
c.id = communityId & c.id
if c.categoryId != "":
chats.add(c)
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.
chats.add(chatDetails)
for k, v in response.result["communityChanges"].getElems()[0]["categoriesAdded"].pairs():
let category = v.toCategory()
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_CREATED,

View File

@ -149,7 +149,7 @@ Item {
id: delegateChooser
role: "type"
DelegateChoice { // In case of category
roleValue: Constants.chatType.unknown
roleValue: Constants.chatType.category
delegate: Repeater {
model: {
if (!subItems) {
@ -163,11 +163,15 @@ Item {
height: {
// dynamically calculate the height of the view, if the active one is the current one
// then set the height to parent otherwise set it to 0
if(!chatContentModule)
return 0
let myChatId = chatContentModule.getMyChatId()
if(myChatId === root.activeChatId || myChatId === root.activeSubItemId)
return parent.height
return 0
}
}
rootStore: root.rootStore
contactsStore: root.contactsStore
sendTransactionNoEnsModal: cmpSendTransactionNoEns
@ -188,9 +192,13 @@ Item {
height: {
// dynamically calculate the height of the view, if the active one is the current one
// then set the height to parent otherwise set it to 0
if(!chatContentModule)
return 0
let myChatId = chatContentModule.getMyChatId()
if(myChatId === root.activeChatId || myChatId === root.activeSubItemId)
return parent.height
return 0
}
rootStore: root.rootStore

View File

@ -394,7 +394,7 @@ ColumnLayout {
Loader {
id: loadingMessagesIndicator
active: messageStore.messageModule.loadingHistoryMessagesInProgress
active: messageStore.messageModule? messageStore.messageModule.loadingHistoryMessagesInProgress : false
sourceComponent: LoadingAnimation { }
anchors {
right: parent.right