Delete public chat messages locally if not stored on the server

pull/596/head
Maxim Shishmarev 6 years ago
parent 5d2c15fd24
commit 1f4af59dad

@ -2425,11 +2425,20 @@
if (!channelAPI) { if (!channelAPI) {
return false; return false;
} }
const success = await channelAPI.deleteMessage(message.getServerId()); const serverId = message.getServerId();
if (success) {
const success = serverId
? await channelAPI.deleteMessage(serverId)
: false;
const shouldDeleteLocally = success || message.hasErrors() || !serverId;
// If the message has errors it is likely not saved
// on the server, so we delete it locally unconditionally
if (shouldDeleteLocally) {
this.removeMessage(message.id); this.removeMessage(message.id);
} }
return success;
return shouldDeleteLocally;
}, },
removeMessage(messageId) { removeMessage(messageId) {

@ -1335,10 +1335,7 @@
? i18n('deletePublicWarning') ? i18n('deletePublicWarning')
: i18n('deleteWarning'); : i18n('deleteWarning');
const dialog = new Whisper.ConfirmationDialogView({ const doDelete = async () => {
message: warningMessage,
okText: i18n('delete'),
resolve: async () => {
if (this.model.isPublic()) { if (this.model.isPublic()) {
const success = await this.model.deletePublicMessage(message); const success = await this.model.deletePublicMessage(message);
if (!success) { if (!success) {
@ -1354,7 +1351,18 @@
message.trigger('unload'); message.trigger('unload');
this.resetPanel(); this.resetPanel();
this.updateHeader(); this.updateHeader();
}, };
// The message wasn't saved, so we don't show any warning
if (message.hasErrors()) {
doDelete();
return;
}
const dialog = new Whisper.ConfirmationDialogView({
message: warningMessage,
okText: i18n('delete'),
resolve: doDelete,
}); });
this.$el.prepend(dialog.el); this.$el.prepend(dialog.el);

Loading…
Cancel
Save