-
-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove m.thread filter from relations API call
We used MSC3981 to pass the recurse param to the /relations endpoint so that we could get relations to events in a thread, but we kept the rel_type filter on (as m.thread) so no second-order relations would ever have been returned (a nested thread isn't a thing). This removes the filter and does some filtering on the client side to remove any events that shouldn't live in the threaded timeline (ie. non-thread relations to the thread root event). This should help fix stuck unreads because it will avoid the event that the receipt refers to going missing (but only on HSes that support MSC3981). For element-hq/element-web#26718
- Loading branch information
Showing
4 changed files
with
95 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2023 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. | ||
*/ | ||
|
||
import { IEvent } from "../../src"; | ||
import { randomString } from "../../src/randomstring"; | ||
import { getRelationsThreadFilter } from "../../src/thread-utils"; | ||
|
||
function makeEvent(relatesToEvent: string, relType: string): Partial<IEvent> { | ||
return { | ||
event_id: randomString(10), | ||
type: "m.room.message", | ||
content: { | ||
"msgtype": "m.text", | ||
"body": "foo", | ||
"m.relates_to": { | ||
rel_type: relType, | ||
event_id: relatesToEvent, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
describe("getRelationsThreadFilter", () => { | ||
it("should filter out relations directly to the thread root event", () => { | ||
const threadId = "thisIsMyThreadRoot"; | ||
|
||
const reactionToRoot = makeEvent(threadId, "m.annotation"); | ||
const editToRoot = makeEvent(threadId, "m.replace"); | ||
const firstThreadedReply = makeEvent(threadId, "m.thread"); | ||
const reactionToThreadedEvent = makeEvent(firstThreadedReply.event_id!, "m.annotation"); | ||
|
||
const filteredEvents = [reactionToRoot, editToRoot, firstThreadedReply, reactionToThreadedEvent].filter( | ||
getRelationsThreadFilter(threadId), | ||
); | ||
|
||
expect(filteredEvents).toEqual([firstThreadedReply, reactionToThreadedEvent]); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2023 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. | ||
*/ | ||
|
||
import { IEvent, THREAD_RELATION_TYPE } from "./matrix"; | ||
|
||
/** | ||
* Returns a filter function for the /relations endpoint to filter out relations directly | ||
* to the thread root event that should not live in the thread timeline | ||
* | ||
* @param threadId - the thread ID (ie. the event ID of the root event of the thread) | ||
* @returns the filtered list of events | ||
*/ | ||
export function getRelationsThreadFilter(threadId: string): (e: Partial<IEvent>) => boolean { | ||
return (e: Partial<IEvent>) => | ||
e.content?.["m.relates_to"]?.event_id !== threadId || | ||
e.content?.["m.relates_to"]?.rel_type === THREAD_RELATION_TYPE.name; | ||
} |