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

Commit 1e09599

Browse files
Add /jumptodate slash command (#7372)
Fix element-hq/element-web#7677 Utilizing MSC3030: matrix-org/matrix-spec-proposals#3030 Experimental Synapse implementation added in matrix-org/synapse#9445 --- Jump to date headers are being worked on in #7339
1 parent 48a3798 commit 1e09599

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

src/SlashCommands.tsx

Lines changed: 45 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,50 @@ 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 (YYYY-MM-DD)'),
294+
isEnabled: () => SettingsStore.getValue("feature_jump_to_date"),
295+
runFn: function(roomId, args) {
296+
if (args) {
297+
return success((async () => {
298+
const unixTimestamp = Date.parse(args);
299+
if (!unixTimestamp) {
300+
throw new Error(
301+
// FIXME: Use newTranslatableError here instead
302+
// otherwise the rageshake error messages will be
303+
// translated too
304+
_t(
305+
// eslint-disable-next-line max-len
306+
'We were unable to understand the given date (%(inputDate)s). Try using the format YYYY-MM-DD.',
307+
{ inputDate: args },
308+
),
309+
);
310+
}
311+
312+
const cli = MatrixClientPeg.get();
313+
const { event_id: eventId, origin_server_ts: originServerTs } = await cli.timestampToEvent(
314+
roomId,
315+
unixTimestamp,
316+
Direction.Forward,
317+
);
318+
logger.log(
319+
`/timestamp_to_event: found ${eventId} (${originServerTs}) for timestamp=${unixTimestamp}`,
320+
);
321+
dis.dispatch({
322+
action: Action.ViewRoom,
323+
eventId,
324+
highlighted: true,
325+
room_id: roomId,
326+
});
327+
})());
328+
}
329+
330+
return reject(this.getUsage());
331+
},
332+
category: CommandCategories.actions,
333+
}),
289334
new Command({
290335
command: 'nick',
291336
args: '<display_name>',

src/components/views/settings/tabs/user/LabsUserSettingsTab.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class LabsSettingToggle extends React.Component<ILabsSettingToggleProps>
4949

5050
interface IState {
5151
showHiddenReadReceipts: boolean;
52+
showJumpToDate: boolean;
5253
}
5354

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

64+
MatrixClientPeg.get().doesServerSupportUnstableFeature("org.matrix.msc2716").then((showJumpToDate) => {
65+
this.setState({ showJumpToDate });
66+
});
67+
6368
this.state = {
6469
showHiddenReadReceipts: false,
70+
showJumpToDate: false,
6571
};
6672
}
6773

@@ -135,6 +141,16 @@ export default class LabsUserSettingsTab extends React.Component<{}, IState> {
135141
);
136142
}
137143

144+
if (this.state.showJumpToDate) {
145+
groups.getOrCreate(LabGroup.Messaging, []).push(
146+
<SettingsFlag
147+
key="feature_jump_to_date"
148+
name="feature_jump_to_date"
149+
level={SettingLevel.DEVICE}
150+
/>,
151+
);
152+
}
153+
138154
labsSection = <div className="mx_SettingsTab_section">
139155
{ sortBy(Array.from(groups.entries()), "0").map(([group, flags]) => (
140156
<div key={group}>

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@
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 (YYYY-MM-DD)": "Jump to the given date in the timeline (YYYY-MM-DD)",
439+
"We were unable to understand the given date (%(inputDate)s). Try using the format YYYY-MM-DD.": "We were unable to understand the given date (%(inputDate)s). Try using the format YYYY-MM-DD.",
438440
"Changes your display nickname": "Changes your display nickname",
439441
"Changes your display nickname in the current room only": "Changes your display nickname in the current room only",
440442
"Changes the avatar of the current room": "Changes the avatar of the current room",
@@ -860,6 +862,7 @@
860862
"Meta Spaces": "Meta Spaces",
861863
"Use new room breadcrumbs": "Use new room breadcrumbs",
862864
"New spotlight search experience": "New spotlight search experience",
865+
"Jump to date (adds /jumptodate)": "Jump to date (adds /jumptodate)",
863866
"Don't send read receipts": "Don't send read receipts",
864867
"Font size": "Font size",
865868
"Use custom size": "Use custom size",

src/settings/Settings.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,15 @@ export const SETTINGS: {[setting: string]: ISetting} = {
367367
displayName: _td("New spotlight search experience"),
368368
default: false,
369369
},
370+
"feature_jump_to_date": {
371+
// We purposely leave out `isFeature: true` so it doesn't show in Labs
372+
// by default. We will conditionally show it depending on whether we can
373+
// detect MSC3030 support (see LabUserSettingsTab.tsx).
374+
// labsGroup: LabGroup.Messaging,
375+
displayName: _td("Jump to date (adds /jumptodate)"),
376+
supportedLevels: LEVELS_FEATURE,
377+
default: false,
378+
},
370379
"RoomList.backgroundImage": {
371380
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
372381
default: null,

0 commit comments

Comments
 (0)