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

Add /jumptodate slash command #7372

Merged
merged 13 commits into from
Dec 15, 2021
36 changes: 36 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,41 @@ 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'),
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
isEnabled: () => SettingsStore.getValue("feature_jump_to_date"),
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}`);
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
}

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

return reject(this.getUsage());
},
category: CommandCategories.actions,
}),
new Command({
command: 'nick',
args: '<display_name>',
Expand Down
2 changes: 2 additions & 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 Expand Up @@ -860,6 +861,7 @@
"Meta Spaces": "Meta Spaces",
"Use new room breadcrumbs": "Use new room breadcrumbs",
"New spotlight search experience": "New spotlight search experience",
"Jump to date (adds /jumptodate). Also requires your homeserver to have MSC3030 enabled": "Jump to date (adds /jumptodate). Also requires your homeserver to have MSC3030 enabled",
"Don't send read receipts": "Don't send read receipts",
"Font size": "Font size",
"Use custom size": "Use custom size",
Expand Down
7 changes: 7 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ export const SETTINGS: {[setting: string]: ISetting} = {
displayName: _td("New spotlight search experience"),
default: false,
},
"feature_jump_to_date": {
isFeature: true,
labsGroup: LabGroup.Messaging,
displayName: _td("Jump to date (adds /jumptodate). Also requires your homeserver to have MSC3030 enabled"),
supportedLevels: LEVELS_FEATURE,
default: false,
},
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
"RoomList.backgroundImage": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
default: null,
Expand Down