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

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

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 20 additions & 5 deletions src/filter-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("*")) {
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down Expand Up @@ -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[] {
Expand All @@ -132,7 +147,7 @@ export class FilterComponent {

/**
* Returns the limit field for a given filter component, providing a default of
* 10 if none is otherwise specified. Cargo-culted from Synapse.
* 10 if none is otherwise specified. Cargo-culted from Synapse.
* @return {Number} the limit for this filter component.
*/
limit(): number {
Expand Down
4 changes: 1 addition & 3 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down