Add /jumptodate
slash command (#7372)
Fix https://github.com/vector-im/element-web/issues/7677 Utilizing MSC3030: https://github.com/matrix-org/matrix-doc/pull/3030 Experimental Synapse implementation added in https://github.com/matrix-org/synapse/pull/9445 --- Jump to date headers are being worked on in https://github.com/matrix-org/matrix-react-sdk/pull/7339
This commit is contained in:
parent
48a37985f5
commit
1e09599447
4 changed files with 73 additions and 0 deletions
|
@ -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";
|
||||
|
@ -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>',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue