Merge pull request #1984 from famedly/krille/make-ephemerals-dont-event-updates

refactor: Do not handle ephemerals as EventUpdates
This commit is contained in:
Krille-chan 2024-12-30 11:41:50 +01:00 committed by GitHub
commit 8f783f6857
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 39 additions and 38 deletions

View File

@ -155,8 +155,7 @@ class Encryption {
} }
Future<void> handleEventUpdate(EventUpdate update) async { Future<void> handleEventUpdate(EventUpdate update) async {
if (update.type == EventUpdateType.ephemeral || if (update.type == EventUpdateType.history) {
update.type == EventUpdateType.history) {
return; return;
} }
if (update.content['type'].startsWith('m.key.verification.') || if (update.content['type'].startsWith('m.key.verification.') ||

View File

@ -2703,7 +2703,7 @@ class Client extends MatrixApi {
final List<ReceiptEventContent> receipts = []; final List<ReceiptEventContent> receipts = [];
for (final event in events) { for (final event in events) {
await _handleRoomEvents(room, [event], EventUpdateType.ephemeral); room.setEphemeral(event);
// Receipt events are deltas between two states. We will create a // Receipt events are deltas between two states. We will create a
// fake room account data event for this and store the difference // fake room account data event for this and store the difference
@ -2808,7 +2808,7 @@ class Client extends MatrixApi {
} }
} }
_updateRoomsByEventUpdate(room, update); _updateRoomsByEventUpdate(room, update);
if (type != EventUpdateType.ephemeral && store) { if (store) {
await database?.storeEventUpdate(update, this); await database?.storeEventUpdate(update, this);
} }
if (encryptionEnabled) { if (encryptionEnabled) {
@ -2982,9 +2982,6 @@ class Client extends MatrixApi {
room.roomAccountData[eventUpdate.content['type']] = room.roomAccountData[eventUpdate.content['type']] =
BasicRoomEvent.fromJson(eventUpdate.content); BasicRoomEvent.fromJson(eventUpdate.content);
break; break;
case EventUpdateType.ephemeral:
room.setEphemeral(BasicRoomEvent.fromJson(eventUpdate.content));
break;
case EventUpdateType.history: case EventUpdateType.history:
case EventUpdateType.decryptedTimelineQueue: case EventUpdateType.decryptedTimelineQueue:
break; break;

View File

@ -1080,9 +1080,6 @@ class HiveCollectionsDatabase extends DatabaseApi {
@override @override
Future<void> storeEventUpdate(EventUpdate eventUpdate, Client client) async { Future<void> storeEventUpdate(EventUpdate eventUpdate, Client client) async {
// Ephemerals should not be stored
if (eventUpdate.type == EventUpdateType.ephemeral) return;
final tmpRoom = client.getRoomById(eventUpdate.roomID) ?? final tmpRoom = client.getRoomById(eventUpdate.roomID) ??
Room(id: eventUpdate.roomID, client: client); Room(id: eventUpdate.roomID, client: client);

View File

@ -1042,9 +1042,6 @@ class FamedlySdkHiveDatabase extends DatabaseApi with ZoneTransactionMixin {
@override @override
Future<void> storeEventUpdate(EventUpdate eventUpdate, Client client) async { Future<void> storeEventUpdate(EventUpdate eventUpdate, Client client) async {
// Ephemerals should not be stored
if (eventUpdate.type == EventUpdateType.ephemeral) return;
// In case of this is a redaction event // In case of this is a redaction event
if (eventUpdate.content['type'] == EventTypes.Redaction) { if (eventUpdate.content['type'] == EventTypes.Redaction) {
final tmpRoom = client.getRoomById(eventUpdate.roomID) ?? final tmpRoom = client.getRoomById(eventUpdate.roomID) ??

View File

@ -1043,8 +1043,6 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
@override @override
Future<void> storeEventUpdate(EventUpdate eventUpdate, Client client) async { Future<void> storeEventUpdate(EventUpdate eventUpdate, Client client) async {
// Ephemerals should not be stored
if (eventUpdate.type == EventUpdateType.ephemeral) return;
final tmpRoom = client.getRoomById(eventUpdate.roomID) ?? final tmpRoom = client.getRoomById(eventUpdate.roomID) ??
Room(id: eventUpdate.roomID, client: client); Room(id: eventUpdate.roomID, client: client);

View File

@ -29,9 +29,6 @@ enum EventUpdateType {
/// Updates to account data /// Updates to account data
accountData, accountData,
/// Ephemeral events like receipts
ephemeral,
/// The state of an invite /// The state of an invite
inviteState, inviteState,

View File

@ -282,7 +282,7 @@ void main() {
final eventUpdateList = await eventUpdateListFuture; final eventUpdateList = await eventUpdateListFuture;
expect(eventUpdateList.length, 20); expect(eventUpdateList.length, 18);
expect(eventUpdateList[0].content['type'], 'm.room.member'); expect(eventUpdateList[0].content['type'], 'm.room.member');
expect(eventUpdateList[0].roomID, '!726s6s6q:example.com'); expect(eventUpdateList[0].roomID, '!726s6s6q:example.com');
@ -308,36 +308,52 @@ void main() {
expect(eventUpdateList[5].roomID, '!726s6s6q:example.com'); expect(eventUpdateList[5].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[5].type, EventUpdateType.timeline); expect(eventUpdateList[5].type, EventUpdateType.timeline);
expect(eventUpdateList[6].content['type'], 'm.typing'); expect(eventUpdateList[6].content['type'], LatestReceiptState.eventType);
expect(eventUpdateList[6].roomID, '!726s6s6q:example.com'); expect(eventUpdateList[6].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[6].type, EventUpdateType.ephemeral); expect(eventUpdateList[6].type, EventUpdateType.accountData);
expect(eventUpdateList[7].content['type'], 'm.receipt'); expect(eventUpdateList[7].content['type'], 'm.tag');
expect(eventUpdateList[7].roomID, '!726s6s6q:example.com'); expect(eventUpdateList[7].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[7].type, EventUpdateType.ephemeral); expect(eventUpdateList[7].type, EventUpdateType.accountData);
expect(eventUpdateList[8].content['type'], LatestReceiptState.eventType); expect(
eventUpdateList[8].content['type'],
'org.example.custom.room.config',
);
expect(eventUpdateList[8].roomID, '!726s6s6q:example.com'); expect(eventUpdateList[8].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[8].type, EventUpdateType.accountData); expect(eventUpdateList[8].type, EventUpdateType.accountData);
expect(eventUpdateList[9].content['type'], 'm.tag'); expect(eventUpdateList[9].content['type'], 'm.room.member');
expect(eventUpdateList[9].roomID, '!726s6s6q:example.com'); expect(eventUpdateList[9].roomID, '!calls:example.com');
expect(eventUpdateList[9].type, EventUpdateType.accountData); expect(eventUpdateList[9].type, EventUpdateType.state);
expect(eventUpdateList[10].content['type'], 'm.room.member');
expect(eventUpdateList[10].roomID, '!calls:example.com');
expect(eventUpdateList[10].type, EventUpdateType.state);
expect( expect(
eventUpdateList[10].content['type'], matrix
'org.example.custom.room.config', .getRoomById('!726s6s6q:example.com')
?.ephemerals['m.typing']
?.content,
{
'user_ids': ['@alice:example.com'],
},
); );
expect(eventUpdateList[10].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[10].type, EventUpdateType.accountData);
expect(eventUpdateList[11].content['type'], 'm.room.member'); expect(
expect(eventUpdateList[11].roomID, '!calls:example.com'); matrix
expect(eventUpdateList[11].type, EventUpdateType.state); .getRoomById('!726s6s6q:example.com')
?.ephemerals['m.receipt']
expect(eventUpdateList[12].content['type'], 'm.room.member'); ?.content,
expect(eventUpdateList[12].roomID, '!calls:example.com'); {
expect(eventUpdateList[12].type, EventUpdateType.state); '\$7365636s6r6432:example.com': {
'm.read': {
'@alice:example.com': {'ts': 1436451550453},
},
},
},
);
await matrix.onToDeviceEvent.close(); await matrix.onToDeviceEvent.close();