1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Update thread info after MSC3440 updates (#2209)

This commit is contained in:
Germain
2022-03-02 10:52:08 +00:00
committed by GitHub
parent 9b429c1902
commit 4e4afdb795
5 changed files with 130 additions and 27 deletions

View File

@@ -1,4 +1,8 @@
import { RelationType, UNSTABLE_FILTER_RELATION_SENDERS, UNSTABLE_FILTER_RELATION_TYPES } from "../../src";
import {
RelationType,
UNSTABLE_FILTER_RELATED_BY_REL_TYPES,
UNSTABLE_FILTER_RELATED_BY_SENDERS,
} from "../../src";
import { FilterComponent } from "../../src/filter-component";
import { mkEvent } from '../test-utils';
@@ -35,7 +39,7 @@ describe("Filter Component", function() {
it("should filter out events by relation participation", function() {
const currentUserId = '@me:server.org';
const filter = new FilterComponent({
[UNSTABLE_FILTER_RELATION_SENDERS.name]: currentUserId,
[UNSTABLE_FILTER_RELATED_BY_SENDERS.name]: [currentUserId],
}, currentUserId);
const threadRootNotParticipated = mkEvent({
@@ -60,7 +64,7 @@ describe("Filter Component", function() {
it("should keep events by relation participation", function() {
const currentUserId = '@me:server.org';
const filter = new FilterComponent({
[UNSTABLE_FILTER_RELATION_SENDERS.name]: currentUserId,
[UNSTABLE_FILTER_RELATED_BY_SENDERS.name]: [currentUserId],
}, currentUserId);
const threadRootParticipated = mkEvent({
@@ -84,7 +88,7 @@ describe("Filter Component", function() {
it("should filter out events by relation type", function() {
const filter = new FilterComponent({
[UNSTABLE_FILTER_RELATION_TYPES.name]: RelationType.Thread,
[UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread],
});
const referenceRelationEvent = mkEvent({
@@ -104,7 +108,7 @@ describe("Filter Component", function() {
it("should keep events by relation type", function() {
const filter = new FilterComponent({
[UNSTABLE_FILTER_RELATION_TYPES.name]: RelationType.Thread,
[UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread],
});
const threadRootEvent = mkEvent({

View File

@@ -1,3 +1,24 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* This is an internal module. See {@link MatrixClient} for the public class.
* @module client
*/
import * as utils from "../test-utils";
import { DuplicateStrategy, EventStatus, MatrixEvent, PendingEventOrdering, RoomEvent } from "../../src";
import { EventTimeline } from "../../src/models/event-timeline";
@@ -5,6 +26,7 @@ import { Room } from "../../src/models/room";
import { RoomState } from "../../src/models/room-state";
import { RelationType, UNSTABLE_ELEMENT_FUNCTIONAL_USERS } from "../../src/@types/event";
import { TestClient } from "../TestClient";
import { Thread } from "../../src/models/thread";
describe("Room", function() {
const roomId = "!foo:bar";
@@ -1845,6 +1867,54 @@ describe("Room", function() {
expect(() => room.createThread(rootEvent, [])).not.toThrow();
});
it("should not add events before server supports is known", function() {
Thread.hasServerSideSupport = undefined;
const rootEvent = new MatrixEvent({
event_id: "$666",
room_id: roomId,
content: {},
unsigned: {
"age": 1,
"m.relations": {
[RelationType.Thread]: {
latest_event: null,
count: 1,
current_user_participated: false,
},
},
},
});
let age = 1;
function mkEvt(id): MatrixEvent {
return new MatrixEvent({
event_id: id,
room_id: roomId,
content: {
"m.relates_to": {
"rel_type": RelationType.Thread,
"event_id": "$666",
},
},
unsigned: {
"age": age++,
},
});
}
const thread = room.createThread(rootEvent, []);
expect(thread.length).toBe(0);
thread.addEvent(mkEvt("$1"));
expect(thread.length).toBe(0);
Thread.hasServerSideSupport = true;
thread.addEvent(mkEvt("$2"));
expect(thread.length).toBeGreaterThan(0);
});
});
});
});