-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Update StopGapWidgetDriver to support sticky events #31205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Half-Shot
wants to merge
5
commits into
develop
Choose a base branch
from
hs/sticky-events
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62b34e0
Update StopGapWidgetDriver to support sticky events
Half-Shot 2628427
Update to-device
Half-Shot 9cc554c
Update tests
Half-Shot 922fcb6
Clean up duplication
Half-Shot 122efd8
Merge branch 'develop' into hs/sticky-events
Half-Shot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
| type ISearchUserDirectoryResult, | ||
| type IGetMediaConfigResult, | ||
| } from "matrix-widget-api"; | ||
| import { | ||
| ClientEvent, | ||
| type ITurnServer as IClientTurnServer, | ||
| EventType, | ||
|
|
@@ -39,6 +39,7 @@ | |
| type SendDelayedEventResponse, | ||
| type StateEvents, | ||
| type TimelineEvents, | ||
| SendDelayedEventRequestOpts, | ||
| } from "matrix-js-sdk/src/matrix"; | ||
| import { logger } from "matrix-js-sdk/src/logger"; | ||
| import { | ||
|
|
@@ -121,6 +122,7 @@ | |
| this.allowedCapabilities.add(`org.matrix.msc2762.timeline:${inRoomId}`); | ||
| this.allowedCapabilities.add(MatrixCapabilities.MSC4157SendDelayedEvent); | ||
| this.allowedCapabilities.add(MatrixCapabilities.MSC4157UpdateDelayedEvent); | ||
| this.allowedCapabilities.add(MatrixCapabilities.MSC4354SendStickyEvent); | ||
|
|
||
| this.allowedCapabilities.add( | ||
| WidgetEventCapability.forStateEvent(EventDirection.Receive, EventType.RoomName).raw, | ||
|
|
@@ -284,6 +286,13 @@ | |
| return allAllowed; | ||
| } | ||
|
|
||
| private getSendEventTarget(roomId: string | null = null) { | ||
| const client = MatrixClientPeg.safeGet(); | ||
| roomId = roomId || SdkContextClass.instance.roomViewStore.getRoomId() || null; | ||
| if (!roomId) throw new Error("No room specified and no room in RoomViewStore focus."); | ||
| return { client, roomId }; | ||
| } | ||
|
|
||
| public async sendEvent<K extends keyof StateEvents>( | ||
| eventType: K, | ||
| content: StateEvents[K], | ||
|
|
@@ -302,10 +311,7 @@ | |
| stateKey: string | null = null, | ||
| targetRoomId: string | null = null, | ||
| ): Promise<ISendEventDetails> { | ||
| const client = MatrixClientPeg.get(); | ||
| const roomId = targetRoomId || SdkContextClass.instance.roomViewStore.getRoomId(); | ||
|
|
||
| if (!client || !roomId) throw new Error("Not in a room or not attached to a client"); | ||
| const { client, roomId } = this.getSendEventTarget(targetRoomId); | ||
|
|
||
| let r: { event_id: string } | null; | ||
| if (stateKey !== null) { | ||
|
|
@@ -344,6 +350,42 @@ | |
| return { roomId, eventId: r.event_id }; | ||
| } | ||
|
|
||
| /** | ||
| * @experimental Part of MSC4354 | ||
| * @see {@link WidgetDriver#sendStickyEvent} | ||
| */ | ||
| public async sendStickyEvent( | ||
| stickyDurationMs: number, | ||
| eventType: string, | ||
| content: unknown, | ||
| targetRoomId?: string | null, | ||
| ): Promise<ISendEventDetails> { | ||
| const { client, roomId } = this.getSendEventTarget(targetRoomId); | ||
|
|
||
| const r = await client._unstable_sendStickyEvent( | ||
| roomId, | ||
| stickyDurationMs, | ||
| null, | ||
| eventType as keyof TimelineEvents, | ||
| content as TimelineEvents[keyof TimelineEvents] & { msc4354_sticky_key: string }, | ||
| ); | ||
| return { roomId, eventId: r.event_id }; | ||
| } | ||
|
|
||
| private getSendDelayedEventOpts(delay: number | null, parentDelayId: string | null): SendDelayedEventRequestOpts { | ||
| if (delay !== null) { | ||
| return { | ||
| delay, | ||
| ...(parentDelayId !== null && { parent_delay_id: parentDelayId }), | ||
| }; | ||
| } else if (parentDelayId !== null) { | ||
| return { | ||
| parent_delay_id: parentDelayId, | ||
| }; | ||
| } | ||
| throw new Error("Must provide at least one of delay or parentDelayId"); | ||
| } | ||
|
|
||
| /** | ||
| * @experimental Part of MSC4140 & MSC4157 | ||
| * @see {@link WidgetDriver#sendDelayedEvent} | ||
|
|
@@ -375,24 +417,8 @@ | |
| stateKey: string | null = null, | ||
| targetRoomId: string | null = null, | ||
| ): Promise<ISendDelayedEventDetails> { | ||
| const client = MatrixClientPeg.get(); | ||
| const roomId = targetRoomId || SdkContextClass.instance.roomViewStore.getRoomId(); | ||
|
|
||
| if (!client || !roomId) throw new Error("Not in a room or not attached to a client"); | ||
|
|
||
| let delayOpts; | ||
| if (delay !== null) { | ||
| delayOpts = { | ||
| delay, | ||
| ...(parentDelayId !== null && { parent_delay_id: parentDelayId }), | ||
| }; | ||
| } else if (parentDelayId !== null) { | ||
| delayOpts = { | ||
| parent_delay_id: parentDelayId, | ||
| }; | ||
| } else { | ||
| throw new Error("Must provide at least one of delay or parentDelayId"); | ||
| } | ||
| const { client, roomId } = this.getSendEventTarget(targetRoomId); | ||
| let delayOpts = this.getSendDelayedEventOpts(delay, parentDelayId); | ||
|
|
||
| let r: SendDelayedEventResponse | null; | ||
| if (stateKey !== null) { | ||
|
|
@@ -421,13 +447,39 @@ | |
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @experimental Part of MSC4354 | ||
| * @see {@link WidgetDriver#sendStickyEvent} | ||
| */ | ||
| public async sendDelayedStickyEvent( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need more parameters :p
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's awful yes :D. |
||
| delay: number | null, | ||
| parentDelayId: string | null, | ||
| stickyDurationMs: number, | ||
| eventType: string, | ||
| content: unknown, | ||
| targetRoomId?: string | null, | ||
| ): Promise<ISendDelayedEventDetails> { | ||
| const { client, roomId } = this.getSendEventTarget(targetRoomId); | ||
| let delayOpts = this.getSendDelayedEventOpts(delay, parentDelayId); | ||
|
|
||
| const r = await client._unstable_sendStickyDelayedEvent( | ||
| roomId, | ||
| stickyDurationMs, | ||
| delayOpts, | ||
| null, | ||
| eventType as keyof TimelineEvents, | ||
| content as TimelineEvents[keyof TimelineEvents] & { msc4354_sticky_key: string }, | ||
| ); | ||
| return { roomId, delayId: r.delay_id }; | ||
| } | ||
|
|
||
| /** | ||
| * @experimental Part of MSC4140 & MSC4157 | ||
| */ | ||
| public async cancelScheduledDelayedEvent(delayId: string): Promise<void> { | ||
| const client = MatrixClientPeg.get(); | ||
|
|
||
| if (!client) throw new Error("Not in a room or not attached to a client"); | ||
| if (!client) throw new Error("Not attached to a client"); | ||
|
|
||
| await client._unstable_cancelScheduledDelayedEvent(delayId); | ||
| } | ||
|
|
@@ -438,7 +490,7 @@ | |
| public async restartScheduledDelayedEvent(delayId: string): Promise<void> { | ||
| const client = MatrixClientPeg.get(); | ||
|
|
||
| if (!client) throw new Error("Not in a room or not attached to a client"); | ||
| if (!client) throw new Error("Not attached to a client"); | ||
|
|
||
| await client._unstable_restartScheduledDelayedEvent(delayId); | ||
| } | ||
|
|
@@ -449,7 +501,7 @@ | |
| public async sendScheduledDelayedEvent(delayId: string): Promise<void> { | ||
| const client = MatrixClientPeg.get(); | ||
|
|
||
| if (!client) throw new Error("Not in a room or not attached to a client"); | ||
| if (!client) throw new Error("Not attached to a client"); | ||
|
|
||
| await client._unstable_sendScheduledDelayedEvent(delayId); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4220,13 +4220,14 @@ | |
|
|
||
| "@vector-im/matrix-wysiwyg-wasm@link:../../../.cache/yarn/v6/npm-@vector-im-matrix-wysiwyg-2.40.0-53c9ca5ea907d91e4515da64f20a82e5586b882c-integrity/node_modules/bindings/wysiwyg-wasm": | ||
| version "0.0.0" | ||
| uid "" | ||
|
|
||
| "@vector-im/[email protected]": | ||
| version "2.40.0" | ||
| resolved "https://registry.yarnpkg.com/@vector-im/matrix-wysiwyg/-/matrix-wysiwyg-2.40.0.tgz#53c9ca5ea907d91e4515da64f20a82e5586b882c" | ||
| integrity sha512-8LRFLs5PEKYs4lOL7aJ4lL/hGCrvEvOYkCR3JggXYXDVMtX4LmfdlKYucSAe98pCmqAAbLRvlRcR1bTOYvM8ug== | ||
| dependencies: | ||
| "@vector-im/matrix-wysiwyg-wasm" "link:../../Library/Caches/Yarn/v6/npm-@vector-im-matrix-wysiwyg-2.40.0-53c9ca5ea907d91e4515da64f20a82e5586b882c-integrity/node_modules/bindings/wysiwyg-wasm" | ||
| "@vector-im/matrix-wysiwyg-wasm" "link:../../../.cache/yarn/v6/npm-@vector-im-matrix-wysiwyg-2.40.0-53c9ca5ea907d91e4515da64f20a82e5586b882c-integrity/node_modules/bindings/wysiwyg-wasm" | ||
|
|
||
| "@vitest/[email protected]": | ||
| version "3.2.4" | ||
|
|
@@ -9669,7 +9670,7 @@ [email protected]: | |
| jwt-decode "^4.0.0" | ||
| loglevel "^1.9.2" | ||
| matrix-events-sdk "0.0.1" | ||
| matrix-widget-api "^1.14.0" | ||
| matrix-widget-api "^1.10.0" | ||
| oidc-client-ts "^3.0.1" | ||
| p-retry "7" | ||
| sdp-transform "^3.0.0" | ||
|
|
@@ -9695,10 +9696,10 @@ matrix-widget-api@^1.14.0: | |
| "@types/events" "^3.0.0" | ||
| events "^3.2.0" | ||
|
|
||
| matrix-widget-api@^1.14.0: | ||
| version "1.14.0" | ||
| resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.14.0.tgz#aa90c40ace27d3165299f7dbc760a53001ce1446" | ||
| integrity sha512-DDvZGOQhI/rilPWg5VlLN7pHIsPt0Jt14lsuHDP+KU+fmpAQNITJ6aIld1ZoXWsrVGv2PS3x6K/MHtfruIOQJQ== | ||
| matrix-widget-api@^1.15.0: | ||
| version "1.15.0" | ||
| resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.15.0.tgz#a508f72a5993a95382bdf890bd9e54525295b321" | ||
| integrity sha512-Yu9rX9wyF3A1sqviKgiYHz8aGgL3HhJe9OXKi/lccr1eZnNb6y+ELdbshTjs+VLKM4rkTWt6CE3THsw3f/CZhg== | ||
| dependencies: | ||
| "@types/events" "^3.0.0" | ||
| events "^3.2.0" | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by update since we fixed the types upstream in the latest release.