Commit 58c5e967 authored by JC Brand's avatar JC Brand

Handle forwarded mentions coming from the MUC, not the host

parent 5e6a6ba6
......@@ -38,6 +38,7 @@ describe("The nickname autocomplete feature", function () {
type: 'groupchat'
}).c('body').t('Hello world').tree();
await view.model.handleMessageStanza(msg);
await u.waitUntil(() => view.model.messages.last()?.get('received'));
// Test that pressing @ brings up all options
const textarea = view.el.querySelector('textarea.chat-textarea');
......@@ -91,6 +92,7 @@ describe("The nickname autocomplete feature", function () {
type: 'groupchat'
}).c('body').t('Hello world').tree();
await view.model.handleMessageStanza(msg);
await u.waitUntil(() => view.model.messages.last()?.get('received'));
// Test that pressing @ brings up all options
const textarea = view.el.querySelector('textarea.chat-textarea');
......@@ -145,6 +147,7 @@ describe("The nickname autocomplete feature", function () {
type: 'groupchat'
}).c('body').t('Hello world').tree();
await view.model.handleMessageStanza(msg);
await u.waitUntil(() => view.model.messages.last()?.get('received'));
// Test that pressing @ brings up all options
const textarea = view.el.querySelector('textarea.chat-textarea');
......
/*global mock, converse */
const { Strophe, dayjs } = converse.env;
const { dayjs } = converse.env;
const u = converse.env.utils;
// See: https://xmpp.org/rfcs/rfc3921.html
......@@ -37,7 +37,7 @@ describe("MUC Mention Notfications", function () {
const base_time = new Date();
let message = u.toStanza(`
<message from="${Strophe.getDomainFromJid(muc_jid)}">
<message from="${muc_jid}">
<mentions xmlns='urn:xmpp:mmn:0'>
<forwarded xmlns='urn:xmpp:forward:0'>
<delay xmlns='urn:xmpp:delay' stamp='${dayjs(base_time).subtract(5, 'minutes').toISOString()}'/>
......@@ -61,7 +61,7 @@ describe("MUC Mention Notfications", function () {
expect(room_el.querySelector('.msgs-indicator')?.textContent.trim()).toBe('1');
message = u.toStanza(`
<message from="${Strophe.getDomainFromJid(muc_jid)}">
<message from="${muc_jid}">
<mentions xmlns='urn:xmpp:mmn:0'>
<forwarded xmlns='urn:xmpp:forward:0'>
<delay xmlns='urn:xmpp:delay' stamp='${dayjs(base_time).subtract(4, 'minutes').toISOString()}'/>
......
......@@ -519,6 +519,7 @@ describe("A Groupchat Message", function () {
type: 'groupchat'
}).c('body').t('I wrote this message!').tree();
await view.model.handleMessageStanza(msg);
await u.waitUntil(() => view.model.messages.last()?.get('received'));
expect(view.model.messages.last().get('sender')).toBe('me');
done();
}));
......
......@@ -791,7 +791,7 @@ describe("Message Retractions", function () {
</message>`);
await view.model.handleMessageStanza(retraction);
expect(view.model.messages.length).toBe(1);
expect(view.model.messages.at(0).get('moderated')).toBe('retracted');
await u.waitUntil(() => view.model.messages.at(0).get('moderated') === 'retracted');
expect(view.model.messages.at(0).get('moderation_reason')).toBe(reason);
expect(view.model.messages.at(0).get('is_ephemeral')).toBe(false);
expect(view.model.messages.at(0).get('editable')).toBe(false);
......
......@@ -440,12 +440,9 @@ const ChatRoomMixin = {
handleMessageFromMUCHost (stanza) {
const conn_status = this.session.get('connection_status');
if (conn_status === converse.ROOMSTATUS.ENTERED) {
// We're not interested in activity indicators or forwarded
// mentions when already joined to the room.
// Also prevents forwarded mentions from being counted twice.
// We're not interested in activity indicators when already joined to the room
return;
}
const rai = sizzle(`rai[xmlns="${Strophe.NS.RAI}"]`, stanza).pop();
const active_mucs = Array.from(rai?.querySelectorAll('activity') || []).map(m => m.textContent);
if (active_mucs.includes(this.get('jid'))) {
......@@ -454,7 +451,13 @@ const ChatRoomMixin = {
'num_unread_general': 0 // Either/or between activity and unreads
});
}
},
handleForwardedMentions (stanza) {
if (this.session.get('connection_status') === converse.ROOMSTATUS.ENTERED) {
// Avoid counting mentions twice
return;
}
const msgs = sizzle(
`mentions[xmlns="${Strophe.NS.MENTIONS}"] forwarded[xmlns="${Strophe.NS.FORWARD}"] message[type="groupchat"]`,
stanza
......@@ -481,6 +484,11 @@ const ChatRoomMixin = {
* @param { XMLElement } stanza
*/
async handleMessageStanza (stanza) {
if (stanza.getAttribute('type') !== 'groupchat') {
this.handleForwardedMentions(stanza);
return;
}
if (isArchived(stanza)) {
// MAM messages are handled in converse-mam.
// We shouldn't get MAM messages here because
......@@ -542,7 +550,7 @@ const ChatRoomMixin = {
stanza => !!this.handleMessageStanza(stanza) || true,
null,
'message',
'groupchat',
null,
null,
muc_jid,
{ 'matchBareFromJid': true }
......
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