@@ -25,6 +25,8 @@ import { RoomPermalinkCreator } from '../../../utils/permalinks/Permalinks';
2525import { replaceableComponent } from "../../../utils/replaceableComponent" ;
2626import DateSeparator from "../messages/DateSeparator" ;
2727import EventTile , { haveTileForEvent } from "./EventTile" ;
28+ import { shouldFormContinuation } from "../../structures/MessagePanel" ;
29+ import { wantsDateSeparator } from "../../../DateUtils" ;
2830
2931interface IProps {
3032 // a matrix-js-sdk SearchResult containing the details of this result
@@ -43,10 +45,10 @@ export default class SearchResultTile extends React.Component<IProps> {
4345
4446 public render ( ) {
4547 const result = this . props . searchResult ;
46- const mxEv = result . context . getEvent ( ) ;
47- const eventId = mxEv . getId ( ) ;
48+ const resultEvent = result . context . getEvent ( ) ;
49+ const eventId = resultEvent . getId ( ) ;
4850
49- const ts1 = mxEv . getTs ( ) ;
51+ const ts1 = resultEvent . getTs ( ) ;
5052 const ret = [ < DateSeparator key = { ts1 + "-search" } ts = { ts1 } /> ] ;
5153 const layout = SettingsStore . getValue ( "layout" ) ;
5254 const isTwelveHour = SettingsStore . getValue ( "showTwelveHourTimestamps" ) ;
@@ -55,17 +57,46 @@ export default class SearchResultTile extends React.Component<IProps> {
5557
5658 const timeline = result . context . getTimeline ( ) ;
5759 for ( let j = 0 ; j < timeline . length ; j ++ ) {
58- const ev = timeline [ j ] ;
60+ const mxEv = timeline [ j ] ;
5961 let highlights ;
6062 const contextual = ( j != result . context . getOurEventIndex ( ) ) ;
6163 if ( ! contextual ) {
6264 highlights = this . props . searchHighlights ;
6365 }
64- if ( haveTileForEvent ( ev , this . context ?. showHiddenEventsInTimeline ) ) {
66+
67+ if ( haveTileForEvent ( mxEv , this . context ?. showHiddenEventsInTimeline ) ) {
68+ // do we need a date separator since the last event?
69+ const prevEv = timeline [ j - 1 ] ;
70+ // is this a continuation of the previous message?
71+ const continuation = prevEv &&
72+ ! wantsDateSeparator ( prevEv . getDate ( ) , mxEv . getDate ( ) ) &&
73+ shouldFormContinuation (
74+ prevEv ,
75+ mxEv ,
76+ this . context ?. showHiddenEventsInTimeline ,
77+ TimelineRenderingType . Search ,
78+ ) ;
79+
80+ let lastInSection = true ;
81+ const nextEv = timeline [ j + 1 ] ;
82+ if ( nextEv ) {
83+ const willWantDateSeparator = wantsDateSeparator ( mxEv . getDate ( ) , nextEv . getDate ( ) ) ;
84+ lastInSection = (
85+ willWantDateSeparator ||
86+ mxEv . getSender ( ) !== nextEv . getSender ( ) ||
87+ ! shouldFormContinuation (
88+ mxEv ,
89+ nextEv ,
90+ this . context ?. showHiddenEventsInTimeline ,
91+ TimelineRenderingType . Search ,
92+ )
93+ ) ;
94+ }
95+
6596 ret . push (
6697 < EventTile
6798 key = { `${ eventId } +${ j } ` }
68- mxEvent = { ev }
99+ mxEvent = { mxEv }
69100 layout = { layout }
70101 contextual = { contextual }
71102 highlights = { highlights }
@@ -76,11 +107,15 @@ export default class SearchResultTile extends React.Component<IProps> {
76107 alwaysShowTimestamps = { alwaysShowTimestamps }
77108 enableFlair = { enableFlair }
78109 timelineRenderingType = { TimelineRenderingType . Search }
110+ lastInSection = { lastInSection }
111+ continuation = { continuation }
79112 /> ,
80113 ) ;
81114 }
82115 }
83116
84- return < li data-scroll-tokens = { eventId } > { ret } </ li > ;
117+ return < li data-scroll-tokens = { eventId } >
118+ < ol > { ret } </ ol >
119+ </ li > ;
85120 }
86121}
0 commit comments