Переглянути джерело

Make various error messages ephemeral.

Also make it possible to specify the timeout for an ephemeral message.
JC Brand 3 роки тому
батько
коміт
7b63b7b30f

+ 4 - 2
src/headless/plugins/chat/message.js

@@ -64,8 +64,10 @@ const MessageMixin = {
         if (this.ephemeral_timer) {
             clearTimeout(this.ephemeral_timer);
         }
-        if (this.isEphemeral()) {
-            this.ephemeral_timer = window.setTimeout(() => this.safeDestroy(), 10000);
+        const is_ephemeral = this.isEphemeral();
+        if (is_ephemeral) {
+            const timeout = typeof is_ephemeral === "number" ? is_ephemeral : 10000;
+            this.ephemeral_timer = window.setTimeout(() => this.safeDestroy(), timeout);
         }
     },
 

+ 2 - 1
src/headless/plugins/chat/model.js

@@ -382,7 +382,8 @@ const ChatBox = ModelWithContact.extend({
             const msg = await this.createMessage({
                 'type': 'error',
                 'message': error.message,
-                'retry_event_id': error.retry_event_id
+                'retry_event_id': error.retry_event_id,
+                'is_ephemeral': 30000,
             });
             msg.error = error;
         }

+ 2 - 1
src/headless/plugins/mam/api.js

@@ -264,7 +264,8 @@ export default {
             }, NS.MAM);
 
             let error;
-            const iq_result = await api.sendIQ(stanza, api.settings.get('message_archiving_timeout'), false)
+            const timeout = api.settings.get('message_archiving_timeout');
+            const iq_result = await api.sendIQ(stanza, timeout, false)
             if (iq_result === null) {
                 const { __ } = _converse;
                 const err_msg = __("Timeout while trying to fetch archived messages.");

+ 3 - 3
src/headless/plugins/muc/muc.js

@@ -1383,7 +1383,7 @@ const ChatRoomMixin = {
         }
         if (show_error) {
             const message = __('Forbidden: you do not have the necessary role in order to do that.');
-            this.createMessage({ message, 'type': 'error' });
+            this.createMessage({ message, 'type': 'error', 'is_ephemeral': 20000 });
         }
         return false;
     },
@@ -1435,7 +1435,7 @@ const ChatRoomMixin = {
                 const { __ } = _converse;
                 log.error(e);
                 const message = __("Error: couldn't register new nickname in members only room");
-                this.createMessage({ message, 'type': 'error' });
+                this.createMessage({ message, 'type': 'error', 'is_ephemeral': true });
                 this.set({ 'nick': old_nick });
                 return;
             }
@@ -1825,7 +1825,7 @@ const ChatRoomMixin = {
                     prev_msg?.get('type') !== 'info' ||
                     prev_msg?.get('message') !== message
                 ) {
-                    this.createMessage({ message, 'nick': attrs.nick, 'type': 'info' });
+                    this.createMessage({ message, 'nick': attrs.nick, 'type': 'info', 'is_ephemeral': true });
                 }
                 if (await this.isSubjectHidden()) {
                     this.toggleSubjectHiddenState();

+ 1 - 1
src/plugins/mam-views/tests/mam.js

@@ -1153,7 +1153,7 @@ describe("Chatboxes", function () {
 
             const view = _converse.chatboxviews.get(contact_jid);
             expect(view.model.messages.length).toBe(1);
-            expect(view.model.messages.at(0).get('is_ephemeral')).toBe(false);
+            expect(view.model.messages.at(0).get('is_ephemeral')).toBe(30000);
             expect(view.model.messages.at(0).get('type')).toBe('error');
             expect(view.model.messages.at(0).get('message')).toBe('Timeout while trying to fetch archived messages.');