Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Do not handle ephemerals as EventUpdates #1984

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/encryption/encryption.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ class Encryption {
}

Future<void> handleEventUpdate(EventUpdate update) async {
if (update.type == EventUpdateType.ephemeral ||
update.type == EventUpdateType.history) {
if (update.type == EventUpdateType.history) {
return;
}
if (update.content['type'].startsWith('m.key.verification.') ||
Expand Down
7 changes: 2 additions & 5 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ class Client extends MatrixApi {
final List<ReceiptEventContent> receipts = [];

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
// fake room account data event for this and store the difference
Expand Down Expand Up @@ -2808,7 +2808,7 @@ class Client extends MatrixApi {
}
}
_updateRoomsByEventUpdate(room, update);
if (type != EventUpdateType.ephemeral && store) {
if (store) {
await database?.storeEventUpdate(update, this);
}
if (encryptionEnabled) {
Expand Down Expand Up @@ -2982,9 +2982,6 @@ class Client extends MatrixApi {
room.roomAccountData[eventUpdate.content['type']] =
BasicRoomEvent.fromJson(eventUpdate.content);
break;
case EventUpdateType.ephemeral:
room.setEphemeral(BasicRoomEvent.fromJson(eventUpdate.content));
break;
case EventUpdateType.history:
case EventUpdateType.decryptedTimelineQueue:
break;
Expand Down
3 changes: 0 additions & 3 deletions lib/src/database/hive_collections_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1080,9 +1080,6 @@ class HiveCollectionsDatabase extends DatabaseApi {

@override
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) ??
Room(id: eventUpdate.roomID, client: client);

Expand Down
3 changes: 0 additions & 3 deletions lib/src/database/hive_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,6 @@ class FamedlySdkHiveDatabase extends DatabaseApi with ZoneTransactionMixin {

@override
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
if (eventUpdate.content['type'] == EventTypes.Redaction) {
final tmpRoom = client.getRoomById(eventUpdate.roomID) ??
Expand Down
2 changes: 0 additions & 2 deletions lib/src/database/matrix_sdk_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,6 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {

@override
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) ??
Room(id: eventUpdate.roomID, client: client);

Expand Down
3 changes: 0 additions & 3 deletions lib/src/utils/event_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ enum EventUpdateType {
/// Updates to account data
accountData,

/// Ephemeral events like receipts
ephemeral,

/// The state of an invite
inviteState,

Expand Down
56 changes: 36 additions & 20 deletions test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void main() {

final eventUpdateList = await eventUpdateListFuture;

expect(eventUpdateList.length, 20);
expect(eventUpdateList.length, 18);

expect(eventUpdateList[0].content['type'], 'm.room.member');
expect(eventUpdateList[0].roomID, '!726s6s6q:example.com');
Expand All @@ -308,36 +308,52 @@ void main() {
expect(eventUpdateList[5].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[5].type, EventUpdateType.timeline);

expect(eventUpdateList[6].content['type'], 'm.typing');
expect(eventUpdateList[6].content['type'], LatestReceiptState.eventType);
krille-chan marked this conversation as resolved.
Show resolved Hide resolved
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].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].type, EventUpdateType.accountData);

expect(eventUpdateList[9].content['type'], 'm.tag');
expect(eventUpdateList[9].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[9].type, EventUpdateType.accountData);
expect(eventUpdateList[9].content['type'], 'm.room.member');
expect(eventUpdateList[9].roomID, '!calls:example.com');
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(
eventUpdateList[10].content['type'],
'org.example.custom.room.config',
matrix
.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(eventUpdateList[11].roomID, '!calls:example.com');
expect(eventUpdateList[11].type, EventUpdateType.state);

expect(eventUpdateList[12].content['type'], 'm.room.member');
expect(eventUpdateList[12].roomID, '!calls:example.com');
expect(eventUpdateList[12].type, EventUpdateType.state);
expect(
matrix
.getRoomById('!726s6s6q:example.com')
?.ephemerals['m.receipt']
?.content,
{
'\$7365636s6r6432:example.com': {
'm.read': {
'@alice:example.com': {'ts': 1436451550453},
},
},
},
);

await matrix.onToDeviceEvent.close();

Expand Down
Loading