|
1 | 1 | // import { EventContext } from "matrix-js-sdk/src/models/event-context"; // eslint-disable-line
|
| 2 | +// import { EventContext } from "matrix-js-sdk/src/models/event-context"; // eslint-disable-line |
| 3 | +// import { MatrixEvent } from "matrix-js-sdk/src/models/event"; // eslint-disable-line |
| 4 | + |
| 5 | +export interface SearchResultItem { |
| 6 | + result: MatrixEventProjection; |
| 7 | + context: EventContextProjection; |
| 8 | +} |
2 | 9 |
|
3 | 10 | export enum DirectionProjection {
|
4 | 11 | Backward = "b",
|
@@ -46,6 +53,8 @@ export interface IPaginateOptsProjection {
|
46 | 53 |
|
47 | 54 | export interface MatrixClientProjection {
|
48 | 55 | paginateEventTimeline(eventTimeline: EventTimelineProjection, opts: IPaginateOptsProjection): Promise<boolean>;
|
| 56 | + // processRoomEventsSearch(searchResults, searchResponse); |
| 57 | + processRoomEventsSearch<T extends ISearchResultsProjection>(searchResults: T, response: ISearchResponseProjection): T; |
49 | 58 | }
|
50 | 59 |
|
51 | 60 | export interface RoomMemberProjection {
|
@@ -114,3 +123,133 @@ export interface EventContextProjection {
|
114 | 123 |
|
115 | 124 | getEvent(): MatrixEventProjection;
|
116 | 125 | }
|
| 126 | + |
| 127 | + |
| 128 | +// export function convertRes(client: MatrixClientProjection, matches : SearchResultItem[]) : any |
| 129 | +// export function convertRes(client: MatrixClientProjection, room: RoomProjection, termObj:any, memberObj : any) : any |
| 130 | +// { |
| 131 | +// const searchResults: ISearchResultsProjection = { |
| 132 | +// results: [], |
| 133 | +// highlights: [], |
| 134 | +// count: 0, |
| 135 | +// }; |
| 136 | + |
| 137 | +// const matches = findAllMatches(termObj, room, memberObj); |
| 138 | + |
| 139 | +// // const converted : |
| 140 | + |
| 141 | +// // Process the matches to produce the equivalent result from a client.search() call |
| 142 | +// // const searchResponse = getClientSearchResponse(searchResults, converted); |
| 143 | + |
| 144 | +// // mimic the original code |
| 145 | +// // const results = client.processRoomEventsSearch(searchResults, searchResponse); |
| 146 | + |
| 147 | +// return matches; |
| 148 | + |
| 149 | +// } |
| 150 | + |
| 151 | +// export function createResultObj(roomEvent : MatrixEvent, prevEvent: MatrixEvent) : EventContext { |
| 152 | +// // export function createResultObj(roomEvent : MatrixEventProjection, prevEvent: MatrixEventProjection) : EventContext { |
| 153 | +// const evCtx = new EventContext(roomEvent); |
| 154 | +// if (prevEvent !== null) { |
| 155 | +// evCtx.addEvents([prevEvent], true); |
| 156 | +// } |
| 157 | + |
| 158 | +// return evCtx; |
| 159 | +// } |
| 160 | + |
| 161 | +// export function reverseEventContext(eventContext: EventContext): EventContextProjection { |
| 162 | +// const contextTimeline = eventContext.getTimeline(); |
| 163 | +// const ourEventIndex = eventContext.getOurEventIndex(); |
| 164 | +// const ourEvent = eventContext.getEvent(); |
| 165 | +// const reversedContext = new EventContext(contextTimeline[ourEventIndex]); |
| 166 | +// let afterOurEvent = false; |
| 167 | + |
| 168 | +// for (let i = 0; i < contextTimeline.length; i++) { |
| 169 | +// const event = contextTimeline[i]; |
| 170 | +// if (event.getId() === ourEvent.getId()) { |
| 171 | +// afterOurEvent = true; |
| 172 | +// continue; |
| 173 | +// } |
| 174 | +// if (afterOurEvent) { |
| 175 | +// reversedContext.addEvents([event], true); |
| 176 | +// this.ourEventIndex += [event].length; |
| 177 | +// } else { |
| 178 | +// this.timeline = this.timeline.concat(event); |
| 179 | +// reversedContext.addEvents([event], false); |
| 180 | +// } |
| 181 | +// } |
| 182 | + |
| 183 | +// const evnt : EventContextProjection[]; |
| 184 | +// evnt.timeline = reversedContext.getTimeline(); |
| 185 | + |
| 186 | +// return evnt; |
| 187 | +// // return reversedContext; |
| 188 | +// } |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | +// // export function findAllMatches(termObj: SearchTerm, room: Room, matchingMembers: MemberObj): SearchResultItem[] { |
| 194 | +// export function findAllMatches(termObj: any, room: RoomProjection, matchingMembers: any): SearchResultItem[] { |
| 195 | +// const matches: SearchResultItem[] = []; |
| 196 | +// let searchHit: SearchResultItem | null = null; |
| 197 | +// let prevEvent: MatrixEventProjection | null = null; |
| 198 | +// let timeline: EventTimelineProjection | null = room.getLiveTimeline(); |
| 199 | + |
| 200 | +// const iterationCallback = (roomEvent: MatrixEventProjection): void => { |
| 201 | +// if (searchHit !== null) { |
| 202 | +// searchHit.context.addEvents([roomEvent], false); |
| 203 | +// } |
| 204 | +// searchHit = null; |
| 205 | + |
| 206 | +// if (roomEvent.getType() === "m.room.message" && !roomEvent.isRedacted()) { |
| 207 | +// if (eventMatchesSearchTerms(termObj, roomEvent, matchingMembers)) { |
| 208 | +// const evCtx = new EventContext(roomEvent); |
| 209 | +// if (prevEvent !== null) { |
| 210 | +// evCtx.addEvents([prevEvent], true); |
| 211 | +// } |
| 212 | + |
| 213 | +// const resObj: SearchResultItem = { result: roomEvent, context: evCtx }; |
| 214 | +// matches.push(resObj); |
| 215 | +// searchHit = resObj; |
| 216 | +// } |
| 217 | + |
| 218 | +// prevEvent = roomEvent; |
| 219 | +// } |
| 220 | +// }; |
| 221 | + |
| 222 | +// // This code iterates over a timeline, retrieves events from the timeline, and invokes a callback function for each event in reverse order. |
| 223 | +// while (timeline) { |
| 224 | +// const events = timeline.getEvents(); |
| 225 | +// for (let i = events.length - 1; i >= 0; i--) { |
| 226 | +// iterationCallback(events[i]); |
| 227 | +// } |
| 228 | +// timeline = timeline.getNeighbouringTimeline(DirectionProjection.Forward); |
| 229 | +// } |
| 230 | + |
| 231 | +// return matches; |
| 232 | +// } |
| 233 | + |
| 234 | +// // function getClientSearchResponse(searchResults: ISearchResults, matches: SearchResultItem[]): ISearchResponse { |
| 235 | +// // const response: ISearchResponse = { |
| 236 | +// // search_categories: { |
| 237 | +// // room_events: { |
| 238 | +// // count: 0, |
| 239 | +// // highlights: [], |
| 240 | +// // results: [], |
| 241 | +// // }, |
| 242 | +// // }, |
| 243 | +// // }; |
| 244 | + |
| 245 | +// // response.search_categories.room_events.count = matches.length; |
| 246 | +// // for (let i = 0; i < matches.length; i++) { |
| 247 | +// // const reversedContext = reverseEventContext(matches[i].context); |
| 248 | + |
| 249 | +// // const sr = new SearchResult(0, reversedContext); |
| 250 | +// // searchResults.results.push(sr); |
| 251 | +// // } |
| 252 | + |
| 253 | +// // return response; |
| 254 | +// // } |
| 255 | + |
0 commit comments