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:
parent
91c2e6d257
commit
c3945f33c0
|
@ -103,7 +103,8 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: Ch
|
||||||
message.quotedMessage.`from`,
|
message.quotedMessage.`from`,
|
||||||
message.quotedMessage.text,
|
message.quotedMessage.text,
|
||||||
self.controller.getRenderedText( message.quotedMessage.parsedText),
|
self.controller.getRenderedText( message.quotedMessage.parsedText),
|
||||||
message.quotedMessage.contentType
|
message.quotedMessage.contentType,
|
||||||
|
message.quotedMessage.deleted,
|
||||||
))
|
))
|
||||||
|
|
||||||
method convertToItems*(
|
method convertToItems*(
|
||||||
|
|
|
@ -107,7 +107,8 @@ proc createFetchMoreMessagesItem(self: Module): Item =
|
||||||
quotedMessageFrom = "",
|
quotedMessageFrom = "",
|
||||||
quotedMessageText = "",
|
quotedMessageText = "",
|
||||||
quotedMessageParsedText = "",
|
quotedMessageParsedText = "",
|
||||||
quotedMessageContentType = -1
|
quotedMessageContentType = -1,
|
||||||
|
quotedMessageDeleted = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
proc createChatIdentifierItem(self: Module): Item =
|
proc createChatIdentifierItem(self: Module): Item =
|
||||||
|
@ -154,7 +155,8 @@ proc createChatIdentifierItem(self: Module): Item =
|
||||||
quotedMessageFrom = "",
|
quotedMessageFrom = "",
|
||||||
quotedMessageText = "",
|
quotedMessageText = "",
|
||||||
quotedMessageParsedText = "",
|
quotedMessageParsedText = "",
|
||||||
quotedMessageContentType = -1
|
quotedMessageContentType = -1,
|
||||||
|
quotedMessageDeleted = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
proc checkIfMessageLoadedAndScrollToItIfItIs(self: Module) =
|
proc checkIfMessageLoadedAndScrollToItIfItIs(self: Module) =
|
||||||
|
@ -240,7 +242,8 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
|
||||||
m.quotedMessage.`from`,
|
m.quotedMessage.`from`,
|
||||||
m.quotedMessage.text,
|
m.quotedMessage.text,
|
||||||
self.controller.getRenderedText(m.quotedMessage.parsedText),
|
self.controller.getRenderedText(m.quotedMessage.parsedText),
|
||||||
m.quotedMessage.contentType
|
m.quotedMessage.contentType,
|
||||||
|
m.quotedMessage.deleted,
|
||||||
)
|
)
|
||||||
|
|
||||||
for r in reactions:
|
for r in reactions:
|
||||||
|
@ -345,7 +348,8 @@ method messageAdded*(self: Module, message: MessageDto) =
|
||||||
message.quotedMessage.`from`,
|
message.quotedMessage.`from`,
|
||||||
message.quotedMessage.text,
|
message.quotedMessage.text,
|
||||||
self.controller.getRenderedText(message.quotedMessage.parsedText),
|
self.controller.getRenderedText(message.quotedMessage.parsedText),
|
||||||
message.quotedMessage.contentType
|
message.quotedMessage.contentType,
|
||||||
|
message.quotedMessage.deleted,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.view.model().insertItemBasedOnClock(item)
|
self.view.model().insertItemBasedOnClock(item)
|
||||||
|
@ -630,7 +634,8 @@ method getMessageById*(self: Module, messageId: string): message_item.Item =
|
||||||
m.quotedMessage.`from`,
|
m.quotedMessage.`from`,
|
||||||
m.quotedMessage.text,
|
m.quotedMessage.text,
|
||||||
self.controller.getRenderedText(m.quotedMessage.parsedText),
|
self.controller.getRenderedText(m.quotedMessage.parsedText),
|
||||||
m.quotedMessage.contentType
|
m.quotedMessage.contentType,
|
||||||
|
m.quotedMessage.deleted,
|
||||||
)
|
)
|
||||||
return item
|
return item
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -203,7 +203,8 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy:
|
||||||
m.quotedMessage.`from`,
|
m.quotedMessage.`from`,
|
||||||
m.quotedMessage.text,
|
m.quotedMessage.text,
|
||||||
self.controller.getRenderedText(m.quotedMessage.parsedText),
|
self.controller.getRenderedText(m.quotedMessage.parsedText),
|
||||||
m.quotedMessage.contentType
|
m.quotedMessage.contentType,
|
||||||
|
m.quotedMessage.deleted,
|
||||||
)
|
)
|
||||||
item.pinned = true
|
item.pinned = true
|
||||||
item.pinnedBy = actionInitiatedBy
|
item.pinnedBy = actionInitiatedBy
|
||||||
|
|
|
@ -48,6 +48,7 @@ type
|
||||||
quotedMessageText: string
|
quotedMessageText: string
|
||||||
quotedMessageParsedText: string
|
quotedMessageParsedText: string
|
||||||
quotedMessageContentType: int
|
quotedMessageContentType: int
|
||||||
|
quotedMessageDeleted: bool
|
||||||
# This is only used to update the author's details when author's details change
|
# This is only used to update the author's details when author's details change
|
||||||
quotedMessageFromIterator: int
|
quotedMessageFromIterator: int
|
||||||
|
|
||||||
|
@ -84,7 +85,8 @@ proc initItem*(
|
||||||
quotedMessageFrom: string,
|
quotedMessageFrom: string,
|
||||||
quotedMessageText: string,
|
quotedMessageText: string,
|
||||||
quotedMessageParsedText: string,
|
quotedMessageParsedText: string,
|
||||||
quotedMessageContentType: int
|
quotedMessageContentType: int,
|
||||||
|
quotedMessageDeleted: bool,
|
||||||
): Item =
|
): Item =
|
||||||
result = Item()
|
result = Item()
|
||||||
result.id = id
|
result.id = id
|
||||||
|
@ -126,6 +128,7 @@ proc initItem*(
|
||||||
result.quotedMessageText = quotedMessageText
|
result.quotedMessageText = quotedMessageText
|
||||||
result.quotedMessageParsedText = quotedMessageParsedText
|
result.quotedMessageParsedText = quotedMessageParsedText
|
||||||
result.quotedMessageContentType = quotedMessageContentType
|
result.quotedMessageContentType = quotedMessageContentType
|
||||||
|
result.quotedMessageDeleted = quotedMessageDeleted
|
||||||
result.quotedMessageFromIterator = 0
|
result.quotedMessageFromIterator = 0
|
||||||
|
|
||||||
if ContentType.DiscordMessage == contentType:
|
if ContentType.DiscordMessage == contentType:
|
||||||
|
@ -180,7 +183,8 @@ proc initNewMessagesMarkerItem*(clock, timestamp: int64): Item =
|
||||||
quotedMessageFrom = "",
|
quotedMessageFrom = "",
|
||||||
quotedMessageText = "",
|
quotedMessageText = "",
|
||||||
quotedMessageParsedText = "",
|
quotedMessageParsedText = "",
|
||||||
quotedMessageContentType = -1
|
quotedMessageContentType = -1,
|
||||||
|
quotedMessageDeleted = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
proc `$`*(self: Item): string =
|
proc `$`*(self: Item): string =
|
||||||
|
@ -403,6 +407,7 @@ proc toJsonNode*(self: Item): JsonNode =
|
||||||
"quotedMessageText": self.quotedMessageText,
|
"quotedMessageText": self.quotedMessageText,
|
||||||
"quotedMessageParsedText": self.quotedMessageParsedText,
|
"quotedMessageParsedText": self.quotedMessageParsedText,
|
||||||
"quotedMessageContentType": self.quotedMessageContentType,
|
"quotedMessageContentType": self.quotedMessageContentType,
|
||||||
|
"quotedMessageDeleted": self.quotedMessageDeleted,
|
||||||
}
|
}
|
||||||
|
|
||||||
proc editMode*(self: Item): bool {.inline.} =
|
proc editMode*(self: Item): bool {.inline.} =
|
||||||
|
@ -455,6 +460,11 @@ proc quotedMessageContentType*(self: Item): int {.inline.} =
|
||||||
proc `quotedMessageContentType=`*(self: Item, value: int) {.inline.} =
|
proc `quotedMessageContentType=`*(self: Item, value: int) {.inline.} =
|
||||||
self.quotedMessageContentType = value
|
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.} =
|
proc quotedMessageFromIterator*(self: Item): int {.inline.} =
|
||||||
self.quotedMessageFromIterator
|
self.quotedMessageFromIterator
|
||||||
proc `quotedMessageFromIterator=`*(self: Item, value: int) {.inline.} =
|
proc `quotedMessageFromIterator=`*(self: Item, value: int) {.inline.} =
|
||||||
|
|
|
@ -42,6 +42,10 @@ QtObject:
|
||||||
QtProperty[int] quotedMessageContentType:
|
QtProperty[int] quotedMessageContentType:
|
||||||
read = 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
|
proc senderId*(self: MessageItem): string {.slot.} = result = ?.self.messageItem.senderId
|
||||||
QtProperty[string] senderId:
|
QtProperty[string] senderId:
|
||||||
read = senderId
|
read = senderId
|
||||||
|
|
|
@ -48,6 +48,7 @@ type
|
||||||
QuotedMessageText
|
QuotedMessageText
|
||||||
QuotedMessageParsedText
|
QuotedMessageParsedText
|
||||||
QuotedMessageContentType
|
QuotedMessageContentType
|
||||||
|
QuotedMessageDeleted
|
||||||
QuotedMessageFromIterator
|
QuotedMessageFromIterator
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
|
@ -137,7 +138,8 @@ QtObject:
|
||||||
ModelRole.QuotedMessageFromIterator.int: "quotedMessageFromIterator",
|
ModelRole.QuotedMessageFromIterator.int: "quotedMessageFromIterator",
|
||||||
ModelRole.QuotedMessageText.int: "quotedMessageText",
|
ModelRole.QuotedMessageText.int: "quotedMessageText",
|
||||||
ModelRole.QuotedMessageParsedText.int: "quotedMessageParsedText",
|
ModelRole.QuotedMessageParsedText.int: "quotedMessageParsedText",
|
||||||
ModelRole.QuotedMessageContentType.int: "quotedMessageContentType"
|
ModelRole.QuotedMessageContentType.int: "quotedMessageContentType",
|
||||||
|
ModelRole.QuotedMessageDeleted.int: "quotedMessageDeleted",
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
method data(self: Model, index: QModelIndex, role: int): QVariant =
|
method data(self: Model, index: QModelIndex, role: int): QVariant =
|
||||||
|
@ -199,6 +201,8 @@ QtObject:
|
||||||
result = newQVariant(item.quotedMessageParsedText)
|
result = newQVariant(item.quotedMessageParsedText)
|
||||||
of ModelRole.QuotedMessageContentType:
|
of ModelRole.QuotedMessageContentType:
|
||||||
result = newQVariant(item.quotedMessageContentType)
|
result = newQVariant(item.quotedMessageContentType)
|
||||||
|
of ModelRole.QuotedMessageDeleted:
|
||||||
|
result = newQVariant(item.quotedMessageDeleted)
|
||||||
of ModelRole.MessageText:
|
of ModelRole.MessageText:
|
||||||
result = newQVariant(item.messageText)
|
result = newQVariant(item.messageText)
|
||||||
of ModelRole.MessageImage:
|
of ModelRole.MessageImage:
|
||||||
|
@ -299,7 +303,7 @@ QtObject:
|
||||||
for item in items:
|
for item in items:
|
||||||
self.insertItemBasedOnClock(item)
|
self.insertItemBasedOnClock(item)
|
||||||
|
|
||||||
|
# Replied message was deleted
|
||||||
proc updateMessagesWithResponseTo(self: Model, messageId: string) =
|
proc updateMessagesWithResponseTo(self: Model, messageId: string) =
|
||||||
for i in 0 ..< self.items.len:
|
for i in 0 ..< self.items.len:
|
||||||
if(self.items[i].responseToMessageWithId == messageId):
|
if(self.items[i].responseToMessageWithId == messageId):
|
||||||
|
@ -308,7 +312,13 @@ QtObject:
|
||||||
item.quotedMessageText = ""
|
item.quotedMessageText = ""
|
||||||
item.quotedMessageParsedText = ""
|
item.quotedMessageParsedText = ""
|
||||||
item.quotedMessageFrom = ""
|
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) =
|
proc removeItem*(self: Model, messageId: string) =
|
||||||
let ind = self.findIndexForMessageId(messageId)
|
let ind = self.findIndexForMessageId(messageId)
|
||||||
|
|
|
@ -36,6 +36,7 @@ type QuotedMessage* = object
|
||||||
text*: string
|
text*: string
|
||||||
parsedText*: seq[ParsedText]
|
parsedText*: seq[ParsedText]
|
||||||
contentType*: int
|
contentType*: int
|
||||||
|
deleted*: bool
|
||||||
|
|
||||||
type DiscordMessageAttachment* = object
|
type DiscordMessageAttachment* = object
|
||||||
id*: string
|
id*: string
|
||||||
|
@ -165,6 +166,7 @@ proc toQuotedMessage*(jsonObj: JsonNode): QuotedMessage =
|
||||||
discard jsonObj.getProp("from", result.`from`)
|
discard jsonObj.getProp("from", result.`from`)
|
||||||
discard jsonObj.getProp("text", result.text)
|
discard jsonObj.getProp("text", result.text)
|
||||||
discard jsonObj.getProp("contentType", result.contentType)
|
discard jsonObj.getProp("contentType", result.contentType)
|
||||||
|
discard jsonObj.getProp("deleted", result.deleted)
|
||||||
|
|
||||||
var parsedTextArr: JsonNode
|
var parsedTextArr: JsonNode
|
||||||
if(jsonObj.getProp("parsedText", parsedTextArr) and parsedTextArr.kind == JArray):
|
if(jsonObj.getProp("parsedText", parsedTextArr) and parsedTextArr.kind == JArray):
|
||||||
|
|
|
@ -271,6 +271,7 @@ Item {
|
||||||
quotedMessageFrom: model.quotedMessageFrom
|
quotedMessageFrom: model.quotedMessageFrom
|
||||||
quotedMessageContentType: model.quotedMessageContentType
|
quotedMessageContentType: model.quotedMessageContentType
|
||||||
quotedMessageFromIterator: model.quotedMessageFromIterator
|
quotedMessageFromIterator: model.quotedMessageFromIterator
|
||||||
|
quotedMessageDeleted: model.quotedMessageDeleted
|
||||||
|
|
||||||
gapFrom: model.gapFrom
|
gapFrom: model.gapFrom
|
||||||
gapTo: model.gapTo
|
gapTo: model.gapTo
|
||||||
|
|
|
@ -65,6 +65,7 @@ Loader {
|
||||||
property string quotedMessageFrom: ""
|
property string quotedMessageFrom: ""
|
||||||
property int quotedMessageContentType: Constants.messageContentType.messageType
|
property int quotedMessageContentType: Constants.messageContentType.messageType
|
||||||
property int quotedMessageFromIterator: -1
|
property int quotedMessageFromIterator: -1
|
||||||
|
property bool quotedMessageDeleted: false
|
||||||
property var quotedMessageAuthorDetails: quotedMessageFromIterator >= 0 && Utils.getContactDetailsAsJson(quotedMessageFrom, false)
|
property var quotedMessageAuthorDetails: quotedMessageFromIterator >= 0 && Utils.getContactDetailsAsJson(quotedMessageFrom, false)
|
||||||
|
|
||||||
// External behavior changers
|
// External behavior changers
|
||||||
|
@ -609,8 +610,15 @@ Loader {
|
||||||
}
|
}
|
||||||
|
|
||||||
replyDetails: StatusMessageDetails {
|
replyDetails: StatusMessageDetails {
|
||||||
messageText: root.quotedMessageText ? root.quotedMessageText
|
messageText: {
|
||||||
: qsTr("Message deleted")
|
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)
|
contentType: delegate.convertContentType(root.quotedMessageContentType)
|
||||||
messageContent: {
|
messageContent: {
|
||||||
if (contentType !== StatusMessage.ContentType.Sticker && contentType !== StatusMessage.ContentType.Image) {
|
if (contentType !== StatusMessage.ContentType.Sticker && contentType !== StatusMessage.ContentType.Image) {
|
||||||
|
|
Loading…
Reference in New Issue