matrix-js-sdk 42.4.0 → 43.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/lib/@types/PushRules.d.ts +3 -1
- package/lib/@types/PushRules.d.ts.map +1 -1
- package/lib/@types/PushRules.js +2 -0
- package/lib/@types/PushRules.js.map +1 -1
- package/lib/@types/event.d.ts +1 -0
- package/lib/@types/event.d.ts.map +1 -1
- package/lib/@types/event.js.map +1 -1
- package/lib/@types/matrix-sdk-crypto-wasm.d.js.map +1 -1
- package/lib/client.d.ts +88 -37
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +72 -47
- package/lib/client.js.map +1 -1
- package/lib/crypto-api/index.d.ts +3 -3
- package/lib/crypto-api/index.d.ts.map +1 -1
- package/lib/crypto-api/index.js.map +1 -1
- package/lib/embedded.d.ts +17 -1
- package/lib/embedded.d.ts.map +1 -1
- package/lib/embedded.js +46 -1
- package/lib/embedded.js.map +1 -1
- package/lib/errors.d.ts +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +2 -2
- package/lib/errors.js.map +1 -1
- package/lib/http-api/fetch.d.ts +7 -1
- package/lib/http-api/fetch.d.ts.map +1 -1
- package/lib/http-api/fetch.js +14 -5
- package/lib/http-api/fetch.js.map +1 -1
- package/lib/http-api/interface.d.ts +34 -8
- package/lib/http-api/interface.d.ts.map +1 -1
- package/lib/http-api/interface.js +10 -3
- package/lib/http-api/interface.js.map +1 -1
- package/lib/http-api/refresh.d.ts +30 -11
- package/lib/http-api/refresh.d.ts.map +1 -1
- package/lib/http-api/refresh.js +72 -5
- package/lib/http-api/refresh.js.map +1 -1
- package/lib/matrix.d.ts +1 -1
- package/lib/matrix.d.ts.map +1 -1
- package/lib/matrix.js.map +1 -1
- package/lib/matrixrtc/CallMembership.d.ts.map +1 -1
- package/lib/matrixrtc/CallMembership.js +20 -6
- package/lib/matrixrtc/CallMembership.js.map +1 -1
- package/lib/matrixrtc/IMembershipManager.d.ts +5 -0
- package/lib/matrixrtc/IMembershipManager.d.ts.map +1 -1
- package/lib/matrixrtc/IMembershipManager.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts +27 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.js +58 -36
- package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.js +1 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.js.map +1 -1
- package/lib/matrixrtc/MembershipManager.d.ts +76 -0
- package/lib/matrixrtc/MembershipManager.d.ts.map +1 -1
- package/lib/matrixrtc/MembershipManager.js +264 -47
- package/lib/matrixrtc/MembershipManager.js.map +1 -1
- package/lib/matrixrtc/index.d.ts +1 -1
- package/lib/matrixrtc/index.d.ts.map +1 -1
- package/lib/matrixrtc/index.js +1 -1
- package/lib/matrixrtc/index.js.map +1 -1
- package/lib/matrixrtc/membershipData/common.d.ts +8 -0
- package/lib/matrixrtc/membershipData/common.d.ts.map +1 -1
- package/lib/matrixrtc/membershipData/common.js +10 -0
- package/lib/matrixrtc/membershipData/common.js.map +1 -1
- package/lib/matrixrtc/membershipData/index.d.ts +1 -1
- package/lib/matrixrtc/membershipData/index.d.ts.map +1 -1
- package/lib/matrixrtc/membershipData/index.js +1 -1
- package/lib/matrixrtc/membershipData/index.js.map +1 -1
- package/lib/matrixrtc/types.d.ts +104 -11
- package/lib/matrixrtc/types.d.ts.map +1 -1
- package/lib/matrixrtc/types.js +263 -19
- package/lib/matrixrtc/types.js.map +1 -1
- package/lib/matrixrtc/utils.d.ts +22 -1
- package/lib/matrixrtc/utils.d.ts.map +1 -1
- package/lib/matrixrtc/utils.js +38 -0
- package/lib/matrixrtc/utils.js.map +1 -1
- package/lib/models/room-sticky-events.d.ts +7 -0
- package/lib/models/room-sticky-events.d.ts.map +1 -1
- package/lib/models/room-sticky-events.js +27 -0
- package/lib/models/room-sticky-events.js.map +1 -1
- package/lib/models/thread.d.ts.map +1 -1
- package/lib/models/thread.js +8 -0
- package/lib/models/thread.js.map +1 -1
- package/lib/oauth/authorize.js +1 -1
- package/lib/oauth/authorize.js.map +1 -1
- package/lib/oauth/index.d.ts +3 -5
- package/lib/oauth/index.d.ts.map +1 -1
- package/lib/oauth/index.js +7 -7
- package/lib/oauth/index.js.map +1 -1
- package/lib/oauth/tokenRefresher.d.ts +10 -4
- package/lib/oauth/tokenRefresher.d.ts.map +1 -1
- package/lib/oauth/tokenRefresher.js +34 -24
- package/lib/oauth/tokenRefresher.js.map +1 -1
- package/lib/receipt-accumulator.d.ts +10 -11
- package/lib/receipt-accumulator.d.ts.map +1 -1
- package/lib/receipt-accumulator.js +26 -25
- package/lib/receipt-accumulator.js.map +1 -1
- package/lib/room-summary-api.d.ts +71 -0
- package/lib/room-summary-api.d.ts.map +1 -0
- package/lib/room-summary-api.js +82 -0
- package/lib/room-summary-api.js.map +1 -0
- package/lib/rust-crypto/backup.d.ts +7 -0
- package/lib/rust-crypto/backup.d.ts.map +1 -1
- package/lib/rust-crypto/backup.js +41 -25
- package/lib/rust-crypto/backup.js.map +1 -1
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +6 -1
- package/lib/sync.js.map +1 -1
- package/package.json +6 -6
- package/src/@types/PushRules.ts +2 -0
- package/src/@types/event.ts +1 -1
- package/src/@types/matrix-sdk-crypto-wasm.d.ts +15 -12
- package/src/client.ts +105 -62
- package/src/crypto-api/index.ts +3 -3
- package/src/embedded.ts +61 -2
- package/src/errors.ts +2 -1
- package/src/http-api/fetch.ts +14 -5
- package/src/http-api/interface.ts +36 -8
- package/src/http-api/refresh.ts +101 -17
- package/src/matrix.ts +1 -1
- package/src/matrixrtc/CallMembership.ts +22 -4
- package/src/matrixrtc/IMembershipManager.ts +6 -0
- package/src/matrixrtc/MatrixRTCSession.ts +72 -49
- package/src/matrixrtc/MatrixRTCSessionManager.ts +1 -1
- package/src/matrixrtc/MembershipManager.ts +284 -61
- package/src/matrixrtc/index.ts +7 -1
- package/src/matrixrtc/membershipData/common.ts +12 -0
- package/src/matrixrtc/membershipData/index.ts +1 -1
- package/src/matrixrtc/types.ts +351 -23
- package/src/matrixrtc/utils.ts +54 -1
- package/src/models/room-sticky-events.ts +26 -1
- package/src/models/thread.ts +9 -0
- package/src/oauth/authorize.ts +1 -1
- package/src/oauth/index.ts +7 -8
- package/src/oauth/tokenRefresher.ts +15 -5
- package/src/receipt-accumulator.ts +30 -26
- package/src/room-summary-api.ts +114 -0
- package/src/rust-crypto/backup.ts +46 -33
- package/src/sync.ts +9 -1
package/lib/matrixrtc/utils.js
CHANGED
|
@@ -16,6 +16,9 @@ limitations under the License.
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import { getEncryptionKeyMapKey } from "./EncryptionManager.js";
|
|
19
|
+
import { EventTimeline } from "../models/event-timeline.js";
|
|
20
|
+
import { EventType } from "../@types/event.js";
|
|
21
|
+
|
|
19
22
|
/**
|
|
20
23
|
* Detects when a key for a given index is outdated.
|
|
21
24
|
*/
|
|
@@ -67,4 +70,39 @@ export function slotIdToDescription(slotId) {
|
|
|
67
70
|
export function computeSlotId(slotDescription) {
|
|
68
71
|
return `${slotDescription.application}#${slotDescription.id}`;
|
|
69
72
|
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Reads the slot state event's content for the given slot description.
|
|
76
|
+
*
|
|
77
|
+
* @returns The slot event's content, or `undefined` if no slot event exists for the given description.
|
|
78
|
+
*/
|
|
79
|
+
export function getSlotEventContent(room, slotDescription) {
|
|
80
|
+
const slotId = computeSlotId(slotDescription);
|
|
81
|
+
const slotEvent = room.getLiveTimeline().getState(EventTimeline.FORWARDS)?.getStateEvents(EventType.RTCSlot, slotId);
|
|
82
|
+
if (!slotEvent) return undefined;
|
|
83
|
+
return slotEvent.getContent();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Whether the given slot is closed.
|
|
88
|
+
*
|
|
89
|
+
* @returns `true` if the slot is closed, `false` if the slot is open or `undefined`
|
|
90
|
+
* if no slot exists.
|
|
91
|
+
*/
|
|
92
|
+
export function isSlotClosed(room, slotDescription) {
|
|
93
|
+
const content = getSlotEventContent(room, slotDescription);
|
|
94
|
+
if (content === undefined) return undefined;
|
|
95
|
+
return content.status !== "open" || typeof content.application !== "object" || content.application?.type !== slotDescription.application;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Whether the given slot is open.
|
|
100
|
+
*
|
|
101
|
+
* @returns `true` if the slot is open, `false` if the slot is closed or `undefined`
|
|
102
|
+
* if no slot exists.
|
|
103
|
+
*/
|
|
104
|
+
export function isSlotOpen(room, slotDescription) {
|
|
105
|
+
const closed = isSlotClosed(room, slotDescription);
|
|
106
|
+
return closed === undefined ? undefined : !closed;
|
|
107
|
+
}
|
|
70
108
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/matrixrtc/utils.ts"],"sourcesContent":["/*\nCopyright 2025-2026 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 { getEncryptionKeyMapKey, type CallMembershipIdentityParts } from \"./EncryptionManager.ts\";\nimport type { InboundEncryptionSession, EncryptionKeyMapKey, SlotDescription } from \"./types.ts\";\n\n/**\n * Detects when a key for a given index is outdated.\n */\nexport class OutdatedKeyFilter {\n // Map of participantId -> keyIndex -> timestamp\n private tsBuffer: Map<EncryptionKeyMapKey, Map<number, number>> = new Map();\n\n /**\n * Check if there is a recent key with the same keyId (index) and then use the creationTS to decide what to\n * do with the key. If the key received is older than the one already in the buffer, it is ignored.\n * @param participantId\n * @param item\n */\n public isOutdated(membership: CallMembershipIdentityParts, item: InboundEncryptionSession): boolean {\n const mapKey = getEncryptionKeyMapKey(membership);\n if (!this.tsBuffer.has(mapKey)) {\n this.tsBuffer.set(mapKey, new Map<number, number>());\n }\n\n const latestTimestamp = this.tsBuffer.get(mapKey)?.get(item.keyIndex);\n if (latestTimestamp && latestTimestamp > item.creationTS) {\n // The existing key is more recent, ignore this one\n return true;\n }\n this.tsBuffer.get(mapKey)!.set(item.keyIndex, item.creationTS);\n return false;\n }\n}\n\n/**\n * Converts a slot ID into it's component application and ID portions.\n * @param slotId e.g. `m.call#call_id`\n * @throws If the format of `slotId` is invalid.\n */\nexport function slotIdToDescription(slotId: string): SlotDescription {\n const [application, id, ...unexpectedAdditionalValues] = slotId.split(\"#\");\n if (unexpectedAdditionalValues.length) {\n throw Error(\n \"MatrixRTC Slot IDs *must* only contain two components seperated by one '#'. Additional '#' characters detected.\",\n );\n }\n return { application, id };\n}\n\n/**\n * Converts a SlotDescription into it's slot ID format.\n */\nexport function computeSlotId(slotDescription: SlotDescription): string {\n return `${slotDescription.application}#${slotDescription.id}`;\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,sBAAsB,QAA0C,wBAAwB;AAGjG;AACA;AACA;AACA,OAAO,MAAM,iBAAiB,CAAC;EAAA;IAC3B;IAAA,kCACkE,IAAI,GAAG,CAAC,CAAC;EAAA;EAE3E;AACJ;AACA;AACA;AACA;AACA;EACW,UAAU,CAAC,UAAuC,EAAE,IAA8B,EAAW;IAChG,MAAM,MAAM,GAAG,sBAAsB,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;MAC5B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,GAAG,CAAiB,CAAC,CAAC;IACxD;IAEA,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;IACrE,IAAI,eAAe,IAAI,eAAe,GAAG,IAAI,CAAC,UAAU,EAAE;MACtD;MACA,OAAO,IAAI;IACf;IACA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC;IAC9D,OAAO,KAAK;EAChB;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,mBAAmB,CAAC,MAAc,EAAmB;EACjE,MAAM,CAAC,WAAW,EAAE,EAAE,EAAE,GAAG,0BAA0B,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;EAC1E,IAAI,0BAA0B,CAAC,MAAM,EAAE;IACnC,MAAM,KAAK,CACP,iHACJ,CAAC;EACL;EACA,OAAO;IAAE,WAAW;IAAE;EAAG,CAAC;AAC9B;;AAEA;AACA;AACA;AACA,OAAO,SAAS,aAAa,CAAC,eAAgC,EAAU;EACpE,OAAO,GAAG,eAAe,CAAC,WAAW,IAAI,eAAe,CAAC,EAAE,EAAE;AACjE","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/matrixrtc/utils.ts"],"sourcesContent":["/*\nCopyright 2025-2026 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 { getEncryptionKeyMapKey, type CallMembershipIdentityParts } from \"./EncryptionManager.ts\";\nimport type { InboundEncryptionSession, EncryptionKeyMapKey, RtcSlotEventContent, SlotDescription } from \"./types.ts\";\nimport type { Room } from \"../models/room.ts\";\nimport { EventTimeline } from \"../models/event-timeline.ts\";\nimport { EventType } from \"../@types/event.ts\";\n\n/**\n * Detects when a key for a given index is outdated.\n */\nexport class OutdatedKeyFilter {\n // Map of participantId -> keyIndex -> timestamp\n private tsBuffer: Map<EncryptionKeyMapKey, Map<number, number>> = new Map();\n\n /**\n * Check if there is a recent key with the same keyId (index) and then use the creationTS to decide what to\n * do with the key. If the key received is older than the one already in the buffer, it is ignored.\n * @param participantId\n * @param item\n */\n public isOutdated(membership: CallMembershipIdentityParts, item: InboundEncryptionSession): boolean {\n const mapKey = getEncryptionKeyMapKey(membership);\n if (!this.tsBuffer.has(mapKey)) {\n this.tsBuffer.set(mapKey, new Map<number, number>());\n }\n\n const latestTimestamp = this.tsBuffer.get(mapKey)?.get(item.keyIndex);\n if (latestTimestamp && latestTimestamp > item.creationTS) {\n // The existing key is more recent, ignore this one\n return true;\n }\n this.tsBuffer.get(mapKey)!.set(item.keyIndex, item.creationTS);\n return false;\n }\n}\n\n/**\n * Converts a slot ID into it's component application and ID portions.\n * @param slotId e.g. `m.call#call_id`\n * @throws If the format of `slotId` is invalid.\n */\nexport function slotIdToDescription(slotId: string): SlotDescription {\n const [application, id, ...unexpectedAdditionalValues] = slotId.split(\"#\");\n if (unexpectedAdditionalValues.length) {\n throw Error(\n \"MatrixRTC Slot IDs *must* only contain two components seperated by one '#'. Additional '#' characters detected.\",\n );\n }\n return { application, id };\n}\n\n/**\n * Converts a SlotDescription into it's slot ID format.\n */\nexport function computeSlotId(slotDescription: SlotDescription): string {\n return `${slotDescription.application}#${slotDescription.id}`;\n}\n\n/**\n * Reads the slot state event's content for the given slot description.\n *\n * @returns The slot event's content, or `undefined` if no slot event exists for the given description.\n */\nexport function getSlotEventContent(\n room: Pick<Room, \"getLiveTimeline\">,\n slotDescription: SlotDescription,\n): RtcSlotEventContent | undefined {\n const slotId = computeSlotId(slotDescription);\n const slotEvent = room\n .getLiveTimeline()\n .getState(EventTimeline.FORWARDS)\n ?.getStateEvents(EventType.RTCSlot, slotId);\n if (!slotEvent) return undefined;\n\n return slotEvent.getContent<RtcSlotEventContent>();\n}\n\n/**\n * Whether the given slot is closed.\n *\n * @returns `true` if the slot is closed, `false` if the slot is open or `undefined`\n * if no slot exists.\n */\nexport function isSlotClosed(\n room: Pick<Room, \"getLiveTimeline\">,\n slotDescription: SlotDescription,\n): boolean | undefined {\n const content = getSlotEventContent(room, slotDescription) as Partial<RtcSlotEventContent> | undefined;\n if (content === undefined) return undefined;\n\n return (\n content.status !== \"open\" ||\n typeof content.application !== \"object\" ||\n content.application?.type !== slotDescription.application\n );\n}\n\n/**\n * Whether the given slot is open.\n *\n * @returns `true` if the slot is open, `false` if the slot is closed or `undefined`\n * if no slot exists.\n */\nexport function isSlotOpen(room: Pick<Room, \"getLiveTimeline\">, slotDescription: SlotDescription): boolean | undefined {\n const closed = isSlotClosed(room, slotDescription);\n return closed === undefined ? undefined : !closed;\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,sBAAsB,QAA0C,wBAAwB;AAGjG,SAAS,aAAa,QAAQ,6BAA6B;AAC3D,SAAS,SAAS,QAAQ,oBAAoB;;AAE9C;AACA;AACA;AACA,OAAO,MAAM,iBAAiB,CAAC;EAAA;IAC3B;IAAA,kCACkE,IAAI,GAAG,CAAC,CAAC;EAAA;EAE3E;AACJ;AACA;AACA;AACA;AACA;EACW,UAAU,CAAC,UAAuC,EAAE,IAA8B,EAAW;IAChG,MAAM,MAAM,GAAG,sBAAsB,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAA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C,OAAO,SAAS,CAAC,UAAU,CAAsB,CAAC;AACtD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,YAAY,CACxB,IAAmC,EACnC,eAAgC,EACb;EACnB,MAAM,OAAO,GAAG,mBAAmB,CAAC,IAAI,EAAE,eAAe,CAA6C;EACtG,IAAI,OAAO,KAAK,SAAS,EAAE,OAAO,SAAS;EAE3C,OACI,OAAO,CAAC,MAAM,KAAK,MAAM,IACzB,OAAO,OAAO,CAAC,WAAW,KAAK,QAAQ,IACvC,OAAO,CAAC,WAAW,EAAE,IAAI,KAAK,eAAe,CAAC,WAAW;AAEjE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,UAAU,CAAC,IAAmC,EAAE,eAAgC,EAAuB;EACnH,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,eAAe,CAAC;EAClD,OAAO,MAAM,KAAK,SAAS,GAAG,SAAS,GAAG,CAAC,MAAM;AACrD","ignoreList":[]}
|
|
@@ -82,6 +82,13 @@ export declare class RoomStickyEventsStore extends TypedEventEmitter<RoomStickyE
|
|
|
82
82
|
* and the previous event it may have replaced.
|
|
83
83
|
*/
|
|
84
84
|
private addStickyEvent;
|
|
85
|
+
/**
|
|
86
|
+
* Adds the event to the map once it has been decrypted, emitting `RoomEvent.StickyEvents` at that point.
|
|
87
|
+
*
|
|
88
|
+
* Decryption may fail because the keys haven't arrived yet, in which case we keep waiting. An event that
|
|
89
|
+
* is never decrypted simply never enters the map.
|
|
90
|
+
*/
|
|
91
|
+
private addStickyEventOnceDecrypted;
|
|
85
92
|
/**
|
|
86
93
|
* Add a series of sticky events, emitting `RoomEvent.StickyEvents` if any
|
|
87
94
|
* changes were made.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-sticky-events.d.ts","sourceRoot":"","sources":["../../src/models/room-sticky-events.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,
|
|
1
|
+
{"version":3,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AAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAE9E;IAED;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAkEtB;;;;;OAKG;IACH,OAAO,CAAC,2BAA2B;IAYnC;;;;OAIG;IACI,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAoBlD;IAED;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAgDvC;IAEF;;;;OAIG;IACI,eAAe,CAAC,aAAa,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAgFhE;IAED;;OAEG;IACI,KAAK,IAAI,IAAI,CAKnB;CACJ"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { logger as loggerInstance } from "../logger.js";
|
|
3
|
+
import { MatrixEventEvent } from "./event.js";
|
|
3
4
|
import { TypedEventEmitter } from "./typed-event-emitter.js";
|
|
4
5
|
const logger = loggerInstance.getChild("RoomStickyEvents");
|
|
5
6
|
export let RoomStickyEventsEvent = /*#__PURE__*/function (RoomStickyEventsEvent) {
|
|
@@ -155,6 +156,14 @@ export class RoomStickyEventsStore extends TypedEventEmitter {
|
|
|
155
156
|
* and the previous event it may have replaced.
|
|
156
157
|
*/
|
|
157
158
|
addStickyEvent(event) {
|
|
159
|
+
// The map is keyed on the event's type and sticky key, both of which are encrypted. Wait for the
|
|
160
|
+
// event to be decrypted, otherwise it would be filed under `m.room.encrypted` with no sticky key.
|
|
161
|
+
if (event.isBeingDecrypted() || event.shouldAttemptDecryption()) {
|
|
162
|
+
this.addStickyEventOnceDecrypted(event);
|
|
163
|
+
return {
|
|
164
|
+
added: false
|
|
165
|
+
};
|
|
166
|
+
}
|
|
158
167
|
const stickyKey = event.getContent().msc4354_sticky_key;
|
|
159
168
|
if (typeof stickyKey !== "string" && stickyKey !== undefined) {
|
|
160
169
|
throw new Error(`${event.getId()} is missing msc4354_sticky_key`);
|
|
@@ -211,6 +220,24 @@ export class RoomStickyEventsStore extends TypedEventEmitter {
|
|
|
211
220
|
};
|
|
212
221
|
}
|
|
213
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Adds the event to the map once it has been decrypted, emitting `RoomEvent.StickyEvents` at that point.
|
|
225
|
+
*
|
|
226
|
+
* Decryption may fail because the keys haven't arrived yet, in which case we keep waiting. An event that
|
|
227
|
+
* is never decrypted simply never enters the map.
|
|
228
|
+
*/
|
|
229
|
+
addStickyEventOnceDecrypted(event) {
|
|
230
|
+
const onEventDecrypted = () => {
|
|
231
|
+
if (event.isDecryptionFailure()) {
|
|
232
|
+
// The event may still be decrypted later, e.g. once the keys arrive. Keep listening.
|
|
233
|
+
event.once(MatrixEventEvent.Decrypted, onEventDecrypted);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
this.addStickyEvents([event]); // Safe to call because it sorts events by timestamp when updating a keyed entry.
|
|
237
|
+
};
|
|
238
|
+
event.once(MatrixEventEvent.Decrypted, onEventDecrypted);
|
|
239
|
+
}
|
|
240
|
+
|
|
214
241
|
/**
|
|
215
242
|
* Add a series of sticky events, emitting `RoomEvent.StickyEvents` if any
|
|
216
243
|
* changes were made.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-sticky-events.js","names":[],"sources":["../../src/models/room-sticky-events.ts"],"sourcesContent":["import { logger as loggerInstance } from \"../logger.ts\";\nimport { type MatrixEvent } from \"./event.ts\";\nimport { TypedEventEmitter } from \"./typed-event-emitter.ts\";\n\nconst logger = loggerInstance.getChild(\"RoomStickyEvents\");\n\nexport enum RoomStickyEventsEvent {\n Update = \"RoomStickyEvents.Update\",\n}\n\nexport type StickyMatrixEvent = MatrixEvent & { unstableStickyExpiresAt: number };\n\nexport type RoomStickyEventsMap = {\n /**\n * Fires when any sticky event changes happen in a room.\n * @param added Any new sticky events with no predecessor events (matching sender, type, and sticky_key)\n * @param updated Any sticky events that supersede an existing event (matching sender, type, and sticky_key)\n * @param removed The events that were removed from the map due to expiry.\n */\n [RoomStickyEventsEvent.Update]: (\n added: StickyMatrixEvent[],\n updated: { current: StickyMatrixEvent; previous: StickyMatrixEvent }[],\n removed: StickyMatrixEvent[],\n ) => void;\n};\n\ntype UserId = `@${string}`;\n\nfunction assertIsUserId(value: unknown): asserts value is UserId {\n if (typeof value !== \"string\") throw new Error(\"Not a string\");\n if (!value.startsWith(\"@\")) throw new Error(\"Not a userId\");\n}\n\n/**\n * Tracks sticky events on behalf of one room, and fires an event\n * whenever a sticky event is updated or replaced.\n */\nexport class RoomStickyEventsStore extends TypedEventEmitter<RoomStickyEventsEvent, RoomStickyEventsMap> {\n /**\n * Sticky event map is a nested map of:\n * eventType -> `content.sticky_key sender` -> StickyMatrixEvent[]\n *\n * The events are ordered in latest to earliest expiry, so that the first event\n * in the array will always be the \"current\" one.\n */\n private readonly stickyEventsMap = new Map<string, Map<string, StickyMatrixEvent[]>>();\n /**\n * These are sticky events that have no sticky key and therefore exist outside the tuple\n * system above. They are just held in this Set until they expire.\n */\n private readonly unkeyedStickyEvents = new Set<StickyMatrixEvent>();\n\n private stickyEventTimer?: ReturnType<typeof setTimeout>;\n private nextStickyEventExpiryTs: number = Number.MAX_SAFE_INTEGER;\n\n /**\n * Sort two sticky events by order of expiry. This assumes the sticky events have the same\n * `type`, `sticky_key` and `sender`.\n * @returns A positive value if event A will expire sooner, or a negative value if event B will expire sooner.\n */\n private static sortStickyEvent(eventA: StickyMatrixEvent, eventB: StickyMatrixEvent): number {\n // Sticky events with the same key have to use the same expiration duration.\n // Hence, comparing via `origin_server_ts` yields the exact same result as comparing their expiration time.\n if (eventB.getTs() !== eventA.getTs()) {\n return eventB.getTs() - eventA.getTs();\n }\n\n if ((eventB.getId() ?? \"\") > (eventA.getId() ?? \"\")) {\n return 1;\n }\n\n // This should fail as we've got corruption in our sticky array.\n throw Error(\"Comparing two sticky events with the same event ID is not allowed.\");\n }\n\n /**\n * Generate the correct key for an event to be found in the inner maps of `stickyEventsMap`.\n * @param stickyKey The sticky key of an event.\n * @param sender The sender of the event.\n */\n private static stickyMapKey(stickyKey: string, sender: UserId): string {\n return `${stickyKey}${sender}`;\n }\n\n /**\n * Get all sticky events that are currently active.\n * @returns An iterable set of events.\n * @yields {@link StickyMatrixEvent}\n */\n public *getStickyEvents(): Iterable<StickyMatrixEvent> {\n yield* this.unkeyedStickyEvents;\n for (const innerMap of this.stickyEventsMap.values()) {\n // Inner map contains a map of sender+stickykeys => all sticky events\n for (const events of innerMap.values()) {\n // The first sticky event is the \"current\" one in the sticky map.\n yield events[0];\n }\n }\n }\n\n /**\n * Get an active sticky event that match the given `type`, `sender`, and `stickyKey`\n * @param type The event `type`.\n * @param sender The sender of the sticky event.\n * @param stickyKey The sticky key used by the event.\n * @returns A matching active sticky event, or undefined.\n */\n public getKeyedStickyEvent(sender: string, type: string, stickyKey: string): StickyMatrixEvent | undefined {\n assertIsUserId(sender);\n return this.stickyEventsMap.get(type)?.get(RoomStickyEventsStore.stickyMapKey(stickyKey, sender))?.[0];\n }\n\n /**\n * Get active sticky events without a sticky key that match the given `type` and `sender`.\n * @param type The event `type`.\n * @param sender The sender of the sticky event.\n * @returns An array of matching sticky events.\n */\n public getUnkeyedStickyEvent(sender: string, type: string): StickyMatrixEvent[] {\n return [...this.unkeyedStickyEvents].filter((ev) => ev.getType() === type && ev.getSender() === sender);\n }\n\n /**\n * Adds a sticky event into the local sticky event map.\n *\n * NOTE: This will not cause `RoomEvent.StickyEvents` to be emitted.\n *\n * @throws If the `event` does not contain valid sticky data.\n * @param event The MatrixEvent that contains sticky data.\n * @returns An object describing whether the event was added to the map,\n * and the previous event it may have replaced.\n */\n private addStickyEvent(event: MatrixEvent): { added: true; prevEvent?: StickyMatrixEvent } | { added: false } {\n const stickyKey = event.getContent().msc4354_sticky_key;\n if (typeof stickyKey !== \"string\" && stickyKey !== undefined) {\n throw new Error(`${event.getId()} is missing msc4354_sticky_key`);\n }\n\n // With this we have the guarantee, that all events in stickyEventsMap are correctly formatted\n if (event.unstableStickyExpiresAt === undefined) {\n throw new Error(`${event.getId()} is missing msc4354_sticky.duration_ms`);\n }\n const sender = event.getSender();\n const type = event.getType();\n assertIsUserId(sender);\n if (event.unstableStickyExpiresAt <= Date.now()) {\n logger.info(\"ignored sticky event with older expiration time than current time\", stickyKey);\n return { added: false };\n }\n\n // While we fully expect the server to always provide the correct value,\n // this is just insurance to protect against attacks on our Map.\n if (!sender.startsWith(\"@\")) {\n throw new Error(\"Expected sender to start with @\");\n }\n\n const stickyEvent = event as StickyMatrixEvent;\n\n if (stickyKey === undefined) {\n this.unkeyedStickyEvents.add(stickyEvent);\n // Recalculate the next expiry time.\n this.nextStickyEventExpiryTs = Math.min(event.unstableStickyExpiresAt, this.nextStickyEventExpiryTs);\n\n this.scheduleStickyTimer();\n return { added: true };\n }\n\n // Why this is safe:\n // A type may contain anything but the *sender* is tightly\n // constrained so that a key will always end with a @<user_id>\n // E.g. Where a malicious event type might be \"rtc.member.event@foo:bar\" the key becomes:\n // \"rtc.member.event.@foo:bar@bar:baz\"\n const innerMapKey = RoomStickyEventsStore.stickyMapKey(stickyKey, sender);\n const currentEventSet = [stickyEvent, ...(this.stickyEventsMap.get(type)?.get(innerMapKey) ?? [])].sort(\n RoomStickyEventsStore.sortStickyEvent,\n );\n if (!this.stickyEventsMap.has(type)) {\n this.stickyEventsMap.set(type, new Map());\n }\n this.stickyEventsMap.get(type)?.set(innerMapKey, currentEventSet);\n\n // Recalculate the next expiry time.\n this.nextStickyEventExpiryTs = Math.min(stickyEvent.unstableStickyExpiresAt, this.nextStickyEventExpiryTs);\n\n this.scheduleStickyTimer();\n return {\n added: currentEventSet[0] === stickyEvent,\n prevEvent: currentEventSet?.[1],\n };\n }\n\n /**\n * Add a series of sticky events, emitting `RoomEvent.StickyEvents` if any\n * changes were made.\n * @param events A set of new sticky events.\n */\n public addStickyEvents(events: MatrixEvent[]): void {\n const added: StickyMatrixEvent[] = [];\n const updated: { current: StickyMatrixEvent; previous: StickyMatrixEvent }[] = [];\n for (const event of events) {\n try {\n const result = this.addStickyEvent(event);\n if (result.added) {\n if (result.prevEvent) {\n // e is validated as a StickyMatrixEvent by virtue of `addStickyEvent` returning added: true.\n updated.push({ current: event as StickyMatrixEvent, previous: result.prevEvent });\n } else {\n added.push(event as StickyMatrixEvent);\n }\n }\n } catch (ex) {\n logger.warn(\"ignored invalid sticky event\", ex);\n }\n }\n if (added.length || updated.length) this.emit(RoomStickyEventsEvent.Update, added, updated, []);\n this.scheduleStickyTimer();\n }\n\n /**\n * Schedule the sticky event expiry timer. The timer will\n * run immediately if an event has already expired.\n */\n private scheduleStickyTimer(): void {\n if (this.stickyEventTimer) {\n clearTimeout(this.stickyEventTimer);\n this.stickyEventTimer = undefined;\n }\n if (this.nextStickyEventExpiryTs === Number.MAX_SAFE_INTEGER) {\n // We have no events due to expire.\n return;\n } // otherwise, schedule in the future\n this.stickyEventTimer = setTimeout(this.cleanExpiredStickyEvents, this.nextStickyEventExpiryTs - Date.now());\n }\n\n /**\n * Clean out any expired sticky events.\n */\n private readonly cleanExpiredStickyEvents = (): void => {\n const now = Date.now();\n const removedEvents: StickyMatrixEvent[] = [];\n\n // We will recalculate this as we check all events.\n this.nextStickyEventExpiryTs = Number.MAX_SAFE_INTEGER;\n for (const [eventType, innerEvents] of this.stickyEventsMap.entries()) {\n for (const [innerMapKey, [currentEvent, ...previousEvents]] of innerEvents) {\n // we only added items with `sticky` into this map so we can assert non-null here\n if (now >= currentEvent.unstableStickyExpiresAt) {\n logger.debug(\"Expiring sticky event\", currentEvent.getId());\n removedEvents.push(currentEvent);\n this.stickyEventsMap.get(eventType)!.delete(innerMapKey);\n } else {\n // Ensure we remove any previous events which have now expired, to avoid unbounded memory consumption.\n this.stickyEventsMap\n .get(eventType)!\n .set(innerMapKey, [\n currentEvent,\n ...previousEvents.filter((e) => e.unstableStickyExpiresAt <= now),\n ]);\n // If not removing the event, check to see if it's the next lowest expiry.\n this.nextStickyEventExpiryTs = Math.min(\n this.nextStickyEventExpiryTs,\n currentEvent.unstableStickyExpiresAt,\n );\n }\n }\n // Clean up map after use.\n if (this.stickyEventsMap.get(eventType)?.size === 0) {\n this.stickyEventsMap.delete(eventType);\n }\n }\n for (const event of this.unkeyedStickyEvents) {\n if (now >= event.unstableStickyExpiresAt) {\n logger.debug(\"Expiring sticky event\", event.getId());\n this.unkeyedStickyEvents.delete(event);\n removedEvents.push(event);\n } else {\n // If not removing the event, check to see if it's the next lowest expiry.\n this.nextStickyEventExpiryTs = Math.min(this.nextStickyEventExpiryTs, event.unstableStickyExpiresAt);\n }\n }\n if (removedEvents.length) {\n this.emit(RoomStickyEventsEvent.Update, [], [], removedEvents);\n }\n // Finally, schedule the next run.\n this.scheduleStickyTimer();\n };\n\n /**\n * Handles incoming event redactions. Checks the sticky map\n * for any active sticky events being redacted.\n * @param redactedEvent The MatrixEvent OR event ID of the event being redacted. MAY not be a sticky event.\n */\n public handleRedaction(redactedEvent: MatrixEvent | string): void {\n // Note, we do not adjust`nextStickyEventExpiryTs` here.\n // If this event happens to be the most recent expiring event\n // then we may do one extra iteration of cleanExpiredStickyEvents\n // but this saves us having to iterate over all events here to calculate\n // the next expiry time.\n\n // Note, as soon as we find a positive match on an event in this function\n // we can return. There is no need to continue iterating on a positive match\n // as an event can only appear in one map.\n\n // Handle unkeyedStickyEvents first since it's *quick*.\n const redactEventId = typeof redactedEvent === \"string\" ? redactedEvent : redactedEvent.getId();\n for (const event of this.unkeyedStickyEvents) {\n if (event.getId() === redactEventId) {\n this.unkeyedStickyEvents.delete(event);\n this.emit(RoomStickyEventsEvent.Update, [], [], [event]);\n return;\n }\n }\n\n // Faster method of finding the event since we have the event cached.\n if (typeof redactedEvent !== \"string\" && !redactedEvent.isRedacted()) {\n const stickyKey = redactedEvent.getContent().msc4354_sticky_key;\n if (typeof stickyKey !== \"string\" && stickyKey !== undefined) {\n return; // Not a sticky event.\n }\n const eventType = redactedEvent.getType();\n const sender = redactedEvent.getSender();\n assertIsUserId(sender);\n const innerMap = this.stickyEventsMap.get(eventType);\n if (!innerMap) {\n return;\n }\n const mapKey = RoomStickyEventsStore.stickyMapKey(stickyKey, sender);\n const [currentEvent, ...previousEvents] = innerMap.get(mapKey) ?? [];\n if (!currentEvent) {\n // No event current in the map so ignore.\n return;\n }\n logger.debug(`Redaction for ${redactEventId} under sticky key ${stickyKey}`);\n // Revert to previous state, taking care to skip any other redacted events.\n const newEvents = previousEvents.filter((e) => !e.isRedacted()).sort(RoomStickyEventsStore.sortStickyEvent);\n this.stickyEventsMap.get(eventType)?.set(mapKey, newEvents);\n if (newEvents.length) {\n this.emit(\n RoomStickyEventsEvent.Update,\n [],\n [\n {\n // This looks confusing. This emits that the newer event\n // has been redacted and the previous event has taken it's place.\n previous: currentEvent,\n current: newEvents[0],\n },\n ],\n [],\n );\n } else {\n // We did not find a previous event, so just expire.\n innerMap.delete(mapKey);\n if (innerMap.size === 0) {\n this.stickyEventsMap.delete(eventType);\n }\n this.emit(RoomStickyEventsEvent.Update, [], [], [currentEvent]);\n }\n return;\n }\n\n // We only know the event ID of the redacted event, so we need to\n // traverse the map to find our event.\n for (const innerMap of this.stickyEventsMap.values()) {\n for (const [currentEvent] of innerMap.values()) {\n if (currentEvent.getId() !== redactEventId) {\n continue;\n }\n // Found the event.\n return this.handleRedaction(currentEvent);\n }\n }\n }\n\n /**\n * Clear all events and stop the timer from firing.\n */\n public clear(): void {\n this.stickyEventsMap.clear();\n // Unschedule timer.\n this.nextStickyEventExpiryTs = Number.MAX_SAFE_INTEGER;\n this.scheduleStickyTimer();\n }\n}\n"],"mappings":";AAAA,SAAS,MAAM,IAAI,cAAc,QAAQ,cAAc;AAEvD,SAAS,iBAAiB,QAAQ,0BAA0B;AAE5D,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,CAAC,kBAAkB,CAAC;AAE1D,WAAY,qBAAqB,0BAArB,qBAAqB;EAArB,qBAAqB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AQ,EAAE,YAAY;UACtB,OAAO,EAAE,SAAS,CAAC,CAAC;QACxB,CAAC,CACJ,EACD,EACJ,CAAC;MACL,CAAC,MAAM;QACH;QACA,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;QACvB,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE;UACrB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC;QAC1C;QACA,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC;MACnE;MACA;IACJ;;IAEA;IACA;IACA,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,EAAE;MAClD,KAAK,MAAM,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE;QAC5C,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,KAAK,aAAa,EAAE;UACxC;QACJ;QACA;QACA,OAAO,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC;MAC7C;IACJ;EACJ;;EAEA;AACJ;AACA;EACW,KAAK,GAAS;IACjB,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC5B;IACA,IAAI,CAAC,uBAAuB,GAAG,MAAM,CAAC,gBAAgB;IACtD,IAAI,CAAC,mBAAmB,CAAC,CAAC;EAC9B;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"room-sticky-events.js","names":[],"sources":["../../src/models/room-sticky-events.ts"],"sourcesContent":["import { logger as loggerInstance } from \"../logger.ts\";\nimport { type MatrixEvent, MatrixEventEvent } from \"./event.ts\";\nimport { TypedEventEmitter } from \"./typed-event-emitter.ts\";\n\nconst logger = loggerInstance.getChild(\"RoomStickyEvents\");\n\nexport enum RoomStickyEventsEvent {\n Update = \"RoomStickyEvents.Update\",\n}\n\nexport type StickyMatrixEvent = MatrixEvent & { unstableStickyExpiresAt: number };\n\nexport type RoomStickyEventsMap = {\n /**\n * Fires when any sticky event changes happen in a room.\n * @param added Any new sticky events with no predecessor events (matching sender, type, and sticky_key)\n * @param updated Any sticky events that supersede an existing event (matching sender, type, and sticky_key)\n * @param removed The events that were removed from the map due to expiry.\n */\n [RoomStickyEventsEvent.Update]: (\n added: StickyMatrixEvent[],\n updated: { current: StickyMatrixEvent; previous: StickyMatrixEvent }[],\n removed: StickyMatrixEvent[],\n ) => void;\n};\n\ntype UserId = `@${string}`;\n\nfunction assertIsUserId(value: unknown): asserts value is UserId {\n if (typeof value !== \"string\") throw new Error(\"Not a string\");\n if (!value.startsWith(\"@\")) throw new Error(\"Not a userId\");\n}\n\n/**\n * Tracks sticky events on behalf of one room, and fires an event\n * whenever a sticky event is updated or replaced.\n */\nexport class RoomStickyEventsStore extends TypedEventEmitter<RoomStickyEventsEvent, RoomStickyEventsMap> {\n /**\n * Sticky event map is a nested map of:\n * eventType -> `content.sticky_key sender` -> StickyMatrixEvent[]\n *\n * The events are ordered in latest to earliest expiry, so that the first event\n * in the array will always be the \"current\" one.\n */\n private readonly stickyEventsMap = new Map<string, Map<string, StickyMatrixEvent[]>>();\n /**\n * These are sticky events that have no sticky key and therefore exist outside the tuple\n * system above. They are just held in this Set until they expire.\n */\n private readonly unkeyedStickyEvents = new Set<StickyMatrixEvent>();\n\n private stickyEventTimer?: ReturnType<typeof setTimeout>;\n private nextStickyEventExpiryTs: number = Number.MAX_SAFE_INTEGER;\n\n /**\n * Sort two sticky events by order of expiry. This assumes the sticky events have the same\n * `type`, `sticky_key` and `sender`.\n * @returns A positive value if event A will expire sooner, or a negative value if event B will expire sooner.\n */\n private static sortStickyEvent(eventA: StickyMatrixEvent, eventB: StickyMatrixEvent): number {\n // Sticky events with the same key have to use the same expiration duration.\n // Hence, comparing via `origin_server_ts` yields the exact same result as comparing their expiration time.\n if (eventB.getTs() !== eventA.getTs()) {\n return eventB.getTs() - eventA.getTs();\n }\n\n if ((eventB.getId() ?? \"\") > (eventA.getId() ?? \"\")) {\n return 1;\n }\n\n // This should fail as we've got corruption in our sticky array.\n throw Error(\"Comparing two sticky events with the same event ID is not allowed.\");\n }\n\n /**\n * Generate the correct key for an event to be found in the inner maps of `stickyEventsMap`.\n * @param stickyKey The sticky key of an event.\n * @param sender The sender of the event.\n */\n private static stickyMapKey(stickyKey: string, sender: UserId): string {\n return `${stickyKey}${sender}`;\n }\n\n /**\n * Get all sticky events that are currently active.\n * @returns An iterable set of events.\n * @yields {@link StickyMatrixEvent}\n */\n public *getStickyEvents(): Iterable<StickyMatrixEvent> {\n yield* this.unkeyedStickyEvents;\n for (const innerMap of this.stickyEventsMap.values()) {\n // Inner map contains a map of sender+stickykeys => all sticky events\n for (const events of innerMap.values()) {\n // The first sticky event is the \"current\" one in the sticky map.\n yield events[0];\n }\n }\n }\n\n /**\n * Get an active sticky event that match the given `type`, `sender`, and `stickyKey`\n * @param type The event `type`.\n * @param sender The sender of the sticky event.\n * @param stickyKey The sticky key used by the event.\n * @returns A matching active sticky event, or undefined.\n */\n public getKeyedStickyEvent(sender: string, type: string, stickyKey: string): StickyMatrixEvent | undefined {\n assertIsUserId(sender);\n return this.stickyEventsMap.get(type)?.get(RoomStickyEventsStore.stickyMapKey(stickyKey, sender))?.[0];\n }\n\n /**\n * Get active sticky events without a sticky key that match the given `type` and `sender`.\n * @param type The event `type`.\n * @param sender The sender of the sticky event.\n * @returns An array of matching sticky events.\n */\n public getUnkeyedStickyEvent(sender: string, type: string): StickyMatrixEvent[] {\n return [...this.unkeyedStickyEvents].filter((ev) => ev.getType() === type && ev.getSender() === sender);\n }\n\n /**\n * Adds a sticky event into the local sticky event map.\n *\n * NOTE: This will not cause `RoomEvent.StickyEvents` to be emitted.\n *\n * @throws If the `event` does not contain valid sticky data.\n * @param event The MatrixEvent that contains sticky data.\n * @returns An object describing whether the event was added to the map,\n * and the previous event it may have replaced.\n */\n private addStickyEvent(event: MatrixEvent): { added: true; prevEvent?: StickyMatrixEvent } | { added: false } {\n // The map is keyed on the event's type and sticky key, both of which are encrypted. Wait for the\n // event to be decrypted, otherwise it would be filed under `m.room.encrypted` with no sticky key.\n if (event.isBeingDecrypted() || event.shouldAttemptDecryption()) {\n this.addStickyEventOnceDecrypted(event);\n return { added: false };\n }\n\n const stickyKey = event.getContent().msc4354_sticky_key;\n if (typeof stickyKey !== \"string\" && stickyKey !== undefined) {\n throw new Error(`${event.getId()} is missing msc4354_sticky_key`);\n }\n\n // With this we have the guarantee, that all events in stickyEventsMap are correctly formatted\n if (event.unstableStickyExpiresAt === undefined) {\n throw new Error(`${event.getId()} is missing msc4354_sticky.duration_ms`);\n }\n const sender = event.getSender();\n const type = event.getType();\n assertIsUserId(sender);\n if (event.unstableStickyExpiresAt <= Date.now()) {\n logger.info(\"ignored sticky event with older expiration time than current time\", stickyKey);\n return { added: false };\n }\n\n // While we fully expect the server to always provide the correct value,\n // this is just insurance to protect against attacks on our Map.\n if (!sender.startsWith(\"@\")) {\n throw new Error(\"Expected sender to start with @\");\n }\n\n const stickyEvent = event as StickyMatrixEvent;\n\n if (stickyKey === undefined) {\n this.unkeyedStickyEvents.add(stickyEvent);\n // Recalculate the next expiry time.\n this.nextStickyEventExpiryTs = Math.min(event.unstableStickyExpiresAt, this.nextStickyEventExpiryTs);\n\n this.scheduleStickyTimer();\n return { added: true };\n }\n\n // Why this is safe:\n // A type may contain anything but the *sender* is tightly\n // constrained so that a key will always end with a @<user_id>\n // E.g. Where a malicious event type might be \"rtc.member.event@foo:bar\" the key becomes:\n // \"rtc.member.event.@foo:bar@bar:baz\"\n const innerMapKey = RoomStickyEventsStore.stickyMapKey(stickyKey, sender);\n const currentEventSet = [stickyEvent, ...(this.stickyEventsMap.get(type)?.get(innerMapKey) ?? [])].sort(\n RoomStickyEventsStore.sortStickyEvent,\n );\n if (!this.stickyEventsMap.has(type)) {\n this.stickyEventsMap.set(type, new Map());\n }\n this.stickyEventsMap.get(type)?.set(innerMapKey, currentEventSet);\n\n // Recalculate the next expiry time.\n this.nextStickyEventExpiryTs = Math.min(stickyEvent.unstableStickyExpiresAt, this.nextStickyEventExpiryTs);\n\n this.scheduleStickyTimer();\n return {\n added: currentEventSet[0] === stickyEvent,\n prevEvent: currentEventSet?.[1],\n };\n }\n\n /**\n * Adds the event to the map once it has been decrypted, emitting `RoomEvent.StickyEvents` at that point.\n *\n * Decryption may fail because the keys haven't arrived yet, in which case we keep waiting. An event that\n * is never decrypted simply never enters the map.\n */\n private addStickyEventOnceDecrypted(event: MatrixEvent): void {\n const onEventDecrypted = (): void => {\n if (event.isDecryptionFailure()) {\n // The event may still be decrypted later, e.g. once the keys arrive. Keep listening.\n event.once(MatrixEventEvent.Decrypted, onEventDecrypted);\n return;\n }\n this.addStickyEvents([event]); // Safe to call because it sorts events by timestamp when updating a keyed entry.\n };\n event.once(MatrixEventEvent.Decrypted, onEventDecrypted);\n }\n\n /**\n * Add a series of sticky events, emitting `RoomEvent.StickyEvents` if any\n * changes were made.\n * @param events A set of new sticky events.\n */\n public addStickyEvents(events: MatrixEvent[]): void {\n const added: StickyMatrixEvent[] = [];\n const updated: { current: StickyMatrixEvent; previous: StickyMatrixEvent }[] = [];\n for (const event of events) {\n try {\n const result = this.addStickyEvent(event);\n if (result.added) {\n if (result.prevEvent) {\n // e is validated as a StickyMatrixEvent by virtue of `addStickyEvent` returning added: true.\n updated.push({ current: event as StickyMatrixEvent, previous: result.prevEvent });\n } else {\n added.push(event as StickyMatrixEvent);\n }\n }\n } catch (ex) {\n logger.warn(\"ignored invalid sticky event\", ex);\n }\n }\n if (added.length || updated.length) this.emit(RoomStickyEventsEvent.Update, added, updated, []);\n this.scheduleStickyTimer();\n }\n\n /**\n * Schedule the sticky event expiry timer. The timer will\n * run immediately if an event has already expired.\n */\n private scheduleStickyTimer(): void {\n if (this.stickyEventTimer) {\n clearTimeout(this.stickyEventTimer);\n this.stickyEventTimer = undefined;\n }\n if (this.nextStickyEventExpiryTs === Number.MAX_SAFE_INTEGER) {\n // We have no events due to expire.\n return;\n } // otherwise, schedule in the future\n this.stickyEventTimer = setTimeout(this.cleanExpiredStickyEvents, this.nextStickyEventExpiryTs - Date.now());\n }\n\n /**\n * Clean out any expired sticky events.\n */\n private readonly cleanExpiredStickyEvents = (): void => {\n const now = Date.now();\n const removedEvents: StickyMatrixEvent[] = [];\n\n // We will recalculate this as we check all events.\n this.nextStickyEventExpiryTs = Number.MAX_SAFE_INTEGER;\n for (const [eventType, innerEvents] of this.stickyEventsMap.entries()) {\n for (const [innerMapKey, [currentEvent, ...previousEvents]] of innerEvents) {\n // we only added items with `sticky` into this map so we can assert non-null here\n if (now >= currentEvent.unstableStickyExpiresAt) {\n logger.debug(\"Expiring sticky event\", currentEvent.getId());\n removedEvents.push(currentEvent);\n this.stickyEventsMap.get(eventType)!.delete(innerMapKey);\n } else {\n // Ensure we remove any previous events which have now expired, to avoid unbounded memory consumption.\n this.stickyEventsMap\n .get(eventType)!\n .set(innerMapKey, [\n currentEvent,\n ...previousEvents.filter((e) => e.unstableStickyExpiresAt <= now),\n ]);\n // If not removing the event, check to see if it's the next lowest expiry.\n this.nextStickyEventExpiryTs = Math.min(\n this.nextStickyEventExpiryTs,\n currentEvent.unstableStickyExpiresAt,\n );\n }\n }\n // Clean up map after use.\n if (this.stickyEventsMap.get(eventType)?.size === 0) {\n this.stickyEventsMap.delete(eventType);\n }\n }\n for (const event of this.unkeyedStickyEvents) {\n if (now >= event.unstableStickyExpiresAt) {\n logger.debug(\"Expiring sticky event\", event.getId());\n this.unkeyedStickyEvents.delete(event);\n removedEvents.push(event);\n } else {\n // If not removing the event, check to see if it's the next lowest expiry.\n this.nextStickyEventExpiryTs = Math.min(this.nextStickyEventExpiryTs, event.unstableStickyExpiresAt);\n }\n }\n if (removedEvents.length) {\n this.emit(RoomStickyEventsEvent.Update, [], [], removedEvents);\n }\n // Finally, schedule the next run.\n this.scheduleStickyTimer();\n };\n\n /**\n * Handles incoming event redactions. Checks the sticky map\n * for any active sticky events being redacted.\n * @param redactedEvent The MatrixEvent OR event ID of the event being redacted. MAY not be a sticky event.\n */\n public handleRedaction(redactedEvent: MatrixEvent | string): void {\n // Note, we do not adjust`nextStickyEventExpiryTs` here.\n // If this event happens to be the most recent expiring event\n // then we may do one extra iteration of cleanExpiredStickyEvents\n // but this saves us having to iterate over all events here to calculate\n // the next expiry time.\n\n // Note, as soon as we find a positive match on an event in this function\n // we can return. There is no need to continue iterating on a positive match\n // as an event can only appear in one map.\n\n // Handle unkeyedStickyEvents first since it's *quick*.\n const redactEventId = typeof redactedEvent === \"string\" ? redactedEvent : redactedEvent.getId();\n for (const event of this.unkeyedStickyEvents) {\n if (event.getId() === redactEventId) {\n this.unkeyedStickyEvents.delete(event);\n this.emit(RoomStickyEventsEvent.Update, [], [], [event]);\n return;\n }\n }\n\n // Faster method of finding the event since we have the event cached.\n if (typeof redactedEvent !== \"string\" && !redactedEvent.isRedacted()) {\n const stickyKey = redactedEvent.getContent().msc4354_sticky_key;\n if (typeof stickyKey !== \"string\" && stickyKey !== undefined) {\n return; // Not a sticky event.\n }\n const eventType = redactedEvent.getType();\n const sender = redactedEvent.getSender();\n assertIsUserId(sender);\n const innerMap = this.stickyEventsMap.get(eventType);\n if (!innerMap) {\n return;\n }\n const mapKey = RoomStickyEventsStore.stickyMapKey(stickyKey, sender);\n const [currentEvent, ...previousEvents] = innerMap.get(mapKey) ?? [];\n if (!currentEvent) {\n // No event current in the map so ignore.\n return;\n }\n logger.debug(`Redaction for ${redactEventId} under sticky key ${stickyKey}`);\n // Revert to previous state, taking care to skip any other redacted events.\n const newEvents = previousEvents.filter((e) => !e.isRedacted()).sort(RoomStickyEventsStore.sortStickyEvent);\n this.stickyEventsMap.get(eventType)?.set(mapKey, newEvents);\n if (newEvents.length) {\n this.emit(\n RoomStickyEventsEvent.Update,\n [],\n [\n {\n // This looks confusing. This emits that the newer event\n // has been redacted and the previous event has taken it's place.\n previous: currentEvent,\n current: newEvents[0],\n },\n ],\n [],\n );\n } else {\n // We did not find a previous event, so just expire.\n innerMap.delete(mapKey);\n if (innerMap.size === 0) {\n this.stickyEventsMap.delete(eventType);\n }\n this.emit(RoomStickyEventsEvent.Update, [], [], [currentEvent]);\n }\n return;\n }\n\n // We only know the event ID of the redacted event, so we need to\n // traverse the map to find our event.\n for (const innerMap of this.stickyEventsMap.values()) {\n for (const [currentEvent] of innerMap.values()) {\n if (currentEvent.getId() !== redactEventId) {\n continue;\n }\n // Found the event.\n return this.handleRedaction(currentEvent);\n }\n }\n }\n\n /**\n * Clear all events and stop the timer from firing.\n */\n public clear(): void {\n this.stickyEventsMap.clear();\n // Unschedule timer.\n this.nextStickyEventExpiryTs = Number.MAX_SAFE_INTEGER;\n this.scheduleStickyTimer();\n }\n}\n"],"mappings":";AAAA,SAAS,MAAM,IAAI,cAAc,QAAQ,cAAc;AACvD,SAA2B,gBAAgB,QAAQ,YAAY;AAC/D,SAAS,iBAAiB,QAAQ,0BAA0B;AAE5D,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,CAAC,kBAAkB,CAAC;AAE1D,WAAY,qBAAqB,0BAArB,qBAAqB;EAArB,qBAAqB;EAAA,OAArB,qBAAqB;AAAA;AAsBjC,SAAS,cAAc,CAAC,KAAc,EAA2B;EAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC;EAC9D,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC;AAC/D;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAM,qBAAqB,SAAS,iBAAiB,CAA6C;EAAA;IAAA;IACrG;AACJ;AACA;AACA;AACA;AACA;AACA;IANI,yCAOmC,IAAI,GAAG,CAA2C,CAAC;IACtF;AACJ;AACA;AACA;IAHI,6CAIuC,IAAI,GAAG,CAAoB,CAAC;IAAA;IAAA,iDAGzB,MAAM,CAAC,gBAAgB;IA8MjE;AACJ;AACA;IAFI,kDAG4C,MAAY;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
308
308
|
// Modify this event to point at our room's state, and mark its thread
|
|
309
309
|
// as this.
|
|
310
310
|
this.setEventMetadata(event);
|
|
311
|
+
|
|
312
|
+
// The bundled `current_user_participated` flag from the server lags behind local activity,
|
|
313
|
+
// so relying on it alone drops just-sent replies out of "participated" views until the next
|
|
314
|
+
// root event bundle refresh. Latch it as soon as the current user authors a thread reply,
|
|
315
|
+
// matching the server's participated semantics: an m.thread relation, not a reaction or edit.
|
|
316
|
+
if (event.getSender() === this.client.getUserId() && event.isRelation(THREAD_RELATION_TYPE.name)) {
|
|
317
|
+
this._currentUserParticipated = true;
|
|
318
|
+
}
|
|
311
319
|
const eventId = event.getId();
|
|
312
320
|
if (!this.initialEventsFetched && eventId && !event.isRelation(RelationType.Annotation) && !event.isRelation(RelationType.Replace)) {
|
|
313
321
|
this.preInitEventTargets.set(eventId, event);
|