mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-05 20:26:19 +02:00
widget-api: Implement driver readStickyEvents (#31872)
* widget-api: Implement driver `readStickyEvents` * Bump matrix widget api version to get new driver interface * review: add comment about capabilitiesm check * bump matrix-widget-api version to ^1.17.0
This commit is contained in:
parent
8ffc8b8537
commit
a5b63d582f
@ -378,6 +378,21 @@ export class ElementWidgetDriver extends WidgetDriver {
|
||||
return { roomId, eventId: r.event_id };
|
||||
}
|
||||
|
||||
public async readStickyEvents(roomId: string): Promise<IRoomEvent[]> {
|
||||
const room = MatrixClientPeg.safeGet().getRoom(roomId);
|
||||
if (!room) {
|
||||
logger.warn(`[ElementWidgetDriver] readStickyEvents: room ${roomId} not found`);
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
const stickyEvents: IRoomEvent[] = [];
|
||||
for (const ev of room._unstable_getStickyEvents()) {
|
||||
stickyEvents.push(ev.getEffectiveEvent() as IRoomEvent);
|
||||
}
|
||||
// Notice that the capability checks are not done here; they are done in the matrix-widget-api.
|
||||
// The ClientWidgetAPI will do the filtering of events based on the capabilities advertised by the driver.
|
||||
return stickyEvents;
|
||||
}
|
||||
|
||||
private getSendDelayedEventOpts(delay: number | null, parentDelayId: string | null): SendDelayedEventRequestOpts {
|
||||
if (delay !== null) {
|
||||
return {
|
||||
|
||||
@ -595,7 +595,7 @@ describe("ElementWidgetDriver", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("sendStickyEvent", () => {
|
||||
describe("StickyEvent", () => {
|
||||
let driver: WidgetDriver;
|
||||
const roomId = "!this-room-id";
|
||||
|
||||
@ -621,6 +621,41 @@ describe("ElementWidgetDriver", () => {
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("Reads sticky message", async () => {
|
||||
const mockStickyEvent = new MatrixEvent({
|
||||
sender: "@alice:example.org",
|
||||
type: EventType.RTCMembership,
|
||||
content: {
|
||||
msc4354_sticky_key: "7f433807-26aa-441b-810f-43b3fd6d0955",
|
||||
},
|
||||
});
|
||||
const mockRoom: Partial<Room> = {
|
||||
roomId: roomId,
|
||||
_unstable_getStickyEvents: jest.fn().mockReturnValue([mockStickyEvent]),
|
||||
};
|
||||
client.getRoom.mockImplementation((roomId) => {
|
||||
if (roomId === mockRoom.roomId) return mockRoom as Room;
|
||||
return null;
|
||||
});
|
||||
|
||||
{
|
||||
const stickyEvents = await driver.readStickyEvents(roomId);
|
||||
|
||||
expect(stickyEvents.length).toBe(1);
|
||||
const stickyEvent = stickyEvents[0];
|
||||
expect(stickyEvent.type).toEqual(mockStickyEvent.getType());
|
||||
expect(stickyEvent.sender).toEqual(mockStickyEvent.getSender());
|
||||
expect(stickyEvent.content).toEqual(mockStickyEvent.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
const stickyEvents = await driver.readStickyEvents("!another-room-id");
|
||||
expect(stickyEvents.length).toBe(0);
|
||||
}
|
||||
|
||||
expect(mockRoom._unstable_getStickyEvents).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("sendDelayedStickyEvent", () => {
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
"testcontainers": "^11.0.0",
|
||||
"wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0",
|
||||
"wrap-ansi": "npm:wrap-ansi@^7.0.0",
|
||||
"matrix-widget-api": "^1.16.1",
|
||||
"matrix-widget-api": "^1.17.0",
|
||||
"qs": "6.14.2"
|
||||
},
|
||||
"dependencies": {},
|
||||
|
||||
4
pnpm-lock.yaml
generated
4
pnpm-lock.yaml
generated
@ -48,7 +48,7 @@ overrides:
|
||||
testcontainers: ^11.0.0
|
||||
wrap-ansi-cjs: npm:wrap-ansi@^7.0.0
|
||||
wrap-ansi: npm:wrap-ansi@^7.0.0
|
||||
matrix-widget-api: ^1.16.1
|
||||
matrix-widget-api: ^1.17.0
|
||||
qs: 6.14.2
|
||||
|
||||
packageExtensionsChecksum: sha256-OFePh8Fn8A1ZEWgJF51vTMPT/HEVyXQyj6YGIztPb0w=
|
||||
@ -285,7 +285,7 @@ importers:
|
||||
specifier: github:matrix-org/matrix-js-sdk#develop
|
||||
version: https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/5739b59faaf33fa55457dcaa76ffebe0506d1466
|
||||
matrix-widget-api:
|
||||
specifier: ^1.16.1
|
||||
specifier: ^1.17.0
|
||||
version: 1.17.0
|
||||
memoize-one:
|
||||
specifier: ^6.0.0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user