diff --git a/lib/client.js b/lib/client.js index 2f062631d..5b357d0e5 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1478,13 +1478,27 @@ MatrixClient.prototype.ban = function(roomId, userId, reason, callback) { /** * @param {string} roomId + * @param {boolean} deleteRoom True to delete the room from the store on success. + * Default: true. * @param {module:client.callback} callback Optional. * @return {module:client.Promise} Resolves: TODO * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixClient.prototype.forget = function(roomId, callback) { - return _membershipChange(this, roomId, undefined, "forget", undefined, +MatrixClient.prototype.forget = function(roomId, deleteRoom, callback) { + if (deleteRoom === undefined) { + deleteRoom = true; + } + var promise = _membershipChange(this, roomId, undefined, "forget", undefined, callback); + if (!deleteRoom) { + return promise; + } + var self = this; + return promise.then(function(response) { + self.store.removeRoom(roomId); + self.emit("deleteRoom", roomId); + return response; + }); }; /** @@ -2641,6 +2655,17 @@ module.exports.CRYPTO_ENABLED = CRYPTO_ENABLED; * }); */ + /** + * Fires whenever a Room is removed. This will fire when you forget a room. + * This event is experimental and may change. + * @event module:client~MatrixClient#"deleteRoom" + * @param {string} roomId The deleted room ID. + * @example + * matrixClient.on("deleteRoom", function(roomId){ + * // update UI from getRooms() + * }); + */ + /** * Fires whenever an incoming call arrives. * @event module:client~MatrixClient#"Call.incoming" diff --git a/lib/store/memory.js b/lib/store/memory.js index b7af1bfd8..ece6fcacf 100644 --- a/lib/store/memory.js +++ b/lib/store/memory.js @@ -73,6 +73,14 @@ module.exports.MatrixInMemoryStore.prototype = { return utils.values(this.rooms); }, + /** + * Permanently delete a room. + * @param {string} roomId + */ + removeRoom: function(roomId) { + delete this.rooms[roomId]; + }, + /** * Retrieve a summary of all the rooms. * @return {RoomSummary[]} A summary of each room. diff --git a/lib/store/stub.js b/lib/store/stub.js index 4cdc1a93e..0aac43098 100644 --- a/lib/store/stub.js +++ b/lib/store/stub.js @@ -54,6 +54,14 @@ StubStore.prototype = { return []; }, + /** + * Permanently delete a room. + * @param {string} roomId + */ + removeRoom: function(roomId) { + return; + }, + /** * No-op. * @return {Array} An empty array.