(Chat): Display system messages about adding/removing members immediately after an update is performed (#14146)
* (Chat): Display system add/remove messages immediately after update fixes #9876 * (Chat): Display system "pinned" message immediately after update fixes #10702 * fix issues from the PR
This commit is contained in:
parent
59453e1189
commit
c53e4aeb92
|
@ -154,7 +154,7 @@ QtObject:
|
||||||
proc updateOrAddChat*(self: Service, chat: ChatDto)
|
proc updateOrAddChat*(self: Service, chat: ChatDto)
|
||||||
proc hydrateChannelGroups*(self: Service, data: JsonNode)
|
proc hydrateChannelGroups*(self: Service, data: JsonNode)
|
||||||
proc updateOrAddChannelGroup*(self: Service, channelGroup: ChannelGroupDto, isCommunityChannelGroup: bool = false)
|
proc updateOrAddChannelGroup*(self: Service, channelGroup: ChannelGroupDto, isCommunityChannelGroup: bool = false)
|
||||||
proc processMessageUpdateAfterSend*(self: Service, response: RpcResponse[JsonNode]): (seq[ChatDto], seq[MessageDto])
|
proc processMessengerResponse*(self: Service, response: RpcResponse[JsonNode]): (seq[ChatDto], seq[MessageDto])
|
||||||
|
|
||||||
proc doConnect(self: Service) =
|
proc doConnect(self: Service) =
|
||||||
self.events.on(SignalType.Message.event) do(e: Args):
|
self.events.on(SignalType.Message.event) do(e: Args):
|
||||||
|
@ -195,7 +195,7 @@ QtObject:
|
||||||
|
|
||||||
self.events.on(SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND) do(e: Args):
|
self.events.on(SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND) do(e: Args):
|
||||||
var args = RpcResponseArgs(e)
|
var args = RpcResponseArgs(e)
|
||||||
discard self.processMessageUpdateAfterSend(args.response)
|
discard self.processMessengerResponse(args.response)
|
||||||
|
|
||||||
proc getChannelGroups*(self: Service): seq[ChannelGroupDto] =
|
proc getChannelGroups*(self: Service): seq[ChannelGroupDto] =
|
||||||
return toSeq(self.channelGroups.values)
|
return toSeq(self.channelGroups.values)
|
||||||
|
@ -389,36 +389,64 @@ QtObject:
|
||||||
proc parseChatResponse*(self: Service, response: RpcResponse[JsonNode]): (seq[ChatDto], seq[MessageDto]) =
|
proc parseChatResponse*(self: Service, response: RpcResponse[JsonNode]): (seq[ChatDto], seq[MessageDto]) =
|
||||||
var chats: seq[ChatDto] = @[]
|
var chats: seq[ChatDto] = @[]
|
||||||
var messages: seq[MessageDto] = @[]
|
var messages: seq[MessageDto] = @[]
|
||||||
if response.result{"messages"} != nil:
|
let errDesription = response.result{"error"}.getStr
|
||||||
for jsonMsg in response.result["messages"]:
|
if errDesription != "":
|
||||||
messages.add(jsonMsg.toMessageDto)
|
error "Error in parseGroupChatResponse: ", errDesription
|
||||||
if response.result{"chats"} != nil:
|
else:
|
||||||
for jsonChat in response.result["chats"]:
|
if response.result{"messages"} != nil:
|
||||||
let chat = chat_dto.toChatDto(jsonChat)
|
for jsonMsg in response.result["messages"]:
|
||||||
# TODO add the channel back to `chat` when it is refactored
|
messages.add(jsonMsg.toMessageDto)
|
||||||
self.updateOrAddChat(chat)
|
if response.result{"chats"} != nil:
|
||||||
chats.add(chat)
|
for jsonChat in response.result["chats"]:
|
||||||
result = (chats, messages)
|
let chat = chat_dto.toChatDto(jsonChat)
|
||||||
|
# TODO add the channel back to `chat` when it is refactored
|
||||||
|
self.updateOrAddChat(chat)
|
||||||
|
chats.add(chat)
|
||||||
|
return (chats, messages)
|
||||||
|
|
||||||
proc processMessageUpdateAfterSend*(self: Service, response: RpcResponse[JsonNode]): (seq[ChatDto], seq[MessageDto]) =
|
proc signalChatsAndMessagesUpdates*(self: Service, chats: seq[ChatDto], messages: seq[MessageDto]) =
|
||||||
result = self.parseChatResponse(response)
|
|
||||||
var (chats, messages) = result
|
|
||||||
if chats.len == 0 or messages.len == 0:
|
if chats.len == 0 or messages.len == 0:
|
||||||
error "no chats or messages in the parsed response"
|
error "no chats or messages in the parsed response"
|
||||||
return
|
return
|
||||||
|
|
||||||
for chat in chats:
|
for chat in chats:
|
||||||
if (chat.active):
|
if (chat.active):
|
||||||
self.events.emit(SIGNAL_CHAT_CREATED, CreatedChatArgs(chat: chat))
|
self.events.emit(SIGNAL_CHAT_CREATED, CreatedChatArgs(chat: chat))
|
||||||
|
var chatMap: Table[string, ChatDto] = initTable[string, ChatDto]()
|
||||||
|
for chat in chats:
|
||||||
|
chatMap[chat.id] = chat
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
for chat in chats:
|
if chatMap.hasKey(msg.chatId):
|
||||||
if chat.id == msg.chatId:
|
let chat = chatMap[msg.chatId]
|
||||||
self.events.emit(SIGNAL_SENDING_SUCCESS, MessageSendingSuccess(message: msg, chat: chat))
|
self.events.emit(SIGNAL_SENDING_SUCCESS, MessageSendingSuccess(message: msg, chat: chat))
|
||||||
break
|
|
||||||
|
proc processMessengerResponse*(self: Service, response: RpcResponse[JsonNode]): (seq[ChatDto], seq[MessageDto]) =
|
||||||
|
result = self.parseChatResponse(response)
|
||||||
|
var (chats, messages) = result
|
||||||
|
self.signalChatsAndMessagesUpdates(chats, messages)
|
||||||
|
|
||||||
|
proc processGroupChatResponse*(self: Service, response: RpcResponse[JsonNode]) =
|
||||||
|
proc parseGroupChatResponse(response: RpcResponse[JsonNode]): (ChatDto, seq[MessageDto], string) =
|
||||||
|
var chat: ChatDto
|
||||||
|
var messages: seq[MessageDto] = @[]
|
||||||
|
|
||||||
|
let errorDescription = response.result{"error"}.getStr
|
||||||
|
|
||||||
|
if response.result{"chat"} != nil:
|
||||||
|
chat = chat_dto.toChatDto(response.result["chat"])
|
||||||
|
if response.result{"messages"} != nil:
|
||||||
|
for jsonMsg in response.result["messages"]:
|
||||||
|
messages.add(jsonMsg.toMessageDto)
|
||||||
|
return (chat, messages, errorDescription)
|
||||||
|
|
||||||
|
var (chat, messages, errorDescription) = parseGroupChatResponse(response)
|
||||||
|
if errorDescription != "":
|
||||||
|
error "Received an error in the ProcessGroupChatResponse: ", errorDescription
|
||||||
|
else:
|
||||||
|
self.updateOrAddChat(chat)
|
||||||
|
self.signalChatsAndMessagesUpdates(@[chat], messages)
|
||||||
|
|
||||||
proc processUpdateForTransaction*(self: Service, messageId: string, response: RpcResponse[JsonNode]) =
|
proc processUpdateForTransaction*(self: Service, messageId: string, response: RpcResponse[JsonNode]) =
|
||||||
var (chats, _) = self.processMessageUpdateAfterSend(response)
|
var (chats, _) = self.processMessengerResponse(response)
|
||||||
# TODO: Signal is not handled anywhere
|
# TODO: Signal is not handled anywhere
|
||||||
self.events.emit(SIGNAL_MESSAGE_REMOVE, MessageArgs(id: messageId, channel: chats[0].id))
|
self.events.emit(SIGNAL_MESSAGE_REMOVE, MessageArgs(id: messageId, channel: chats[0].id))
|
||||||
|
|
||||||
|
@ -533,7 +561,7 @@ QtObject:
|
||||||
for imagePath in imagePaths:
|
for imagePath in imagePaths:
|
||||||
removeFile(imagePath)
|
removeFile(imagePath)
|
||||||
|
|
||||||
discard self.processMessageUpdateAfterSend(response)
|
discard self.processMessengerResponse(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error sending images", msg = e.msg
|
error "Error sending images", msg = e.msg
|
||||||
result = fmt"Error sending images: {e.msg}"
|
result = fmt"Error sending images: {e.msg}"
|
||||||
|
@ -560,7 +588,7 @@ QtObject:
|
||||||
linkPreviews,
|
linkPreviews,
|
||||||
communityId) # Only send a community ID for the community invites
|
communityId) # Only send a community ID for the community invites
|
||||||
|
|
||||||
let (chats, messages) = self.processMessageUpdateAfterSend(response)
|
let (chats, messages) = self.processMessengerResponse(response)
|
||||||
if chats.len == 0 or messages.len == 0:
|
if chats.len == 0 or messages.len == 0:
|
||||||
self.events.emit(SIGNAL_SENDING_FAILED, ChatArgs(chatId: chatId))
|
self.events.emit(SIGNAL_SENDING_FAILED, ChatArgs(chatId: chatId))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -570,7 +598,7 @@ QtObject:
|
||||||
try:
|
try:
|
||||||
let address = if (tokenAddress == ZERO_ADDRESS): "" else: tokenAddress
|
let address = if (tokenAddress == ZERO_ADDRESS): "" else: tokenAddress
|
||||||
let response = status_chat_commands.requestAddressForTransaction(chatId, fromAddress, amount, address)
|
let response = status_chat_commands.requestAddressForTransaction(chatId, fromAddress, amount, address)
|
||||||
discard self.processMessageUpdateAfterSend(response)
|
discard self.processMessengerResponse(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error requesting address for transaction", msg = e.msg
|
error "Error requesting address for transaction", msg = e.msg
|
||||||
|
|
||||||
|
@ -578,7 +606,7 @@ QtObject:
|
||||||
try:
|
try:
|
||||||
let address = if (tokenAddress == ZERO_ADDRESS): "" else: tokenAddress
|
let address = if (tokenAddress == ZERO_ADDRESS): "" else: tokenAddress
|
||||||
let response = status_chat_commands.requestTransaction(chatId, fromAddress, amount, address)
|
let response = status_chat_commands.requestTransaction(chatId, fromAddress, amount, address)
|
||||||
discard self.processMessageUpdateAfterSend(response)
|
discard self.processMessengerResponse(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error requesting transaction", msg = e.msg
|
error "Error requesting transaction", msg = e.msg
|
||||||
|
|
||||||
|
@ -606,7 +634,7 @@ QtObject:
|
||||||
proc acceptRequestTransaction*(self: Service, transactionHash: string, messageId: string, signature: string) =
|
proc acceptRequestTransaction*(self: Service, transactionHash: string, messageId: string, signature: string) =
|
||||||
try:
|
try:
|
||||||
let response = status_chat_commands.acceptRequestTransaction(transactionHash, messageId, signature)
|
let response = status_chat_commands.acceptRequestTransaction(transactionHash, messageId, signature)
|
||||||
discard self.processMessageUpdateAfterSend(response)
|
discard self.processMessengerResponse(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error requesting transaction", msg = e.msg
|
error "Error requesting transaction", msg = e.msg
|
||||||
|
|
||||||
|
@ -665,6 +693,7 @@ QtObject:
|
||||||
let response = status_group_chat.addMembers(communityID, chatId, members)
|
let response = status_group_chat.addMembers(communityID, chatId, members)
|
||||||
if (response.error.isNil):
|
if (response.error.isNil):
|
||||||
self.events.emit(SIGNAL_CHAT_MEMBERS_ADDED, ChatMembersAddedArgs(chatId: chatId, ids: members))
|
self.events.emit(SIGNAL_CHAT_MEMBERS_ADDED, ChatMembersAddedArgs(chatId: chatId, ids: members))
|
||||||
|
self.processGroupChatResponse(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "error while adding group members: ", msg = e.msg
|
error "error while adding group members: ", msg = e.msg
|
||||||
|
|
||||||
|
@ -673,6 +702,7 @@ QtObject:
|
||||||
let response = status_group_chat.removeMember(communityID, chatId, member)
|
let response = status_group_chat.removeMember(communityID, chatId, member)
|
||||||
if (response.error.isNil):
|
if (response.error.isNil):
|
||||||
self.events.emit(SIGNAL_CHAT_MEMBER_REMOVED, ChatMemberRemovedArgs(chatId: chatId, id: member))
|
self.events.emit(SIGNAL_CHAT_MEMBER_REMOVED, ChatMemberRemovedArgs(chatId: chatId, id: member))
|
||||||
|
self.processGroupChatResponse(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "error while removing member from group: ", msg = e.msg
|
error "error while removing member from group: ", msg = e.msg
|
||||||
|
|
||||||
|
|
|
@ -2085,7 +2085,7 @@ QtObject:
|
||||||
# We no longer send invites, but merely share the community so
|
# We no longer send invites, but merely share the community so
|
||||||
# users can request access (with automatic acception)
|
# users can request access (with automatic acception)
|
||||||
let response = status_go.shareCommunityToUsers(communityId, pubKeys, inviteMessage)
|
let response = status_go.shareCommunityToUsers(communityId, pubKeys, inviteMessage)
|
||||||
discard self.chatService.processMessageUpdateAfterSend(response)
|
discard self.chatService.processMessengerResponse(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error sharing community", msg = e.msg
|
error "Error sharing community", msg = e.msg
|
||||||
result = "Error sharing community: " & e.msg
|
result = "Error sharing community: " & e.msg
|
||||||
|
|
|
@ -644,6 +644,7 @@ QtObject:
|
||||||
if(not pinned and not pin):
|
if(not pinned and not pin):
|
||||||
self.numOfPinnedMessagesPerChat[chatId] = self.getNumOfPinnedMessages(chatId) - 1
|
self.numOfPinnedMessagesPerChat[chatId] = self.getNumOfPinnedMessages(chatId) - 1
|
||||||
self.events.emit(SIGNAL_MESSAGE_UNPINNED, data)
|
self.events.emit(SIGNAL_MESSAGE_UNPINNED, data)
|
||||||
|
discard self.chatService.processMessengerResponse(response)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "error: ", procName="pinUnpinMessage", errName = e.name, errDesription = e.msg
|
error "error: ", procName="pinUnpinMessage", errName = e.name, errDesription = e.msg
|
||||||
|
|
|
@ -369,7 +369,7 @@ QtObject:
|
||||||
communityId = "", # communityId is not necessary when sending a sticker
|
communityId = "", # communityId is not necessary when sending a sticker
|
||||||
sticker.hash,
|
sticker.hash,
|
||||||
sticker.packId)
|
sticker.packId)
|
||||||
discard self.chatService.processMessageUpdateAfterSend(response)
|
discard self.chatService.processMessengerResponse(response)
|
||||||
self.addStickerToRecent(sticker)
|
self.addStickerToRecent(sticker)
|
||||||
|
|
||||||
proc removeRecentStickers*(self: Service, packId: string) =
|
proc removeRecentStickers*(self: Service, packId: string) =
|
||||||
|
|
Loading…
Reference in New Issue