fix: load old user status, and fix code review obs.

This commit is contained in:
Richard Ramos 2021-07-12 12:22:47 -04:00 committed by Iuri Matias
parent 7aaca9ec4d
commit 07c399530b
7 changed files with 28 additions and 5 deletions

View File

@ -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

View File

@ -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"

View File

@ -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)

View File

@ -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.}

View File

@ -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] = "";

View File

@ -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:

View File

@ -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)
}
}
}
}