feat(replies): add deleted to QuotedMessage to change msg displayed

Adds `deleted` to the QuotedMessage object so that on the frontend, we can show "Delete message" only when we know the message was deleted.
Otherwise, when we don't know the quoted message, we show "Unknown message [...]"
This commit is contained in:
Jonathan Rainville 2023-01-11 16:16:35 -05:00 committed by Iuri Matias
parent 91c2e6d257
commit c3945f33c0
9 changed files with 56 additions and 14 deletions

View File

@ -103,7 +103,8 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: Ch
message.quotedMessage.`from`,
message.quotedMessage.text,
self.controller.getRenderedText( message.quotedMessage.parsedText),
message.quotedMessage.contentType
message.quotedMessage.contentType,
message.quotedMessage.deleted,
))
method convertToItems*(

View File

@ -107,7 +107,8 @@ proc createFetchMoreMessagesItem(self: Module): Item =
quotedMessageFrom = "",
quotedMessageText = "",
quotedMessageParsedText = "",
quotedMessageContentType = -1
quotedMessageContentType = -1,
quotedMessageDeleted = false,
)
proc createChatIdentifierItem(self: Module): Item =
@ -154,7 +155,8 @@ proc createChatIdentifierItem(self: Module): Item =
quotedMessageFrom = "",
quotedMessageText = "",
quotedMessageParsedText = "",
quotedMessageContentType = -1
quotedMessageContentType = -1,
quotedMessageDeleted = false,
)
proc checkIfMessageLoadedAndScrollToItIfItIs(self: Module) =
@ -240,7 +242,8 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
m.quotedMessage.`from`,
m.quotedMessage.text,
self.controller.getRenderedText(m.quotedMessage.parsedText),
m.quotedMessage.contentType
m.quotedMessage.contentType,
m.quotedMessage.deleted,
)
for r in reactions:
@ -345,7 +348,8 @@ method messageAdded*(self: Module, message: MessageDto) =
message.quotedMessage.`from`,
message.quotedMessage.text,
self.controller.getRenderedText(message.quotedMessage.parsedText),
message.quotedMessage.contentType
message.quotedMessage.contentType,
message.quotedMessage.deleted,
)
self.view.model().insertItemBasedOnClock(item)
@ -630,7 +634,8 @@ method getMessageById*(self: Module, messageId: string): message_item.Item =
m.quotedMessage.`from`,
m.quotedMessage.text,
self.controller.getRenderedText(m.quotedMessage.parsedText),
m.quotedMessage.contentType
m.quotedMessage.contentType,
m.quotedMessage.deleted,
)
return item
return nil

View File

@ -203,7 +203,8 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy:
m.quotedMessage.`from`,
m.quotedMessage.text,
self.controller.getRenderedText(m.quotedMessage.parsedText),
m.quotedMessage.contentType
m.quotedMessage.contentType,
m.quotedMessage.deleted,
)
item.pinned = true
item.pinnedBy = actionInitiatedBy

View File

@ -48,6 +48,7 @@ type
quotedMessageText: string
quotedMessageParsedText: string
quotedMessageContentType: int
quotedMessageDeleted: bool
# This is only used to update the author's details when author's details change
quotedMessageFromIterator: int
@ -84,7 +85,8 @@ proc initItem*(
quotedMessageFrom: string,
quotedMessageText: string,
quotedMessageParsedText: string,
quotedMessageContentType: int
quotedMessageContentType: int,
quotedMessageDeleted: bool,
): Item =
result = Item()
result.id = id
@ -126,6 +128,7 @@ proc initItem*(
result.quotedMessageText = quotedMessageText
result.quotedMessageParsedText = quotedMessageParsedText
result.quotedMessageContentType = quotedMessageContentType
result.quotedMessageDeleted = quotedMessageDeleted
result.quotedMessageFromIterator = 0
if ContentType.DiscordMessage == contentType:
@ -180,7 +183,8 @@ proc initNewMessagesMarkerItem*(clock, timestamp: int64): Item =
quotedMessageFrom = "",
quotedMessageText = "",
quotedMessageParsedText = "",
quotedMessageContentType = -1
quotedMessageContentType = -1,
quotedMessageDeleted = false,
)
proc `$`*(self: Item): string =
@ -403,6 +407,7 @@ proc toJsonNode*(self: Item): JsonNode =
"quotedMessageText": self.quotedMessageText,
"quotedMessageParsedText": self.quotedMessageParsedText,
"quotedMessageContentType": self.quotedMessageContentType,
"quotedMessageDeleted": self.quotedMessageDeleted,
}
proc editMode*(self: Item): bool {.inline.} =
@ -455,6 +460,11 @@ proc quotedMessageContentType*(self: Item): int {.inline.} =
proc `quotedMessageContentType=`*(self: Item, value: int) {.inline.} =
self.quotedMessageContentType = value
proc quotedMessageDeleted*(self: Item): bool {.inline.} =
self.quotedMessageDeleted
proc `quotedMessageDeleted=`*(self: Item, value: bool) {.inline.} =
self.quotedMessageDeleted = value
proc quotedMessageFromIterator*(self: Item): int {.inline.} =
self.quotedMessageFromIterator
proc `quotedMessageFromIterator=`*(self: Item, value: int) {.inline.} =

View File

@ -42,6 +42,10 @@ QtObject:
QtProperty[int] quotedMessageContentType:
read = quotedMessageContentType
proc quotedMessageDeleted*(self: MessageItem): bool {.slot.} = result = ?.self.messageItem.quotedMessageDeleted
QtProperty[bool] quotedMessageDeleted:
read = quotedMessageDeleted
proc senderId*(self: MessageItem): string {.slot.} = result = ?.self.messageItem.senderId
QtProperty[string] senderId:
read = senderId

View File

@ -48,6 +48,7 @@ type
QuotedMessageText
QuotedMessageParsedText
QuotedMessageContentType
QuotedMessageDeleted
QuotedMessageFromIterator
QtObject:
@ -137,7 +138,8 @@ QtObject:
ModelRole.QuotedMessageFromIterator.int: "quotedMessageFromIterator",
ModelRole.QuotedMessageText.int: "quotedMessageText",
ModelRole.QuotedMessageParsedText.int: "quotedMessageParsedText",
ModelRole.QuotedMessageContentType.int: "quotedMessageContentType"
ModelRole.QuotedMessageContentType.int: "quotedMessageContentType",
ModelRole.QuotedMessageDeleted.int: "quotedMessageDeleted",
}.toTable
method data(self: Model, index: QModelIndex, role: int): QVariant =
@ -199,6 +201,8 @@ QtObject:
result = newQVariant(item.quotedMessageParsedText)
of ModelRole.QuotedMessageContentType:
result = newQVariant(item.quotedMessageContentType)
of ModelRole.QuotedMessageDeleted:
result = newQVariant(item.quotedMessageDeleted)
of ModelRole.MessageText:
result = newQVariant(item.messageText)
of ModelRole.MessageImage:
@ -299,7 +303,7 @@ QtObject:
for item in items:
self.insertItemBasedOnClock(item)
# Replied message was deleted
proc updateMessagesWithResponseTo(self: Model, messageId: string) =
for i in 0 ..< self.items.len:
if(self.items[i].responseToMessageWithId == messageId):
@ -308,7 +312,13 @@ QtObject:
item.quotedMessageText = ""
item.quotedMessageParsedText = ""
item.quotedMessageFrom = ""
self.dataChanged(ind, ind, @[ModelRole.QuotedMessageFrom.int, ModelRole.QuotedMessageParsedText.int, ModelRole.QuotedMessageContentType.int])
item.quotedMessageDeleted = true
self.dataChanged(ind, ind, @[
ModelRole.QuotedMessageFrom.int,
ModelRole.QuotedMessageParsedText.int,
ModelRole.QuotedMessageContentType.int,
ModelRole.QuotedMessageDeleted.int,
])
proc removeItem*(self: Model, messageId: string) =
let ind = self.findIndexForMessageId(messageId)

View File

@ -36,6 +36,7 @@ type QuotedMessage* = object
text*: string
parsedText*: seq[ParsedText]
contentType*: int
deleted*: bool
type DiscordMessageAttachment* = object
id*: string
@ -165,6 +166,7 @@ proc toQuotedMessage*(jsonObj: JsonNode): QuotedMessage =
discard jsonObj.getProp("from", result.`from`)
discard jsonObj.getProp("text", result.text)
discard jsonObj.getProp("contentType", result.contentType)
discard jsonObj.getProp("deleted", result.deleted)
var parsedTextArr: JsonNode
if(jsonObj.getProp("parsedText", parsedTextArr) and parsedTextArr.kind == JArray):

View File

@ -271,6 +271,7 @@ Item {
quotedMessageFrom: model.quotedMessageFrom
quotedMessageContentType: model.quotedMessageContentType
quotedMessageFromIterator: model.quotedMessageFromIterator
quotedMessageDeleted: model.quotedMessageDeleted
gapFrom: model.gapFrom
gapTo: model.gapTo

View File

@ -65,6 +65,7 @@ Loader {
property string quotedMessageFrom: ""
property int quotedMessageContentType: Constants.messageContentType.messageType
property int quotedMessageFromIterator: -1
property bool quotedMessageDeleted: false
property var quotedMessageAuthorDetails: quotedMessageFromIterator >= 0 && Utils.getContactDetailsAsJson(quotedMessageFrom, false)
// External behavior changers
@ -609,8 +610,15 @@ Loader {
}
replyDetails: StatusMessageDetails {
messageText: root.quotedMessageText ? root.quotedMessageText
: qsTr("Message deleted")
messageText: {
if (root.quotedMessageDeleted) {
return qsTr("Message deleted")
}
if (!root.quotedMessageText) {
return qsTr("Unknown message. Try fetching more messages")
}
return root.quotedMessageText
}
contentType: delegate.convertContentType(root.quotedMessageContentType)
messageContent: {
if (contentType !== StatusMessage.ContentType.Sticker && contentType !== StatusMessage.ContentType.Image) {