UNPKG

9.45 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../src/filter.js"],"names":["FilterComponent","require","setProp","obj","keyNesting","val","nestedKeys","split","currentObj","i","length","Filter","userId","filterId","definition","LAZY_LOADING_MESSAGES_FILTER","lazy_load_members","LAZY_LOADING_SYNC_FILTER","room","state","prototype","getFilterId","getDefinition","setDefinition","room_filter_json","room_filter_fields","rooms","not_rooms","_include_leave","include_leave","_room_filter","_room_timeline_filter","timeline","getRoomTimelineFilterComponent","filterRoomTimeline","events","filter","setTimelineLimit","limit","setIncludeLeaveRooms","includeLeave","fromJson","jsonObj","module","exports"],"mappings":"AAAA;;;;;;;;;;;;;;;AAeA;AACA;;;;AAIA,IAAMA,kBAAkBC,QAAQ,oBAAR,CAAxB;;AAEA;;;;;AAKA,SAASC,OAAT,CAAiBC,GAAjB,EAAsBC,UAAtB,EAAkCC,GAAlC,EAAuC;AACnC,QAAMC,aAAaF,WAAWG,KAAX,CAAiB,GAAjB,CAAnB;AACA,QAAIC,aAAaL,GAAjB;AACA,SAAK,IAAIM,IAAI,CAAb,EAAgBA,IAAKH,WAAWI,MAAX,GAAoB,CAAzC,EAA6CD,GAA7C,EAAkD;AAC9C,YAAI,CAACD,WAAWF,WAAWG,CAAX,CAAX,CAAL,EAAgC;AAC5BD,uBAAWF,WAAWG,CAAX,CAAX,IAA4B,EAA5B;AACH;AACDD,qBAAaA,WAAWF,WAAWG,CAAX,CAAX,CAAb;AACH;AACDD,eAAWF,WAAWA,WAAWI,MAAX,GAAoB,CAA/B,CAAX,IAAgDL,GAAhD;AACH;;AAED;;;;;;;;AAQA,SAASM,MAAT,CAAgBC,MAAhB,EAAwBC,QAAxB,EAAkC;AAC9B,SAAKD,MAAL,GAAcA,MAAd;AACA,SAAKC,QAAL,GAAgBA,QAAhB;AACA,SAAKC,UAAL,GAAkB,EAAlB;AACH;;AAEDH,OAAOI,4BAAP,GAAsC;AAClCC,uBAAmB;AADe,CAAtC;;AAIAL,OAAOM,wBAAP,GA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P,CAAiBc,kBAAjB,GAAsC,UAASC,MAAT,EAAiB;AACnD,WAAO,KAAKJ,qBAAL,CAA2BK,MAA3B,CAAkC,KAAKN,YAAL,CAAkBM,MAAlB,CAAyBD,MAAzB,CAAlC,CAAP;AACH,CAFD;;AAIA;;;;AAIAxB,OAAOS,SAAP,CAAiBiB,gBAAjB,GAAoC,UAASC,KAAT,EAAgB;AAChDpC,YAAQ,KAAKY,UAAb,EAAyB,qBAAzB,EAAgDwB,KAAhD;AACH,CAFD;;AAIA;;;;;AAKA3B,OAAOS,SAAP,CAAiBmB,oBAAjB,GAAwC,UAASC,YAAT,EAAuB;AAC3DtC,YAAQ,KAAKY,UAAb,EAAyB,oBAAzB,EAA+C0B,YAA/C;AACH,CAFD;;AAIA;;;;;;;;AAQA7B,OAAO8B,QAAP,GAAkB,UAAS7B,MAAT,EAAiBC,QAAjB,EAA2B6B,OAA3B,EAAoC;AAClD,QAAMN,SAAS,IAAIzB,MAAJ,CAAWC,MAAX,EAAmBC,QAAnB,CAAf;AACAuB,WAAOb,aAAP,CAAqBmB,OAArB;AACA,WAAON,MAAP;AACH,CAJD;;AAMA;AACAO,OAAOC,OAAP,GAAiBjC,MAAjB","file":"filter.js","sourcesContent":["/*\nCopyright 2015, 2016 OpenMarket Ltd\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\"use strict\";\n/**\n * @module filter\n */\n\nconst FilterComponent = require(\"./filter-component\");\n\n/**\n * @param {Object} obj\n * @param {string} keyNesting\n * @param {*} val\n */\nfunction setProp(obj, keyNesting, val) {\n const nestedKeys = keyNesting.split(\".\");\n let currentObj = obj;\n for (let i = 0; i < (nestedKeys.length - 1); i++) {\n if (!currentObj[nestedKeys[i]]) {\n currentObj[nestedKeys[i]] = {};\n }\n currentObj = currentObj[nestedKeys[i]];\n }\n currentObj[nestedKeys[nestedKeys.length - 1]] = val;\n}\n\n/**\n * Construct a new Filter.\n * @constructor\n * @param {string} userId The user ID for this filter.\n * @param {string=} filterId The filter ID if known.\n * @prop {string} userId The user ID of the filter\n * @prop {?string} filterId The filter ID\n */\nfunction Filter(userId, filterId) {\n this.userId = userId;\n this.filterId = filterId;\n this.definition = {};\n}\n\nFilter.LAZY_LOADING_MESSAGES_FILTER = {\n lazy_load_members: true,\n};\n\nFilter.LAZY_LOADING_SYNC_FILTER = {\n room: {\n state: Filter.LAZY_LOADING_MESSAGES_FILTER,\n },\n};\n\n\n/**\n * Get the ID of this filter on your homeserver (if known)\n * @return {?Number} The filter ID\n */\nFilter.prototype.getFilterId = function() {\n return this.filterId;\n};\n\n/**\n * Get the JSON body of the filter.\n * @return {Object} The filter definition\n */\nFilter.prototype.getDefinition = function() {\n return this.definition;\n};\n\n/**\n * Set the JSON body of the filter\n * @param {Object} definition The filter definition\n */\nFilter.prototype.setDefinition = function(definition) {\n this.definition = definition;\n\n // This is all ported from synapse's FilterCollection()\n\n // definitions look something like:\n // {\n // \"room\": {\n // \"rooms\": [\"!abcde:example.com\"],\n // \"not_rooms\": [\"!123456:example.com\"],\n // \"state\": {\n // \"types\": [\"m.room.*\"],\n // \"not_rooms\": [\"!726s6s6q:example.com\"],\n // },\n // \"timeline\": {\n // \"limit\": 10,\n // \"types\": [\"m.room.message\"],\n // \"not_rooms\": [\"!726s6s6q:example.com\"],\n // \"not_senders\": [\"@spam:example.com\"]\n // \"contains_url\": true\n // },\n // \"ephemeral\": {\n // \"types\": [\"m.receipt\", \"m.typing\"],\n // \"not_rooms\": [\"!726s6s6q:example.com\"],\n // \"not_senders\": [\"@spam:example.com\"]\n // }\n // },\n // \"presence\": {\n // \"types\": [\"m.presence\"],\n // \"not_senders\": [\"@alice:example.com\"]\n // },\n // \"event_format\": \"client\",\n // \"event_fields\": [\"type\", \"content\", \"sender\"]\n // }\n\n const room_filter_json = definition.room;\n\n // consider the top level rooms/not_rooms filter\n const room_filter_fields = {};\n if (room_filter_json) {\n if (room_filter_json.rooms) {\n room_filter_fields.rooms = room_filter_json.rooms;\n }\n if (room_filter_json.rooms) {\n room_filter_fields.not_rooms = room_filter_json.not_rooms;\n }\n\n this._include_leave = room_filter_json.include_leave || false;\n }\n\n this._room_filter = new FilterComponent(room_filter_fields);\n this._room_timeline_filter = new FilterComponent(\n room_filter_json ? (room_filter_json.timeline || {}) : {},\n );\n\n // don't bother porting this from synapse yet:\n // this._room_state_filter =\n // new FilterComponent(room_filter_json.state || {});\n // this._room_ephemeral_filter =\n // new FilterComponent(room_filter_json.ephemeral || {});\n // this._room_account_data_filter =\n // new FilterComponent(room_filter_json.account_data || {});\n // this._presence_filter =\n // new FilterComponent(definition.presence || {});\n // this._account_data_filter =\n // new FilterComponent(definition.account_data || {});\n};\n\n/**\n * Get the room.timeline filter component of the filter\n * @return {FilterComponent} room timeline filter component\n */\nFilter.prototype.getRoomTimelineFilterComponent = function() {\n return this._room_timeline_filter;\n};\n\n/**\n * Filter the list of events based on whether they are allowed in a timeline\n * based on this filter\n * @param {MatrixEvent[]} events the list of events being filtered\n * @return {MatrixEvent[]} the list of events which match the filter\n */\nFilter.prototype.filterRoomTimeline = function(events) {\n return this._room_timeline_filter.filter(this._room_filter.filter(events));\n};\n\n/**\n * Set the max number of events to return for each room's timeline.\n * @param {Number} limit The max number of events to return for each room.\n */\nFilter.prototype.setTimelineLimit = function(limit) {\n setProp(this.definition, \"room.timeline.limit\", limit);\n};\n\n/**\n * Control whether left rooms should be included in responses.\n * @param {boolean} includeLeave True to make rooms the user has left appear\n * in responses.\n */\nFilter.prototype.setIncludeLeaveRooms = function(includeLeave) {\n setProp(this.definition, \"room.include_leave\", includeLeave);\n};\n\n/**\n * Create a filter from existing data.\n * @static\n * @param {string} userId\n * @param {string} filterId\n * @param {Object} jsonObj\n * @return {Filter}\n */\nFilter.fromJson = function(userId, filterId, jsonObj) {\n const filter = new Filter(userId, filterId);\n filter.setDefinition(jsonObj);\n return filter;\n};\n\n/** The Filter class */\nmodule.exports = Filter;\n"]}
\No newline at end of file