1
|
{"version":3,"file":"search-result.js","names":["_eventContext","require","SearchResult","fromJson","jsonObj","eventMapper","jsonContext","context","eventsBefore","events_before","map","eventsAfter","events_after","EventContext","result","threadRootId","ourEvent","filter","e","setPaginateToken","start","addEvents","end","rank","constructor","exports"],"sources":["../../src/models/search-result.ts"],"sourcesContent":["/*\nCopyright 2015 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { EventContext } from \"./event-context\";\nimport { EventMapper } from \"../event-mapper\";\nimport { IResultContext, ISearchResult } from \"../@types/search\";\n\nexport class SearchResult {\n /**\n * Create a SearchResponse from the response to /search\n */\n\n public static fromJson(jsonObj: ISearchResult, eventMapper: EventMapper): SearchResult {\n const jsonContext = jsonObj.context || ({} as IResultContext);\n let eventsBefore = (jsonContext.events_before || []).map(eventMapper);\n let eventsAfter = (jsonContext.events_after || []).map(eventMapper);\n\n const context = new EventContext(eventMapper(jsonObj.result));\n\n // Filter out any contextual events which do not correspond to the same timeline (thread or room)\n const threadRootId = context.ourEvent.threadRootId;\n eventsBefore = eventsBefore.filter((e) => e.threadRootId === threadRootId);\n eventsAfter = eventsAfter.filter((e) => e.threadRootId === threadRootId);\n\n context.setPaginateToken(jsonContext.start, true);\n context.addEvents(eventsBefore, true);\n context.addEvents(eventsAfter, false);\n context.setPaginateToken(jsonContext.end, false);\n\n return new SearchResult(jsonObj.rank, context);\n }\n\n /**\n * Construct a new SearchResult\n *\n * @param rank - where this SearchResult ranks in the results\n * @param context - the matching event and its\n * context\n */\n public constructor(public readonly rank: number, public readonly context: EventContext) {}\n}\n"],"mappings":";;;;;;AAg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