Merge pull request #1999 from famedly/krille/remove-basic-room-event

refactor: Remove BasicRoomEvent type
This commit is contained in:
Krille-chan 2025-01-09 12:14:59 +01:00 committed by GitHub
commit 928f6ba96f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 37 additions and 87 deletions

View File

@ -22,7 +22,7 @@ jobs:
export HOMESERVER_IMPLEMENTATION=${{matrix.homeserver}} export HOMESERVER_IMPLEMENTATION=${{matrix.homeserver}}
export HOMESERVER="localhost:80" export HOMESERVER="localhost:80"
scripts/integration-server-${{matrix.homeserver}}.sh 2>&1 > /dev/null & 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 source scripts/integration-create-environment-variables.sh
scripts/integration-prepare-homeserver.sh scripts/integration-prepare-homeserver.sh
scripts/prepare.sh scripts/prepare.sh

View File

@ -245,10 +245,9 @@ class FakeMatrixApi extends BaseClient {
join: { join: {
roomId: JoinedRoomUpdate( roomId: JoinedRoomUpdate(
accountData: [ accountData: [
sdk.BasicRoomEvent( sdk.BasicEvent(
content: decodeJson(data), content: decodeJson(data),
type: type, type: type,
roomId: roomId,
), ),
], ],
), ),

View File

@ -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/auth/authentication_user_identifier.dart';
export 'matrix_api_lite/model/basic_event.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_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/event_types.dart';
export 'matrix_api_lite/model/events/forwarded_room_key_content.dart'; export 'matrix_api_lite/model/events/forwarded_room_key_content.dart';
export 'matrix_api_lite/model/events/image_pack_content.dart'; export 'matrix_api_lite/model/events/image_pack_content.dart';

View File

@ -1,45 +0,0 @@
/* MIT License
*
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import 'package:matrix/matrix_api_lite/model/basic_event.dart';
class BasicRoomEvent extends BasicEvent {
String? roomId;
BasicRoomEvent({
this.roomId,
required super.content,
required super.type,
});
BasicRoomEvent.fromJson(super.json)
: roomId = json['room_id'] as String?,
super.fromJson();
@override
Map<String, Object?> toJson() {
final data = super.toJson();
if (roomId != null) data['room_id'] = roomId;
return data;
}
}

View File

@ -170,8 +170,8 @@ class JoinedRoomUpdate extends SyncRoomUpdate {
RoomSummary? summary; RoomSummary? summary;
List<MatrixEvent>? state; List<MatrixEvent>? state;
TimelineUpdate? timeline; TimelineUpdate? timeline;
List<BasicRoomEvent>? ephemeral; List<BasicEvent>? ephemeral;
List<BasicRoomEvent>? accountData; List<BasicEvent>? accountData;
UnreadNotificationCounts? unreadNotifications; UnreadNotificationCounts? unreadNotifications;
JoinedRoomUpdate({ JoinedRoomUpdate({
@ -192,11 +192,11 @@ class JoinedRoomUpdate extends SyncRoomUpdate {
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson), timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
ephemeral = json ephemeral = json
.tryGetMap<String, List<Object?>>('ephemeral')?['events'] .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(), .toList(),
accountData = json accountData = json
.tryGetMap<String, List<Object?>>('account_data')?['events'] .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(), .toList(),
unreadNotifications = json.tryGetFromJson( unreadNotifications = json.tryGetFromJson(
'unread_notifications', 'unread_notifications',
@ -280,7 +280,7 @@ class KnockRoomUpdate extends SyncRoomUpdate {
class LeftRoomUpdate extends SyncRoomUpdate { class LeftRoomUpdate extends SyncRoomUpdate {
List<MatrixEvent>? state; List<MatrixEvent>? state;
TimelineUpdate? timeline; TimelineUpdate? timeline;
List<BasicRoomEvent>? accountData; List<BasicEvent>? accountData;
LeftRoomUpdate({ LeftRoomUpdate({
this.state, this.state,
@ -296,7 +296,7 @@ class LeftRoomUpdate extends SyncRoomUpdate {
timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson), timeline = json.tryGetFromJson('timeline', TimelineUpdate.fromJson),
accountData = json accountData = json
.tryGetMap<String, List<Object?>>('account_data')?['events'] .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(); .toList();
Map<String, Object?> toJson() { Map<String, Object?> toJson() {

View File

@ -1200,7 +1200,7 @@ class Client extends MatrixApi {
roomAccountData: roomUpdate.accountData roomAccountData: roomUpdate.accountData
?.asMap() ?.asMap()
.map((k, v) => MapEntry(v.type, v)) ?? .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 // 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 // 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 = []; final List<ReceiptEventContent> receipts = [];
for (final event in events) { for (final event in events) {
@ -2734,9 +2734,8 @@ class Client extends MatrixApi {
await receiptStateContent.update(e, room); await receiptStateContent.update(e, room);
} }
final event = BasicRoomEvent( final event = BasicEvent(
type: LatestReceiptState.eventType, type: LatestReceiptState.eventType,
roomId: room.id,
content: receiptStateContent.toJson(), content: receiptStateContent.toJson(),
); );
await database?.storeRoomAccountData(room.id, event); await database?.storeRoomAccountData(room.id, event);

View File

@ -134,7 +134,7 @@ abstract class DatabaseApi {
Future storeAccountData(String type, Map<String, Object?> content); 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); Future<Map<String, DeviceKeysList>> getUserDeviceKeys(Client client);

View File

@ -580,7 +580,7 @@ class HiveCollectionsDatabase extends DatabaseApi {
for (final data in roomAccountDataList) { for (final data in roomAccountDataList) {
if (data == null) continue; if (data == null) continue;
final event = BasicRoomEvent.fromJson(copyMap(data)); final event = BasicEvent.fromJson(copyMap(data));
room.roomAccountData[event.type] = event; room.roomAccountData[event.type] = event;
} }
@ -696,7 +696,7 @@ class HiveCollectionsDatabase extends DatabaseApi {
final roomAccountDataRaws = await _roomAccountDataBox.getAllValues(); final roomAccountDataRaws = await _roomAccountDataBox.getAllValues();
for (final entry in roomAccountDataRaws.entries) { for (final entry in roomAccountDataRaws.entries) {
final keys = TupleKey.fromString(entry.key); final keys = TupleKey.fromString(entry.key);
final basicRoomEvent = BasicRoomEvent.fromJson( final basicRoomEvent = BasicEvent.fromJson(
copyMap(entry.value), copyMap(entry.value),
); );
final roomId = keys.parts.first; final roomId = keys.parts.first;
@ -1096,7 +1096,7 @@ class HiveCollectionsDatabase extends DatabaseApi {
} }
@override @override
Future<void> storeRoomAccountData(String roomId, BasicRoomEvent event) async { Future<void> storeRoomAccountData(String roomId, BasicEvent event) async {
await _roomAccountDataBox.put( await _roomAccountDataBox.put(
TupleKey(roomId, event.type).toString(), TupleKey(roomId, event.type).toString(),
copyMap(event.toJson()), copyMap(event.toJson()),

View File

@ -626,7 +626,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
for (final data in roomAccountDataList) { for (final data in roomAccountDataList) {
if (data == null) continue; if (data == null) continue;
final event = BasicRoomEvent.fromJson(copyMap(data)); final event = BasicEvent.fromJson(copyMap(data));
room.roomAccountData[event.type] = event; room.roomAccountData[event.type] = event;
} }
@ -683,7 +683,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
final roomAccountDataRaws = await _roomAccountDataBox.getAllValues(); final roomAccountDataRaws = await _roomAccountDataBox.getAllValues();
for (final entry in roomAccountDataRaws.entries) { for (final entry in roomAccountDataRaws.entries) {
final keys = TupleKey.fromString(entry.key); final keys = TupleKey.fromString(entry.key);
final basicRoomEvent = BasicRoomEvent.fromJson( final basicRoomEvent = BasicEvent.fromJson(
copyMap(entry.value), copyMap(entry.value),
); );
final roomId = keys.parts.first; final roomId = keys.parts.first;
@ -1084,7 +1084,7 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
} }
@override @override
Future<void> storeRoomAccountData(String roomId, BasicRoomEvent event) async { Future<void> storeRoomAccountData(String roomId, BasicEvent event) async {
await _roomAccountDataBox.put( await _roomAccountDataBox.put(
TupleKey(roomId, event.type).toString(), TupleKey(roomId, event.type).toString(),
event.toJson(), event.toJson(),

View File

@ -67,10 +67,10 @@ class Room {
Map<String, Map<String, StrippedStateEvent>> states = {}; Map<String, Map<String, StrippedStateEvent>> states = {};
/// Key-Value store for ephemerals. /// 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. /// Key-Value store for private account data only visible for this user.
Map<String, BasicRoomEvent> roomAccountData = {}; Map<String, BasicEvent> roomAccountData = {};
final _sendingQueue = <Completer>[]; final _sendingQueue = <Completer>[];
@ -372,7 +372,7 @@ class Room {
Event? lastEvent; Event? lastEvent;
void setEphemeral(BasicRoomEvent ephemeral) { void setEphemeral(BasicEvent ephemeral) {
ephemerals[ephemeral.type] = ephemeral; ephemerals[ephemeral.type] = ephemeral;
if (ephemeral.type == 'm.typing') { if (ephemeral.type == 'm.typing') {
_clearTypingIndicatorTimer?.cancel(); _clearTypingIndicatorTimer?.cancel();
@ -403,10 +403,10 @@ class Room {
this.highlightCount = 0, this.highlightCount = 0,
this.prev_batch, this.prev_batch,
required this.client, required this.client,
Map<String, BasicRoomEvent>? roomAccountData, Map<String, BasicEvent>? roomAccountData,
RoomSummary? summary, RoomSummary? summary,
this.lastEvent, this.lastEvent,
}) : roomAccountData = roomAccountData ?? <String, BasicRoomEvent>{}, }) : roomAccountData = roomAccountData ?? <String, BasicEvent>{},
summary = summary ?? summary = summary ??
RoomSummary.fromJson({ RoomSummary.fromJson({
'm.joined_member_count': 0, 'm.joined_member_count': 0,
@ -572,9 +572,8 @@ class Room {
join: { join: {
id: JoinedRoomUpdate( id: JoinedRoomUpdate(
accountData: [ accountData: [
BasicRoomEvent( BasicEvent(
content: content, content: content,
roomId: id,
type: EventType.markedUnread, type: EventType.markedUnread,
), ),
], ],

View File

@ -257,10 +257,9 @@ void main() {
await database.storeRoomAccountData( await database.storeRoomAccountData(
roomid, roomid,
BasicRoomEvent( BasicEvent(
content: {'foo': 'bar'}, content: {'foo': 'bar'},
type: 'm.test', type: 'm.test',
roomId: roomid,
), ),
); );

View File

@ -82,11 +82,11 @@ void main() {
'm.heroes': heroes, 'm.heroes': heroes,
}), }),
roomAccountData: { roomAccountData: {
'com.test.foo': BasicRoomEvent( 'com.test.foo': BasicEvent(
type: 'com.test.foo', type: 'com.test.foo',
content: {'foo': 'bar'}, content: {'foo': 'bar'},
), ),
'm.fully_read': BasicRoomEvent( 'm.fully_read': BasicEvent(
type: 'm.fully_read', type: 'm.fully_read',
content: {'event_id': '\$event_id:example.com'}, content: {'event_id': '\$event_id:example.com'},
), ),
@ -1292,7 +1292,7 @@ void main() {
await room.addTag(TagType.favourite, order: 0.1); await room.addTag(TagType.favourite, order: 0.1);
await room.removeTag(TagType.favourite); await room.removeTag(TagType.favourite);
expect(room.isFavourite, false); expect(room.isFavourite, false);
room.roomAccountData['m.tag'] = BasicRoomEvent.fromJson({ room.roomAccountData['m.tag'] = BasicEvent.fromJson({
'content': { 'content': {
'tags': { 'tags': {
'm.favourite': {'order': 0.1}, 'm.favourite': {'order': 0.1},
@ -1311,7 +1311,7 @@ void main() {
await room.markUnread(true); await room.markUnread(true);
await room.markUnread(false); await room.markUnread(false);
expect(room.markedUnread, false); expect(room.markedUnread, false);
room.roomAccountData['m.marked_unread'] = BasicRoomEvent.fromJson({ room.roomAccountData['m.marked_unread'] = BasicEvent.fromJson({
'content': {'unread': true}, 'content': {'unread': true},
'type': 'm.marked_unread', 'type': 'm.marked_unread',
}); });

View File

@ -177,7 +177,7 @@ void main() {
join: { join: {
timeline.room.id: JoinedRoomUpdate( timeline.room.id: JoinedRoomUpdate(
ephemeral: [ ephemeral: [
BasicRoomEvent.fromJson({ BasicEvent.fromJson({
'type': 'm.receipt', 'type': 'm.receipt',
'content': { 'content': {
timeline.events.first.eventId: { timeline.events.first.eventId: {
@ -294,7 +294,7 @@ void main() {
join: { join: {
timeline.room.id: JoinedRoomUpdate( timeline.room.id: JoinedRoomUpdate(
ephemeral: [ ephemeral: [
BasicRoomEvent.fromJson({ BasicEvent.fromJson({
'type': 'm.receipt', 'type': 'm.receipt',
'content': { 'content': {
'\$2': { '\$2': {
@ -328,7 +328,7 @@ void main() {
join: { join: {
timeline.room.id: JoinedRoomUpdate( timeline.room.id: JoinedRoomUpdate(
ephemeral: [ ephemeral: [
BasicRoomEvent.fromJson({ BasicEvent.fromJson({
'type': 'm.receipt', 'type': 'm.receipt',
'content': { 'content': {
'\$2': { '\$2': {
@ -371,7 +371,7 @@ void main() {
join: { join: {
timeline.room.id: JoinedRoomUpdate( timeline.room.id: JoinedRoomUpdate(
ephemeral: [ ephemeral: [
BasicRoomEvent.fromJson({ BasicEvent.fromJson({
'type': 'm.receipt', 'type': 'm.receipt',
'content': { 'content': {
'\$2': { '\$2': {
@ -421,7 +421,7 @@ void main() {
join: { join: {
timeline.room.id: JoinedRoomUpdate( timeline.room.id: JoinedRoomUpdate(
ephemeral: [ ephemeral: [
BasicRoomEvent.fromJson({ BasicEvent.fromJson({
'type': 'm.receipt', 'type': 'm.receipt',
'content': { 'content': {
'\$1': { '\$1': {
@ -467,7 +467,7 @@ void main() {
join: { join: {
timeline.room.id: JoinedRoomUpdate( timeline.room.id: JoinedRoomUpdate(
ephemeral: [ ephemeral: [
BasicRoomEvent.fromJson({ BasicEvent.fromJson({
'type': 'm.receipt', 'type': 'm.receipt',
'content': { 'content': {
'\$2': { '\$2': {
@ -511,7 +511,7 @@ void main() {
join: { join: {
timeline.room.id: JoinedRoomUpdate( timeline.room.id: JoinedRoomUpdate(
ephemeral: [ ephemeral: [
BasicRoomEvent.fromJson({ BasicEvent.fromJson({
'type': 'm.receipt', 'type': 'm.receipt',
'content': { 'content': {
'\$2': { '\$2': {
@ -559,7 +559,7 @@ void main() {
], ],
), ),
ephemeral: [ ephemeral: [
BasicRoomEvent.fromJson({ BasicEvent.fromJson({
'type': 'm.receipt', 'type': 'm.receipt',
'content': { 'content': {
'\$2': { '\$2': {