1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Fix broken /messages filtering due to internal field changes in FilterComponent

This commit is contained in:
Michael Telatynski
2021-06-29 11:34:59 +01:00
parent 8c11839e4d
commit 393047dec5
3 changed files with 22 additions and 9 deletions

View File

@@ -4427,7 +4427,7 @@ export class MatrixClient extends EventEmitter {
// XXX: it's horrific that /messages' filter parameter doesn't match
// /sync's one - see https://matrix.org/jira/browse/SPEC-451
filter = filter || {};
Object.assign(filter, timelineFilter.getRoomTimelineFilterComponent());
Object.assign(filter, timelineFilter.getRoomTimelineFilterComponent()?.toJSON());
}
if (filter) {
params.filter = JSON.stringify(filter);

View File

@@ -25,7 +25,7 @@ import { MatrixEvent } from "./models/event";
* wildcard pattern.
* @param {String} actualValue The value to be compared
* @param {String} filterValue The filter pattern to be compared
* @return {bool} true if the actualValue matches the filterValue
* @return {boolean} true if the actualValue matches the filterValue
*/
function matchesWildcard(actualValue: string, filterValue: string): boolean {
if (filterValue.endsWith("*")) {
@@ -66,9 +66,9 @@ export class FilterComponent {
/**
* Checks with the filter component matches the given event
* @param {MatrixEvent} event event to be checked against the filter
* @return {bool} true if the event matches the filter
* @return {boolean} true if the event matches the filter
*/
check(event: MatrixEvent): boolean {
public check(event: MatrixEvent): boolean {
return this.checkFields(
event.getRoomId(),
event.getSender(),
@@ -77,6 +77,21 @@ export class FilterComponent {
);
}
/**
* Converts the filter component into the form expected over the wire
*/
public toJSON(): object {
return {
types: this.filterJson.types || null,
not_types: this.filterJson.not_types || [],
rooms: this.filterJson.rooms || null,
not_rooms: this.filterJson.not_rooms || [],
senders: this.filterJson.senders || null,
not_senders: this.filterJson.not_senders || [],
contains_url: this.filterJson.contains_url || null,
};
}
/**
* Checks whether the filter component matches the given event fields.
* @param {String} roomId the roomId for the event being checked
@@ -123,7 +138,7 @@ export class FilterComponent {
/**
* Filters a list of events down to those which match this filter component
* @param {MatrixEvent[]} events Events to be checked againt the filter component
* @param {MatrixEvent[]} events Events to be checked against the filter component
* @return {MatrixEvent[]} events which matched the filter component
*/
filter(events: MatrixEvent[]): MatrixEvent[] {

View File

@@ -168,9 +168,7 @@ export class Filter {
}
this.roomFilter = new FilterComponent(roomFilterFields);
this.roomTimelineFilter = new FilterComponent(
roomFilterJson ? (roomFilterJson.timeline || {}) : {},
);
this.roomTimelineFilter = new FilterComponent(roomFilterJson?.timeline || {});
// don't bother porting this from synapse yet:
// this._room_state_filter =