1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2026-01-03 23:22:30 +03:00

Delete the room when it is forgotten and fire a new experimental event

This commit is contained in:
Kegan Dougal
2015-12-16 16:25:09 +00:00
parent 8bd43a8d53
commit 7e35ef258f
3 changed files with 43 additions and 2 deletions

View File

@@ -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.
* <strong>This event is experimental and may change.</strong>
* @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"

View File

@@ -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.

View File

@@ -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.