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

Commit

Permalink
Add /jumptodate slash command
Browse files Browse the repository at this point in the history
Fix element-hq/element-web#7677

Utilizing MSC3030: matrix-org/matrix-spec-proposals#3030

Experimental Synapse implementation added in matrix-org/synapse#9445
  • Loading branch information
MadLittleMods committed Dec 15, 2021
1 parent 42b14bf commit d15e609
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/SlashCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.

import * as React from 'react';
import { User } from "matrix-js-sdk/src/models/user";
import { Direction } from 'matrix-js-sdk/src/models/event-timeline';
import { EventType } from "matrix-js-sdk/src/@types/event";
import * as ContentHelpers from 'matrix-js-sdk/src/content-helpers';
import { parseFragment as parseHtml, Element as ChildElement } from "parse5";
Expand Down Expand Up @@ -286,6 +287,38 @@ export const Commands = [
category: CommandCategories.admin,
renderingTypes: [TimelineRenderingType.Room],
}),
new Command({
command: 'jumptodate',
args: '<date>',
description: _td('Jump to the given date in the timeline'),
runFn: function(roomId, args) {
if (args) {
return success((async () => {
const unixTimestamp = Date.parse(args);
if (!unixTimestamp) {
throw new Error(`Unable to parse given date ${args}`);
}

const cli = MatrixClientPeg.get();
const { event_id, origin_server_ts } = await cli.timestampToEvent(
roomId,
unixTimestamp,
Direction.Forward,
)
logger.log(`/timestamp_to_event: found ${event_id} (${origin_server_ts}) for timestamp=${unixTimestamp}`);
dis.dispatch({
action: Action.ViewRoom,
event_id,
highlighted: true,
room_id: roomId,
});
})());
}

return reject(this.getUsage());
},
category: CommandCategories.actions,
}),
new Command({
command: 'nick',
args: '<display_name>',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
"Sends a message as html, without interpreting it as markdown": "Sends a message as html, without interpreting it as markdown",
"Upgrades a room to a new version": "Upgrades a room to a new version",
"You do not have the required permissions to use this command.": "You do not have the required permissions to use this command.",
"Jump to the given date in the timeline": "Jump to the given date in the timeline",
"Changes your display nickname": "Changes your display nickname",
"Changes your display nickname in the current room only": "Changes your display nickname in the current room only",
"Changes the avatar of the current room": "Changes the avatar of the current room",
Expand Down

0 comments on commit d15e609

Please sign in to comment.