fix: deleting last message is edited

This commit is contained in:
Mohammad Reza Moradi 2025-04-10 11:49:35 +02:00
parent 0b4ee0e60e
commit defe47a198
No known key found for this signature in database
GPG Key ID: 5255BD653356ACD7
2 changed files with 22 additions and 5 deletions

View File

@ -2854,7 +2854,7 @@ class Client extends MatrixApi {
room.setState(user);
}
}
_updateRoomsByEventUpdate(room, event, type);
await _updateRoomsByEventUpdate(room, event, type);
if (store) {
await database?.storeEventUpdate(room.id, event, type, this);
}
@ -3020,11 +3020,11 @@ class Client extends MatrixApi {
return room;
}
void _updateRoomsByEventUpdate(
Future<void> _updateRoomsByEventUpdate(
Room room,
StrippedStateEvent eventUpdate,
EventUpdateType type,
) {
) async {
if (type == EventUpdateType.history) return;
switch (type) {
@ -3060,13 +3060,29 @@ class Client extends MatrixApi {
if (event.type == EventTypes.Redaction &&
({
room.lastEvent?.eventId,
room.lastEvent?.relationshipEventId,
}.contains(
event.redacts ?? event.content.tryGet<String>('redacts'),
))) {
room.lastEvent?.setRedactionEvent(event);
break;
}
// Is this event redacting the last event which is a edited event.
final relationshipEventId = room.lastEvent?.relationshipEventId;
if (relationshipEventId != null &&
relationshipEventId ==
(event.redacts ?? event.content.tryGet<String>('redacts')) &&
event.type == EventTypes.Redaction &&
room.lastEvent?.relationshipType == RelationshipTypes.edit) {
final originalEvent = await database?.getEventById(
relationshipEventId,
room,
) ??
room.lastEvent;
// Manually remove the data as it's already in cache until relogin.
originalEvent?.setRedactionEvent(event);
room.lastEvent = originalEvent;
break;
}
// Is this event an edit of the last event? Otherwise ignore it.
if (event.relationshipType == RelationshipTypes.edit) {

View File

@ -509,7 +509,8 @@ void main() {
nextBatch: '',
),
);
expect(room.lastEvent?.eventId, 'testLastEventAfterEdit');
// We do not delete the last edited event. Manually set the last event to original redacted event.
expect(room.lastEvent?.eventId, 'testLastEventBeforeEdit');
expect(room.lastEvent?.body, 'Redacted');
});