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/messages as messages_model
|
||||||
import ../../status/signals/types
|
import ../../status/signals/types
|
||||||
import ../../status/libstatus/types as status_types
|
import ../../status/libstatus/types as status_types
|
||||||
|
import ../../status/libstatus/settings as status_settings
|
||||||
import ../../status/[chat, contacts, status, wallet, stickers]
|
import ../../status/[chat, contacts, status, wallet, stickers]
|
||||||
import view, views/channels_list, views/message_list, views/reactions, views/stickers as stickers_view
|
import view, views/channels_list, views/message_list, views/reactions, views/stickers as stickers_view
|
||||||
import ../../eventemitter
|
import ../../eventemitter
|
||||||
|
@ -34,8 +35,11 @@ proc init*(self: ChatController) =
|
||||||
self.handleChatEvents()
|
self.handleChatEvents()
|
||||||
self.handleSignals()
|
self.handleSignals()
|
||||||
|
|
||||||
|
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||||
|
|
||||||
|
self.view.pubKey = pubKey
|
||||||
self.status.mailservers.init()
|
self.status.mailservers.init()
|
||||||
self.status.chat.init()
|
self.status.chat.init(pubKey)
|
||||||
self.status.stickers.init()
|
self.status.stickers.init()
|
||||||
self.view.reactions.init()
|
self.view.reactions.init()
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ QtObject:
|
||||||
unreadMessageCnt: int
|
unreadMessageCnt: int
|
||||||
oldestMessageTimestamp: int64
|
oldestMessageTimestamp: int64
|
||||||
loadingMessages: bool
|
loadingMessages: bool
|
||||||
|
pubKey*: string
|
||||||
|
|
||||||
proc setup(self: ChatsView) = self.QAbstractListModel.setup
|
proc setup(self: ChatsView) = self.QAbstractListModel.setup
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ QtObject:
|
||||||
proc plainText(self: ChatsView, input: string): string {.slot.} =
|
proc plainText(self: ChatsView, input: string): string {.slot.} =
|
||||||
result = plain_text(input)
|
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 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 ensPattern = re(r"(@\w+(?=(\.stateofus)?\.eth))", flags = {reStudy, reIgnoreCase})
|
||||||
let namePattern = re(r"(@\w+)", 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))
|
var m = self.replaceMentionsWithPubKeys(aliasMentions, contacts, message, (c => c.alias))
|
||||||
m = self.replaceMentionsWithPubKeys(ensMentions, contacts, m, (c => c.ensName))
|
m = self.replaceMentionsWithPubKeys(ensMentions, contacts, m, (c => c.ensName))
|
||||||
m = self.replaceMentionsWithPubKeys(nameMentions, contacts, m, (c => c.ensName.split(".")[0]))
|
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.} =
|
proc verifyMessageSent*(self: ChatsView, data: string) {.slot.} =
|
||||||
let messageData = data.parseJson
|
let messageData = data.parseJson
|
||||||
|
@ -148,12 +155,18 @@ QtObject:
|
||||||
self.status.chat.resendMessage(messageId)
|
self.status.chat.resendMessage(messageId)
|
||||||
self.messageList[chatId].resetTimeOut(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 = ""
|
result = ""
|
||||||
try:
|
try:
|
||||||
var image = image_utils.formatImagePath(imagePath)
|
var image = image_utils.formatImagePath(imagePath)
|
||||||
let tmpImagePath = image_resizer(image, 2000, TMPDIR)
|
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)
|
removeFile(tmpImagePath)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error sending the image", msg = e.msg
|
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.contacts[c.id] = c
|
||||||
self.events.emit("chatUpdate", ChatUpdateArgs(contacts: contacts))
|
self.events.emit("chatUpdate", ChatUpdateArgs(contacts: contacts))
|
||||||
|
|
||||||
proc init*(self: ChatModel) =
|
proc init*(self: ChatModel, pubKey: string) =
|
||||||
let chatList = status_chat.loadChats()
|
var chatList = status_chat.loadChats()
|
||||||
|
|
||||||
var filters:seq[JsonNode] = @[]
|
var filters:seq[JsonNode] = @[]
|
||||||
for chat in chatList:
|
for chat in chatList:
|
||||||
|
|
Loading…
Reference in New Issue