MUC: Clear typing notification when a message is received

This commit is contained in:
JC Brand 2020-04-07 22:04:25 +02:00
parent c7e702368b
commit a065b0c88c

View File

@ -1931,19 +1931,29 @@ converse.plugins.add('converse-muc', {
} }
}, },
removeNotification (actor, state) { /**
* @param {String} actor - The nickname of the actor that caused the notification
* @param {String|Array<String>} states - The state or states representing the type of notificcation
*/
removeNotification (actor, states) {
const actors_per_state = this.notifications.toJSON(); const actors_per_state = this.notifications.toJSON();
const existing_actors = Array.from(actors_per_state[state]) || []; states = Array.isArray(states) ? states : [states];
if (existing_actors.includes(actor)) { states.forEach(state => {
const idx = existing_actors.indexOf(actor); const existing_actors = Array.from(actors_per_state[state]) || [];
existing_actors.splice(idx, 1); if (existing_actors.includes(actor)) {
this.notifications.set(state, Array.from(existing_actors)); const idx = existing_actors.indexOf(actor);
} existing_actors.splice(idx, 1);
this.notifications.set(state, Array.from(existing_actors));
}
});
}, },
/** /**
* Update the notifications model by adding the passed in nickname * Update the notifications model by adding the passed in nickname
* to the array of nicknames that all match a particular state. * to the array of nicknames that all match a particular state.
*
* Removes the nickname from any other states it might be associated with.
*
* The state can be a XEP-0085 Chat State or a XEP-0045 join/leave * The state can be a XEP-0085 Chat State or a XEP-0045 join/leave
* state. * state.
* @param {String} actor - The nickname of the actor that causes the notification * @param {String} actor - The nickname of the actor that causes the notification
@ -2004,14 +2014,17 @@ converse.plugins.add('converse-muc', {
if (message) { if (message) {
this.updateMessage(message, original_stanza); this.updateMessage(message, original_stanza);
} }
if (message || stanza_utils.isReceipt(stanza) || stanza_utils.isChatMarker(stanza)) { if (message ||
stanza_utils.isReceipt(stanza) ||
stanza_utils.isChatMarker(stanza) ||
this.ignorableCSN(attrs)) {
return api.trigger('message', {'stanza': original_stanza}); return api.trigger('message', {'stanza': original_stanza});
} }
if (await this.handleRetraction(attrs) || if (await this.handleRetraction(attrs) ||
await this.handleModeration(attrs) || await this.handleModeration(attrs) ||
this.handleSubjectChange(attrs) || this.handleSubjectChange(attrs)) {
this.ignorableCSN(attrs)) { this.removeNotification(attrs.nick, ['composing', 'paused']);
return api.trigger('message', {'stanza': original_stanza}); return api.trigger('message', {'stanza': original_stanza});
} }
this.setEditable(attrs, attrs.time); this.setEditable(attrs, attrs.time);
@ -2021,6 +2034,7 @@ converse.plugins.add('converse-muc', {
} }
if (u.shouldCreateGroupchatMessage(attrs)) { if (u.shouldCreateGroupchatMessage(attrs)) {
const msg = this.handleCorrection(attrs) || await this.createMessage(attrs); const msg = this.handleCorrection(attrs) || await this.createMessage(attrs);
this.removeNotification(attrs.nick, ['composing', 'paused']);
this.incrementUnreadMsgCounter(msg); this.incrementUnreadMsgCounter(msg);
} }
api.trigger('message', {'stanza': original_stanza, 'chatbox': this}); api.trigger('message', {'stanza': original_stanza, 'chatbox': this});