fix: fix pinnedBy not being right when reopening the app

This commit is contained in:
Jonathan Rainville 2021-06-11 10:45:44 -04:00
parent 086653ac52
commit 32676d50af
4 changed files with 25 additions and 15 deletions

View File

@ -646,7 +646,7 @@ QtObject:
let pinnedMsgs = rpcResponseObj{"pinnedMessages"} let pinnedMsgs = rpcResponseObj{"pinnedMessages"}
if(pinnedMsgs != nil and pinnedMsgs.kind != JNull): if(pinnedMsgs != nil and pinnedMsgs.kind != JNull):
let pinnedMessages = parseChatMessagesResponse(chatId, pinnedMsgs, true) let pinnedMessages = parseChatPinnedMessagesResponse(chatId, pinnedMsgs)
self.status.chat.pinnedMessagesByChatID(chatId, pinnedMessages[0], pinnedMessages[1]) self.status.chat.pinnedMessagesByChatID(chatId, pinnedMessages[0], pinnedMessages[1])
proc hideLoadingIndicator*(self: ChatsView) {.slot.} = proc hideLoadingIndicator*(self: ChatsView) {.slot.} =

View File

@ -73,13 +73,13 @@ proc loadChats*(): seq[Chat] =
result.add(chat) result.add(chat)
result.sort(sortChats) result.sort(sortChats)
proc parseChatMessagesResponse*(chatId: string, rpcResult: JsonNode, isPin: bool = false): (string, seq[Message]) = proc parseChatMessagesResponse*(chatId: string, rpcResult: JsonNode): (string, seq[Message]) =
let pk = status_settings.getSetting[string](Setting.PublicKey, "0x0")
var messages: seq[Message] = @[] var messages: seq[Message] = @[]
var msg: Message let messagesObj = rpcResult{"messages"}
if rpcResult["messages"].kind != JNull: if(messagesObj != nil and messagesObj.kind != JNull):
for jsonMsg in rpcResult["messages"]: let pk = status_settings.getSetting[string](Setting.PublicKey, "0x0")
messages.add(jsonMsg.toMessage(pk, isPin)) for jsonMsg in messagesObj:
messages.add(jsonMsg.toMessage(pk))
return (rpcResult{"cursor"}.getStr, messages) return (rpcResult{"cursor"}.getStr, messages)
proc rpcChatMessages*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string = proc rpcChatMessages*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string =
@ -516,10 +516,24 @@ proc banUserFromCommunity*(pubKey: string, communityId: string): string =
"user": pubKey "user": pubKey
}]) }])
proc parseChatPinnedMessagesResponse*(chatId: string, rpcResult: JsonNode): (string, seq[Message]) =
var messages: seq[Message] = @[]
let messagesObj = rpcResult{"pinnedMessages"}
if(messagesObj != nil and messagesObj.kind != JNull):
let pk = status_settings.getSetting[string](Setting.PublicKey, "0x0")
var msg: Message
for jsonMsg in messagesObj:
msg = jsonMsg["message"].toMessage(pk)
msg.pinnedBy = $jsonMsg{"pinnedBy"}.getStr
messages.add(msg)
return (rpcResult{"cursor"}.getStr, messages)
proc rpcPinnedChatMessages*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string = proc rpcPinnedChatMessages*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string =
success = true success = true
try: try:
result = callPrivateRPC("chatPinnedMessages".prefix, %* [chatId, cursorVal, limit]) result = callPrivateRPC("chatPinnedMessages".prefix, %* [chatId, cursorVal, limit])
debug "chatPinnedMessages", result
except RpcException as e: except RpcException as e:
success = false success = false
result = e.msg result = e.msg
@ -535,7 +549,7 @@ proc pinnedMessagesByChatID*(chatId: string, cursor: string): (string, seq[Messa
var success: bool var success: bool
let callResult = rpcPinnedChatMessages(chatId, cursorVal, 20, success) let callResult = rpcPinnedChatMessages(chatId, cursorVal, 20, success)
if success: if success:
result = parseChatMessagesResponse(chatId, callResult.parseJson()["result"], true) result = parseChatPinnedMessagesResponse(chatId, callResult.parseJson()["result"])
proc setPinMessage*(messageId: string, chatId: string, pinned: bool) = proc setPinMessage*(messageId: string, chatId: string, pinned: bool) =
discard callPrivateRPC("sendPinMessage".prefix, %*[{ discard callPrivateRPC("sendPinMessage".prefix, %*[{

View File

@ -13,7 +13,7 @@ import types
import web3/conversions import web3/conversions
from ../libstatus/utils import parseAddress, wei2Eth from ../libstatus/utils import parseAddress, wei2Eth
proc toMessage*(jsonMsg: JsonNode, pk: string, isPin: bool = false): Message proc toMessage*(jsonMsg: JsonNode, pk: string): Message
proc toChat*(jsonChat: JsonNode): Chat proc toChat*(jsonChat: JsonNode): Chat
@ -271,7 +271,7 @@ proc toTextItem*(jsonText: JsonNode): TextItem =
result.children.add(child.toTextItem) result.children.add(child.toTextItem)
proc toMessage*(jsonMsg: JsonNode, pk: string, isPin: bool = false): Message = proc toMessage*(jsonMsg: JsonNode, pk: string): Message =
var contentType: ContentType var contentType: ContentType
try: try:
contentType = ContentType(jsonMsg{"contentType"}.getInt) contentType = ContentType(jsonMsg{"contentType"}.getInt)
@ -313,10 +313,6 @@ proc toMessage*(jsonMsg: JsonNode, pk: string, isPin: bool = false): Message =
hasMention: false hasMention: false
) )
if isPin:
message.pinnedBy = message.fromAuthor
message.fromAuthor = ""
if contentType == ContentType.Gap: if contentType == ContentType.Gap:
message.gapFrom = jsonMsg["gapParameters"]["from"].getInt message.gapFrom = jsonMsg["gapParameters"]["from"].getInt
message.gapTo = jsonMsg["gapParameters"]["to"].getInt message.gapTo = jsonMsg["gapParameters"]["to"].getInt

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit b395144704f29c9e1f4fd11714d1031a10160ad1 Subproject commit f80b5e66a2c7da8d18e9a182bfdcf9a11c8365fc