You've already forked matrix-js-sdk
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:
@@ -4427,7 +4427,7 @@ export class MatrixClient extends EventEmitter {
|
|||||||
// XXX: it's horrific that /messages' filter parameter doesn't match
|
// XXX: it's horrific that /messages' filter parameter doesn't match
|
||||||
// /sync's one - see https://matrix.org/jira/browse/SPEC-451
|
// /sync's one - see https://matrix.org/jira/browse/SPEC-451
|
||||||
filter = filter || {};
|
filter = filter || {};
|
||||||
Object.assign(filter, timelineFilter.getRoomTimelineFilterComponent());
|
Object.assign(filter, timelineFilter.getRoomTimelineFilterComponent()?.toJSON());
|
||||||
}
|
}
|
||||||
if (filter) {
|
if (filter) {
|
||||||
params.filter = JSON.stringify(filter);
|
params.filter = JSON.stringify(filter);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import { MatrixEvent } from "./models/event";
|
|||||||
* wildcard pattern.
|
* wildcard pattern.
|
||||||
* @param {String} actualValue The value to be compared
|
* @param {String} actualValue The value to be compared
|
||||||
* @param {String} filterValue The filter pattern 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 {
|
function matchesWildcard(actualValue: string, filterValue: string): boolean {
|
||||||
if (filterValue.endsWith("*")) {
|
if (filterValue.endsWith("*")) {
|
||||||
@@ -66,9 +66,9 @@ export class FilterComponent {
|
|||||||
/**
|
/**
|
||||||
* Checks with the filter component matches the given event
|
* Checks with the filter component matches the given event
|
||||||
* @param {MatrixEvent} event event to be checked against the filter
|
* @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(
|
return this.checkFields(
|
||||||
event.getRoomId(),
|
event.getRoomId(),
|
||||||
event.getSender(),
|
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.
|
* Checks whether the filter component matches the given event fields.
|
||||||
* @param {String} roomId the roomId for the event being checked
|
* @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
|
* 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
|
* @return {MatrixEvent[]} events which matched the filter component
|
||||||
*/
|
*/
|
||||||
filter(events: MatrixEvent[]): MatrixEvent[] {
|
filter(events: MatrixEvent[]): MatrixEvent[] {
|
||||||
@@ -132,7 +147,7 @@ export class FilterComponent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the limit field for a given filter component, providing a default of
|
* 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.
|
* @return {Number} the limit for this filter component.
|
||||||
*/
|
*/
|
||||||
limit(): number {
|
limit(): number {
|
||||||
|
|||||||
@@ -168,9 +168,7 @@ export class Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.roomFilter = new FilterComponent(roomFilterFields);
|
this.roomFilter = new FilterComponent(roomFilterFields);
|
||||||
this.roomTimelineFilter = new FilterComponent(
|
this.roomTimelineFilter = new FilterComponent(roomFilterJson?.timeline || {});
|
||||||
roomFilterJson ? (roomFilterJson.timeline || {}) : {},
|
|
||||||
);
|
|
||||||
|
|
||||||
// don't bother porting this from synapse yet:
|
// don't bother porting this from synapse yet:
|
||||||
// this._room_state_filter =
|
// this._room_state_filter =
|
||||||
|
|||||||
Reference in New Issue
Block a user