fix(@desktop/chat): delete message not working

fixes #4411
This commit is contained in:
Khushboo Mehta 2022-01-13 16:14:34 +01:00 committed by Sale Djenic
parent edc7a92445
commit e757c07c96
13 changed files with 116 additions and 44 deletions

View File

@ -99,6 +99,13 @@ method init*(self: Controller) =
var args = ContactArgs(e)
self.delegate.onContactDetailsUpdated(args.contactId)
self.events.on(SIGNAL_MESSAGE_DELETION) do(e: Args):
let args = MessageDeletedArgs(e)
if(self.chatId != args.chatId):
return
# remove from pinned messages model
self.delegate.onUnpinMessage(args.messageId)
method getMyChatId*(self: Controller): string =
return self.chatId
@ -152,4 +159,4 @@ method getCurrentFleet*(self: Controller): string =
return self.settingsService.getFleetAsString()
method getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText]): string =
return self.messageService.getRenderedText(parsedTextArray)
return self.messageService.getRenderedText(parsedTextArray)

View File

@ -102,6 +102,12 @@ method init*(self: Controller) =
var args = ContactArgs(e)
self.delegate.updateContactDetails(args.contactId)
self.events.on(SIGNAL_MESSAGE_DELETION) do(e: Args):
let args = MessageDeletedArgs(e)
if(self.chatId != args.chatId):
return
self.delegate.onMessageDeleted(args.messageId)
method getMySectionId*(self: Controller): string =
return self.sectionId
@ -146,4 +152,7 @@ method getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText]): str
method getMessageDetails*(self: Controller, messageId: string):
tuple[message: MessageDto, reactions: seq[ReactionDto], error: string] =
return self.messageService.getDetailsForMessage(self.chatId, messageId)
return self.messageService.getDetailsForMessage(self.chatId, messageId)
method deleteMessage*(self: Controller, messageId: string) =
self.messageService.deleteMessage(messageId)

View File

@ -58,4 +58,7 @@ method getRenderedText*(self: AccessInterface, parsedTextArray: seq[ParsedText])
method getMessageDetails*(self: AccessInterface, messageId: string):
tuple[message: MessageDto, reactions: seq[ReactionDto], error: string] {.base.} =
raise newException(ValueError, "No implementation available")
raise newException(ValueError, "No implementation available")
method deleteMessage*(self: AccessInterface, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -213,4 +213,8 @@ method updateContactDetails*(self: Module, contactId: string) =
item.messageText = self.controller.getRenderedText(m.parsedText)
item.messageContainsMentions = m.containsContactMentions()
method deleteMessage*(self: Module, messageId: string) =
self.controller.deleteMessage(messageId)
method onMessageDeleted*(self: Module, messageId: string) =
self.view.model().removeItem(messageId)

View File

@ -20,4 +20,10 @@ method amIChatAdmin*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method getNumberOfPinnedMessages*(self: AccessInterface): int {.base.} =
raise newException(ValueError, "No implementation available")
raise newException(ValueError, "No implementation available")
method deleteMessage*(self: AccessInterface, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onMessageDeleted*(self: AccessInterface, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -105,4 +105,7 @@ QtObject:
proc sendingMessageFailed*(self: View) {.signal.}
proc emitSendingMessageErrorSignal*(self: View) =
self.sendingMessageFailed()
self.sendingMessageFailed()
proc deleteMessage*(self: View, messageId: string) {.slot.} =
self.delegate.deleteMessage(messageId)

View File

@ -187,6 +187,8 @@ QtObject:
self.countChanged()
proc appendItem*(self: Model, item: Item) =
if(self.findIndexForMessageId(item.id) != -1):
return
let parentModelIndex = newQModelIndex()
defer: parentModelIndex.delete
@ -292,4 +294,4 @@ QtObject:
if(roles.len > 0):
let index = self.createIndex(i, 0, nil)
self.dataChanged(index, index, roles)
self.dataChanged(index, index, roles)

View File

@ -30,6 +30,7 @@ const SIGNAL_SEARCH_MESSAGES_LOADED* = "new-searchMessagesLoaded"
const SIGNAL_MESSAGES_MARKED_AS_READ* = "new-messagesMarkedAsRead"
const SIGNAL_MESSAGE_REACTION_ADDED* = "new-messageReactionAdded"
const SIGNAL_MESSAGE_REACTION_REMOVED* = "new-messageReactionRemoved"
const SIGNAL_MESSAGE_DELETION* = "new-messageDeleted"
include async_tasks
@ -63,6 +64,10 @@ type
emojiId*: int
reactionId*: string
MessageDeletedArgs* = ref object of Args
chatId*: string
messageId*: string
QtObject:
type Service* = ref object of QObject
events: EventEmitter
@ -143,6 +148,12 @@ QtObject:
self.numOfPinnedMessagesPerChat[pm.chatId] = self.numOfPinnedMessagesPerChat[pm.chatId] - 1
self.events.emit(SIGNAL_MESSAGE_UNPINNED, data)
# Handling deleted messages updates
if (receivedData.deletedMessages.len > 0):
for dm in receivedData.deletedMessages:
let data = MessageDeletedArgs(chatId: dm.chatId, messageId: dm.messageId)
self.events.emit(SIGNAL_MESSAGE_DELETION, data)
proc initialMessagesFetched(self: Service, chatId: string): bool =
return self.msgCursor.hasKey(chatId)
@ -542,4 +553,30 @@ proc getRenderedText*(self: Service, parsedTextArray: seq[ParsedText]): string =
"</table>")
of PARSED_TEXT_TYPE_CODEBLOCK:
result = result & "<code>" & escape_html(parsedText.literal) & "</code>"
result = result.strip()
result = result.strip()
proc deleteMessage*(self: Service, messageId: string) =
try:
let response = status_go.deleteMessageAndSend(messageId)
var deletesMessagesObj: JsonNode
if(not response.result.getProp("removedMessages", deletesMessagesObj) or deletesMessagesObj.kind != JArray):
error "error: ", methodName="deleteMessage", errDesription = "no messages deleted or it's not an array"
return
let deletedMessagesArr = deletesMessagesObj.getElems()
if(deletedMessagesArr.len == 0): # an array is returned
error "error: ", methodName="deleteMessage", errDesription = "array has no message to delete"
return
let deletedMessageObj = deletedMessagesArr[0]
var chat_Id, message_Id: string
if not deletedMessageObj.getProp("chatId", chat_Id) or not deletedMessageObj.getProp("messageId", message_Id):
error "error: ", methodName="deleteMessage", errDesription = "there is no set chat id or message id in response"
return
let data = MessageDeletedArgs(chatId: chat_Id, messageId: message_Id)
self.events.emit(SIGNAL_MESSAGE_DELETION, data)
except Exception as e:
error "error: ", methodName="deleteMessage", errName = e.name, errDesription = e.msg

View File

@ -152,4 +152,10 @@ QtObject {
}
return tooltip
}
function deleteMessage(messageId) {
if(!messageModule)
return
messageModule.deleteMessage(messageId)
}
}

View File

@ -102,11 +102,6 @@ QtObject {
globalUtils.copyToClipboard(text)
}
function deleteMessage(messageId) {
// Not Refactored Yet
// chatsModelInst.messageView.deleteMessage(messageId);
}
function getCommunity(communityId) {
// Not Refactored Yet
// try {

View File

@ -335,6 +335,10 @@ ColumnLayout {
onOpenProfileClicked: {
Global.openProfilePopup(publicKey)
}
onDeleteMessage: {
messageStore.deleteMessage(messageId)
}
}
ColumnLayout {

View File

@ -60,6 +60,7 @@ StatusPopupMenu {
signal createOneToOneChat(string chatId, string ensName)
signal showReplyArea()
signal toggleReaction(string messageId, int emojiId)
signal deleteMessage(string messageId)
onHeightChanged: {
root.y = setYPosition()
@ -328,27 +329,11 @@ StatusPopupMenu {
text: qsTrId("delete-message")
onTriggered: {
if (!localAccountSensitiveSettings.showDeleteMessageWarning) {
// Not Refactored Yet
// return root.store.chatsModelInst.messageView.deleteMessage(messageId)
deleteMessage(messageId)
}
else {
Global.openPopup(deleteMessageConfirmationDialogComponent)
}
let confirmationDialog = openPopup(genericConfirmationDialog, {
//% "Confirm deleting this message"
title: qsTrId("confirm-deleting-this-message"),
//% "Are you sure you want to delete this message? Be aware that other clients are not guaranteed to delete the message as well."
confirmationText: qsTrId("are-you-sure-you-want-to-delete-this-message--be-aware-that-other-clients-are-not-guaranteed-to-delete-the-message-as-well-"),
height: 260,
"checkbox.visible": true,
executeConfirm: function () {
if (confirmationDialog.checkbox.checked) {
localAccountSensitiveSettings.showDeleteMessageWarning = false
}
confirmationDialog.close()
// Not Refactored Yet
// root.store.chatsModelInst.messageView.deleteMessage(messageId)
}
})
}
icon.name: "delete"
type: StatusMenuItem.Type.Danger
@ -380,4 +365,27 @@ StatusPopupMenu {
fileDialog.close()
}
}
Component {
id: deleteMessageConfirmationDialogComponent
ConfirmationDialog {
//% "Confirm deleting this message"
header.title: qsTrId("confirm-deleting-this-message")
//% "Are you sure you want to delete this message? Be aware that other clients are not guaranteed to delete the message as well."
confirmationText: qsTrId("are-you-sure-you-want-to-delete-this-message--be-aware-that-other-clients-are-not-guaranteed-to-delete-the-message-as-well-")
height: 260
checkbox.visible: true
executeConfirm: function () {
if (checkbox.checked) {
localAccountSensitiveSettings.showDeleteMessageWarning = false
}
close()
root.deleteMessage(messageId)
}
onClosed: {
destroy()
}
}
}
}

View File

@ -216,18 +216,6 @@ Column {
// }
// }
// }
// }
// Connections {
// enabled: !!root.rootStore
// target: !!root.rootStore ? root.chatsModel.messageView : null
// onHideMessage: {
// // This hack is used because message_list deleteMessage sometimes does not remove the messages (there might be an issue with the delegate model)
// if(mId === messageId){
// root.visible = 0;
// root.height = 0;
// }
// }
// }
Loader {