Skip to content

Commit

Permalink
Merge pull request #1999 from famedly/krille/remove-basic-room-event
Browse files Browse the repository at this point in the history
refactor: Remove BasicRoomEvent type
  • Loading branch information
krille-chan authored Jan 9, 2025
2 parents 8d7b4dd + 3642ff6 commit 928f6ba
Showing 13 changed files with 37 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/app.yml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ jobs:
export HOMESERVER_IMPLEMENTATION=${{matrix.homeserver}}
export HOMESERVER="localhost:80"
scripts/integration-server-${{matrix.homeserver}}.sh 2>&1 > /dev/null &
sudo apt-get update && sudo apt-get install --no-install-recommends --no-install-suggests -y libolm3 libssl3
sudo apt-get update && sudo apt-get install --no-install-recommends --no-install-suggests -y libolm3 libssl3 sqlite3 libsqlite3-dev
source scripts/integration-create-environment-variables.sh
scripts/integration-prepare-homeserver.sh
scripts/prepare.sh
3 changes: 1 addition & 2 deletions lib/fake_matrix_api.dart
Original file line number Diff line number Diff line change
@@ -245,10 +245,9 @@ class FakeMatrixApi extends BaseClient {
join: {
roomId: JoinedRoomUpdate(
accountData: [
sdk.BasicRoomEvent(
sdk.BasicEvent(
content: decodeJson(data),
type: type,
roomId: roomId,
),
],
),
1 change: 0 additions & 1 deletion lib/matrix_api_lite.dart
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ export 'matrix_api_lite/model/auth/authentication_types.dart';
export 'matrix_api_lite/model/auth/authentication_user_identifier.dart';
export 'matrix_api_lite/model/basic_event.dart';
export 'matrix_api_lite/model/basic_event_with_sender.dart';
export 'matrix_api_lite/model/basic_room_event.dart';
export 'matrix_api_lite/model/event_types.dart';
export 'matrix_api_lite/model/events/forwarded_room_key_content.dart';
export 'matrix_api_lite/model/events/image_pack_content.dart';
45 changes: 0 additions & 45 deletions lib/matrix_api_lite/model/basic_room_event.dart

This file was deleted.

12 changes: 6 additions & 6 deletions lib/matrix_api_lite/model/sync_update.dart
Original file line number Diff line number Diff line change
@@ -170,8 +170,8 @@ class JoinedRoomUpdate extends SyncRoomUpdate {
RoomSummary? summary;
List<MatrixEvent>? state;
TimelineUpdate? timeline;
List<BasicRoomEvent>? ephemeral;
List<BasicRoomEvent>? accountData;
List<BasicEvent>? ephemeral;
List<BasicEvent>? accountData;
UnreadNotificationCounts? unreadNotifications;

JoinedRoomUpdate({
@@ -192,11 +192,11 @@ class JoinedRoomUpdate extends SyncRoomUpdate {
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
ephemeral = json
.tryGetMap<String, List<Object?>>('ephemeral')?['events']
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
?.map((i) => BasicEvent.fromJson(i as Map<String, Object?>))
.toList(),
accountData = json
.tryGetMap<String, List<Object?>>('account_data')?['events']
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
?.map((i) => BasicEvent.fromJson(i as Map<String, Object?>))
.toList(),
unreadNotifications = json.tryGetFromJson(
'unread_notifications',
@@ -280,7 +280,7 @@ class KnockRoomUpdate extends SyncRoomUpdate {
class LeftRoomUpdate extends SyncRoomUpdate {
List<MatrixEvent>? state;
TimelineUpdate? timeline;
List<BasicRoomEvent>? accountData;
List<BasicEvent>? accountData;

LeftRoomUpdate({
this.state,
@@ -296,7 +296,7 @@ class LeftRoomUpdate extends SyncRoomUpdate {
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
accountData = json
.tryGetMap<String, List<Object?>>('account_data')?['events']
?.map((i) => BasicRoomEvent.fromJson(i as Map<String, Object?>))
?.map((i) => BasicEvent.fromJson(i as Map<String, Object?>))
.toList();

Map<String, Object?> toJson() {
7 changes: 3 additions & 4 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -1200,7 +1200,7 @@ class Client extends MatrixApi {
roomAccountData: roomUpdate.accountData
?.asMap()
.map((k, v) => MapEntry(v.type, v)) ??
<String, BasicRoomEvent>{},
<String, BasicEvent>{},
);
// Set membership of room to leave, in the case we got a left room passed, otherwise
// the left room would have still membership join, which would be wrong for the setState later
@@ -2713,7 +2713,7 @@ class Client extends MatrixApi {
}
}

Future<void> _handleEphemerals(Room room, List<BasicRoomEvent> events) async {
Future<void> _handleEphemerals(Room room, List<BasicEvent> events) async {
final List<ReceiptEventContent> receipts = [];

for (final event in events) {
@@ -2734,9 +2734,8 @@ class Client extends MatrixApi {
await receiptStateContent.update(e, room);
}

final event = BasicRoomEvent(
final event = BasicEvent(
type: LatestReceiptState.eventType,
roomId: room.id,
content: receiptStateContent.toJson(),
);
await database?.storeRoomAccountData(room.id, event);
2 changes: 1 addition & 1 deletion lib/src/database/database_api.dart
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ abstract class DatabaseApi {

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

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

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

6 changes: 3 additions & 3 deletions lib/src/database/hive_collections_database.dart
Original file line number Diff line number Diff line change
@@ -580,7 +580,7 @@ class HiveCollectionsDatabase extends DatabaseApi {

for (final data in roomAccountDataList) {
if (data == null) continue;
final event = BasicRoomEvent.fromJson(copyMap(data));
final event = BasicEvent.fromJson(copyMap(data));
room.roomAccountData[event.type] = event;
}

@@ -696,7 +696,7 @@ class HiveCollectionsDatabase extends DatabaseApi {
final roomAccountDataRaws = await _roomAccountDataBox.getAllValues();
for (final entry in roomAccountDataRaws.entries) {
final keys = TupleKey.fromString(entry.key);
final basicRoomEvent = BasicRoomEvent.fromJson(
final basicRoomEvent = BasicEvent.fromJson(
copyMap(entry.value),
);
final roomId = keys.parts.first;
@@ -1096,7 +1096,7 @@ class HiveCollectionsDatabase extends DatabaseApi {
}

@override
Future<void> storeRoomAccountData(String roomId, BasicRoomEvent event) async {
Future<void> storeRoomAccountData(String roomId, BasicEvent event) async {
await _roomAccountDataBox.put(
TupleKey(roomId, event.type).toString(),
copyMap(event.toJson()),
6 changes: 3 additions & 3 deletions lib/src/database/matrix_sdk_database.dart
Original file line number Diff line number Diff line change
@@ -626,7 +626,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {

for (final data in roomAccountDataList) {
if (data == null) continue;
final event = BasicRoomEvent.fromJson(copyMap(data));
final event = BasicEvent.fromJson(copyMap(data));
room.roomAccountData[event.type] = event;
}

@@ -683,7 +683,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
final roomAccountDataRaws = await _roomAccountDataBox.getAllValues();
for (final entry in roomAccountDataRaws.entries) {
final keys = TupleKey.fromString(entry.key);
final basicRoomEvent = BasicRoomEvent.fromJson(
final basicRoomEvent = BasicEvent.fromJson(
copyMap(entry.value),
);
final roomId = keys.parts.first;
@@ -1084,7 +1084,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
}

@override
Future<void> storeRoomAccountData(String roomId, BasicRoomEvent event) async {
Future<void> storeRoomAccountData(String roomId, BasicEvent event) async {
await _roomAccountDataBox.put(
TupleKey(roomId, event.type).toString(),
event.toJson(),
13 changes: 6 additions & 7 deletions lib/src/room.dart
Original file line number Diff line number Diff line change
@@ -67,10 +67,10 @@ class Room {
Map<String, Map<String, StrippedStateEvent>> states = {};

/// Key-Value store for ephemerals.
Map<String, BasicRoomEvent> ephemerals = {};
Map<String, BasicEvent> ephemerals = {};

/// Key-Value store for private account data only visible for this user.
Map<String, BasicRoomEvent> roomAccountData = {};
Map<String, BasicEvent> roomAccountData = {};

final _sendingQueue = <Completer>[];

@@ -372,7 +372,7 @@ class Room {

Event? lastEvent;

void setEphemeral(BasicRoomEvent ephemeral) {
void setEphemeral(BasicEvent ephemeral) {
ephemerals[ephemeral.type] = ephemeral;
if (ephemeral.type == 'm.typing') {
_clearTypingIndicatorTimer?.cancel();
@@ -403,10 +403,10 @@ class Room {
this.highlightCount = 0,
this.prev_batch,
required this.client,
Map<String, BasicRoomEvent>? roomAccountData,
Map<String, BasicEvent>? roomAccountData,
RoomSummary? summary,
this.lastEvent,
}) : roomAccountData = roomAccountData ?? <String, BasicRoomEvent>{},
}) : roomAccountData = roomAccountData ?? <String, BasicEvent>{},
summary = summary ??
RoomSummary.fromJson({
'm.joined_member_count': 0,
@@ -572,9 +572,8 @@ class Room {
join: {
id: JoinedRoomUpdate(
accountData: [
BasicRoomEvent(
BasicEvent(
content: content,
roomId: id,
type: EventType.markedUnread,
),
],
3 changes: 1 addition & 2 deletions test/database_api_test.dart
Original file line number Diff line number Diff line change
@@ -257,10 +257,9 @@ void main() {

await database.storeRoomAccountData(
roomid,
BasicRoomEvent(
BasicEvent(
content: {'foo': 'bar'},
type: 'm.test',
roomId: roomid,
),
);

8 changes: 4 additions & 4 deletions test/room_test.dart
Original file line number Diff line number Diff line change
@@ -82,11 +82,11 @@ void main() {
'm.heroes': heroes,
}),
roomAccountData: {
'com.test.foo': BasicRoomEvent(
'com.test.foo': BasicEvent(
type: 'com.test.foo',
content: {'foo': 'bar'},
),
'm.fully_read': BasicRoomEvent(
'm.fully_read': BasicEvent(
type: 'm.fully_read',
content: {'event_id': '\$event_id:example.com'},
),
@@ -1292,7 +1292,7 @@ void main() {
await room.addTag(TagType.favourite, order: 0.1);
await room.removeTag(TagType.favourite);
expect(room.isFavourite, false);
room.roomAccountData['m.tag'] = BasicRoomEvent.fromJson({
room.roomAccountData['m.tag'] = BasicEvent.fromJson({
'content': {
'tags': {
'm.favourite': {'order': 0.1},
@@ -1311,7 +1311,7 @@ void main() {
await room.markUnread(true);
await room.markUnread(false);
expect(room.markedUnread, false);
room.roomAccountData['m.marked_unread'] = BasicRoomEvent.fromJson({
room.roomAccountData['m.marked_unread'] = BasicEvent.fromJson({
'content': {'unread': true},
'type': 'm.marked_unread',
});
16 changes: 8 additions & 8 deletions test/timeline_test.dart
Original file line number Diff line number Diff line change
@@ -177,7 +177,7 @@ void main() {
join: {
timeline.room.id: JoinedRoomUpdate(
ephemeral: [
BasicRoomEvent.fromJson({
BasicEvent.fromJson({
'type': 'm.receipt',
'content': {
timeline.events.first.eventId: {
@@ -294,7 +294,7 @@ void main() {
join: {
timeline.room.id: JoinedRoomUpdate(
ephemeral: [
BasicRoomEvent.fromJson({
BasicEvent.fromJson({
'type': 'm.receipt',
'content': {
'\$2': {
@@ -328,7 +328,7 @@ void main() {
join: {
timeline.room.id: JoinedRoomUpdate(
ephemeral: [
BasicRoomEvent.fromJson({
BasicEvent.fromJson({
'type': 'm.receipt',
'content': {
'\$2': {
@@ -371,7 +371,7 @@ void main() {
join: {
timeline.room.id: JoinedRoomUpdate(
ephemeral: [
BasicRoomEvent.fromJson({
BasicEvent.fromJson({
'type': 'm.receipt',
'content': {
'\$2': {
@@ -421,7 +421,7 @@ void main() {
join: {
timeline.room.id: JoinedRoomUpdate(
ephemeral: [
BasicRoomEvent.fromJson({
BasicEvent.fromJson({
'type': 'm.receipt',
'content': {
'\$1': {
@@ -467,7 +467,7 @@ void main() {
join: {
timeline.room.id: JoinedRoomUpdate(
ephemeral: [
BasicRoomEvent.fromJson({
BasicEvent.fromJson({
'type': 'm.receipt',
'content': {
'\$2': {
@@ -511,7 +511,7 @@ void main() {
join: {
timeline.room.id: JoinedRoomUpdate(
ephemeral: [
BasicRoomEvent.fromJson({
BasicEvent.fromJson({
'type': 'm.receipt',
'content': {
'\$2': {
@@ -559,7 +559,7 @@ void main() {
],
),
ephemeral: [
BasicRoomEvent.fromJson({
BasicEvent.fromJson({
'type': 'm.receipt',
'content': {
'\$2': {

0 comments on commit 928f6ba

Please sign in to comment.