feat: introduce isStatusUpdate flag in sendMessage APIs
When sending a profile status update, the message has to be sent to a specific channel that has the id `@PUBKEY`. This commit introduces a flag that controls whether the message is sent to the currently active channel, or tot he profile status channel. The same is done for the `sendImage` API.
This commit is contained in:
parent
400b020118
commit
3e5047cfaf
|
@ -4,6 +4,7 @@ import ../../status/mailservers as mailserver_model
|
|||
import ../../status/messages as messages_model
|
||||
import ../../status/signals/types
|
||||
import ../../status/libstatus/types as status_types
|
||||
import ../../status/libstatus/settings as status_settings
|
||||
import ../../status/[chat, contacts, status, wallet, stickers]
|
||||
import view, views/channels_list, views/message_list, views/reactions, views/stickers as stickers_view
|
||||
import ../../eventemitter
|
||||
|
@ -34,8 +35,11 @@ proc init*(self: ChatController) =
|
|||
self.handleChatEvents()
|
||||
self.handleSignals()
|
||||
|
||||
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
|
||||
self.view.pubKey = pubKey
|
||||
self.status.mailservers.init()
|
||||
self.status.chat.init()
|
||||
self.status.chat.init(pubKey)
|
||||
self.status.stickers.init()
|
||||
self.view.reactions.init()
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ QtObject:
|
|||
unreadMessageCnt: int
|
||||
oldestMessageTimestamp: int64
|
||||
loadingMessages: bool
|
||||
pubKey*: string
|
||||
|
||||
proc setup(self: ChatsView) = self.QAbstractListModel.setup
|
||||
|
||||
|
@ -123,7 +124,7 @@ QtObject:
|
|||
proc plainText(self: ChatsView, input: string): string {.slot.} =
|
||||
result = plain_text(input)
|
||||
|
||||
proc sendMessage*(self: ChatsView, message: string, replyTo: string, contentType: int = ContentType.Message.int) {.slot.} =
|
||||
proc sendMessage*(self: ChatsView, message: string, replyTo: string, contentType: int = ContentType.Message.int, isStatusUpdate: bool = false) {.slot.} =
|
||||
let aliasPattern = re(r"(@[A-z][a-z]+ [A-z][a-z]* [A-z][a-z]*)", flags = {reStudy, reIgnoreCase})
|
||||
let ensPattern = re(r"(@\w+(?=(\.stateofus)?\.eth))", flags = {reStudy, reIgnoreCase})
|
||||
let namePattern = re(r"(@\w+)", flags = {reStudy, reIgnoreCase})
|
||||
|
@ -137,7 +138,13 @@ QtObject:
|
|||
var m = self.replaceMentionsWithPubKeys(aliasMentions, contacts, message, (c => c.alias))
|
||||
m = self.replaceMentionsWithPubKeys(ensMentions, contacts, m, (c => c.ensName))
|
||||
m = self.replaceMentionsWithPubKeys(nameMentions, contacts, m, (c => c.ensName.split(".")[0]))
|
||||
self.status.chat.sendMessage(self.activeChannel.id, m, replyTo, contentType)
|
||||
|
||||
var channelId = self.activeChannel.id
|
||||
|
||||
if isStatusUpdate:
|
||||
channelId = "@" & self.pubKey
|
||||
|
||||
self.status.chat.sendMessage(channelId, m, replyTo, contentType)
|
||||
|
||||
proc verifyMessageSent*(self: ChatsView, data: string) {.slot.} =
|
||||
let messageData = data.parseJson
|
||||
|
@ -148,12 +155,18 @@ QtObject:
|
|||
self.status.chat.resendMessage(messageId)
|
||||
self.messageList[chatId].resetTimeOut(messageId)
|
||||
|
||||
proc sendImage*(self: ChatsView, imagePath: string): string {.slot.} =
|
||||
proc sendImage*(self: ChatsView, imagePath: string, isStatusUpdate: bool = false): string {.slot.} =
|
||||
result = ""
|
||||
try:
|
||||
var image = image_utils.formatImagePath(imagePath)
|
||||
let tmpImagePath = image_resizer(image, 2000, TMPDIR)
|
||||
self.status.chat.sendImage(self.activeChannel.id, tmpImagePath)
|
||||
|
||||
var channelId = self.activeChannel.id
|
||||
|
||||
if isStatusUpdate:
|
||||
channelId = "@" & self.pubKey
|
||||
|
||||
self.status.chat.sendImage(channelId, tmpImagePath)
|
||||
removeFile(tmpImagePath)
|
||||
except Exception as e:
|
||||
error "Error sending the image", msg = e.msg
|
||||
|
|
|
@ -125,8 +125,8 @@ proc updateContacts*(self: ChatModel, contacts: seq[Profile]) =
|
|||
self.contacts[c.id] = c
|
||||
self.events.emit("chatUpdate", ChatUpdateArgs(contacts: contacts))
|
||||
|
||||
proc init*(self: ChatModel) =
|
||||
let chatList = status_chat.loadChats()
|
||||
proc init*(self: ChatModel, pubKey: string) =
|
||||
var chatList = status_chat.loadChats()
|
||||
|
||||
var filters:seq[JsonNode] = @[]
|
||||
for chat in chatList:
|
||||
|
|
Loading…
Reference in New Issue