Skip to content
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

Poll model - page /relations results #3073

Merged
merged 42 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5ca533c
first cut poll model
Dec 30, 2022
984e5eb
process incoming poll relations
Dec 30, 2022
e578d84
allow alt event types in relations model
Jan 4, 2023
1123f1d
allow alt event types in relations model
Jan 4, 2023
ea71efe
remove unneccesary checks on remove relation
Jan 4, 2023
dfe4038
comment
Jan 4, 2023
515db7a
Revert "allow alt event types in relations model"
Jan 4, 2023
ae6ffb7
Revert "Revert "allow alt event types in relations model""
Jan 4, 2023
f189901
Merge branch 'psg-1014/relations-alt-event-types' into psg-1014/poll-…
Jan 4, 2023
cace5d4
basic handling for new poll relations
Jan 4, 2023
6b4f630
Merge branch 'develop' into psg-1014/poll-model
Jan 5, 2023
0f7829a
tests
Jan 9, 2023
32abfed
test room.processPollEvents
Jan 9, 2023
797123c
join processBeaconEvents and poll events in client
Jan 9, 2023
51896e1
Merge branch 'develop' into psg-1014/poll-model
Jan 9, 2023
ad49a00
Merge branch 'develop' into psg-1014/poll-model
Jan 10, 2023
b158dcc
tidy and set 23 copyrights
Jan 11, 2023
924a6c0
use rooms instance of matrixClient
Jan 11, 2023
d09700f
tidy
Jan 11, 2023
9e0d95e
more copyright
Jan 11, 2023
b173130
simplify processPollEvent code
Jan 12, 2023
15dd1c4
Merge branch 'develop' into psg-1014/poll-model
Jan 12, 2023
4a0494c
throw when poll start event has no roomId
Jan 12, 2023
07d154a
Merge branch 'develop' into psg-1014/poll-model
Jan 15, 2023
68ffea1
updates for events-sdk move
Jan 16, 2023
7d8f51c
more type changes for events-sdk changes
Jan 16, 2023
a4832d1
page poll relation results
Jan 17, 2023
10117e7
validate poll end event senders
Jan 17, 2023
0a618a2
reformatted copyright
Jan 17, 2023
68291e8
undo more comment reformatting
Jan 17, 2023
9c239b2
Merge branch 'develop' into psg-1014/poll-model-only-valid-end-events
Jan 17, 2023
48ea040
Merge branch 'psg-1014/poll-model-only-valid-end-events' into psg-101…
Jan 17, 2023
8e90212
test paging
Jan 17, 2023
7588f07
Merge branch 'develop' into psg-1014/poll-model-only-valid-end-events
Jan 26, 2023
0d965e3
Merge branch 'psg-1014/poll-model-only-valid-end-events' into psg-101…
Jan 26, 2023
9996113
use correct pollstartevent type
Jan 26, 2023
ed93046
emit after updating _isFetchingResponses state
Jan 27, 2023
a2fc0b9
Merge branch 'develop' into psg-1014/poll-model-only-valid-end-events
Jan 29, 2023
35c5b32
Merge branch 'psg-1014/poll-model-only-valid-end-events' into psg-101…
Jan 29, 2023
48db239
make rootEvent public readonly
Jan 30, 2023
4b80253
fix poll end validation logic to allow poll creator to end poll regar…
Jan 31, 2023
e2fc68a
Merge branch 'develop' into psg-1014/poll-relations-paging
Feb 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify processPollEvent code
  • Loading branch information
Kerry Archibald committed Jan 12, 2023
commit b17313087366043d282d1ef9eded2f22b17ac897
10 changes: 5 additions & 5 deletions spec/unit/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3251,19 +3251,19 @@ describe("Room", function () {
return event;
};

it("adds poll models to room state for a poll start event ", () => {
it("adds poll models to room state for a poll start event ", async () => {
const pollStartEvent = makePollStart("1");
const events = [pollStartEvent];

room.processPollEvents(events);
await room.processPollEvents(events);
expect(client.decryptEventIfNeeded).toHaveBeenCalledWith(pollStartEvent);
const pollInstance = room.polls.get(pollStartEvent.getId()!);
expect(pollInstance).toBeTruthy();

expect(room.emit).toHaveBeenCalledWith(PollEvent.New, pollInstance);
});

it("adds related events to poll models", () => {
it("adds related events to poll models", async () => {
const pollStartEvent = makePollStart("1");
const pollStartEvent2 = makePollStart("2");
const events = [pollStartEvent, pollStartEvent2];
Expand All @@ -3284,14 +3284,14 @@ describe("Room", function () {
});

// init poll
room.processPollEvents(events);
await room.processPollEvents(events);

const poll = room.polls.get(pollStartEvent.getId()!)!;
const poll2 = room.polls.get(pollStartEvent2.getId()!)!;
jest.spyOn(poll, "onNewRelation");
jest.spyOn(poll2, "onNewRelation");

room.processPollEvents([pollResponseEvent, messageEvent]);
await room.processPollEvents([pollResponseEvent, messageEvent]);

// only called for relevant event
expect(poll.onNewRelation).toHaveBeenCalledTimes(1);
Expand Down
18 changes: 6 additions & 12 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
this.threadsReady = true;
}

public processPollEvents(events: MatrixEvent[]): void {
public async processPollEvents(events: MatrixEvent[]): Promise<void> {
const processPollStartEvent = (event: MatrixEvent): void => {
if (!M_POLL_START.matches(event.getType())) return;
const poll = new Poll(event, this.client);
Expand All @@ -1909,18 +1909,12 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
processPollRelationEvent(event);
};

events.forEach((event: MatrixEvent) => {
this.client.decryptEventIfNeeded(event);

if (event.isBeingDecrypted() || event.isDecryptionFailure()) {
// add an event listener for once the event is decrypted.
event.once(MatrixEventEvent.Decrypted, async () => {
processPollEvent(event);
});
} else {
for (const event of events) {
try {
await this.client.decryptEventIfNeeded(event);
processPollEvent(event);
}
});
} catch {}
}
}

/**
Expand Down