From 387ad09c5f5afb8797d367dff8879124427486cb Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 8 Jan 2016 03:22:08 +0000 Subject: [PATCH 1/6] implement account data --- lib/client.js | 38 +++++++++++++++++++++++++++++++++++++- lib/models/event.js | 12 ++++++++++++ lib/models/room.js | 41 +++++++++++++++++++++++++++++++++++++++++ lib/sync.js | 23 +++++++++++++---------- 4 files changed, 103 insertions(+), 11 deletions(-) diff --git a/lib/client.js b/lib/client.js index bef4b8bc8..ce15af2b6 100644 --- a/lib/client.js +++ b/lib/client.js @@ -722,6 +722,42 @@ MatrixClient.prototype.deleteRoomTag = function(roomId, tagName, callback) { ); }; +/** + * @param {MatrixEvent} account_data event + * @param {string} event type to be set + * @param {object} content event content + * @return {module:client.Promise} Resolves: TODO + * @return {module:http-api.MatrixError} Rejects: with an error response. + */ +MatrixClient.prototype.setAccountData = function(event, eventType, content) { + var path = utils.encodeUri("/user/$userId/account_data/$type", { + $userId: this.credentials.userId, + $type: event.getType(), + }); + return this._http.authedRequestWithPrefix( + callback, "PUT", path, undefined, content, httpApi.PREFIX_V2_ALPHA + ); +}; + +/** + * @param {string} roomId + * @param {string} event type to be set + * @param {object} content event content + * @param {module:client.callback} callback Optional. + * @return {module:client.Promise} Resolves: TODO + * @return {module:http-api.MatrixError} Rejects: with an error response. + */ +MatrixClient.prototype.setRoomAccountData = function(roomId, eventType, content, callback) { + var path = utils.encodeUri("/user/$userId/rooms/$roomId/account_data/$type", { + $userId: this.credentials.userId, + $roomId: roomId, + $type: eventType, + }); + return this._http.authedRequestWithPrefix( + callback, "PUT", path, undefined, content, httpApi.PREFIX_V2_ALPHA + ); +}; + /** * Set a user's power level. * @param {string} roomId @@ -1782,7 +1818,7 @@ MatrixClient.prototype.setPresence = function(presence, callback) { * @return {module:http-api.MatrixError} Rejects: with an error response. */ MatrixClient.prototype.publicRooms = function(callback) { - return this._http.request(callback, "GET", "/publicRooms"); + return this._http.authedRequest(callback, "GET", "/publicRooms"); }; /** diff --git a/lib/models/event.js b/lib/models/event.js index 5c763a8c5..dc8de26ec 100644 --- a/lib/models/event.js +++ b/lib/models/event.js @@ -53,6 +53,9 @@ module.exports.EventStatus = { * @prop {boolean} forwardLooking True if this event is 'forward looking', meaning * that getDirectionalContent() will return event.content and not event.prev_content. * Default: true. This property is experimental and may change. + * @prop {String} section The type of /sync section this event came from, if any + * one of 'state', 'account_data', 'ephemeral', or 'timeline'. Useful for recognising + * 'account_data' events. */ module.exports.MatrixEvent = function MatrixEvent(event, encrypted) { this.event = event || {}; @@ -61,6 +64,7 @@ module.exports.MatrixEvent = function MatrixEvent(event, encrypted) { this.status = null; this.forwardLooking = true; this.encrypted = Boolean(encrypted); + this.section = null; }; module.exports.MatrixEvent.prototype = { @@ -178,6 +182,14 @@ module.exports.MatrixEvent.prototype = { return this.event.state_key !== undefined; }, + /** + * Check if this event is account_data. + * @return {boolean} True if this event describes account_data + */ + isAccountData: function() { + return this.section === "account_data"; + }, + /** * Check if the event is encrypted. * @return {boolean} True if this event is encrypted. diff --git a/lib/models/room.js b/lib/models/room.js index 7fe3ea5c8..41783ce63 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -62,6 +62,9 @@ function synthesizeReceipt(userId, event, receiptType) { * this room. * @prop {object} tags Dict of room tags; the keys are the tag name and the values * are any metadata associated with the tag - e.g. { "fav" : { order: 1 } } + * @prop {object} accountData Dict of per-room account_data events; the keys are the + * event type and the values are the events. + * are any metadata associated with the tag - e.g. { "fav" : { order: 1 } } * @prop {RoomState} oldState The state of the room at the time of the oldest * event in the timeline. * @prop {RoomState} currentState The state of the room at the time of the @@ -88,6 +91,9 @@ function Room(roomId, opts) { // $tagName: { $metadata: $value }, // $tagName: { $metadata: $value }, }; + this.accountData = { + // $eventType: $event + }; this.oldState = new RoomState(roomId); this.currentState = new RoomState(roomId); this.summary = null; @@ -336,6 +342,10 @@ Room.prototype.addEvents = function(events, duplicateStrategy) { else if (events[i].getType() === "m.tag") { this.addTags(events[i]); } + else if (events[i].isAccountData()) { + this.addAccountData(events[i]); + continue; + } else { if (duplicateStrategy) { // is there a duplicate? @@ -600,6 +610,24 @@ Room.prototype.addTags = function(event) { this.emit("Room.tags", event, this); }; +/** + * Update the account_data events for this room, overwriting events of the same type. + * @param {MatrixEvent} event the account_data event + */ +Room.prototype.addAccountData = function(event) { + this.accountData[event.getType()] = event; + this.emit("Room.accountData", event, this); +}; + +/** + * Access account_data event of given event type for this room + * @param {string} type the type of account_data event to be accessed + * @return {MatrixEvent} the account_data event in question + */ +Room.prototype.getAccountData = function(type) { + return this.accountData[type]; +}; + function setEventMetadata(event, stateContext, toStartOfTimeline) { // set sender and target properties event.sender = stateContext.getSentinelMember( @@ -750,3 +778,16 @@ module.exports = Room; * if (newTags["favourite"]) showStar(room); * }); */ + +/** + * Fires whenever a room's account_data is updated. + * @event module:client~MatrixClient#"Room.accountData" + * @param {event} event The account_data event + * @param {Room} room The room whose account_data was updated. + * @example + * matrixClient.on("Room.accountData", function(event, room){ + * if (event.getType() === "m.room.colorscheme") { + * applyColorScheme(event.getContents()); + * } + * }); + */ diff --git a/lib/sync.js b/lib/sync.js index cb43b347f..9502fa423 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -138,8 +138,8 @@ SyncApi.prototype.syncLeftRooms = function() { return; } leaveObj.timeline = leaveObj.timeline || {}; - var timelineEvents = self._mapSyncEventsFormat(leaveObj.timeline, room); - var stateEvents = self._mapSyncEventsFormat(leaveObj.state, room); + var timelineEvents = self._mapSyncEventsFormat(leaveObj.timeline, room, 'timeline'); + var stateEvents = self._mapSyncEventsFormat(leaveObj.state, room, 'state'); var paginationToken = ( leaveObj.timeline.limited ? leaveObj.timeline.prev_batch : null ); @@ -324,7 +324,7 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { // Handle invites inviteRooms.forEach(function(inviteObj) { var room = inviteObj.room; - var stateEvents = self._mapSyncEventsFormat(inviteObj.invite_state, room); + var stateEvents = self._mapSyncEventsFormat(inviteObj.invite_state, room, 'state'); self._processRoomEvents(room, stateEvents); if (inviteObj.isBrandNewRoom) { room.recalculate(client.credentials.userId); @@ -337,10 +337,10 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { // Handle joins joinRooms.forEach(function(joinObj) { var room = joinObj.room; - var stateEvents = self._mapSyncEventsFormat(joinObj.state, room); - var timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room); - var ephemeralEvents = self._mapSyncEventsFormat(joinObj.ephemeral); - var accountDataEvents = self._mapSyncEventsFormat(joinObj.account_data); + var stateEvents = self._mapSyncEventsFormat(joinObj.state, room, 'state'); + var timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room, 'timeline'); + var ephemeralEvents = self._mapSyncEventsFormat(joinObj.ephemeral, undefined, 'ephemeral'); + var accountDataEvents = self._mapSyncEventsFormat(joinObj.account_data, undefined, 'account_data'); // we do this first so it's correct when any of the events fire room.unread_notification_count = joinObj.unread_notification_count; @@ -379,7 +379,7 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { leaveRooms.forEach(function(leaveObj) { // Do the bear minimum to register rejected invites / you leaving rooms var room = leaveObj.room; - var timelineEvents = self._mapSyncEventsFormat(leaveObj.timeline, room); + var timelineEvents = self._mapSyncEventsFormat(leaveObj.timeline, room, 'timeline'); room.addEvents(timelineEvents); timelineEvents.forEach(function(e) { client.emit("event", e); }); }); @@ -457,9 +457,10 @@ SyncApi.prototype._mapSyncResponseToRoomArray = function(obj) { /** * @param {Object} obj * @param {Room} room + * @param {String} /sync section (timeline, state, ephemeral, account_data) * @return {MatrixEvent[]} */ -SyncApi.prototype._mapSyncEventsFormat = function(obj, room) { +SyncApi.prototype._mapSyncEventsFormat = function(obj, room, section) { if (!obj || !utils.isArray(obj.events)) { return []; } @@ -468,7 +469,9 @@ SyncApi.prototype._mapSyncEventsFormat = function(obj, room) { if (room) { e.room_id = room.roomId; } - return mapper(e); + var event = mapper(e); + event.section = section; + return event; }); }; From c64aebdb17512bf06d796b846b7c5d9de793de22 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 8 Jan 2016 03:41:05 +0000 Subject: [PATCH 2/6] lint and thinkos --- lib/client.js | 5 +++-- lib/sync.js | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/client.js b/lib/client.js index ce15af2b6..a810c96a1 100644 --- a/lib/client.js +++ b/lib/client.js @@ -729,7 +729,7 @@ MatrixClient.prototype.deleteRoomTag = function(roomId, tagName, callback) { * @return {module:client.Promise} Resolves: TODO * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixClient.prototype.setAccountData = function(event, eventType, content) { +MatrixClient.prototype.setAccountData = function(eventType, content, callback) { var path = utils.encodeUri("/user/$userId/account_data/$type", { $userId: this.credentials.userId, $type: event.getType(), @@ -747,7 +747,8 @@ MatrixClient.prototype.setAccountData = function(event, eventType, content) { * @return {module:client.Promise} Resolves: TODO * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixClient.prototype.setRoomAccountData = function(roomId, eventType, content, callback) { +MatrixClient.prototype.setRoomAccountData = function(roomId, eventType, + content, callback) { var path = utils.encodeUri("/user/$userId/rooms/$roomId/account_data/$type", { $userId: this.credentials.userId, $roomId: roomId, diff --git a/lib/sync.js b/lib/sync.js index 9502fa423..8dcf300bb 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -138,7 +138,8 @@ SyncApi.prototype.syncLeftRooms = function() { return; } leaveObj.timeline = leaveObj.timeline || {}; - var timelineEvents = self._mapSyncEventsFormat(leaveObj.timeline, room, 'timeline'); + var timelineEvents = + self._mapSyncEventsFormat(leaveObj.timeline, room, 'timeline'); var stateEvents = self._mapSyncEventsFormat(leaveObj.state, room, 'state'); var paginationToken = ( leaveObj.timeline.limited ? leaveObj.timeline.prev_batch : null @@ -324,7 +325,8 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { // Handle invites inviteRooms.forEach(function(inviteObj) { var room = inviteObj.room; - var stateEvents = self._mapSyncEventsFormat(inviteObj.invite_state, room, 'state'); + var stateEvents = + self._mapSyncEventsFormat(inviteObj.invite_state, room, 'state'); self._processRoomEvents(room, stateEvents); if (inviteObj.isBrandNewRoom) { room.recalculate(client.credentials.userId); @@ -338,9 +340,12 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { joinRooms.forEach(function(joinObj) { var room = joinObj.room; var stateEvents = self._mapSyncEventsFormat(joinObj.state, room, 'state'); - var timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room, 'timeline'); - var ephemeralEvents = self._mapSyncEventsFormat(joinObj.ephemeral, undefined, 'ephemeral'); - var accountDataEvents = self._mapSyncEventsFormat(joinObj.account_data, undefined, 'account_data'); + var timelineEvents = + self._mapSyncEventsFormat(joinObj.timeline, room, 'timeline'); + var ephemeralEvents = + self._mapSyncEventsFormat(joinObj.ephemeral, undefined, 'ephemeral'); + var accountDataEvents = + self._mapSyncEventsFormat(joinObj.account_data, undefined, 'account_data'); // we do this first so it's correct when any of the events fire room.unread_notification_count = joinObj.unread_notification_count; @@ -379,7 +384,8 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { leaveRooms.forEach(function(leaveObj) { // Do the bear minimum to register rejected invites / you leaving rooms var room = leaveObj.room; - var timelineEvents = self._mapSyncEventsFormat(leaveObj.timeline, room, 'timeline'); + var timelineEvents = + self._mapSyncEventsFormat(leaveObj.timeline, room, 'timeline'); room.addEvents(timelineEvents); timelineEvents.forEach(function(e) { client.emit("event", e); }); }); @@ -457,7 +463,8 @@ SyncApi.prototype._mapSyncResponseToRoomArray = function(obj) { /** * @param {Object} obj * @param {Room} room - * @param {String} /sync section (timeline, state, ephemeral, account_data) + * @param {String} section /sync section + * (timeline, state, ephemeral, account_data) * @return {MatrixEvent[]} */ SyncApi.prototype._mapSyncEventsFormat = function(obj, room, section) { From 9bd45cf7c7f0d3f8f749bd9897e7cfe6e4918824 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 8 Jan 2016 03:45:05 +0000 Subject: [PATCH 3/6] more lint and thinkos --- lib/client.js | 8 ++++---- lib/sync.js | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/client.js b/lib/client.js index a810c96a1..8ea601f7e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -723,16 +723,16 @@ MatrixClient.prototype.deleteRoomTag = function(roomId, tagName, callback) { }; /** - * @param {MatrixEvent} account_data event - * @param {string} event type to be set + * @param {string} eventType event type to be set * @param {object} content event content + * @param {module:client.callback} callback Optional. * @return {module:client.Promise} Resolves: TODO * @return {module:http-api.MatrixError} Rejects: with an error response. */ MatrixClient.prototype.setAccountData = function(eventType, content, callback) { var path = utils.encodeUri("/user/$userId/account_data/$type", { $userId: this.credentials.userId, - $type: event.getType(), + $type: eventType, }); return this._http.authedRequestWithPrefix( callback, "PUT", path, undefined, content, httpApi.PREFIX_V2_ALPHA @@ -741,7 +741,7 @@ MatrixClient.prototype.setAccountData = function(eventType, content, callback) { /** * @param {string} roomId - * @param {string} event type to be set + * @param {string} eventType event type to be set * @param {object} content event content * @param {module:client.callback} callback Optional. * @return {module:client.Promise} Resolves: TODO diff --git a/lib/sync.js b/lib/sync.js index 8dcf300bb..8d6541677 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -345,7 +345,8 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { var ephemeralEvents = self._mapSyncEventsFormat(joinObj.ephemeral, undefined, 'ephemeral'); var accountDataEvents = - self._mapSyncEventsFormat(joinObj.account_data, undefined, 'account_data'); + self._mapSyncEventsFormat(joinObj.account_data, undefined, + 'account_data'); // we do this first so it's correct when any of the events fire room.unread_notification_count = joinObj.unread_notification_count; From db5ca49ee28e39762ff3e820409111768e1a6dec Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 11 Jan 2016 09:31:00 +0000 Subject: [PATCH 4/6] Linting --- lib/sync.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sync.js b/lib/sync.js index 8d6541677..f0d3bbc6c 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -340,7 +340,7 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { joinRooms.forEach(function(joinObj) { var room = joinObj.room; var stateEvents = self._mapSyncEventsFormat(joinObj.state, room, 'state'); - var timelineEvents = + var timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room, 'timeline'); var ephemeralEvents = self._mapSyncEventsFormat(joinObj.ephemeral, undefined, 'ephemeral'); From 88c7293838afe5f49b432d32a7744521815c9bf8 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 11 Jan 2016 19:25:44 +0000 Subject: [PATCH 5/6] based on PR review, rewrite account_data support to avoid tracking the section that events came from, and instead having /sync results piped into the right bit of the room directly --- lib/models/event.js | 12 ------------ lib/models/room.js | 24 ++++++++++++------------ lib/sync.js | 37 ++++++++++++++++++------------------- 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/lib/models/event.js b/lib/models/event.js index dc8de26ec..5c763a8c5 100644 --- a/lib/models/event.js +++ b/lib/models/event.js @@ -53,9 +53,6 @@ module.exports.EventStatus = { * @prop {boolean} forwardLooking True if this event is 'forward looking', meaning * that getDirectionalContent() will return event.content and not event.prev_content. * Default: true. This property is experimental and may change. - * @prop {String} section The type of /sync section this event came from, if any - * one of 'state', 'account_data', 'ephemeral', or 'timeline'. Useful for recognising - * 'account_data' events. */ module.exports.MatrixEvent = function MatrixEvent(event, encrypted) { this.event = event || {}; @@ -64,7 +61,6 @@ module.exports.MatrixEvent = function MatrixEvent(event, encrypted) { this.status = null; this.forwardLooking = true; this.encrypted = Boolean(encrypted); - this.section = null; }; module.exports.MatrixEvent.prototype = { @@ -182,14 +178,6 @@ module.exports.MatrixEvent.prototype = { return this.event.state_key !== undefined; }, - /** - * Check if this event is account_data. - * @return {boolean} True if this event describes account_data - */ - isAccountData: function() { - return this.section === "account_data"; - }, - /** * Check if the event is encrypted. * @return {boolean} True if this event is encrypted. diff --git a/lib/models/room.js b/lib/models/room.js index 41783ce63..0dacdd224 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -64,7 +64,6 @@ function synthesizeReceipt(userId, event, receiptType) { * are any metadata associated with the tag - e.g. { "fav" : { order: 1 } } * @prop {object} accountData Dict of per-room account_data events; the keys are the * event type and the values are the events. - * are any metadata associated with the tag - e.g. { "fav" : { order: 1 } } * @prop {RoomState} oldState The state of the room at the time of the oldest * event in the timeline. * @prop {RoomState} currentState The state of the room at the time of the @@ -339,13 +338,8 @@ Room.prototype.addEvents = function(events, duplicateStrategy) { else if (events[i].getType() === "m.receipt") { this.addReceipt(events[i]); } - else if (events[i].getType() === "m.tag") { - this.addTags(events[i]); - } - else if (events[i].isAccountData()) { - this.addAccountData(events[i]); - continue; - } + // N.B. account_data is added directly by /sync to avoid + // having to maintain an event.isAccountData() here else { if (duplicateStrategy) { // is there a duplicate? @@ -612,11 +606,17 @@ Room.prototype.addTags = function(event) { /** * Update the account_data events for this room, overwriting events of the same type. - * @param {MatrixEvent} event the account_data event + * @param {Array} events an array of account_data events to add */ -Room.prototype.addAccountData = function(event) { - this.accountData[event.getType()] = event; - this.emit("Room.accountData", event, this); +Room.prototype.addAccountData = function(events) { + for (var i = 0; i < events.length; i++) { + var event = events[i]; + if (event.getType() === "m.tag") { + this.addTags(event); + } + this.accountData[event.getType()] = event; + this.emit("Room.accountData", event, this); + } }; /** diff --git a/lib/sync.js b/lib/sync.js index f0d3bbc6c..8f9ea50d3 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -139,8 +139,8 @@ SyncApi.prototype.syncLeftRooms = function() { } leaveObj.timeline = leaveObj.timeline || {}; var timelineEvents = - self._mapSyncEventsFormat(leaveObj.timeline, room, 'timeline'); - var stateEvents = self._mapSyncEventsFormat(leaveObj.state, room, 'state'); + self._mapSyncEventsFormat(leaveObj.timeline, room); + var stateEvents = self._mapSyncEventsFormat(leaveObj.state, room); var paginationToken = ( leaveObj.timeline.limited ? leaveObj.timeline.prev_batch : null ); @@ -326,7 +326,7 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { inviteRooms.forEach(function(inviteObj) { var room = inviteObj.room; var stateEvents = - self._mapSyncEventsFormat(inviteObj.invite_state, room, 'state'); + self._mapSyncEventsFormat(inviteObj.invite_state, room); self._processRoomEvents(room, stateEvents); if (inviteObj.isBrandNewRoom) { room.recalculate(client.credentials.userId); @@ -339,14 +339,10 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { // Handle joins joinRooms.forEach(function(joinObj) { var room = joinObj.room; - var stateEvents = self._mapSyncEventsFormat(joinObj.state, room, 'state'); - var timelineEvents = - self._mapSyncEventsFormat(joinObj.timeline, room, 'timeline'); - var ephemeralEvents = - self._mapSyncEventsFormat(joinObj.ephemeral, undefined, 'ephemeral'); - var accountDataEvents = - self._mapSyncEventsFormat(joinObj.account_data, undefined, - 'account_data'); + var stateEvents = self._mapSyncEventsFormat(joinObj.state, room); + var timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room); + var ephemeralEvents = self._mapSyncEventsFormat(joinObj.ephemeral); + var accountDataEvents = self._mapSyncEventsFormat(joinObj.account_data); // we do this first so it's correct when any of the events fire room.unread_notification_count = joinObj.unread_notification_count; @@ -368,8 +364,15 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { self._processRoomEvents( room, stateEvents, timelineEvents, paginationToken ); + + // XXX: should we be adding ephemeralEvents to the timeline? + // It feels like that for symmetry with room.addAccountData() + // there should be a room.addEphemeralEvents() or similar. room.addEvents(ephemeralEvents); - room.addEvents(accountDataEvents); + + // we deliberately don't add accountData to the timeline + room.addAccountData(accountDataEvents); + room.recalculate(client.credentials.userId); if (joinObj.isBrandNewRoom) { client.store.storeRoom(room); @@ -386,7 +389,7 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { // Do the bear minimum to register rejected invites / you leaving rooms var room = leaveObj.room; var timelineEvents = - self._mapSyncEventsFormat(leaveObj.timeline, room, 'timeline'); + self._mapSyncEventsFormat(leaveObj.timeline, room); room.addEvents(timelineEvents); timelineEvents.forEach(function(e) { client.emit("event", e); }); }); @@ -464,11 +467,9 @@ SyncApi.prototype._mapSyncResponseToRoomArray = function(obj) { /** * @param {Object} obj * @param {Room} room - * @param {String} section /sync section - * (timeline, state, ephemeral, account_data) * @return {MatrixEvent[]} */ -SyncApi.prototype._mapSyncEventsFormat = function(obj, room, section) { +SyncApi.prototype._mapSyncEventsFormat = function(obj, room) { if (!obj || !utils.isArray(obj.events)) { return []; } @@ -477,9 +478,7 @@ SyncApi.prototype._mapSyncEventsFormat = function(obj, room, section) { if (room) { e.room_id = room.roomId; } - var event = mapper(e); - event.section = section; - return event; + return mapper(e); }); }; From 87db054e22740ab300c68b5244ab396b6184f710 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Jan 2016 12:43:42 +0000 Subject: [PATCH 6/6] fix jsdoc --- lib/models/room.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/room.js b/lib/models/room.js index 0dacdd224..46e96dd4b 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -622,7 +622,7 @@ Room.prototype.addAccountData = function(events) { /** * Access account_data event of given event type for this room * @param {string} type the type of account_data event to be accessed - * @return {MatrixEvent} the account_data event in question + * @return {?MatrixEvent} the account_data event in question */ Room.prototype.getAccountData = function(type) { return this.accountData[type];