This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 832
Implement MSC3869: Read event relations with the Widget API #9210
Merged
robintown
merged 5 commits into
matrix-org:develop
from
nordeck:nic/feat/read-relations
Sep 14, 2022
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1dc48c2
Add an action to read relations according to MSC3869
dhenneke c89787d
Merge branch 'develop' into nic/feat/read-relations
dhenneke 10b6cea
Apply review comments
dhenneke c43d889
Fix test
dhenneke 975964f
Update matrix-widget-api to 1.1.1
dhenneke 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 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 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ import { | |
IOpenIDUpdate, | ||
ISendEventDetails, | ||
ITurnServer, | ||
IReadEventRelationsResult, | ||
IRoomEvent, | ||
MatrixCapabilities, | ||
OpenIDRequestState, | ||
|
@@ -37,6 +38,7 @@ import { IContent, IEvent, MatrixEvent } from "matrix-js-sdk/src/models/event"; | |
import { Room } from "matrix-js-sdk/src/models/room"; | ||
import { logger } from "matrix-js-sdk/src/logger"; | ||
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; | ||
import { Direction } from "matrix-js-sdk/src/matrix"; | ||
|
||
import { iterableDiff, iterableIntersection } from "../../utils/iterables"; | ||
import { MatrixClientPeg } from "../../MatrixClientPeg"; | ||
|
@@ -366,4 +368,50 @@ export class StopGapWidgetDriver extends WidgetDriver { | |
client.off(ClientEvent.TurnServersError, onTurnServersError); | ||
} | ||
} | ||
|
||
public async readEventRelations( | ||
eventId: string, | ||
roomId?: string, | ||
relationType?: string, | ||
eventType?: string, | ||
from?: string, | ||
to?: string, | ||
limit?: number, | ||
direction?: 'f' | 'b', | ||
): Promise<IReadEventRelationsResult> { | ||
const client = MatrixClientPeg.get(); | ||
const dir = | ||
direction && Object.values(Direction as Record<string, string>).includes(direction) | ||
? direction as Direction | ||
: undefined; | ||
const room = roomId !== undefined ? roomId : RoomViewStore.instance.getRoomId(); | ||
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. "room" typically means a 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.
|
||
|
||
if (typeof room !== "string") { | ||
throw new Error('Error while reading the current room'); | ||
} | ||
|
||
const { | ||
originalEvent, | ||
events, | ||
nextBatch, | ||
prevBatch, | ||
} = await client.relations( | ||
room, | ||
eventId, | ||
relationType ?? null, | ||
eventType ?? null, | ||
{ | ||
from, | ||
to, | ||
limit, | ||
direction: dir, | ||
}); | ||
|
||
return { | ||
originalEvent: originalEvent?.getEffectiveEvent(), | ||
chunk: events.map(e => e.getEffectiveEvent()), | ||
nextBatch, | ||
prevBatch, | ||
}; | ||
} | ||
} |
This file contains 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 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
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.
direction
should already be compatible with theDirection
enum, which means this shouldn't be needed as a check.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.
I added it as a safeguard since the type guards of typescript are relatively weak hints considering this value was provided over the post message channel. On the other hand, we don't really do a similar input validation for the other fields so we could as well skip it here.