diff --git a/_locales/en/messages.json b/_locales/en/messages.json index daa221739..729cc1181 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -948,6 +948,10 @@ "delete": { "message": "Delete" }, + "deletePublicWarning": { + "message": + "Are you sure? Clicking 'delete' will permanently remove this message for everyone in this channel." + }, "deleteWarning": { "message": "Are you sure? Clicking 'delete' will permanently remove this message from this device only." diff --git a/js/background.js b/js/background.js index a791a9ccc..705b936ea 100644 --- a/js/background.js +++ b/js/background.js @@ -487,6 +487,28 @@ } }); + Whisper.events.on( + 'deleteLocalPublicMessage', + async ({ messageServerId, conversationId }) => { + const message = await window.Signal.Data.getMessageByServerId( + messageServerId, + conversationId, + { + Message: Whisper.Message, + } + ); + if (message) { + const conversation = ConversationController.get(conversationId); + if (conversation) { + conversation.removeMessage(message.id); + } + await window.Signal.Data.removeMessage(message.id, { + Message: Whisper.Message, + }); + } + } + ); + Whisper.events.on('setupAsNewDevice', () => { const { appView } = window.owsDesktopApp; if (appView) { @@ -1418,6 +1440,7 @@ let messageData = { source: data.source, sourceDevice: data.sourceDevice, + serverId: data.serverId, sent_at: data.timestamp, received_at: data.receivedAt || Date.now(), conversationId: data.source, diff --git a/js/models/conversations.js b/js/models/conversations.js index 4b674503e..e28762909 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -2288,6 +2288,31 @@ }); }, + async deletePublicMessage(message) { + const serverAPI = lokiPublicChatAPI.findOrCreateServer( + this.get('server') + ); + const channelAPI = serverAPI.findOrCreateChannel( + this.get('channelId'), + this.id + ); + const success = await channelAPI.deleteMessage(message.getServerId()); + if (success) { + this.removeMessage(message.id); + } + return success; + }, + + removeMessage(messageId) { + const message = this.messageCollection.models.find( + msg => msg.id === messageId + ); + if (message) { + message.trigger('unload'); + this.messageCollection.remove(messageId); + } + }, + deleteMessages() { Whisper.events.trigger('showConfirmationDialog', { message: i18n('deleteConversationConfirmation'), diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index e9489ed96..7fdebbadc 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -257,7 +257,7 @@ export class Message extends React.PureComponent { `module-message__metadata__${badgeType}--${direction}` )} > -  • ${badgeText} +  • {badgeText} ) : null} {expirationLength && expirationTimestamp ? (