fix: Properly handle redacted events in event.getDisplayEvent

This commit is contained in:
Sorunome 2020-11-07 11:40:13 +01:00
parent 33b1e36efd
commit 5aec7aab32
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 21 additions and 0 deletions

View File

@ -745,6 +745,9 @@ class Event extends MatrixEvent {
/// Fetches the event to be rendered, taking into account all the edits and the like. /// Fetches the event to be rendered, taking into account all the edits and the like.
/// It needs a [timeline] for that. /// It needs a [timeline] for that.
Event getDisplayEvent(Timeline timeline) { Event getDisplayEvent(Timeline timeline) {
if (redacted) {
return this;
}
if (hasAggregatedEvents(timeline, RelationshipTypes.Edit)) { if (hasAggregatedEvents(timeline, RelationshipTypes.Edit)) {
// alright, we have an edit // alright, we have an edit
final allEditEvents = aggregatedEvents(timeline, RelationshipTypes.Edit) final allEditEvents = aggregatedEvents(timeline, RelationshipTypes.Edit)

View File

@ -978,6 +978,24 @@ void main() {
displayEvent = event.getDisplayEvent( displayEvent = event.getDisplayEvent(
Timeline(events: <Event>[event, edit1, edit2, edit3], room: room)); Timeline(events: <Event>[event, edit1, edit2, edit3], room: room));
expect(displayEvent.body, 'edit 2'); expect(displayEvent.body, 'edit 2');
event = Event.fromJson({
'type': EventTypes.Message,
'content': {
'body': 'blah',
'msgtype': 'm.text',
},
'event_id': '\$source',
'sender': '@alice:example.org',
'unsigned': {
'redacted_because': {
'evnet_id': '\$redact',
'sender': '@alice:example.org',
},
},
}, null);
displayEvent = event.getDisplayEvent(
Timeline(events: <Event>[event, edit1, edit2, edit3], room: room));
expect(displayEvent.body, 'Redacted');
}); });
test('downloadAndDecryptAttachment', () async { test('downloadAndDecryptAttachment', () async {
final FILE_BUFF = Uint8List.fromList([0]); final FILE_BUFF = Uint8List.fromList([0]);