1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

WIP filtered timelines

This commit is contained in:
Matthew Hodgson
2016-08-23 14:31:47 +01:00
parent 6432a64442
commit dd5878015a
3 changed files with 209 additions and 0 deletions

View File

@@ -18,6 +18,8 @@ limitations under the License.
* @module filter
*/
var FilterComponent = require("./filter-component");
/**
* @param {Object} obj
* @param {string} keyNesting
@@ -63,6 +65,70 @@ Filter.prototype.getDefinition = function() {
*/
Filter.prototype.setDefinition = function(definition) {
this.definition = definition;
// This is all ported from synapse's FilterCollection()
// definitions look something like:
// {
// "room": {
// "rooms": ["!abcde:example.com"],
// "not_rooms": ["!123456:example.com"],
// "state": {
// "types": ["m.room.*"],
// "not_rooms": ["!726s6s6q:example.com"]
// },
// "timeline": {
// "limit": 10,
// "types": ["m.room.message"],
// "not_rooms": ["!726s6s6q:example.com"],
// "not_senders": ["@spam:example.com"]
// },
// "ephemeral": {
// "types": ["m.receipt", "m.typing"],
// "not_rooms": ["!726s6s6q:example.com"],
// "not_senders": ["@spam:example.com"]
// }
// },
// "presence": {
// "types": ["m.presence"],
// "not_senders": ["@alice:example.com"]
// },
// "event_format": "client",
// "event_fields": ["type", "content", "sender"]
// }
var room_filter_json = definition.room;
// consider the top level rooms/not_rooms filter
var room_filter_fields = {};
if (room_filter_json) {
if (room_filter_json.rooms) {
room_filter_fields.rooms = room_filter_json.rooms;
}
if (room_filter_json.rooms) {
room_filter_fields.not_rooms = room_filter_json.not_rooms;
}
this._include_leave = room_filter_json.include_leave || false;
}
this._room_filter = new FilterComponent(room_filter_fields);
this._room_timeline_filter = new FilterComponent(room_filter_json.timeline || {});
// don't bother porting this from synapse yet:
// this._room_state_filter = new FilterComponent(room_filter_json.state || {});
// this._room_ephemeral_filter = new FilterComponent(room_filter_json.ephemeral || {});
// this._room_account_data_filter = new FilterComponent(room_filter_json.account_data || {});
// this._presence_filter = new FilterComponent(definition.presence || {});
// this._account_data_filter = new FilterComponent(definition.account_data || {});
};
/**
* Filter the list of events based on whether they are allowed in a timeline
* based on this filter
*/
Filter.prototype.filterRoomTimeline = function(events) {
return this._room_timeline_filter.filter(this._room_filter.filter(events));
};
/**