Skip to content

Commit

Permalink
Merge pull request #1997 from famedly/krille/room-id-null-in-basic-ro…
Browse files Browse the repository at this point in the history
…om-event

fix: No roomId in BasicRoomEvent stores roomaccountdata silently wrong
  • Loading branch information
krille-chan authored Jan 8, 2025
2 parents 32e051c + 50ac4b5 commit a6ee302
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2670,7 +2670,7 @@ class Client extends MatrixApi {
final accountData = syncRoomUpdate.accountData;
if (accountData != null && accountData.isNotEmpty) {
for (final event in accountData) {
await database?.storeRoomAccountData(event);
await database?.storeRoomAccountData(room.id, event);
room.roomAccountData[event.type] = event;
}
}
Expand Down Expand Up @@ -2739,7 +2739,7 @@ class Client extends MatrixApi {
roomId: room.id,
content: receiptStateContent.toJson(),
);
await database?.storeRoomAccountData(event);
await database?.storeRoomAccountData(room.id, event);
room.roomAccountData[event.type] = event;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/database/database_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ abstract class DatabaseApi {

Future storeAccountData(String type, Map<String, Object?> content);

Future storeRoomAccountData(BasicRoomEvent event);
Future storeRoomAccountData(String roomId, BasicRoomEvent event);

Future<Map<String, DeviceKeysList>> getUserDeviceKeys(Client client);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/database/hive_collections_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,9 @@ class HiveCollectionsDatabase extends DatabaseApi {
}

@override
Future<void> storeRoomAccountData(BasicRoomEvent event) async {
Future<void> storeRoomAccountData(String roomId, BasicRoomEvent event) async {
await _roomAccountDataBox.put(
TupleKey(event.roomId ?? '', event.type).toString(),
TupleKey(roomId, event.type).toString(),
copyMap(event.toJson()),
);
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/database/matrix_sdk_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1084,9 +1084,9 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
}

@override
Future<void> storeRoomAccountData(BasicRoomEvent event) async {
Future<void> storeRoomAccountData(String roomId, BasicRoomEvent event) async {
await _roomAccountDataBox.put(
TupleKey(event.roomId ?? '', event.type).toString(),
TupleKey(roomId, event.type).toString(),
event.toJson(),
);
return;
Expand Down
1 change: 1 addition & 0 deletions test/database_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void main() {
);

await database.storeRoomAccountData(
roomid,
BasicRoomEvent(
content: {'foo': 'bar'},
type: 'm.test',
Expand Down

0 comments on commit a6ee302

Please sign in to comment.