1
|
{"version":3,"file":"event-context.js","names":["_eventTimeline","require","EventContext","constructor","ourEvent","_defineProperty2","default","Direction","Backward","Forward","timeline","getEvent","ourEventIndex","getTimeline","getOurEventIndex","getPaginateToken","backwards","paginateTokens","setPaginateToken","token","addEvents","events","atStart","concat","length","exports"],"sources":["../../src/models/event-context.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 { MatrixEvent } from \"./event\";\nimport { Direction } from \"./event-timeline\";\n\nexport class EventContext {\n private timeline: MatrixEvent[];\n private ourEventIndex = 0;\n private paginateTokens: Record<Direction, string | null> = {\n [Direction.Backward]: null,\n [Direction.Forward]: null,\n };\n\n /**\n * Construct a new EventContext\n *\n * An eventcontext is used for circumstances such as search results, when we\n * have a particular event of interest, and a bunch of events before and after\n * it.\n *\n * It also stores pagination tokens for going backwards and forwards in the\n * timeline.\n *\n * @param ourEvent - the event at the centre of this context\n */\n public constructor(public readonly ourEvent: MatrixEvent) {\n this.timeline = [ourEvent];\n }\n\n /**\n * Get the main event of interest\n *\n * This is a convenience function for getTimeline()[getOurEventIndex()].\n *\n * @returns The event at the centre of this context.\n */\n public getEvent(): MatrixEvent {\n return this.timeline[this.ourEventIndex];\n }\n\n /**\n * Get the list of events in this context\n *\n * @returns An array of MatrixEvents\n */\n public getTimeline(): MatrixEvent[] {\n return this.timeline;\n }\n\n /**\n * Get the index in the timeline of our event\n */\n public getOurEventIndex(): number {\n return this.ourEventIndex;\n }\n\n /**\n * Get a pagination token.\n *\n * @param backwards - true to get the pagination token for going\n */\n public getPaginateToken(backwards = false): string | null {\n return this.paginateTokens[backwards ? Direction.Backward : Direction.Forward];\n }\n\n /**\n * Set a pagination token.\n *\n * Generally this will be used only by the matrix js sdk.\n *\n * @param token - pagination token\n * @param backwards - true to set the pagination token for going\n * backwards in time\n */\n public setPaginateToken(token?: string, backwards = false): void {\n this.paginateTokens[backwards ? Direction.Backward : Direction.Forward] = token ?? null;\n }\n\n /**\n * Add more events to the timeline\n *\n * @param events - new events, in timeline order\n * @param atStart - true to insert new events at the start\n */\n public addEvents(events: MatrixEvent[], atStart = false): void {\n // TODO: should we share logic with Room.addEventsToTimeline?\n // Should Room even use EventContext?\n\n if (atStart) {\n this.timeline = events.concat(this.timeline);\n this.ourEventIndex += events.length;\n } else {\n this.timeline = this.timeline.concat(events);\n }\n }\n}\n"],"mappings":";;;;;;;;AAiBA,IAAAA,cAAA,GAAAC,OAAA;AAjBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKO,MAAMC,YAAY,CAAC;EAQtB;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACWC,WAAWA,CAAiBC,QAAqB,EAAE;IAAA,KAAvBA,QAAqB,GAArBA,QAAqB;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA,yBAlBhC,CAAC;IAAA,IAAAD,gBAAA,CAAAC,OAAA,0BACkC;MACvD,CAACC,wBAAS,CAACC,QAAQ,GAAG,IAAI;MAC1B,CAACD,wBAAS,CAACE,OAAO,GAAG;IACzB,CAAC;IAeG,IAAI,CAACC,QAAQ,GAAG,CAACN,QAAQ,CAAC;EAC9B;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;EACWO,QAAQA,CAAA,EAAgB;IAC3B,OAAO,IAAI,CAACD,QAAQ,CAAC,IAAI,CAACE,aAAa,CAAC;EAC5C;;EAEA;AACJ;AACA;AACA;AACA;EACWC,WAAWA,CAAA,EAAkB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