Merge pull request #1870 from famedly/td/editRedactLastEvent
fix: lastEvent after edit and redact
This commit is contained in:
commit
87ee7f4cac
|
|
@ -2443,8 +2443,11 @@ class Client extends MatrixApi {
|
||||||
|
|
||||||
// Is this event redacting the last event?
|
// Is this event redacting the last event?
|
||||||
if (event.type == EventTypes.Redaction &&
|
if (event.type == EventTypes.Redaction &&
|
||||||
(event.content.tryGet<String>('redacts') ?? event.redacts) ==
|
({
|
||||||
room.lastEvent?.eventId) {
|
room.lastEvent?.eventId,
|
||||||
|
room.lastEvent?.relationshipEventId
|
||||||
|
}.contains(
|
||||||
|
event.redacts ?? event.content.tryGet<String>('redacts')))) {
|
||||||
room.lastEvent?.setRedactionEvent(event);
|
room.lastEvent?.setRedactionEvent(event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -649,12 +649,14 @@ class Room {
|
||||||
event['formatted_body'] = html;
|
event['formatted_body'] = html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sendEvent(event,
|
return sendEvent(
|
||||||
txid: txid,
|
event,
|
||||||
inReplyTo: inReplyTo,
|
txid: txid,
|
||||||
editEventId: editEventId,
|
inReplyTo: inReplyTo,
|
||||||
threadRootEventId: threadRootEventId,
|
editEventId: editEventId,
|
||||||
threadLastEventId: threadLastEventId);
|
threadRootEventId: threadRootEventId,
|
||||||
|
threadLastEventId: threadLastEventId,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a reaction to an event with an [eventId] and the content [key] into a room.
|
/// Sends a reaction to an event with an [eventId] and the content [key] into a room.
|
||||||
|
|
|
||||||
|
|
@ -363,6 +363,103 @@ void main() {
|
||||||
expect(room.lastEvent?.status, EventStatus.sent);
|
expect(room.lastEvent?.status, EventStatus.sent);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('lastEvent when edited and deleted', () async {
|
||||||
|
await room.client.handleSync(
|
||||||
|
SyncUpdate(
|
||||||
|
rooms: RoomsUpdate(
|
||||||
|
join: {
|
||||||
|
room.id: JoinedRoomUpdate(
|
||||||
|
timeline: TimelineUpdate(
|
||||||
|
events: [
|
||||||
|
Event(
|
||||||
|
content: {
|
||||||
|
'body': 'A',
|
||||||
|
'm.mentions': {},
|
||||||
|
'msgtype': 'm.text'
|
||||||
|
},
|
||||||
|
type: 'm.room.message',
|
||||||
|
eventId: 'testLastEventBeforeEdit',
|
||||||
|
senderId: '@test:example.com',
|
||||||
|
originServerTs: DateTime.now(),
|
||||||
|
room: room,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
nextBatch: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(room.lastEvent?.eventId, 'testLastEventBeforeEdit');
|
||||||
|
expect(room.lastEvent?.body, 'A');
|
||||||
|
|
||||||
|
await room.client.handleSync(
|
||||||
|
SyncUpdate(
|
||||||
|
rooms: RoomsUpdate(
|
||||||
|
join: {
|
||||||
|
room.id: JoinedRoomUpdate(
|
||||||
|
timeline: TimelineUpdate(
|
||||||
|
events: [
|
||||||
|
Event(
|
||||||
|
content: {
|
||||||
|
'body': ' * A-edited',
|
||||||
|
'm.mentions': {},
|
||||||
|
'm.new_content': {
|
||||||
|
'body': 'A-edited',
|
||||||
|
'm.mentions': {},
|
||||||
|
'msgtype': 'm.text'
|
||||||
|
},
|
||||||
|
'm.relates_to': {
|
||||||
|
'event_id': 'testLastEventBeforeEdit',
|
||||||
|
'rel_type': 'm.replace'
|
||||||
|
},
|
||||||
|
'msgtype': 'm.text'
|
||||||
|
},
|
||||||
|
type: 'm.room.message',
|
||||||
|
eventId: 'testLastEventAfterEdit',
|
||||||
|
senderId: '@test:example.com',
|
||||||
|
originServerTs: DateTime.now(),
|
||||||
|
room: room,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
nextBatch: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(room.lastEvent?.eventId, 'testLastEventAfterEdit');
|
||||||
|
expect(room.lastEvent?.body, ' * A-edited');
|
||||||
|
|
||||||
|
await room.client.handleSync(
|
||||||
|
SyncUpdate(
|
||||||
|
rooms: RoomsUpdate(
|
||||||
|
join: {
|
||||||
|
room.id: JoinedRoomUpdate(
|
||||||
|
timeline: TimelineUpdate(
|
||||||
|
events: [
|
||||||
|
Event(
|
||||||
|
content: {'redacts': 'testLastEventBeforeEdit'},
|
||||||
|
type: 'm.room.redaction',
|
||||||
|
eventId: 'testLastEventAfterEditAndDelete',
|
||||||
|
senderId: '@test:example.com',
|
||||||
|
originServerTs: DateTime.now(),
|
||||||
|
room: room,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
nextBatch: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(room.lastEvent?.eventId, 'testLastEventAfterEdit');
|
||||||
|
expect(room.lastEvent?.body, 'Redacted');
|
||||||
|
});
|
||||||
|
|
||||||
test('lastEvent when reply parent edited', () async {
|
test('lastEvent when reply parent edited', () async {
|
||||||
await updateLastEvent(
|
await updateLastEvent(
|
||||||
Event(
|
Event(
|
||||||
|
|
@ -678,7 +775,7 @@ void main() {
|
||||||
|
|
||||||
test('getTimeline', () async {
|
test('getTimeline', () async {
|
||||||
final timeline = await room.getTimeline();
|
final timeline = await room.getTimeline();
|
||||||
expect(timeline.events.length, 14);
|
expect(timeline.events.length, 17);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getUserByMXID', () async {
|
test('getUserByMXID', () async {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue