Skip to content

Node.js based forum software built for the modern web

feat: Activity Intent trigger modal

Julian Lam2aa97baa5351
diff --git a/public/language/en-GB/intents.json b/public/language/en-GB/intents.json
index cff9c83f59..4e5e92b113 100644
--- a/public/language/en-GB/intents.json
+++ b/public/language/en-GB/intents.json
@@ -8,5 +8,10 @@
"no-handles": "No handles registered yet.",
"intents-label": "Supported Intents",
"register-error": "Failed to register handle. Please check the handle format and try again.",
- "invalid-handle": "Please enter a valid handle in the format @[email protected]"
+ "invalid-handle": "Please enter a valid handle in the format @[email protected]",
+ "trigger-title": "%1 via Open Social Web",
+ "trigger-description": "Please log in to your forum account, or choose an Open Social Web handle to complete this action",
+ "trigger-your-handles": "Your Registered Handles",
+ "trigger-yes": "Yes, use this",
+ "trigger-no-matching": "No registered handles support this intent. Register a new handle or log in."
}
diff --git a/public/src/modules/intents.js b/public/src/modules/intents.js
index eca46b2439..42e19bc98b 100644
--- a/public/src/modules/intents.js
+++ b/public/src/modules/intents.js
@@ -158,4 +158,45 @@ export function register() {
}
});
});
-}
\ No newline at end of file
+}
+
+export function trigger(intent) {
+ const map = list();
+ const requiredIntent = intent.toLowerCase();
+ const displayIntent = INTENT_DISPLAY_MAP[requiredIntent] || intent;
+
+ const entries = Array.from(map.entries()).map(([handle, intents]) => ({ handle, intents }));
+ const matchingHandles = entries
+ .filter(entry => Array.isArray(entry.intents) && entry.intents.some(i => i.toLowerCase() === requiredIntent))
+ .map(entry => ({ handle: entry.handle, intents: mapIntentNames(entry.intents).join(', ') }));
+
+ app.parseAndTranslate('modals/intents/trigger', {
+ displayIntent,
+ matchingHandles,
+ hasAnyHandles: map.size > 0,
+ }, (html) => {
+ const modal = dialog({
+ title: `[[intents:trigger-title, ${displayIntent}]]`,
+ message: html,
+ });
+
+ // Handle intent execution from a registered handle
+ modal.on('click', '[data-action="execute-intent"]', function () {
+ const handle = $(this).attr('data-handle');
+ modal.modal('hide');
+ console.log('Intent triggered:', intent, 'Handle:', handle);
+ });
+
+ // Open handle registration modal
+ modal.on('click', '[data-action="open-register"]', function () {
+ modal.modal('hide');
+ setTimeout(() => register(), 300);
+ });
+
+ // Redirect to login
+ modal.on('click', '[data-action="go-login"]', function () {
+ modal.modal('hide');
+ ajaxify.go('login');
+ });
+ });
+}
diff --git a/src/views/modals/intents/trigger.tpl b/src/views/modals/intents/trigger.tpl
new file mode 100644
index 0000000000..de88f009f2
--- /dev/null
+++ b/src/views/modals/intents/trigger.tpl
@@ -0,0 +1,39 @@
+<div class="modal-intents-trigger">
+ <button type="button" class="btn btn-primary text-capitalize w-100" data-action="go-login">
+ <i class="fa fa-sign-in-alt"></i> [[globals:login]]
+ </button>
+
+ <hr />
+
+ <p>[[intents:trigger-description]]</p>
+
+ {{{ if (matchingHandles && matchingHandles.length) }}}
+ <hr />
+ <h6 class="mt-3">[[intents:trigger-your-handles]]</h6>
+ <ul class="list-group list-group-flush" id="intents-trigger-list">
+ {{{ each matchingHandles }}}
+ <li class="list-group-item d-flex justify-content-between align-items-center">
+ <div>
+ <strong>{./handle}</strong>
+ {{{ if ./intents }}}<small class="text-muted ms-2">({./intents})</small>{{{ end }}}
+ </div>
+ <button type="button" class="btn btn-sm btn-outline-primary" data-action="execute-intent" data-handle="{./handle}">
+ <i class="fa fa-check"></i> [[intents:trigger-yes]]
+ </button>
+ </li>
+ {{{ end }}}
+ </ul>
+ {{{ end }}}
+
+ {{{ if (hasAnyHandles && (!matchingHandles || !matchingHandles.length)) }}}
+ <hr />
+ <p class="text-muted mt-3 text-sm">[[intents:trigger-no-matching]]</p>
+ {{{ end }}}
+
+ <hr />
+ <div class="d-flex gap-2 mt-3">
+ <button type="button" class="btn btn-link" data-action="open-register">
+ <i class="fa fa-share-alt"></i> [[login:manage-social-web-handles]]
+ </button>
+ </div>
+</div>