Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit d15e609

Browse files
committed
Add /jumptodate slash command
Fix element-hq/element-web#7677 Utilizing MSC3030: matrix-org/matrix-spec-proposals#3030 Experimental Synapse implementation added in matrix-org/synapse#9445
1 parent 42b14bf commit d15e609

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/SlashCommands.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ limitations under the License.
1919

2020
import * as React from 'react';
2121
import { User } from "matrix-js-sdk/src/models/user";
22+
import { Direction } from 'matrix-js-sdk/src/models/event-timeline';
2223
import { EventType } from "matrix-js-sdk/src/@types/event";
2324
import * as ContentHelpers from 'matrix-js-sdk/src/content-helpers';
2425
import { parseFragment as parseHtml, Element as ChildElement } from "parse5";
@@ -286,6 +287,38 @@ export const Commands = [
286287
category: CommandCategories.admin,
287288
renderingTypes: [TimelineRenderingType.Room],
288289
}),
290+
new Command({
291+
command: 'jumptodate',
292+
args: '<date>',
293+
description: _td('Jump to the given date in the timeline'),
294+
runFn: function(roomId, args) {
295+
if (args) {
296+
return success((async () => {
297+
const unixTimestamp = Date.parse(args);
298+
if (!unixTimestamp) {
299+
throw new Error(`Unable to parse given date ${args}`);
300+
}
301+
302+
const cli = MatrixClientPeg.get();
303+
const { event_id, origin_server_ts } = await cli.timestampToEvent(
304+
roomId,
305+
unixTimestamp,
306+
Direction.Forward,
307+
)
308+
logger.log(`/timestamp_to_event: found ${event_id} (${origin_server_ts}) for timestamp=${unixTimestamp}`);
309+
dis.dispatch({
310+
action: Action.ViewRoom,
311+
event_id,
312+
highlighted: true,
313+
room_id: roomId,
314+
});
315+
})());
316+
}
317+
318+
return reject(this.getUsage());
319+
},
320+
category: CommandCategories.actions,
321+
}),
289322
new Command({
290323
command: 'nick',
291324
args: '<display_name>',

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@
435435
"Sends a message as html, without interpreting it as markdown": "Sends a message as html, without interpreting it as markdown",
436436
"Upgrades a room to a new version": "Upgrades a room to a new version",
437437
"You do not have the required permissions to use this command.": "You do not have the required permissions to use this command.",
438+
"Jump to the given date in the timeline": "Jump to the given date in the timeline",
438439
"Changes your display nickname": "Changes your display nickname",
439440
"Changes your display nickname in the current room only": "Changes your display nickname in the current room only",
440441
"Changes the avatar of the current room": "Changes the avatar of the current room",

0 commit comments

Comments
 (0)