fix(@desktop/chat-content): [base_bc] can't select a community channel

Fixes #4538
This commit is contained in:
Sale Djenic 2022-01-25 19:39:41 +01:00
parent 15793b2a35
commit 7421967d96
5 changed files with 38 additions and 72 deletions

View File

@ -115,7 +115,7 @@ method init*(self: Controller) =
self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args):
let args = CommunityChatArgs(e) let args = CommunityChatArgs(e)
if(args.communityId != self.sectionId or self.chatId != args.chat.id or not self.belongsToCommunity): if(args.chat.communityId != self.sectionId or args.chat.id != self.chatId):
return return
self.delegate.onChatEdited(args.chat) self.delegate.onChatEdited(args.chat)

View File

@ -11,3 +11,6 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} = method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method updateChatIdentifier*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -35,8 +35,5 @@ method updateContactDetails*(self: AccessInterface, contactId: string) {.base.}
method onMessageEdited*(self: AccessInterface, message: MessageDto) {.base.} = method onMessageEdited*(self: AccessInterface, message: MessageDto) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method updateChatIdentifier*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method setLoadingHistoryMessagesInProgress*(self: AccessInterface, isLoading: bool) {.base.} = method setLoadingHistoryMessagesInProgress*(self: AccessInterface, isLoading: bool) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -88,7 +88,7 @@ method init*(self: Controller) =
if (self.isCommunitySection): if (self.isCommunitySection):
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args):
let args = CommunityChatArgs(e) let args = CommunityChatArgs(e)
if (args.communityId == self.sectionId): if (args.chat.communityId == self.sectionId):
self.chatService.updateOrAddChat(args.chat) self.chatService.updateOrAddChat(args.chat)
self.delegate.addNewChat( self.delegate.addNewChat(
args.chat, args.chat,
@ -109,7 +109,7 @@ method init*(self: Controller) =
self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args):
let args = CommunityChatArgs(e) let args = CommunityChatArgs(e)
if (args.communityId == self.sectionId): if (args.chat.communityId == self.sectionId):
self.chatService.updateOrAddChat(args.chat) self.chatService.updateOrAddChat(args.chat)
self.delegate.onCommunityChannelEdited(args.chat) self.delegate.onCommunityChannelEdited(args.chat)

View File

@ -22,7 +22,6 @@ type
communities*: seq[CommunityDto] communities*: seq[CommunityDto]
CommunityChatArgs* = ref object of Args CommunityChatArgs* = ref object of Args
communityId*: string
chat*: ChatDto chat*: ChatDto
CommunityIdArgs* = ref object of Args CommunityIdArgs* = ref object of Args
@ -100,13 +99,9 @@ QtObject:
# Handling community updates # Handling community updates
if (receivedData.communities.len > 0): if (receivedData.communities.len > 0):
# Channel added removed is notified in the chats param # Channel added removed is notified in the chats param
if (receivedData.chats.len > 0):
self.handleCommunityUpdates(receivedData.communities, receivedData.chats) self.handleCommunityUpdates(receivedData.communities, receivedData.chats)
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: receivedData.communities)) # Handling membership requests
self.events.on(SignalType.Message.event) do(e:Args):
var receivedData = MessageSignal(e)
if(receivedData.membershipRequests.len > 0): if(receivedData.membershipRequests.len > 0):
for membershipRequest in receivedData.membershipRequests: for membershipRequest in receivedData.membershipRequests:
if (not self.joinedCommunities.contains(membershipRequest.communityId)): if (not self.joinedCommunities.contains(membershipRequest.communityId)):
@ -120,6 +115,7 @@ QtObject:
proc mapChatToChatDto(chat: Chat, communityId: string): ChatDto = proc mapChatToChatDto(chat: Chat, communityId: string): ChatDto =
result = ChatDto() result = ChatDto()
result.id = chat.id result.id = chat.id
result.communityId = communityId
result.name = chat.name result.name = chat.name
result.chatType = ChatType.CommunityChat result.chatType = ChatType.CommunityChat
result.color = chat.color result.color = chat.color
@ -149,6 +145,7 @@ QtObject:
return return
let prev_community = self.joinedCommunities[community.id] let prev_community = self.joinedCommunities[community.id]
self.joinedCommunities[community.id] = community
# channel was added # channel was added
if(community.chats.len > prev_community.chats.len): if(community.chats.len > prev_community.chats.len):
@ -160,22 +157,21 @@ QtObject:
chat_to_be_added.id = community.id&chat.id chat_to_be_added.id = community.id&chat.id
chat_to_be_added.color = updated_chat.color chat_to_be_added.color = updated_chat.color
self.events.emit( let data = CommunityChatArgs(chat: mapChatToChatDto(chat_to_be_added, community.id))
SIGNAL_COMMUNITY_CHANNEL_CREATED, self.events.emit(SIGNAL_COMMUNITY_CHANNEL_CREATED, data)
CommunityChatArgs(communityId: community.id, chat: mapChatToChatDto(chat_to_be_added, community.id)))
# channel was removed # channel was removed
elif(community.chats.len < prev_community.chats.len): elif(community.chats.len < prev_community.chats.len):
for prv_chat in prev_community.chats: for prv_chat in prev_community.chats:
if findIndexById(prv_chat.id, community.chats) == -1: if findIndexById(prv_chat.id, community.chats) == -1:
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_DELETED, CommunityChatIdArgs(communityId: community.id, chatId: community.id&prv_chat.id)) self.events.emit(SIGNAL_COMMUNITY_CHANNEL_DELETED, CommunityChatIdArgs(communityId: community.id,
chatId: community.id&prv_chat.id))
# some property has changed # some property has changed
else: else:
for chat in community.chats: for chat in community.chats:
# id is present # id is present
if findIndexById(chat.id, prev_community.chats) == -1: if findIndexById(chat.id, prev_community.chats) == -1:
error "error: chat not present" continue
return
# but something is different # but something is different
for prev_chat in prev_community.chats: for prev_chat in prev_community.chats:
@ -184,7 +180,8 @@ QtObject:
# Handle position changes # Handle position changes
if(chat.id == prev_chat.id and chat.position != prev_chat.position): if(chat.id == prev_chat.id and chat.position != prev_chat.position):
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: community.id, chatId: community.id&chat.id, categoryId: chat.categoryId, position: chat.position)) self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: community.id,
chatId: community.id&chat.id, categoryId: chat.categoryId, position: chat.position))
# Handle name/description changes # Handle name/description changes
if(chat.id == prev_chat.id and (chat.name != prev_chat.name or chat.description != prev_chat.description)): if(chat.id == prev_chat.id and (chat.name != prev_chat.name or chat.description != prev_chat.description)):
@ -195,11 +192,10 @@ QtObject:
if(updated_chat.color != ""): if(updated_chat.color != ""):
chat_to_be_edited.color = updated_chat.color chat_to_be_edited.color = updated_chat.color
self.events.emit( let data = CommunityChatArgs(chat: mapChatToChatDto(chat_to_be_edited, community.id))
SIGNAL_COMMUNITY_CHANNEL_EDITED, self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, data)
CommunityChatArgs(communityId: community.id, chat: mapChatToChatDto(chat_to_be_edited, community.id)))
self.joinedCommunities[community.id].chats = community.chats self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: communities))
proc init*(self: Service) = proc init*(self: Service) =
self.doConnect() self.doConnect()
@ -458,22 +454,15 @@ QtObject:
try: try:
let response = status_go.createCommunityChannel(communityId, name, description) let response = status_go.createCommunityChannel(communityId, name, description)
if response.error != nil: if not response.error.isNil:
let error = Json.decode($response.error, RpcError) let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "Error creating community channel: " & error.message) raise newException(RpcException, "Error creating community channel: " & error.message)
if response.result != nil and response.result.kind != JNull: if response.result.isNil or response.result.kind == JNull:
let chat = response.result["chats"][0].toChat() error "response is invalid", methodName="createCommunityChannel"
# update the joined communities
self.joinedCommunities[communityId].chats.add(chat)
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_CREATED, CommunityChatArgs(
communityId: communityId,
chat: mapChatToChatDto(chat, communityId))
)
except Exception as e: except Exception as e:
error "Error creating community channel", msg = e.msg, communityId, name, description error "Error creating community channel", msg = e.msg, communityId, name, description, methodName="createCommunityChannel"
proc editCommunityChannel*( proc editCommunityChannel*(
self: Service, self: Service,
@ -496,17 +485,11 @@ QtObject:
let error = Json.decode($response.error, RpcError) let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "Error editing community channel: " & error.message) raise newException(RpcException, "Error editing community channel: " & error.message)
if response.result != nil and response.result.kind != JNull: if response.result.isNil or response.result.kind == JNull:
let chat = response.result["chats"][0].toChat() error "response is invalid", methodName="editCommunityChannel"
# update the joined communities
let idx = self.joinedCommunities[communityId].chats.find(chat)
if(idx != -1):
self.joinedCommunities[communityId].chats[idx] = chat
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, CommunityChatArgs(chat: mapChatToChatDto(chat, communityId)))
except Exception as e: except Exception as e:
error "Error editing community channel", msg = e.msg, communityId, channelId error "Error editing community channel", msg = e.msg, communityId, channelId, methodName="editCommunityChannel"
proc reorderCommunityChat*( proc reorderCommunityChat*(
self: Service, self: Service,
@ -521,46 +504,29 @@ QtObject:
chatId, chatId,
position) position)
if response.error != nil: if not response.error.isNil:
let error = Json.decode($response.error, RpcError) let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "Error reordering community channel: " & error.message) raise newException(RpcException, "Error reordering community channel: " & error.message)
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, if response.result.isNil or response.result.kind == JNull:
CommunityChatOrderArgs( error "response is invalid", methodName="reorderCommunityChat"
communityId: communityId,
categoryId: categoryId,
chatId: chatId,
position: position
)
)
except Exception as e: except Exception as e:
error "Error reordering community channel", msg = e.msg, communityId, chatId, position error "Error reordering community channel", msg = e.msg, communityId, chatId, position, methodName="reorderCommunityChat"
proc deleteCommunityChat*(self: Service, communityId: string, chatId: string) = proc deleteCommunityChat*(self: Service, communityId: string, chatId: string) =
try: try:
let response = status_go.deleteCommunityChat(communityId, chatId) let response = status_go.deleteCommunityChat(communityId, chatId)
if response.error != nil: if not response.error.isNil:
let error = Json.decode($response.error, RpcError) let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "Error deleting community chat: " & error.message) raise newException(RpcException, "Error deleting community chat: " & error.message)
if response.result == nil or response.result.kind == JNull: if response.result.isNil or response.result.kind == JNull:
error "response is invalid" error "response is invalid", methodName="deleteCommunityChat"
return
let community = response.result["communities"][0].toCommunityDto()
# update the joined communities
self.joinedCommunities[community.id].chats = community.chats
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_DELETED,
CommunityChatIdArgs(
communityId: communityId,
chatId: chatId
)
)
except Exception as e: except Exception as e:
error "Error deleting community channel", msg = e.msg, communityId, chatId error "Error deleting community channel", msg = e.msg, communityId, chatId, methodName="deleteCommunityChat"
proc createCommunityCategory*( proc createCommunityCategory*(
self: Service, self: Service,