From 07c399530b0ed2cee3ee9424eaf6c35f87888010 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 12 Jul 2021 12:22:47 -0400 Subject: [PATCH] fix: load old user status, and fix code review obs. --- src/app/chat/event_handling.nim | 10 ++++++++-- src/app/chat/views/communities.nim | 4 +++- src/app/chat/views/community_list.nim | 2 +- src/app/chat/views/messages.nim | 2 ++ src/status/chat.nim | 5 +++++ src/status/libstatus/chat.nim | 6 ++++++ .../AppLayouts/Profile/Sections/AdvancedContainer.qml | 4 +++- 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/app/chat/event_handling.nim b/src/app/chat/event_handling.nim index bda12a3c1d..d7d024c4b9 100644 --- a/src/app/chat/event_handling.nim +++ b/src/app/chat/event_handling.nim @@ -9,7 +9,12 @@ import # status-desktop libs proc handleChatEvents(self: ChatController) = # Display already saved messages self.status.events.on("messagesLoaded") do(e:Args): - self.view.pushMessages(MsgsLoadedArgs(e).messages) + let evArgs = MsgsLoadedArgs(e) + self.view.pushMessages(evArgs.messages) + for statusUpdate in evArgs.statusUpdates: + echo "updating member visibility", $statusUpdate + self.view.communities.updateMemberVisibility(statusUpdate) + # Display emoji reactions self.status.events.on("reactionsLoaded") do(e:Args): self.view.reactions.push(ReactionsLoadedArgs(e).reactions) @@ -34,7 +39,7 @@ proc handleChatEvents(self: ChatController) = self.view.updateChats(evArgs.chats) self.view.pushMessages(evArgs.messages) - # TODO: update current user status + # TODO: update current user status (once it's possible to switch between ONLINE and DO_NOT_DISTURB) for statusUpdate in evArgs.statusUpdates: self.view.communities.updateMemberVisibility(statusUpdate) @@ -120,6 +125,7 @@ proc handleChatEvents(self: ChatController) = self.view.setActiveChannel(channel.chat.id) self.status.chat.chatMessages(channel.chat.id) self.status.chat.chatReactions(channel.chat.id) + self.status.chat.statusUpdates() self.status.events.on("channelLeft") do(e: Args): let chatId = ChatIdArg(e).chatId diff --git a/src/app/chat/views/communities.nim b/src/app/chat/views/communities.nim index a15f6f4fd6..a404912721 100644 --- a/src/app/chat/views/communities.nim +++ b/src/app/chat/views/communities.nim @@ -380,7 +380,8 @@ QtObject: result = fmt"Error inviting to the community: {e.msg}" proc inviteUsersToCommunity*(self: CommunitiesView, pubKeysJSON: string): string {.slot.} = - self.inviteUsersToCommunityById(self.activeCommunity.id(), pubKeysJSON) + result = self.inviteUsersToCommunityById(self.activeCommunity.id(), pubKeysJSON) + self.status.chat.statusUpdates() proc exportCommunity*(self: CommunitiesView): string {.slot.} = try: @@ -441,6 +442,7 @@ QtObject: try: self.status.chat.acceptRequestToJoinCommunity(requestId) self.removeMembershipRequest(requestId, true) + self.status.chat.statusUpdates() except Exception as e: error "Error accepting request to join the community", msg = e.msg return "Error accepting request to join the community" diff --git a/src/app/chat/views/community_list.nim b/src/app/chat/views/community_list.nim index 716bd1cd31..a507a5aefb 100644 --- a/src/app/chat/views/community_list.nim +++ b/src/app/chat/views/community_list.nim @@ -179,7 +179,7 @@ QtObject: community.memberStatus[statusUpdate.publicKey] = statusUpdate else: community.memberStatus[statusUpdate.publicKey] = statusUpdate - break + proc addChannelToCommunity*(self: CommunityList, communityId: string, chat: Chat) = var community = self.getCommunityById(communityId) diff --git a/src/app/chat/views/messages.nim b/src/app/chat/views/messages.nim index 92437a61f1..fb249e43b2 100644 --- a/src/app/chat/views/messages.nim +++ b/src/app/chat/views/messages.nim @@ -318,6 +318,7 @@ QtObject: trace "Loading more messages", chaId = self.channelView.activeChannel.id self.status.chat.chatMessages(self.channelView.activeChannel.id, false) self.status.chat.chatReactions(self.channelView.activeChannel.id, false) + self.status.chat.statusUpdates() self.messagesLoaded(); proc loadMoreMessagesWithIndex*(self: MessageView, channelIndex: int) {.slot.} = @@ -327,6 +328,7 @@ QtObject: trace "Loading more messages", chaId = selectedChannel.id self.status.chat.chatMessages(selectedChannel.id, false) self.status.chat.chatReactions(selectedChannel.id, false) + self.status.chat.statusUpdates() self.messagesLoaded(); proc loadingMessagesChanged*(self: MessageView, value: bool) {.signal.} diff --git a/src/status/chat.nim b/src/status/chat.nim index 27f41e22c8..23ecd322a5 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -44,6 +44,7 @@ type MsgsLoadedArgs* = ref object of Args messages*: seq[Message] + statusUpdates*: seq[StatusUpdate] ActivityCenterNotificationsArgs* = ref object of Args activityCenterNotifications*: seq[ActivityCenterNotification] @@ -286,6 +287,10 @@ proc chatMessages*(self: ChatModel, chatId: string, initialLoad:bool = true) = self.events.emit("messagesLoaded", MsgsLoadedArgs(messages: messageTuple[1])) +proc statusUpdates*(self: ChatModel) = + let statusUpdates = status_chat.statusUpdates() + self.events.emit("messagesLoaded", MsgsLoadedArgs(statusUpdates: statusUpdates)) + proc chatMessages*(self: ChatModel, chatId: string, initialLoad:bool = true, cursor: string = "", messages: seq[Message]) = if not self.msgCursor.hasKey(chatId): self.msgCursor[chatId] = ""; diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index c14dca5705..620b9b67cc 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -89,6 +89,12 @@ proc parseActivityCenterNotifications*(rpcResult: JsonNode): (string, seq[Activi notifs.add(jsonMsg.toActivityCenterNotification()) return (rpcResult{"cursor"}.getStr, notifs) +proc statusUpdates*(): seq[StatusUpdate] = + let rpcResult = callPrivateRPC("statusUpdates".prefix, %* []).parseJson()["result"] + if rpcResult != nil and rpcResult{"statusUpdates"} != nil and rpcResult["statusUpdates"].len != 0: + for jsonStatusUpdate in rpcResult["statusUpdates"]: + result.add(jsonStatusUpdate.toStatusUpdate) + proc rpcChatMessages*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string = success = true try: diff --git a/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml b/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml index 6efc523bcf..0b6599e335 100644 --- a/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml +++ b/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml @@ -144,7 +144,9 @@ Item { isSwitch: true switchChecked: profileModel.profile.sendUserStatus onClicked: function (checked) { - profileModel.setSendUserStatus(checked) + if (profileModel.profile.sendUserStatus !== checked) { + profileModel.setSendUserStatus(checked) + } } } }