@@ -19,6 +19,7 @@ limitations under the License.
1919
2020import * as React from 'react' ;
2121import { User } from "matrix-js-sdk/src/models/user" ;
22+ import { Direction } from 'matrix-js-sdk/src/models/event-timeline' ;
2223import { EventType } from "matrix-js-sdk/src/@types/event" ;
2324import * as ContentHelpers from 'matrix-js-sdk/src/content-helpers' ;
2425import { parseFragment as parseHtml , Element as ChildElement } from "parse5" ;
@@ -286,6 +287,38 @@ 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' ) ,
294+ runFn : function ( roomId , args ) {
295+ if ( args ) {
296+ return success ( ( async ( ) => {
297+ const unixTimestamp = Date . parse ( args ) ;
298+ if ( ! unixTimestamp ) {
299+ throw new Error ( `Unable to parse given date ${ args } ` ) ;
300+ }
301+
302+ const cli = MatrixClientPeg . get ( ) ;
303+ const { event_id, origin_server_ts } = await cli . timestampToEvent (
304+ roomId ,
305+ unixTimestamp ,
306+ Direction . Forward ,
307+ )
308+ logger . log ( `/timestamp_to_event: found ${ event_id } (${ origin_server_ts } ) for timestamp=${ unixTimestamp } ` ) ;
309+ dis . dispatch ( {
310+ action : Action . ViewRoom ,
311+ event_id,
312+ highlighted : true ,
313+ room_id : roomId ,
314+ } ) ;
315+ } ) ( ) ) ;
316+ }
317+
318+ return reject ( this . getUsage ( ) ) ;
319+ } ,
320+ category : CommandCategories . actions ,
321+ } ) ,
289322 new Command ( {
290323 command : 'nick' ,
291324 args : '<display_name>' ,
0 commit comments