-
-
Notifications
You must be signed in to change notification settings - Fork 801
Adding support for protocol handler #3870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marcellintacite
wants to merge
17
commits into
conversejs:master
Choose a base branch
from
marcellintacite:add-protocol-handler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2ba6ada
Adding support for protocol handler
marcellintacite 9c5f20d
Move protocol handler into chatView and update the route to chat func…
marcellintacite 5b41936
Adding support for the XEP-0147 (Protocol handler)
marcellintacite be0d75c
Update src/plugins/chatview/utils.js
marcellintacite a32cec0
Update src/plugins/chatview/utils.js
marcellintacite 956b471
Update src/plugins/chatview/utils.js
marcellintacite 40f8f7f
Updating the DOAP, updating url
marcellintacite 29af0c9
Adding test for the routeToQuestionAction function
marcellintacite 80114ef
Merge branch 'conversejs:master' into add-protocol-handler
marcellintacite 40538e3
Update CHANGES.md
marcellintacite 71e9037
Updating the doap file
marcellintacite baaced6
Update manifest.json
marcellintacite ff769df
Removing the protocol handler (?uri=...)
marcellintacite 0e3175b
Fix: Adding routeToQuery in the u object
marcellintacite a22c1a0
Fix: Adding routeToQuery in the u object
marcellintacite 8c91e48
Fixing tests
marcellintacite cd88326
chore: remove genkit metadata
marcellintacite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import { __ } from 'i18n'; | ||
| import { _converse, api } from '@converse/headless'; | ||
| import log from "@converse/log"; | ||
|
|
||
|
|
||
| export function clearHistory (jid) { | ||
| if (location.hash === `converse/chat?jid=${jid}`) { | ||
|
|
@@ -71,3 +73,121 @@ export function resetElementHeight (ev) { | |
| ev.target.style = ''; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Handle XEP-0147 "query actions" invoked via xmpp: URIs. | ||
| * Supports message sending, roster management, and future actions. | ||
| * | ||
| * Example URIs: | ||
| * xmpp:[email protected]?action=message&body=Hello | ||
| * xmpp:[email protected]?action=add-roster&name=John&group=Friends | ||
| */ | ||
| export async function routeToQueryAction(event) { | ||
| const { u } = _converse.env; | ||
|
|
||
| try { | ||
| const uri = extractXMPPURI(event); | ||
| if (!uri) return; | ||
|
|
||
| const { jid, queryParams } = parseXMPPURI(uri); | ||
| if (!u.isValidJID(jid)) { | ||
| return log.warn(`Invalid JID: "${jid}"`); | ||
marcellintacite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| const action = queryParams.get('action'); | ||
| if (!action) { | ||
| log.debug(`No action specified, opening chat for "${jid}"`); | ||
marcellintacite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return api.chats.open(jid); | ||
| } | ||
|
|
||
| switch (action) { | ||
| case 'message': | ||
| await handleMessageAction(jid, queryParams); | ||
| break; | ||
|
|
||
| case 'add-roster': | ||
| await handleRosterAction(jid, queryParams); | ||
| break; | ||
|
|
||
| default: | ||
| log.warn(`Unsupported XEP-0147 action: "${action}"`); | ||
marcellintacite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await api.chats.open(jid); | ||
| } | ||
| } catch (error) { | ||
| log.error('Failed to process XMPP query action:', error); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extracts and decodes the xmpp: URI from the window location or hash. | ||
| */ | ||
| function extractXMPPURI(event) { | ||
| let uri = null; | ||
|
|
||
| // Case 1: protocol handler (?uri=...) | ||
| const searchParams = new URLSearchParams(window.location.search); | ||
marcellintacite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| uri = searchParams.get('uri'); | ||
|
|
||
| // Case 2: hash-based (#converse/action?uri=...) | ||
marcellintacite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!uri && location.hash.startsWith('#converse/action?uri=')) { | ||
|
||
| event?.preventDefault(); | ||
| uri = location.hash.split('uri=').pop(); | ||
| } | ||
|
|
||
| if (!uri) return null; | ||
|
|
||
| // Decode URI and remove xmpp: prefix | ||
| uri = decodeURIComponent(uri); | ||
| if (uri.startsWith('xmpp:')) uri = uri.slice(5); | ||
|
|
||
| // Clean up URL (remove ?uri=... for a clean view) | ||
| const cleanUrl = `${window.location.origin}${window.location.pathname}`; | ||
| window.history.replaceState({}, document.title, cleanUrl); | ||
|
|
||
| return uri; | ||
| } | ||
|
|
||
| /** | ||
| * Splits an xmpp: URI into a JID and query parameters. | ||
| */ | ||
| function parseXMPPURI(uri) { | ||
| const [jid, query] = uri.split('?'); | ||
| const queryParams = new URLSearchParams(query); | ||
| return { jid, queryParams }; | ||
| } | ||
|
|
||
| /** | ||
| * Handles the `action=message` case. | ||
| */ | ||
| async function handleMessageAction(jid, params) { | ||
| const body = params.get('body') || ''; | ||
| const chat = await api.chats.open(jid); | ||
|
|
||
| if (body && chat) { | ||
| await chat.sendMessage({ body }); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Handles the `action=add-roster` case. | ||
| */ | ||
| async function handleRosterAction(jid, params) { | ||
| await api.waitUntil('connected'); | ||
| await api.waitUntil('rosterContactsFetched'); | ||
marcellintacite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const name = params.get('name') || jid.split('@')[0]; | ||
| const group = params.get('group'); | ||
| const groups = group ? [group] : []; | ||
|
|
||
| try { | ||
| await api.contacts.add( | ||
| { jid, name, groups }, | ||
| true, // persist on server | ||
| true, // subscribe to presence | ||
| '' // no custom message | ||
| ); | ||
| } catch (err) { | ||
| log.error(`Failed to add "${jid}" to roster:`, err); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.