Commit 13ffe5a6 authored by JC Brand's avatar JC Brand

Various smaller retraction related fixes and improvements

parent 53df5d6b
{ {
"name": "converse.js", "name": "converse.js",
"version": "5.0.4", "version": "6.0.0",
"description": "Browser based XMPP chat client", "description": "Browser based XMPP chat client",
"browser": "dist/converse.js", "browser": "dist/converse.js",
"module": "src/converse.js", "module": "src/converse.js",
......
...@@ -247,7 +247,7 @@ converse.plugins.add('converse-message-view', { ...@@ -247,7 +247,7 @@ converse.plugins.add('converse-message-view', {
const is_own_message = this.model.get('sender') === 'me'; const is_own_message = this.model.get('sender') === 'me';
const chatbox = this.model.collection.chatbox; const chatbox = this.model.collection.chatbox;
const may_retract_own_message = is_own_message && ['all', 'own'].includes(_converse.allow_message_retraction); const may_retract_own_message = is_own_message && ['all', 'own'].includes(_converse.allow_message_retraction);
const may_moderate_message = is_groupchat && const may_moderate_message = !is_own_message && is_groupchat &&
['all', 'moderator'].includes(_converse.allow_message_retraction) && ['all', 'moderator'].includes(_converse.allow_message_retraction) &&
await chatbox.canRetractMessages(); await chatbox.canRetractMessages();
...@@ -306,22 +306,19 @@ converse.plugins.add('converse-message-view', { ...@@ -306,22 +306,19 @@ converse.plugins.add('converse-message-view', {
}, },
getRetractionText () { getRetractionText () {
const username = this.model.getDisplayName(); if (this.model.get('type') === 'groupchat' && this.model.get('moderated_by')) {
let retraction_text = __('%1$s has retracted this message', username);
if (this.model.get('type') === 'groupchat') {
const retracted_by_mod = this.model.get('moderated_by'); const retracted_by_mod = this.model.get('moderated_by');
if (retracted_by_mod) { const chatbox = this.model.collection.chatbox;
const chatbox = this.model.collection.chatbox; if (!this.model.mod) {
if (!this.model.mod) { this.model.mod =
this.model.mod = chatbox.occupants.findOccupant({'jid': retracted_by_mod}) ||
chatbox.occupants.findOccupant({'jid': retracted_by_mod}) || chatbox.occupants.findOccupant({'nick': Strophe.getResourceFromJid(retracted_by_mod)});
chatbox.occupants.findOccupant({'nick': Strophe.getResourceFromJid(retracted_by_mod)});
}
const modname = this.model.mod ? this.model.mod.getDisplayName() : 'A moderator';
retraction_text = __('%1$s has retracted this message from %2$s', modname , username);
} }
const modname = this.model.mod ? this.model.mod.getDisplayName() : 'A moderator';
return __('%1$s has retracted this message', modname);
} else {
return __('%1$s has retracted this message', this.model.getDisplayName());
} }
return retraction_text;
}, },
renderErrorMessage () { renderErrorMessage () {
......
...@@ -582,7 +582,7 @@ converse.plugins.add('converse-chat', { ...@@ -582,7 +582,7 @@ converse.plugins.add('converse-chat', {
* whether a message was retracted or not. * whether a message was retracted or not.
*/ */
handleRetraction (attrs) { handleRetraction (attrs) {
const RETRACTION_ATTRIBUTES = ['retracted', 'retracted_id']; const RETRACTION_ATTRIBUTES = ['retracted', 'retracted_id', 'editable'];
if (attrs.retracted) { if (attrs.retracted) {
if (attrs.is_tombstone) { if (attrs.is_tombstone) {
return false; return false;
...@@ -877,7 +877,7 @@ converse.plugins.add('converse-chat', { ...@@ -877,7 +877,7 @@ converse.plugins.add('converse-chat', {
return; return;
} }
if (_converse.allow_message_corrections === 'all') { if (_converse.allow_message_corrections === 'all') {
attrs.editable = !(attrs.file || 'oob_url' in attrs); attrs.editable = !(attrs.file || attrs.retracted || 'oob_url' in attrs);
} else if ((_converse.allow_message_corrections === 'last') && } else if ((_converse.allow_message_corrections === 'last') &&
(send_time > this.get('time_sent'))) { (send_time > this.get('time_sent'))) {
this.set({'time_sent': send_time}); this.set({'time_sent': send_time});
...@@ -885,7 +885,7 @@ converse.plugins.add('converse-chat', { ...@@ -885,7 +885,7 @@ converse.plugins.add('converse-chat', {
if (msg) { if (msg) {
msg.save({'editable': false}); msg.save({'editable': false});
} }
attrs.editable = !(attrs.file || 'oob_url' in attrs); attrs.editable = !(attrs.file || attrs.retracted || 'oob_url' in attrs);
} }
}, },
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* @description * @description
* Implements the non-view logic for XEP-0045 Multi-User Chat * Implements the non-view logic for XEP-0045 Multi-User Chat
*/ */
import "./converse-chat";
import "./converse-disco"; import "./converse-disco";
import "./converse-emoji"; import "./converse-emoji";
import { clone, get, intersection, invoke, isElement, isObject, isString, pick, uniq, zipObject } from "lodash"; import { clone, get, intersection, invoke, isElement, isObject, isString, pick, uniq, zipObject } from "lodash";
......
...@@ -130,6 +130,7 @@ const stanza_utils = { ...@@ -130,6 +130,7 @@ const stanza_utils = {
const delay = sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, original_stanza).pop(); const delay = sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, original_stanza).pop();
const time = delay ? dayjs(delay.getAttribute('stamp')).toISOString() : (new Date()).toISOString(); const time = delay ? dayjs(delay.getAttribute('stamp')).toISOString() : (new Date()).toISOString();
return { return {
'editable': false,
'retracted': time, 'retracted': time,
'retracted_id': applies_to_id 'retracted_id': applies_to_id
} }
...@@ -138,8 +139,9 @@ const stanza_utils = { ...@@ -138,8 +139,9 @@ const stanza_utils = {
const tombstone = sizzle(`> retracted[xmlns="${Strophe.NS.RETRACT}"]`, stanza).pop(); const tombstone = sizzle(`> retracted[xmlns="${Strophe.NS.RETRACT}"]`, stanza).pop();
if (tombstone) { if (tombstone) {
return { return {
'retracted': tombstone.getAttribute('stamp'), 'editable': false,
'is_tombstone': true 'is_tombstone': true,
'retracted': tombstone.getAttribute('stamp')
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment