Commit 80c955f2 authored by JC Brand's avatar JC Brand

Fix "retry" feature for message errors.

By registering a one-time event handler for a unique event name
parent 3f7e5e29
...@@ -3234,7 +3234,8 @@ ...@@ -3234,7 +3234,8 @@
"dependencies": { "dependencies": {
"filesize": { "filesize": {
"version": "6.1.0", "version": "6.1.0",
"resolved": false "resolved": "https://registry.npmjs.org/filesize/-/filesize-6.1.0.tgz",
"integrity": "sha512-LpCHtPQ3sFx67z+uh2HnSyWSLLu5Jxo21795uRDuar/EOuYWXib5EmPaGIBuSnRqH2IODiKA2k5re/K9OnN/Yg=="
}, },
"fs-extra": { "fs-extra": {
"version": "8.1.0", "version": "8.1.0",
...@@ -3268,7 +3269,8 @@ ...@@ -3268,7 +3269,8 @@
}, },
"jed": { "jed": {
"version": "1.1.1", "version": "1.1.1",
"resolved": false "resolved": "https://registry.npmjs.org/jed/-/jed-1.1.1.tgz",
"integrity": "sha1-elSbvZ/+FYWwzQoZHiAwVb7ldLQ="
}, },
"jsonfile": { "jsonfile": {
"version": "5.0.0", "version": "5.0.0",
...@@ -3289,7 +3291,8 @@ ...@@ -3289,7 +3291,8 @@
}, },
"localforage": { "localforage": {
"version": "1.7.3", "version": "1.7.3",
"resolved": false, "resolved": "https://registry.npmjs.org/localforage/-/localforage-1.7.3.tgz",
"integrity": "sha512-1TulyYfc4udS7ECSBT2vwJksWbkwwTX8BzeUIiq8Y07Riy7bDAAnxDaPU/tWyOVmQAcWJIEIFP9lPfBGqVoPgQ==",
"requires": { "requires": {
"lie": "3.1.1" "lie": "3.1.1"
} }
...@@ -3301,13 +3304,14 @@ ...@@ -3301,13 +3304,14 @@
}, },
"pluggable.js": { "pluggable.js": {
"version": "2.0.1", "version": "2.0.1",
"resolved": false, "resolved": "https://registry.npmjs.org/pluggable.js/-/pluggable.js-2.0.1.tgz",
"integrity": "sha512-SBt6v6Tbp20Jf8hU0cpcc/+HBHGMY8/Q+yA6Ih0tBQE8tfdZ6U4PRG0iNvUUjLx/hVyOP53n0UfGBymlfaaXCg==",
"requires": { "requires": {
"lodash": "^4.17.11" "lodash": "^4.17.11"
} }
}, },
"skeletor.js": { "skeletor.js": {
"version": "0.0.1", "version": "github:skeletorjs/skeletor#bf6d9c86f9fcf224fa9d9af5a25380b77aa4b561",
"from": "github:skeletorjs/skeletor#bf6d9c86f9fcf224fa9d9af5a25380b77aa4b561", "from": "github:skeletorjs/skeletor#bf6d9c86f9fcf224fa9d9af5a25380b77aa4b561",
"requires": { "requires": {
"lodash": "^4.17.14" "lodash": "^4.17.14"
...@@ -3315,11 +3319,13 @@ ...@@ -3315,11 +3319,13 @@
}, },
"strophe.js": { "strophe.js": {
"version": "1.3.4", "version": "1.3.4",
"resolved": false "resolved": "https://registry.npmjs.org/strophe.js/-/strophe.js-1.3.4.tgz",
"integrity": "sha512-jSLDG8jolhAwGOSgiJ7DTMSYK3wVoEJHKtpVRyEacQZ6CWA6z2WRPJpcFMjsIweq5aP9/XIvKUQqHBu/ZhvESA=="
}, },
"twemoji": { "twemoji": {
"version": "12.1.5", "version": "12.1.5",
"resolved": false, "resolved": "https://registry.npmjs.org/twemoji/-/twemoji-12.1.5.tgz",
"integrity": "sha512-B0PBVy5xomwb1M/WZxf/IqPZfnoIYy1skXnlHjMwLwTNfZ9ljh8VgWQktAPcJXu8080WoEh6YwQGPVhDVqvrVQ==",
"requires": { "requires": {
"fs-extra": "^8.0.1", "fs-extra": "^8.0.1",
"jsonfile": "^5.0.0", "jsonfile": "^5.0.0",
......
...@@ -1065,8 +1065,6 @@ describe("Chatboxes", function () { ...@@ -1065,8 +1065,6 @@ describe("Chatboxes", function () {
`</query>`+ `</query>`+
`</iq>`); `</iq>`);
await u.waitUntil(() => view.el.querySelector('converse-chat-message .spinner'), 1000);
const msg1 = $msg({'id':'aeb212', 'to': contact_jid}) const msg1 = $msg({'id':'aeb212', 'to': contact_jid})
.c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid': queryid, 'id':'28482-98726-73623'}) .c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid': queryid, 'id':'28482-98726-73623'})
.c('forwarded', {'xmlns':'urn:xmpp:forward:0'}) .c('forwarded', {'xmlns':'urn:xmpp:forward:0'})
......
...@@ -14,7 +14,6 @@ const tpl_message = (o) => html` ...@@ -14,7 +14,6 @@ const tpl_message = (o) => html`
.chatview=${o.chatview} .chatview=${o.chatview}
.hats=${o.hats} .hats=${o.hats}
.model=${o.model} .model=${o.model}
?allow_retry=${o.retry}
?correcting=${o.correcting} ?correcting=${o.correcting}
?editable=${o.editable} ?editable=${o.editable}
?has_mentions=${o.has_mentions} ?has_mentions=${o.has_mentions}
...@@ -44,6 +43,7 @@ const tpl_message = (o) => html` ...@@ -44,6 +43,7 @@ const tpl_message = (o) => html`
progress=${o.progress || 0 } progress=${o.progress || 0 }
reason=${o.reason || ''} reason=${o.reason || ''}
received=${o.received || ''} received=${o.received || ''}
retry_event_id=${o.retry_event_id || ''}
sender=${o.sender} sender=${o.sender}
spoiler_hint=${o.spoiler_hint || ''} spoiler_hint=${o.spoiler_hint || ''}
subject=${o.subject || ''} subject=${o.subject || ''}
......
...@@ -24,16 +24,15 @@ class Message extends CustomElement { ...@@ -24,16 +24,15 @@ class Message extends CustomElement {
static get properties () { static get properties () {
return { return {
allow_retry: { type: Boolean },
chatview: { type: Object}, chatview: { type: Object},
correcting: { type: Boolean }, correcting: { type: Boolean },
editable: { type: Boolean }, editable: { type: Boolean },
edited: { type: String },
error: { type: String }, error: { type: String },
error_text: { type: String }, error_text: { type: String },
from: { type: String }, from: { type: String },
has_mentions: { type: Boolean }, has_mentions: { type: Boolean },
hats: { type: Array }, hats: { type: Array },
edited: { type: String },
is_delayed: { type: Boolean }, is_delayed: { type: Boolean },
is_encrypted: { type: Boolean }, is_encrypted: { type: Boolean },
is_first_unread: { type: Boolean }, is_first_unread: { type: Boolean },
...@@ -54,6 +53,7 @@ class Message extends CustomElement { ...@@ -54,6 +53,7 @@ class Message extends CustomElement {
reason: { type: String }, reason: { type: String },
received: { type: String }, received: { type: String },
retractable: { type: Boolean }, retractable: { type: Boolean },
retry_event_id: { type: String },
sender: { type: String }, sender: { type: String },
show_spinner: { type: Boolean }, show_spinner: { type: Boolean },
spoiler_hint: { type: String }, spoiler_hint: { type: String },
...@@ -104,7 +104,7 @@ class Message extends CustomElement { ...@@ -104,7 +104,7 @@ class Message extends CustomElement {
</div> </div>
${ this.reason ? html`<q class="reason">${this.reason}</q>` : `` } ${ this.reason ? html`<q class="reason">${this.reason}</q>` : `` }
${ this.error_text ? html`<q class="reason">${this.error_text}</q>` : `` } ${ this.error_text ? html`<q class="reason">${this.error_text}</q>` : `` }
${ this.allow_retry ? html`<a class="retry" @click=${this.onRetryClicked}>${i18n_retry}</a>` : '' } ${ this.retry_event_id ? html`<a class="retry" @click=${this.onRetryClicked}>${i18n_retry}</a>` : '' }
</div> </div>
`; `;
} }
...@@ -144,7 +144,7 @@ class Message extends CustomElement { ...@@ -144,7 +144,7 @@ class Message extends CustomElement {
async onRetryClicked () { async onRetryClicked () {
this.show_spinner = true; this.show_spinner = true;
await this.model.error.retry(); await api.trigger(this.retry_event_id, {'synchronous': true});
this.model.destroy(); this.model.destroy();
this.parentElement.removeChild(this); this.parentElement.removeChild(this);
} }
......
...@@ -543,7 +543,7 @@ converse.plugins.add('converse-chat', { ...@@ -543,7 +543,7 @@ converse.plugins.add('converse-chat', {
const msg = await this.createMessage({ const msg = await this.createMessage({
'type': 'error', 'type': 'error',
'message': error.message, 'message': error.message,
'retry': true 'retry_event_id': error.retry_event_id
}); });
msg.error = error; msg.error = error;
} }
......
...@@ -63,7 +63,8 @@ const MAMEnabledChat = { ...@@ -63,7 +63,8 @@ const MAMEnabledChat = {
result.messages.forEach(m => this.queueMessage(m)); result.messages.forEach(m => this.queueMessage(m));
if (result.error) { if (result.error) {
result.error.retry = () => this.fetchArchivedMessages(options, page_direction); const event_id = result.error.retry_event_id = u.getUniqueId();
api.listen.once(event_id, () => this.fetchArchivedMessages(options, page_direction));
this.createMessageFromError(result.error); this.createMessageFromError(result.error);
} }
}, },
......
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