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
Merge branch 'develop' into psg-1014/poll-model
  • Loading branch information
Kerry Archibald committed Jan 5, 2023
commit 6b4f6304ff7609880b37886be0972c4e6aa198cc
32 changes: 14 additions & 18 deletions spec/unit/models/poll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { PollStartEvent, M_POLL_KIND_DISCLOSED, M_POLL_RESPONSE, REFERENCE_RELATION, M_POLL_END } from "matrix-events-sdk";
import {
PollStartEvent,
M_POLL_KIND_DISCLOSED,
M_POLL_RESPONSE,
REFERENCE_RELATION,
M_POLL_END,
} from "matrix-events-sdk";

import { IEvent, MatrixEvent, PollEvent } from "../../../src";
import { Poll } from "../../../src/models/poll";
Expand Down Expand Up @@ -110,23 +116,18 @@ describe("Poll", () => {
expect(responses.getRelations()).toEqual([stableResponseEvent, unstableResponseEvent]);
});

describe('with poll end event', () => {
const stablePollEndEvent = makeRelatedEvent({ type: M_POLL_END.stable! })
const unstablePollEndEvent = makeRelatedEvent({ type: M_POLL_END.unstable! })
describe("with poll end event", () => {
const stablePollEndEvent = makeRelatedEvent({ type: M_POLL_END.stable! });
const unstablePollEndEvent = makeRelatedEvent({ type: M_POLL_END.unstable! });
const responseEventBeforeEnd = makeRelatedEvent({ type: M_POLL_RESPONSE.name }, now - 1000);
const responseEventAtEnd = makeRelatedEvent({ type: M_POLL_RESPONSE.name }, now);
const responseEventAfterEnd = makeRelatedEvent({ type: M_POLL_RESPONSE.name }, now + 1000);

beforeEach(() => {
mockClient.relations.mockResolvedValue({
events: [
responseEventAfterEnd,
responseEventAtEnd,
responseEventBeforeEnd,
stablePollEndEvent
],
events: [responseEventAfterEnd, responseEventAtEnd, responseEventBeforeEnd, stablePollEndEvent],
});
})
});

it("sets poll end event with stable event type", async () => {
const poll = new Poll(basePollStartEvent, mockClient);
Expand All @@ -137,9 +138,7 @@ describe("Poll", () => {

it("sets poll end event with unstable event type", async () => {
mockClient.relations.mockResolvedValue({
events: [
unstablePollEndEvent
],
events: [unstablePollEndEvent],
});
const poll = new Poll(basePollStartEvent, mockClient);
await poll.getResponses();
Expand All @@ -153,10 +152,7 @@ describe("Poll", () => {

// just response type events
// and response with ts after poll end event is excluded
expect(responses.getRelations()).toEqual([
responseEventAtEnd,
responseEventBeforeEnd,
]);
expect(responses.getRelations()).toEqual([responseEventAtEnd, responseEventBeforeEnd]);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/relations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe("Relations", function () {

// event added
expect(relations.getRelations()).toEqual([event]);
expect(emitSpy).toHaveBeenCalled();
expect(emitSpy).toHaveBeenCalledWith(RelationsEvent.Add, event);
});

it("should not add events of incorrect relation type", async () => {
Expand Down
9 changes: 3 additions & 6 deletions src/models/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,9 @@ export class Poll extends TypedEventEmitter<Exclude<PollEvent, PollEvent.New>, P

// @TODO(kerrya) paging results

const responses = new Relations(
"m.reference",
M_POLL_RESPONSE.name,
this.matrixClient,
[M_POLL_RESPONSE.altName!]
);
const responses = new Relations("m.reference", M_POLL_RESPONSE.name, this.matrixClient, [
M_POLL_RESPONSE.altName!,
]);

const pollEndEvent = allRelations.events.find((event) => M_POLL_END.matches(event.getType()));
const pollCloseTimestamp = pollEndEvent?.getTs() || Number.MAX_SAFE_INTEGER;
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.