Merge pull request #1870 from famedly/td/editRedactLastEvent

fix: lastEvent after edit and redact
This commit is contained in:
Krille-chan 2024-07-02 08:41:25 +02:00 committed by GitHub
commit 87ee7f4cac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 111 additions and 9 deletions

View File

@ -2443,8 +2443,11 @@ class Client extends MatrixApi {
// Is this event redacting the last event?
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);
break;
}

View File

@ -649,12 +649,14 @@ class Room {
event['formatted_body'] = html;
}
}
return sendEvent(event,
txid: txid,
inReplyTo: inReplyTo,
editEventId: editEventId,
threadRootEventId: threadRootEventId,
threadLastEventId: threadLastEventId);
return sendEvent(
event,
txid: txid,
inReplyTo: inReplyTo,
editEventId: editEventId,
threadRootEventId: threadRootEventId,
threadLastEventId: threadLastEventId,
);
}
/// Sends a reaction to an event with an [eventId] and the content [key] into a room.

View File

@ -363,6 +363,103 @@ void main() {
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 {
await updateLastEvent(
Event(
@ -678,7 +775,7 @@ void main() {
test('getTimeline', () async {
final timeline = await room.getTimeline();
expect(timeline.events.length, 14);
expect(timeline.events.length, 17);
});
test('getUserByMXID', () async {