fix: fix pinnedBy not being right when reopening the app
This commit is contained in:
parent
086653ac52
commit
32676d50af
|
@ -646,7 +646,7 @@ QtObject:
|
|||
|
||||
let pinnedMsgs = rpcResponseObj{"pinnedMessages"}
|
||||
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])
|
||||
|
||||
proc hideLoadingIndicator*(self: ChatsView) {.slot.} =
|
||||
|
|
|
@ -73,13 +73,13 @@ proc loadChats*(): seq[Chat] =
|
|||
result.add(chat)
|
||||
result.sort(sortChats)
|
||||
|
||||
proc parseChatMessagesResponse*(chatId: string, rpcResult: JsonNode, isPin: bool = false): (string, seq[Message]) =
|
||||
let pk = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
proc parseChatMessagesResponse*(chatId: string, rpcResult: JsonNode): (string, seq[Message]) =
|
||||
var messages: seq[Message] = @[]
|
||||
var msg: Message
|
||||
if rpcResult["messages"].kind != JNull:
|
||||
for jsonMsg in rpcResult["messages"]:
|
||||
messages.add(jsonMsg.toMessage(pk, isPin))
|
||||
let messagesObj = rpcResult{"messages"}
|
||||
if(messagesObj != nil and messagesObj.kind != JNull):
|
||||
let pk = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
for jsonMsg in messagesObj:
|
||||
messages.add(jsonMsg.toMessage(pk))
|
||||
return (rpcResult{"cursor"}.getStr, messages)
|
||||
|
||||
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
|
||||
}])
|
||||
|
||||
|
||||
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 =
|
||||
success = true
|
||||
try:
|
||||
result = callPrivateRPC("chatPinnedMessages".prefix, %* [chatId, cursorVal, limit])
|
||||
debug "chatPinnedMessages", result
|
||||
except RpcException as e:
|
||||
success = false
|
||||
result = e.msg
|
||||
|
@ -535,7 +549,7 @@ proc pinnedMessagesByChatID*(chatId: string, cursor: string): (string, seq[Messa
|
|||
var success: bool
|
||||
let callResult = rpcPinnedChatMessages(chatId, cursorVal, 20, success)
|
||||
if success:
|
||||
result = parseChatMessagesResponse(chatId, callResult.parseJson()["result"], true)
|
||||
result = parseChatPinnedMessagesResponse(chatId, callResult.parseJson()["result"])
|
||||
|
||||
proc setPinMessage*(messageId: string, chatId: string, pinned: bool) =
|
||||
discard callPrivateRPC("sendPinMessage".prefix, %*[{
|
||||
|
|
|
@ -13,7 +13,7 @@ import types
|
|||
import web3/conversions
|
||||
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
|
||||
|
||||
|
@ -271,7 +271,7 @@ proc toTextItem*(jsonText: JsonNode): TextItem =
|
|||
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
|
||||
try:
|
||||
contentType = ContentType(jsonMsg{"contentType"}.getInt)
|
||||
|
@ -313,10 +313,6 @@ proc toMessage*(jsonMsg: JsonNode, pk: string, isPin: bool = false): Message =
|
|||
hasMention: false
|
||||
)
|
||||
|
||||
if isPin:
|
||||
message.pinnedBy = message.fromAuthor
|
||||
message.fromAuthor = ""
|
||||
|
||||
if contentType == ContentType.Gap:
|
||||
message.gapFrom = jsonMsg["gapParameters"]["from"].getInt
|
||||
message.gapTo = jsonMsg["gapParameters"]["to"].getInt
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b395144704f29c9e1f4fd11714d1031a10160ad1
|
||||
Subproject commit f80b5e66a2c7da8d18e9a182bfdcf9a11c8365fc
|
Loading…
Reference in New Issue