You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-09 10:22:46 +03:00
Ensure we send spec-compliant filter strings by stripping out null values (#4865)
* Ensure we send spec-compliant filter strings by stripping out null values Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
99972ce0a9
commit
73cbcfa4ee
@@ -170,4 +170,11 @@ describe("Filter Component", function () {
|
|||||||
expect(filter.check(noMatchEvent)).toBe(false);
|
expect(filter.check(noMatchEvent)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("toJSON", () => {
|
||||||
|
it("should omit empty values", () => {
|
||||||
|
const filter = new FilterComponent({ types: ["m.room.message"], senders: ["@alice:example.com"] });
|
||||||
|
expect(filter.toJSON()).toEqual({ types: ["m.room.message"], senders: ["@alice:example.com"] });
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -99,17 +99,19 @@ export class FilterComponent {
|
|||||||
* Converts the filter component into the form expected over the wire
|
* Converts the filter component into the form expected over the wire
|
||||||
*/
|
*/
|
||||||
public toJSON(): object {
|
public toJSON(): object {
|
||||||
return {
|
return Object.fromEntries(
|
||||||
types: this.filterJson.types || null,
|
Object.entries({
|
||||||
not_types: this.filterJson.not_types || [],
|
types: this.filterJson.types,
|
||||||
rooms: this.filterJson.rooms || null,
|
not_types: this.filterJson.not_types,
|
||||||
not_rooms: this.filterJson.not_rooms || [],
|
rooms: this.filterJson.rooms,
|
||||||
senders: this.filterJson.senders || null,
|
not_rooms: this.filterJson.not_rooms,
|
||||||
not_senders: this.filterJson.not_senders || [],
|
senders: this.filterJson.senders,
|
||||||
contains_url: this.filterJson.contains_url || null,
|
not_senders: this.filterJson.not_senders,
|
||||||
[FILTER_RELATED_BY_SENDERS.name]: this.filterJson[FILTER_RELATED_BY_SENDERS.name] || [],
|
contains_url: this.filterJson.contains_url,
|
||||||
[FILTER_RELATED_BY_REL_TYPES.name]: this.filterJson[FILTER_RELATED_BY_REL_TYPES.name] || [],
|
[FILTER_RELATED_BY_SENDERS.name]: this.filterJson[FILTER_RELATED_BY_SENDERS.name],
|
||||||
};
|
[FILTER_RELATED_BY_REL_TYPES.name]: this.filterJson[FILTER_RELATED_BY_REL_TYPES.name],
|
||||||
|
}).filter(([_key, value]) => value),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user