Remove call to api.confirm in @converse/headless

This commit is contained in:
JC Brand 2023-02-22 15:21:56 +01:00
parent c38c706079
commit 05c5cd1046
4 changed files with 36 additions and 16 deletions

View File

@ -5,6 +5,7 @@
- Add the ability to set roles and affiliations via the MUC occupant modal - Add the ability to set roles and affiliations via the MUC occupant modal
- Fix `isOnlyEmojis is not a function` when using only `@converse/headless` - Fix `isOnlyEmojis is not a function` when using only `@converse/headless`
- Fix `autojoin` checkbox state in MUC bookmark form - Fix `autojoin` checkbox state in MUC bookmark form
- Remove call to `api.confirm` in `@converse/headless`
## 10.1.2 (2023-02-17) ## 10.1.2 (2023-02-17)

View File

@ -88,7 +88,6 @@ export async function openChatRoom (jid, settings) {
* @param { XMLElement } message - The message stanza containing the invitation. * @param { XMLElement } message - The message stanza containing the invitation.
*/ */
export async function onDirectMUCInvitation (message) { export async function onDirectMUCInvitation (message) {
const { __ } = _converse;
const x_el = sizzle('x[xmlns="jabber:x:conference"]', message).pop(), const x_el = sizzle('x[xmlns="jabber:x:conference"]', message).pop(),
from = Strophe.getBareJidFromJid(message.getAttribute('from')), from = Strophe.getBareJidFromJid(message.getAttribute('from')),
room_jid = x_el.getAttribute('jid'), room_jid = x_el.getAttribute('jid'),
@ -99,21 +98,20 @@ export async function onDirectMUCInvitation (message) {
result = true; result = true;
} else { } else {
// Invite request might come from someone not your roster list // Invite request might come from someone not your roster list
let contact = _converse.roster.get(from); const contact = _converse.roster.get(from)?.getDisplayName() ?? from;
contact = contact ? contact.getDisplayName() : from;
if (!reason) { /**
result = await api.confirm(__('%1$s has invited you to join a groupchat: %2$s', contact, room_jid)); * *Hook* which is used to gather confirmation whether a direct MUC
} else { * invitation should be accepted or not.
result = await api.confirm( *
__( * It's meant for consumers of `@converse/headless` to subscribe to
'%1$s has invited you to join a groupchat: %2$s, and left the following reason: "%3$s"', * this hook and then ask the user to confirm.
contact, *
room_jid, * @event _converse#confirmDirectMUCInvitation
reason */
) result = await api.hook('confirmDirectMUCInvitation', { contact, reason, jid: room_jid }, false);
);
}
} }
if (result) { if (result) {
const chatroom = await openChatRoom(room_jid, { 'password': x_el.getAttribute('password') }); const chatroom = await openChatRoom(room_jid, { 'password': x_el.getAttribute('password') });
if (chatroom.session.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED) { if (chatroom.session.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED) {

View File

@ -8,7 +8,7 @@ import './affiliation-form.js';
import './role-form.js'; import './role-form.js';
import MUCView from './muc.js'; import MUCView from './muc.js';
import { api, converse } from '@converse/headless/core.js'; import { api, converse } from '@converse/headless/core.js';
import { clearHistory, parseMessageForMUCCommands } from './utils.js'; import { clearHistory, confirmDirectMUCInvitation, parseMessageForMUCCommands } from './utils.js';
const { Strophe } = converse.env; const { Strophe } = converse.env;
@ -92,5 +92,6 @@ converse.plugins.add('converse-muc-views', {
}); });
api.listen.on('parseMessageForCommands', parseMessageForMUCCommands); api.listen.on('parseMessageForCommands', parseMessageForMUCCommands);
api.listen.on('confirmDirectMUCInvitation', confirmDirectMUCInvitation);
} }
}); });

View File

@ -24,6 +24,26 @@ const COMMAND_TO_ROLE = {
'voice': 'participant' 'voice': 'participant'
}; };
/**
* @async
* Presents a confirmation modal to the user asking them to accept or decline a
* MUC invitation.
*/
export function confirmDirectMUCInvitation ({ contact, jid, reason }) {
if (!reason) {
return api.confirm(__('%1$s has invited you to join a groupchat: %2$s', contact, jid));
} else {
return api.confirm(
__(
'%1$s has invited you to join a groupchat: %2$s, and left the following reason: "%3$s"',
contact,
jid,
reason
)
);
}
}
export function clearHistory (jid) { export function clearHistory (jid) {
if (_converse.router.history.getFragment() === `converse/room?jid=${jid}`) { if (_converse.router.history.getFragment() === `converse/room?jid=${jid}`) {
_converse.router.navigate(''); _converse.router.navigate('');