fix(@desktop/chat): add message sent and delivered handlers
Fixes #7367
This commit is contained in:
parent
fc3daa1451
commit
06b6b9258b
|
@ -30,6 +30,16 @@ type MessageSignal* = ref object of Signal
|
||||||
clearedHistories*: seq[ClearedHistoryDto]
|
clearedHistories*: seq[ClearedHistoryDto]
|
||||||
verificationRequests*: seq[VerificationRequest]
|
verificationRequests*: seq[VerificationRequest]
|
||||||
|
|
||||||
|
type MessageDeliveredSignal* = ref object of Signal
|
||||||
|
chatId*: string
|
||||||
|
messageId*: string
|
||||||
|
|
||||||
|
proc fromEvent*(T: type MessageDeliveredSignal, event: JsonNode): MessageDeliveredSignal =
|
||||||
|
result = MessageDeliveredSignal()
|
||||||
|
result.signalType = SignalType.MessageDelivered
|
||||||
|
result.chatId = event["event"]["chatID"].getStr
|
||||||
|
result.messageId = event["event"]["messageID"].getStr
|
||||||
|
|
||||||
proc fromEvent*(T: type MessageSignal, event: JsonNode): MessageSignal =
|
proc fromEvent*(T: type MessageSignal, event: JsonNode): MessageSignal =
|
||||||
var signal:MessageSignal = MessageSignal()
|
var signal:MessageSignal = MessageSignal()
|
||||||
signal.messages = @[]
|
signal.messages = @[]
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
type SignalType* {.pure.} = enum
|
type SignalType* {.pure.} = enum
|
||||||
Message = "messages.new"
|
Message = "messages.new"
|
||||||
|
MessageDelivered = "message.delivered"
|
||||||
Wallet = "wallet"
|
Wallet = "wallet"
|
||||||
NodeReady = "node.ready"
|
NodeReady = "node.ready"
|
||||||
NodeCrashed = "node.crashed"
|
NodeCrashed = "node.crashed"
|
||||||
|
|
|
@ -65,6 +65,7 @@ QtObject:
|
||||||
|
|
||||||
result = case signalType:
|
result = case signalType:
|
||||||
of SignalType.Message: MessageSignal.fromEvent(jsonSignal)
|
of SignalType.Message: MessageSignal.fromEvent(jsonSignal)
|
||||||
|
of SignalType.MessageDelivered: MessageDeliveredSignal.fromEvent(jsonSignal)
|
||||||
of SignalType.EnvelopeSent: EnvelopeSentSignal.fromEvent(jsonSignal)
|
of SignalType.EnvelopeSent: EnvelopeSentSignal.fromEvent(jsonSignal)
|
||||||
of SignalType.EnvelopeExpired: EnvelopeExpiredSignal.fromEvent(jsonSignal)
|
of SignalType.EnvelopeExpired: EnvelopeExpiredSignal.fromEvent(jsonSignal)
|
||||||
of SignalType.WhisperFilterAdded: WhisperFilterSignal.fromEvent(jsonSignal)
|
of SignalType.WhisperFilterAdded: WhisperFilterSignal.fromEvent(jsonSignal)
|
||||||
|
|
|
@ -77,6 +77,16 @@ proc init*(self: Controller) =
|
||||||
return
|
return
|
||||||
self.delegate.onSendingMessageError()
|
self.delegate.onSendingMessageError()
|
||||||
|
|
||||||
|
self.events.on(SIGNAL_ENVELOPE_SENT) do(e:Args):
|
||||||
|
let args = EnvelopeSentArgs(e)
|
||||||
|
self.delegate.onEnvelopeSent(args.messagesIds)
|
||||||
|
|
||||||
|
self.events.on(SIGNAL_MESSAGE_DELIVERED) do(e:Args):
|
||||||
|
let args = MessageDeliveredArgs(e)
|
||||||
|
if(self.chatId != args.chatId):
|
||||||
|
return
|
||||||
|
self.delegate.onMessageDelivered(args.messageId)
|
||||||
|
|
||||||
self.events.on(SIGNAL_MESSAGE_PINNED) do(e:Args):
|
self.events.on(SIGNAL_MESSAGE_PINNED) do(e:Args):
|
||||||
let args = MessagePinUnpinArgs(e)
|
let args = MessagePinUnpinArgs(e)
|
||||||
if(self.chatId != args.chatId):
|
if(self.chatId != args.chatId):
|
||||||
|
|
|
@ -53,6 +53,12 @@ method onSendingMessageSuccess*(self: AccessInterface, message: MessageDto) {.ba
|
||||||
method onSendingMessageError*(self: AccessInterface) {.base.} =
|
method onSendingMessageError*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method onEnvelopeSent*(self: AccessInterface, messagesIds: seq[string]) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method onMessageDelivered*(self: AccessInterface, messageId: string) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method updateContactDetails*(self: AccessInterface, contactId: string) {.base.} =
|
method updateContactDetails*(self: AccessInterface, contactId: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -268,6 +268,7 @@ method messageAdded*(self: Module, message: MessageDto) =
|
||||||
let index = self.view.model().findIndexForMessageId(message.replace)
|
let index = self.view.model().findIndexForMessageId(message.replace)
|
||||||
if(index != -1):
|
if(index != -1):
|
||||||
self.view.model().removeItem(message.replace)
|
self.view.model().removeItem(message.replace)
|
||||||
|
|
||||||
var item = initItem(
|
var item = initItem(
|
||||||
message.id,
|
message.id,
|
||||||
message.communityId,
|
message.communityId,
|
||||||
|
@ -312,6 +313,13 @@ method onSendingMessageSuccess*(self: Module, message: MessageDto) =
|
||||||
method onSendingMessageError*(self: Module) =
|
method onSendingMessageError*(self: Module) =
|
||||||
self.view.emitSendingMessageErrorSignal()
|
self.view.emitSendingMessageErrorSignal()
|
||||||
|
|
||||||
|
method onEnvelopeSent*(self: Module, messagesIds: seq[string]) =
|
||||||
|
for messageId in messagesIds:
|
||||||
|
self.view.model().itemSent(messageId)
|
||||||
|
|
||||||
|
method onMessageDelivered*(self: Module, messageId: string) =
|
||||||
|
self.view.model().itemDelivered(messageId)
|
||||||
|
|
||||||
method loadMoreMessages*(self: Module) =
|
method loadMoreMessages*(self: Module) =
|
||||||
self.controller.loadMoreMessages()
|
self.controller.loadMoreMessages()
|
||||||
|
|
||||||
|
|
|
@ -209,6 +209,9 @@ proc `senderEnsVerified=`*(self: Item, value: bool) {.inline.} =
|
||||||
proc outgoingStatus*(self: Item): string {.inline.} =
|
proc outgoingStatus*(self: Item): string {.inline.} =
|
||||||
self.outgoingStatus
|
self.outgoingStatus
|
||||||
|
|
||||||
|
proc `outgoingStatus=`*(self: Item, value: string) {.inline.} =
|
||||||
|
self.outgoingStatus = value
|
||||||
|
|
||||||
proc messageText*(self: Item): string {.inline.} =
|
proc messageText*(self: Item): string {.inline.} =
|
||||||
self.messageText
|
self.messageText
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ import NimQml, Tables, json, strutils, strformat
|
||||||
|
|
||||||
import message_item, message_reaction_item, message_transaction_parameters_item
|
import message_item, message_reaction_item, message_transaction_parameters_item
|
||||||
|
|
||||||
|
import ../../../app_service/service/message/dto/message# as message_dto
|
||||||
|
|
||||||
type
|
type
|
||||||
ModelRole {.pure.} = enum
|
ModelRole {.pure.} = enum
|
||||||
Id = UserRole + 1
|
Id = UserRole + 1
|
||||||
|
@ -352,6 +354,20 @@ QtObject:
|
||||||
|
|
||||||
return self.items[ind]
|
return self.items[ind]
|
||||||
|
|
||||||
|
proc setOutgoingStatus(self: Model, messageId: string, status: string) =
|
||||||
|
let ind = self.findIndexForMessageId(messageId)
|
||||||
|
if(ind == -1):
|
||||||
|
return
|
||||||
|
self.items[ind].outgoingStatus = status
|
||||||
|
let index = self.createIndex(ind, 0, nil)
|
||||||
|
self.dataChanged(index, index, @[ModelRole.OutgoingStatus.int])
|
||||||
|
|
||||||
|
proc itemSent*(self: Model, messageId: string) =
|
||||||
|
self.setOutgoingStatus(messageId, PARSED_TEXT_OUTGOING_STATUS_SENT)
|
||||||
|
|
||||||
|
proc itemDelivered*(self: Model, messageId: string) =
|
||||||
|
self.setOutgoingStatus(messageId, PARSED_TEXT_OUTGOING_STATUS_DELIVERED)
|
||||||
|
|
||||||
proc addReaction*(self: Model, messageId: string, emojiId: EmojiId, didIReactWithThisEmoji: bool,
|
proc addReaction*(self: Model, messageId: string, emojiId: EmojiId, didIReactWithThisEmoji: bool,
|
||||||
userPublicKey: string, userDisplayName: string, reactionId: string) =
|
userPublicKey: string, userDisplayName: string, reactionId: string) =
|
||||||
let ind = self.findIndexForMessageId(messageId)
|
let ind = self.findIndexForMessageId(messageId)
|
||||||
|
|
|
@ -17,6 +17,10 @@ const PARSED_TEXT_CHILD_TYPE_STATUS_TAG* = "status-tag"
|
||||||
const PARSED_TEXT_CHILD_TYPE_DEL* = "del"
|
const PARSED_TEXT_CHILD_TYPE_DEL* = "del"
|
||||||
const PARSED_TEXT_CHILD_TYPE_LINK* = "link"
|
const PARSED_TEXT_CHILD_TYPE_LINK* = "link"
|
||||||
|
|
||||||
|
const PARSED_TEXT_OUTGOING_STATUS_SENDING* = "sending"
|
||||||
|
const PARSED_TEXT_OUTGOING_STATUS_SENT* = "sent"
|
||||||
|
const PARSED_TEXT_OUTGOING_STATUS_DELIVERED* = "delivered"
|
||||||
|
|
||||||
type ParsedText* = object
|
type ParsedText* = object
|
||||||
`type`*: string
|
`type`*: string
|
||||||
literal*: string
|
literal*: string
|
||||||
|
|
|
@ -48,7 +48,9 @@ const SIGNAL_MESSAGE_REACTION_ADDED* = "messageReactionAdded"
|
||||||
const SIGNAL_MESSAGE_REACTION_REMOVED* = "messageReactionRemoved"
|
const SIGNAL_MESSAGE_REACTION_REMOVED* = "messageReactionRemoved"
|
||||||
const SIGNAL_MESSAGE_REACTION_FROM_OTHERS* = "messageReactionFromOthers"
|
const SIGNAL_MESSAGE_REACTION_FROM_OTHERS* = "messageReactionFromOthers"
|
||||||
const SIGNAL_MESSAGE_DELETION* = "messageDeleted"
|
const SIGNAL_MESSAGE_DELETION* = "messageDeleted"
|
||||||
|
const SIGNAL_MESSAGE_DELIVERED* = "messageDelivered"
|
||||||
const SIGNAL_MESSAGE_EDITED* = "messageEdited"
|
const SIGNAL_MESSAGE_EDITED* = "messageEdited"
|
||||||
|
const SIGNAL_ENVELOPE_SENT* = "envelopeSent"
|
||||||
const SIGNAL_MESSAGE_LINK_PREVIEW_DATA_LOADED* = "messageLinkPreviewDataLoaded"
|
const SIGNAL_MESSAGE_LINK_PREVIEW_DATA_LOADED* = "messageLinkPreviewDataLoaded"
|
||||||
const SIGNAL_MENTIONED_IN_EDITED_MESSAGE* = "mentionedInEditedMessage"
|
const SIGNAL_MENTIONED_IN_EDITED_MESSAGE* = "mentionedInEditedMessage"
|
||||||
const SIGNAL_RELOAD_MESSAGES* = "reloadMessages"
|
const SIGNAL_RELOAD_MESSAGES* = "reloadMessages"
|
||||||
|
@ -92,6 +94,13 @@ type
|
||||||
chatId*: string
|
chatId*: string
|
||||||
messageId*: string
|
messageId*: string
|
||||||
|
|
||||||
|
MessageDeliveredArgs* = ref object of Args
|
||||||
|
chatId*: string
|
||||||
|
messageId*: string
|
||||||
|
|
||||||
|
EnvelopeSentArgs* = ref object of Args
|
||||||
|
messagesIds*: seq[string]
|
||||||
|
|
||||||
MessageEditedArgs* = ref object of Args
|
MessageEditedArgs* = ref object of Args
|
||||||
chatId*: string
|
chatId*: string
|
||||||
message*: MessageDto
|
message*: MessageDto
|
||||||
|
@ -261,6 +270,16 @@ QtObject:
|
||||||
self.events.emit(SIGNAL_RELOAD_MESSAGES, ReloadMessagesArgs(communityId: communityId))
|
self.events.emit(SIGNAL_RELOAD_MESSAGES, ReloadMessagesArgs(communityId: communityId))
|
||||||
|
|
||||||
proc init*(self: Service) =
|
proc init*(self: Service) =
|
||||||
|
self.events.on(SignalType.MessageDelivered.event) do(e: Args):
|
||||||
|
let receivedData = MessageDeliveredSignal(e)
|
||||||
|
let data = MessageDeliveredArgs(chatId: receivedData.chatId, messageId: receivedData.messageId)
|
||||||
|
self.events.emit(SIGNAL_MESSAGE_DELIVERED, data)
|
||||||
|
|
||||||
|
self.events.on(SignalType.EnvelopeSent.event) do(e: Args):
|
||||||
|
let receivedData = EnvelopeSentSignal(e)
|
||||||
|
let data = EnvelopeSentArgs(messagesIds: receivedData.messageIds)
|
||||||
|
self.events.emit(SIGNAL_ENVELOPE_SENT, data)
|
||||||
|
|
||||||
self.events.on(SignalType.Message.event) do(e: Args):
|
self.events.on(SignalType.Message.event) do(e: Args):
|
||||||
var receivedData = MessageSignal(e)
|
var receivedData = MessageSignal(e)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue