Skip to content

Commit 9c5f20d

Browse files
Move protocol handler into chatView and update the route to chat function
1 parent 2ba6ada commit 9c5f20d

File tree

5 files changed

+19
-61
lines changed

5 files changed

+19
-61
lines changed

dev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
muc_show_logs_before_join: true,
3737
notify_all_room_messages: ['discuss@conference.conversejs.org'],
3838
fetch_url_headers: true,
39-
whitelisted_plugins: ['converse-debug','converse-protocol-handler'],
39+
whitelisted_plugins: ['converse-debug'],
4040
bosh_service_url: 'https://conversejs.org/http-bind/', // Please use this connection manager only for testing purposes
4141
// view_mode: 'overlayed',
4242
show_controlbox_by_default: true,

src/headless/plugins/chat/utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ export function routeToChat (event) {
2222
return;
2323
}
2424
event?.preventDefault();
25-
const jid = location.hash.split('=').pop();
25+
let jid = location.hash.split('=').pop();
26+
// decodeURIComponent is needed in case the JID contains special characters
27+
// that were URL-encoded, e.g. `user%40domain` instead of `user@domain`.
28+
jid = decodeURIComponent(jid);
29+
30+
// Remove xmpp: prefix if present
31+
if (jid.startsWith('xmpp:')) {
32+
jid = jid.slice(5);
33+
}
34+
2635
if (!u.isValidJID(jid)) {
2736
return log.warn(`Invalid JID "${jid}" provided in URL fragment`);
2837
}

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import "./plugins/rosterview/index.js";
4242
import "./plugins/singleton/index.js";
4343
import "./plugins/dragresize/index.js"; // Allows chat boxes to be resized by dragging them
4444
import "./plugins/fullscreen/index.js";
45-
import "./plugins/protocol-handler/index.js"; // Handle xmpp: links
4645
/* END: Removable components */
4746

4847
_converse.exports.CustomElement = CustomElement;

src/plugins/chatview/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ converse.plugins.add('converse-chatview', {
6565
Object.assign(_converse, exports); // DEPRECATED
6666
Object.assign(_converse.exports, exports);
6767

68+
if ('registerProtocolHandler' in navigator) {
69+
try {
70+
const handlerUrl = `${window.location.origin}${window.location.pathname}#converse/chat?jid=%s`;
71+
navigator.registerProtocolHandler('xmpp', handlerUrl);
72+
} catch (error) {
73+
console.warn('Failed to register protocol handler:', error);
74+
}
75+
}
6876
api.listen.on('connected', () => api.disco.own.features.add(Strophe.NS.SPOILER));
6977
api.listen.on('chatBoxClosed', (model) => clearHistory(model.get('jid')));
7078
}

src/plugins/protocol-handler/index.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)