-
-
Notifications
You must be signed in to change notification settings - Fork 819
XEP-0202 Entity Time #3978
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
SeveFP
wants to merge
7
commits into
conversejs:master
Choose a base branch
from
SeveFP:xep-0202-entity-time
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
XEP-0202 Entity Time #3978
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
152cfa9
XEP-0202 Entity Time
SeveFP 31315c9
follow reply-preview element for time alerts
SeveFP bfb502e
specify support
SeveFP ba6a233
improve tests
SeveFP cc5b6aa
send_entity_time: disable responding to entity time queries
SeveFP a145837
being explicit allows better testing
SeveFP ad8ca3a
user-friendly text and icon
SeveFP 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
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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import api from '../../shared/api/index.js'; | ||
| import converse from '../../shared/api/public.js'; | ||
| import log from '@converse/log'; | ||
|
|
||
| const { Strophe, stx, u } = converse.env; | ||
|
|
||
| export default { | ||
| /** | ||
| * The "time" namespace groups methods for XEP-0202 Entity Time | ||
| * @namespace api.time | ||
| * @memberOf api | ||
| */ | ||
| time: { | ||
| /** | ||
| * Gets the entity time from a JID per XEP-0202 | ||
| * @method api.time.get | ||
| * @param {string} jid - The JID to query for time | ||
| * @param {number} [timeout=10000] - Timeout in milliseconds | ||
| * @returns {Promise<{utc: Date, tzo: string}|null>} The entity's time info or null on error | ||
| */ | ||
| async get(jid, timeout = 10000) { | ||
| if (!api.connection.authenticated()) { | ||
| log.debug('Not querying time when not authenticated'); | ||
| return null; | ||
| } | ||
|
|
||
| const iq = stx` | ||
| <iq type="get" to="${jid}" id="${u.getUniqueId('time')}" xmlns="jabber:client"> | ||
| <time xmlns="${Strophe.NS.TIME}"/> | ||
| </iq>`; | ||
|
|
||
| const result = await api.sendIQ(iq, timeout, false); | ||
|
|
||
| if (result === null) { | ||
| log.warn(`Timeout while getting time from ${jid}`); | ||
| return null; | ||
| } else if (u.isErrorStanza(result)) { | ||
| log.debug(`Error getting time from ${jid} (entity may not support XEP-0202)`); | ||
| return null; | ||
| } | ||
|
|
||
| const time_el = result.querySelector('time'); | ||
| const utc_str = time_el?.querySelector('utc')?.textContent; | ||
| const tzo = time_el?.querySelector('tzo')?.textContent; | ||
|
|
||
| if (!utc_str || !tzo) { | ||
| log.error('Invalid time response - missing utc or tzo'); | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| utc: new Date(utc_str), | ||
| tzo: tzo | ||
| }; | ||
| } | ||
| } | ||
| }; |
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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * @description | ||
| * Converse.js plugin which adds support for XEP-0202 Entity Time. | ||
| * @see https://xmpp.org/extensions/xep-0202.html | ||
| * @copyright 2026, the Converse.js contributors | ||
| * @license Mozilla Public License (MPLv2) | ||
| */ | ||
| import api from '../../shared/api/index.js'; | ||
| import converse from '../../shared/api/public.js'; | ||
| import time_api from './api.js'; | ||
| import { registerTimeHandler } from './utils.js'; | ||
|
|
||
| const { Strophe } = converse.env; | ||
|
|
||
| converse.plugins.add('converse-time', { | ||
|
|
||
| initialize() { | ||
| api.settings.extend({ | ||
| 'send_entity_time': true, // Whether to respond to time requests | ||
| 'show_entity_time': true, | ||
| 'entity_time_warning_start': 22, | ||
| 'entity_time_warning_end': 7, | ||
| 'entity_time_min_diff_hours': 0, // Minimum timezone difference to show warning (0 = any different timezone) | ||
| }); | ||
|
|
||
| Object.assign(api, time_api); | ||
|
|
||
| api.listen.on('connected', registerTimeHandler); | ||
| api.listen.on('reconnected', registerTimeHandler); | ||
| } | ||
| }); | ||
Oops, something went wrong.
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.