1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Redactions: only remove the keys that are specced for removal

This commit is contained in:
Richard van der Hoff
2016-02-16 16:03:18 +00:00
parent 5eff278454
commit 4c6d0a5128
2 changed files with 57 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ limitations under the License.
* @module models/event
*/
var utils = require("../utils");
/**
* Enum for event statuses.
@@ -202,7 +203,19 @@ module.exports.MatrixEvent.prototype = {
this.event.unsigned = {};
}
this.event.unsigned.redacted_because = redaction_event;
this.event.content = {};
for (var key in utils.keys(this.event)) {
if (!_REDACT_KEEP_KEY_MAP[key]) {
delete this.event[key];
}
}
var keeps = _REDACT_KEEP_CONTENT_MAP[this.getType()] || {};
for (var key in utils.keys(this.event.content)) {
if (!keeps[key]) {
delete this.event.content[key];
}
}
},
/**
@@ -214,3 +227,40 @@ module.exports.MatrixEvent.prototype = {
return Boolean(this.getUnsigned().redacted_because);
},
};
/* http://matrix.org/docs/spec/r0.0.1/client_server.html#redactions says:
*
* the server should strip off any keys not in the following list:
* event_id
* type
* room_id
* user_id
* state_key
* prev_state
* content
* [we keep 'unsigned' as well, since that is created by the local server]
*
* The content object should also be stripped of all keys, unless it is one of one of the following event types:
* m.room.member allows key membership
* m.room.create allows key creator
* m.room.join_rules allows key join_rule
* m.room.power_levels allows keys ban, events, events_default, kick, redact, state_default, users, users_default.
* m.room.aliases allows key aliases
*/
// a map giving the keys we keep when an event is redacted
var _REDACT_KEEP_KEY_MAP = [
'event_id', 'type', 'room_id', 'user_id', 'state_key', 'prev_state', 'content', 'unsigned',
].reduce(function(ret, val) { ret[val] = 1; return ret}, {});
// a map from event type to the .content keys we keep when an event is redacted
var _REDACT_KEEP_CONTENT_MAP = {
'm.room.member': {'membership': 1},
'm.room.create': {'creator': 1},
'm.room.join_rules': {'join_rule': 1},
'm.room.power_levels': {'ban': 1, 'events': 1, 'events_default': 1,
'kick': 1, 'redact': 1, 'state_default': 1,
'users': 1, 'users_default': 1,
},
'm.room.aliases': {'aliases': 1},
};