Add status and show elements to MUC join presence in status plugin

and not in the muc plugin.

This decouples the plugins more. Ideally we can remove the status plugin
entirely from a customized Converse build (but we're not there yet).
This commit is contained in:
JC Brand 2022-04-07 11:08:00 +02:00
parent 4d4e0ffc8d
commit f0297fe075
6 changed files with 34 additions and 15 deletions

View File

@ -14,6 +14,7 @@ function onDiscoInfoRequest (stanza) {
if (from !== null) {
iqresult.attrs({'to': from});
}
iqresult.c('query', attrs);
_converse.disco._identities.forEach(identity => {
const attrs = {

View File

@ -30,7 +30,6 @@ export async function getAffiliationList (affiliation, muc_jid) {
const err_msg = __('Error: timeout while fetching %1s list for MUC %2s', affiliation, muc_jid);
const err = new Error(err_msg);
log.warn(err_msg);
log.warn(result);
return err;
}
if (u.isErrorStanza(result)) {

View File

@ -206,17 +206,13 @@ const ChatRoomMixin = {
stanza.cnode(Strophe.xmlElement('password', [], password));
}
stanza.up(); // Go one level up, out of the `x` element.
const status = _converse.xmppstatus.get('status');
if (['away', 'chat', 'dnd', 'xa'].includes(status)) {
stanza.c('show').t(status).up();
}
const status_message = _converse.xmppstatus.get('status_message');
if (status_message) {
stanza.c('status').t(status_message).up();
}
stanza = await api.hook('constructedMUCPresence', null, stanza);
/**
* *Hook* which allows plugins to update an outgoing MUC join presence stanza
* @event _converse#constructedMUCPresence
* @param { _converse.ChatRoom } - The MUC from which this message stanza is being sent.
* @param { XMLElement } stanza - The stanza which will be sent out
*/
stanza = await api.hook('constructedMUCPresence', this, stanza);
return stanza;
},

View File

@ -24,10 +24,11 @@ function pong (ping) {
}
export function registerPongHandler () {
if (_converse.connection.disco !== undefined) {
const { connection } = _converse;
if (connection.disco) {
api.disco.own.features.add(Strophe.NS.PING);
}
return _converse.connection.addHandler(pong, Strophe.NS.PING, "iq", "get");
return connection.addHandler(pong, Strophe.NS.PING, "iq", "get");
}
export function registerPingHandler () {

View File

@ -5,7 +5,14 @@
import XMPPStatus from './status.js';
import status_api from './api.js';
import { _converse, api, converse } from '@converse/headless/core';
import { initStatus, onEverySecond, onUserActivity, registerIntervalHandler, sendCSI } from './utils.js';
import {
addStatusToMUCJoinPresence,
initStatus,
onEverySecond,
onUserActivity,
registerIntervalHandler,
sendCSI
} from './utils.js';
const { Strophe } = converse.env;
@ -54,5 +61,6 @@ converse.plugins.add('converse-status', {
api.listen.on('connected', () => initStatus(false));
api.listen.on('reconnected', () => initStatus(true));
api.listen.on('constructedMUCPresence', addStatusToMUCJoinPresence);
}
});

View File

@ -126,3 +126,17 @@ export function registerIntervalHandler () {
window.addEventListener(unloadevent, () => _converse.session?.save('active', false));
_converse.everySecondTrigger = window.setInterval(_converse.onEverySecond, 1000);
}
export function addStatusToMUCJoinPresence (_, stanza) {
const { xmppstatus } = _converse;
const status = xmppstatus.get('status');
if (['away', 'chat', 'dnd', 'xa'].includes(status)) {
stanza.c('show').t(status).up();
}
const status_message = xmppstatus.get('status_message');
if (status_message) {
stanza.c('status').t(status_message).up();
}
return stanza;
}