refactor: Deprecate eventType in EventUpdate

This commit is contained in:
Christian Pauly 2021-02-26 12:53:28 +01:00
parent 62ad8569ae
commit c9d3c327f6
11 changed files with 26 additions and 63 deletions

View File

@ -118,8 +118,8 @@ class Encryption {
if (update.type == EventUpdateType.ephemeral) {
return;
}
if (update.eventType.startsWith('m.key.verification.') ||
(update.eventType == EventTypes.Message &&
if (update.content['type'].startsWith('m.key.verification.') ||
(update.content['type'] == EventTypes.Message &&
(update.content['content']['msgtype'] is String) &&
update.content['content']['msgtype']
.startsWith('m.key.verification.'))) {
@ -281,7 +281,6 @@ class Encryption {
await client.database?.storeEventUpdate(
client.id,
EventUpdate(
eventType: event.type,
content: event.toJson(),
roomID: event.roomId,
type: updateType,

View File

@ -1271,7 +1271,6 @@ class Client extends MatrixApi {
? (sortAtTheEnd ? room.oldSortOrder : room.newSortOrder)
: 0.0;
var update = EventUpdate(
eventType: event['type'],
roomID: roomID,
type: type,
content: event,
@ -1421,11 +1420,11 @@ sort order of ${prevState.sortOrder}. This should never happen...''');
}
break;
case EventUpdateType.accountData:
room.roomAccountData[eventUpdate.eventType] =
room.roomAccountData[eventUpdate.content['type']] =
BasicRoomEvent.fromJson(eventUpdate.content);
break;
case EventUpdateType.ephemeral:
room.ephemerals[eventUpdate.eventType] =
room.ephemerals[eventUpdate.content['type']] =
BasicRoomEvent.fromJson(eventUpdate.content);
break;
case EventUpdateType.history:

View File

@ -461,7 +461,7 @@ class Database extends _$Database {
stateKey = eventContent['state_key'];
}
if (eventUpdate.eventType == api.EventTypes.Redaction) {
if (eventUpdate.content['type'] == api.EventTypes.Redaction) {
await redactMessage(clientId, eventUpdate);
}
@ -556,7 +556,7 @@ class Database extends _$Database {
api.EventTypes.Message,
api.EventTypes.Sticker,
api.EventTypes.Encrypted
].contains(eventUpdate.eventType))) {
].contains(eventUpdate.content['type']))) {
final now = DateTime.now();
await storeRoomState(
clientId,

View File

@ -320,7 +320,6 @@ class Event extends MatrixEvent {
room.client.onEvent.add(EventUpdate(
roomID: room.id,
type: EventUpdateType.timeline,
eventType: type,
content: {
'event_id': eventId,
'status': -2,

View File

@ -1301,7 +1301,6 @@ class Room {
content: content,
roomID: id,
type: EventUpdateType.state,
eventType: EventTypes.RoomMember,
sortOrder: 0.0),
);
});

View File

@ -263,7 +263,7 @@ class Timeline {
: null) ??
2;
// Redaction events are handled as modification for existing events.
if (eventUpdate.eventType == EventTypes.Redaction) {
if (eventUpdate.content['type'] == EventTypes.Redaction) {
final eventId = _findEvent(event_id: eventUpdate.content['redacts']);
if (eventId < events.length) {
removeAggregatedEvent(events[eventId]);

View File

@ -36,10 +36,8 @@ class EventUpdate {
/// Most events belong to a room. If not, this equals to eventType.
final String roomID;
/// See (Matrix Room Events)[https://matrix.org/docs/spec/client_server/r0.4.0.html#room-events]
/// and (Matrix Events)[https://matrix.org/docs/spec/client_server/r0.4.0.html#id89] for more
/// informations.
final String eventType;
@Deprecated("Use `content['eventType']` instead.")
String get eventType => content['type'];
// The json payload of the content of this event.
final Map<String, dynamic> content;
@ -47,11 +45,11 @@ class EventUpdate {
// the order where to stort this event
final double sortOrder;
EventUpdate(
{this.eventType, this.roomID, this.type, this.content, this.sortOrder});
EventUpdate({this.roomID, this.type, this.content, this.sortOrder});
Future<EventUpdate> decrypt(Room room, {bool store = false}) async {
if (eventType != EventTypes.Encrypted || !room.client.encryptionEnabled) {
if (content['type'] != EventTypes.Encrypted ||
!room.client.encryptionEnabled) {
return this;
}
try {
@ -59,7 +57,6 @@ class EventUpdate {
room.id, Event.fromJson(content, room, sortOrder),
store: store, updateType: type);
return EventUpdate(
eventType: decrpytedEvent.type,
roomID: roomID,
type: type,
content: decrpytedEvent.toJson(),

View File

@ -245,55 +245,56 @@ void main() {
expect(eventUpdateList.length, 14);
expect(eventUpdateList[0].eventType, 'm.room.member');
expect(eventUpdateList[0].content['type'], 'm.room.member');
expect(eventUpdateList[0].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[0].type, EventUpdateType.state);
expect(eventUpdateList[1].eventType, 'm.room.canonical_alias');
expect(eventUpdateList[1].content['type'], 'm.room.canonical_alias');
expect(eventUpdateList[1].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[1].type, EventUpdateType.state);
expect(eventUpdateList[2].eventType, 'm.room.encryption');
expect(eventUpdateList[2].content['type'], 'm.room.encryption');
expect(eventUpdateList[2].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[2].type, EventUpdateType.state);
expect(eventUpdateList[3].eventType, 'm.room.pinned_events');
expect(eventUpdateList[3].content['type'], 'm.room.pinned_events');
expect(eventUpdateList[3].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[3].type, EventUpdateType.state);
expect(eventUpdateList[4].eventType, 'm.room.member');
expect(eventUpdateList[4].content['type'], 'm.room.member');
expect(eventUpdateList[4].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[4].type, EventUpdateType.timeline);
expect(eventUpdateList[5].eventType, 'm.room.message');
expect(eventUpdateList[5].content['type'], 'm.room.message');
expect(eventUpdateList[5].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[5].type, EventUpdateType.timeline);
expect(eventUpdateList[6].eventType, 'm.typing');
expect(eventUpdateList[6].content['type'], 'm.typing');
expect(eventUpdateList[6].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[6].type, EventUpdateType.ephemeral);
expect(eventUpdateList[7].eventType, 'm.receipt');
expect(eventUpdateList[7].content['type'], 'm.receipt');
expect(eventUpdateList[7].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[7].type, EventUpdateType.ephemeral);
expect(eventUpdateList[8].eventType, 'm.receipt');
expect(eventUpdateList[8].content['type'], 'm.receipt');
expect(eventUpdateList[8].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[8].type, EventUpdateType.accountData);
expect(eventUpdateList[9].eventType, 'm.tag');
expect(eventUpdateList[9].content['type'], 'm.tag');
expect(eventUpdateList[9].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[9].type, EventUpdateType.accountData);
expect(eventUpdateList[10].eventType, 'org.example.custom.room.config');
expect(eventUpdateList[10].content['type'],
'org.example.custom.room.config');
expect(eventUpdateList[10].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[10].type, EventUpdateType.accountData);
expect(eventUpdateList[11].eventType, 'm.room.name');
expect(eventUpdateList[11].content['type'], 'm.room.name');
expect(eventUpdateList[11].roomID, '!696r7674:example.com');
expect(eventUpdateList[11].type, EventUpdateType.inviteState);
expect(eventUpdateList[12].eventType, 'm.room.member');
expect(eventUpdateList[12].content['type'], 'm.room.member');
expect(eventUpdateList[12].roomID, '!696r7674:example.com');
expect(eventUpdateList[12].type, EventUpdateType.inviteState);
});

View File

@ -53,7 +53,6 @@ EventUpdate getLastSentEvent(KeyVerification req) {
'origin_server_ts': DateTime.now().millisecondsSinceEpoch,
'sender': req.client.userID,
},
eventType: type,
type: EventUpdateType.timeline,
roomID: req.room.id,
);
@ -448,7 +447,6 @@ void main() {
'origin_server_ts': DateTime.now().millisecondsSinceEpoch,
'sender': client2.userID,
},
eventType: 'm.key.verification.ready',
type: EventUpdateType.timeline,
roomID: req2.room.id,
));

View File

@ -45,7 +45,6 @@ void main() {
var update = EventUpdate(
type: EventUpdateType.timeline,
roomID: room.id,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'origin_server_ts': 100,
@ -63,7 +62,6 @@ void main() {
update = EventUpdate(
type: EventUpdateType.timeline,
roomID: room.id,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'origin_server_ts': 100,
@ -80,7 +78,6 @@ void main() {
update = EventUpdate(
type: EventUpdateType.timeline,
roomID: room.id,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'origin_server_ts': 100,
@ -103,7 +100,6 @@ void main() {
update = EventUpdate(
type: EventUpdateType.timeline,
roomID: room.id,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'origin_server_ts': 100,
@ -120,7 +116,6 @@ void main() {
update = EventUpdate(
type: EventUpdateType.timeline,
roomID: room.id,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'origin_server_ts': 100,
@ -145,7 +140,6 @@ void main() {
update = EventUpdate(
type: EventUpdateType.timeline,
roomID: room.id,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'origin_server_ts': 100,
@ -162,7 +156,6 @@ void main() {
update = EventUpdate(
type: EventUpdateType.timeline,
roomID: room.id,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'origin_server_ts': 100,

View File

@ -71,7 +71,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -84,7 +83,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -133,7 +131,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.redaction',
content: {
'type': 'm.room.redaction',
'content': {'reason': 'spamming'},
@ -168,7 +165,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'test'},
@ -193,7 +189,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -257,7 +252,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -314,7 +308,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -327,7 +320,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -347,7 +339,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -363,7 +354,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -383,7 +373,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -399,7 +388,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -416,7 +404,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -437,7 +424,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -456,7 +442,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -475,7 +460,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -497,7 +481,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -513,7 +496,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -529,7 +511,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -549,7 +530,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -565,7 +545,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
@ -582,7 +561,6 @@ void main() {
client.onEvent.add(EventUpdate(
type: EventUpdateType.timeline,
roomID: roomID,
eventType: 'm.room.message',
content: {
'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'Testcase'},