Преглед изворни кода

Show policy violation errors to the user and make them ephemeral

Also, remove ephemeral messages after 10 seconds, not 20
JC Brand пре 6 година
родитељ
комит
599f7596f6
3 измењених фајлова са 21 додато и 6 уклоњено
  1. 0 4
      src/converse-muc-views.js
  2. 6 2
      src/headless/converse-chatboxes.js
  3. 15 0
      src/headless/converse-muc.js

+ 0 - 4
src/converse-muc-views.js

@@ -1666,10 +1666,6 @@ converse.plugins.add('converse-muc-views', {
                     } else if (!_.isNull(error.querySelector('forbidden'))) {
                         this.showDisconnectMessages(__('You have been banned from this groupchat.'));
                     }
-                } else if (error.getAttribute('type') === 'modify') {
-                    if (!_.isNull(error.querySelector('jid-malformed'))) {
-                        this.showDisconnectMessages(__('No nickname was specified.'));
-                    }
                 } else if (error.getAttribute('type') === 'cancel') {
                     if (!_.isNull(error.querySelector('not-allowed'))) {
                         this.showDisconnectMessages(__('You are not allowed to create new groupchats.'));

+ 6 - 2
src/headless/converse-chatboxes.js

@@ -94,14 +94,14 @@ converse.plugins.add('converse-chatboxes', {
                 if (this.get('file')) {
                     this.on('change:put', this.uploadFile, this);
                 }
-                if (this.isOnlyChatStateNotification()) {
+                if (this.isEphemeral()) {
                     window.setTimeout(() => {
                         try {
                             this.destroy()
                         } catch (e) {
                             _converse.log(e, Strophe.LogLevel.ERROR);
                         }
-                    }, 20000);
+                    }, 10000);
                 }
             },
 
@@ -150,6 +150,10 @@ converse.plugins.add('converse-chatboxes', {
                 return u.isOnlyChatStateNotification(this);
             },
 
+            isEphemeral () {
+                return this.isOnlyChatStateNotification() || this.get('type') === 'error';
+            },
+
             getDisplayName () {
                 if (this.get('type') === 'groupchat') {
                     return this.get('nick');

+ 15 - 0
src/headless/converse-muc.js

@@ -1353,6 +1353,19 @@ converse.plugins.add('converse-muc', {
                 _converse.api.trigger('message', {'stanza': original_stanza, 'chatbox': this});
             },
 
+
+            handleModifyError(pres) {
+                const text = _.get(pres.querySelector('error text'), 'textContent');
+                if (text) {
+                    const attrs = {
+                        'type': 'error',
+                        'message': text
+                    }
+                    this.messages.create(attrs);
+                }
+            },
+
+
             onErrorPresence (pres) {
                 // TODO: currently showErrorMessageFromPresence handles
                 // 'error" presences in converse-muc-views.
@@ -1360,6 +1373,8 @@ converse.plugins.add('converse-muc', {
                 // handler removed from there.
                 if (sizzle(`error not-authorized[xmlns="${Strophe.NS.STANZAS}"]`, pres).length) {
                     this.save('connection_status', converse.ROOMSTATUS.PASSWORD_REQUIRED);
+                } else if (sizzle(`error[type="modify"]`, pres).length) {
+                    this.handleModifyError(pres);
                 } else {
                     this.save('connection_status', converse.ROOMSTATUS.DISCONNECTED);
                 }