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 (#7372)
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

---

Jump to date headers are being worked on in #7339
  • Loading branch information
MadLittleMods authored Dec 15, 2021
1 parent 48a3798 commit 1e09599
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
45 changes: 45 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,50 @@ 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(
// FIXME: Use newTranslatableError here instead
// otherwise the rageshake error messages will be
// translated too
_t(
// eslint-disable-next-line max-len
'We were unable to understand the given date (%(inputDate)s). Try using the format YYYY-MM-DD.',
{ inputDate: args },
),
);
}

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
3 changes: 3 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@
"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 (YYYY-MM-DD)": "Jump to the given date in the timeline (YYYY-MM-DD)",
"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.",
"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 +862,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)": "Jump to date (adds /jumptodate)",
"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

0 comments on commit 1e09599

Please sign in to comment.