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 (YYYY-MM-DD)'),
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(`We were unable to understand the given date (${args}). Try using the format YYYY-MM-DD.`);
}

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
16 changes: 16 additions & 0 deletions src/components/views/settings/tabs/user/LabsUserSettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class LabsSettingToggle extends React.Component<ILabsSettingToggleProps>

interface IState {
showHiddenReadReceipts: boolean;
showJumpToDate: boolean;
}

@replaceableComponent("views.settings.tabs.user.LabsUserSettingsTab")
Expand All @@ -60,8 +61,13 @@ export default class LabsUserSettingsTab extends React.Component<{}, IState> {
this.setState({ showHiddenReadReceipts });
});

MatrixClientPeg.get().doesServerSupportUnstableFeature("org.matrix.msc2716").then((showJumpToDate) => {
this.setState({ showJumpToDate });
});

this.state = {
showHiddenReadReceipts: false,
showJumpToDate: false,
};
}

Expand Down Expand Up @@ -135,6 +141,16 @@ export default class LabsUserSettingsTab extends React.Component<{}, IState> {
);
}

if (this.state.showJumpToDate) {
groups.getOrCreate(LabGroup.Messaging, []).push(
<SettingsFlag
key="feature_jump_to_date"
name="feature_jump_to_date"
level={SettingLevel.DEVICE}
/>,
);
}

labsSection = <div className="mx_SettingsTab_section">
{ sortBy(Array.from(groups.entries()), "0").map(([group, flags]) => (
<div key={group}>
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
9 changes: 9 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ export const SETTINGS: {[setting: string]: ISetting} = {
displayName: _td("New spotlight search experience"),
default: false,
},
"feature_jump_to_date": {
// We purposely leave out `isFeature: true` so it doesn't show in Labs
// by default. We will conditionally show it depending on whether we can
// detect MSC3030 support (see LabUserSettingsTab.tsx).
// labsGroup: LabGroup.Messaging,
displayName: _td("Jump to date (adds /jumptodate)"),
supportedLevels: LEVELS_FEATURE,
default: false,
},
"RoomList.backgroundImage": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
default: null,
Expand Down