refactor: Event Update Type

This commit is contained in:
Christian Pauly 2020-10-22 12:21:20 +02:00
parent be6824b746
commit 66e590073e
11 changed files with 118 additions and 90 deletions

View File

@ -105,7 +105,7 @@ class Encryption {
} }
Future<void> handleEventUpdate(EventUpdate update) async { Future<void> handleEventUpdate(EventUpdate update) async {
if (update.type == 'ephemeral') { if (update.type == EventUpdateType.ephemeral) {
return; return;
} }
if (update.eventType.startsWith('m.key.verification.') || if (update.eventType.startsWith('m.key.verification.') ||
@ -235,7 +235,8 @@ class Encryption {
} }
Future<Event> decryptRoomEvent(String roomId, Event event, Future<Event> decryptRoomEvent(String roomId, Event event,
{bool store = false, String updateType = 'timeline'}) async { {bool store = false,
EventUpdateType updateType = EventUpdateType.timeline}) async {
final doStore = () async { final doStore = () async {
await client.database?.storeEventUpdate( await client.database?.storeEventUpdate(
client.id, client.id,
@ -247,7 +248,7 @@ class Encryption {
sortOrder: event.sortOrder, sortOrder: event.sortOrder,
), ),
); );
if (updateType != 'history') { if (updateType != EventUpdateType.history) {
event.room?.setState(event); event.room?.setState(event);
} }
}; };

View File

@ -887,14 +887,16 @@ class Client extends MatrixApi {
if (room.state?.isNotEmpty ?? false) { if (room.state?.isNotEmpty ?? false) {
// TODO: This method seems to be comperatively slow for some updates // TODO: This method seems to be comperatively slow for some updates
await _handleRoomEvents( await _handleRoomEvents(
id, room.state.map((i) => i.toJson()).toList(), 'state'); id,
room.state.map((i) => i.toJson()).toList(),
EventUpdateType.state);
handledEvents = true; handledEvents = true;
} }
if (room.timeline?.events?.isNotEmpty ?? false) { if (room.timeline?.events?.isNotEmpty ?? false) {
await _handleRoomEvents( await _handleRoomEvents(
id, id,
room.timeline.events.map((i) => i.toJson()).toList(), room.timeline.events.map((i) => i.toJson()).toList(),
sortAtTheEnd ? 'history' : 'timeline', sortAtTheEnd ? EventUpdateType.history : EventUpdateType.timeline,
sortAtTheEnd: sortAtTheEnd); sortAtTheEnd: sortAtTheEnd);
handledEvents = true; handledEvents = true;
} }
@ -904,30 +906,40 @@ class Client extends MatrixApi {
id, room.ephemeral.map((i) => i.toJson()).toList()); id, room.ephemeral.map((i) => i.toJson()).toList());
} }
if (room.accountData?.isNotEmpty ?? false) { if (room.accountData?.isNotEmpty ?? false) {
await _handleRoomEvents(id, await _handleRoomEvents(
room.accountData.map((i) => i.toJson()).toList(), 'account_data'); id,
room.accountData.map((i) => i.toJson()).toList(),
EventUpdateType.accountData);
} }
} }
if (room is LeftRoomUpdate) { if (room is LeftRoomUpdate) {
if (room.timeline?.events?.isNotEmpty ?? false) { if (room.timeline?.events?.isNotEmpty ?? false) {
await _handleRoomEvents(id, await _handleRoomEvents(
room.timeline.events.map((i) => i.toJson()).toList(), 'timeline'); id,
room.timeline.events.map((i) => i.toJson()).toList(),
EventUpdateType.timeline);
handledEvents = true; handledEvents = true;
} }
if (room.accountData?.isNotEmpty ?? false) { if (room.accountData?.isNotEmpty ?? false) {
await _handleRoomEvents(id, await _handleRoomEvents(
room.accountData.map((i) => i.toJson()).toList(), 'account_data'); id,
room.accountData.map((i) => i.toJson()).toList(),
EventUpdateType.accountData);
} }
if (room.state?.isNotEmpty ?? false) { if (room.state?.isNotEmpty ?? false) {
await _handleRoomEvents( await _handleRoomEvents(
id, room.state.map((i) => i.toJson()).toList(), 'state'); id,
room.state.map((i) => i.toJson()).toList(),
EventUpdateType.state);
handledEvents = true; handledEvents = true;
} }
} }
if (room is InvitedRoomUpdate && if (room is InvitedRoomUpdate &&
(room.inviteState?.isNotEmpty ?? false)) { (room.inviteState?.isNotEmpty ?? false)) {
await _handleRoomEvents(id, await _handleRoomEvents(
room.inviteState.map((i) => i.toJson()).toList(), 'invite_state'); id,
room.inviteState.map((i) => i.toJson()).toList(),
EventUpdateType.inviteState);
} }
if (handledEvents && database != null && roomObj != null) { if (handledEvents && database != null && roomObj != null) {
await roomObj.updateSortOrder(); await roomObj.updateSortOrder();
@ -937,7 +949,7 @@ class Client extends MatrixApi {
Future<void> _handleEphemerals(String id, List<dynamic> events) async { Future<void> _handleEphemerals(String id, List<dynamic> events) async {
for (num i = 0; i < events.length; i++) { for (num i = 0; i < events.length; i++) {
await _handleEvent(events[i], id, 'ephemeral'); await _handleEvent(events[i], id, EventUpdateType.ephemeral);
// Receipt events are deltas between two states. We will create a // Receipt events are deltas between two states. We will create a
// fake room account data event for this and store the difference // fake room account data event for this and store the difference
@ -974,13 +986,13 @@ class Client extends MatrixApi {
} }
} }
events[i]['content'] = receiptStateContent; events[i]['content'] = receiptStateContent;
await _handleEvent(events[i], id, 'account_data'); await _handleEvent(events[i], id, EventUpdateType.accountData);
} }
} }
} }
Future<void> _handleRoomEvents( Future<void> _handleRoomEvents(
String chat_id, List<dynamic> events, String type, String chat_id, List<dynamic> events, EventUpdateType type,
{bool sortAtTheEnd = false}) async { {bool sortAtTheEnd = false}) async {
for (num i = 0; i < events.length; i++) { for (num i = 0; i < events.length; i++) {
await _handleEvent(events[i], chat_id, type, sortAtTheEnd: sortAtTheEnd); await _handleEvent(events[i], chat_id, type, sortAtTheEnd: sortAtTheEnd);
@ -988,7 +1000,7 @@ class Client extends MatrixApi {
} }
Future<void> _handleEvent( Future<void> _handleEvent(
Map<String, dynamic> event, String roomID, String type, Map<String, dynamic> event, String roomID, EventUpdateType type,
{bool sortAtTheEnd = false}) async { {bool sortAtTheEnd = false}) async {
if (event['type'] is String && event['content'] is Map<String, dynamic>) { if (event['type'] is String && event['content'] is Map<String, dynamic>) {
// The client must ignore any new m.room.encryption event to prevent // The client must ignore any new m.room.encryption event to prevent
@ -1004,7 +1016,7 @@ class Client extends MatrixApi {
// ephemeral events aren't persisted and don't need a sort order - they are // ephemeral events aren't persisted and don't need a sort order - they are
// expected to be processed as soon as they come in // expected to be processed as soon as they come in
final sortOrder = type != 'ephemeral' final sortOrder = type != EventUpdateType.ephemeral
? (sortAtTheEnd ? room.oldSortOrder : room.newSortOrder) ? (sortAtTheEnd ? room.oldSortOrder : room.newSortOrder)
: 0.0; : 0.0;
var update = EventUpdate( var update = EventUpdate(
@ -1027,7 +1039,7 @@ class Client extends MatrixApi {
room.setState(user); room.setState(user);
} }
} }
if (type != 'ephemeral' && database != null) { if (type != EventUpdateType.ephemeral && database != null) {
await database.storeEventUpdate(id, update); await database.storeEventUpdate(id, update);
} }
_updateRoomsByEventUpdate(update); _updateRoomsByEventUpdate(update);
@ -1038,7 +1050,7 @@ class Client extends MatrixApi {
final rawUnencryptedEvent = update.content; final rawUnencryptedEvent = update.content;
if (prevBatch != null && type == 'timeline') { if (prevBatch != null && type == EventUpdateType.timeline) {
if (rawUnencryptedEvent['type'] == EventTypes.CallInvite) { if (rawUnencryptedEvent['type'] == EventTypes.CallInvite) {
onCallInvite onCallInvite
.add(Event.fromJson(rawUnencryptedEvent, room, sortOrder)); .add(Event.fromJson(rawUnencryptedEvent, room, sortOrder));
@ -1117,15 +1129,15 @@ class Client extends MatrixApi {
} }
void _updateRoomsByEventUpdate(EventUpdate eventUpdate) { void _updateRoomsByEventUpdate(EventUpdate eventUpdate) {
if (eventUpdate.type == 'history') return; if (eventUpdate.type == EventUpdateType.history) return;
final room = getRoomById(eventUpdate.roomID); final room = getRoomById(eventUpdate.roomID);
if (room == null) return; if (room == null) return;
switch (eventUpdate.type) { switch (eventUpdate.type) {
case 'timeline': case EventUpdateType.timeline:
case 'state': case EventUpdateType.state:
case 'invite_state': case EventUpdateType.inviteState:
var stateEvent = var stateEvent =
Event.fromJson(eventUpdate.content, room, eventUpdate.sortOrder); Event.fromJson(eventUpdate.content, room, eventUpdate.sortOrder);
var prevState = room.getState(stateEvent.type, stateEvent.stateKey); var prevState = room.getState(stateEvent.type, stateEvent.stateKey);
@ -1151,14 +1163,16 @@ sort order of ${prevState.sortOrder}. This should never happen...''');
room.setState(stateEvent); room.setState(stateEvent);
} }
break; break;
case 'account_data': case EventUpdateType.accountData:
room.roomAccountData[eventUpdate.eventType] = room.roomAccountData[eventUpdate.eventType] =
BasicRoomEvent.fromJson(eventUpdate.content); BasicRoomEvent.fromJson(eventUpdate.content);
break; break;
case 'ephemeral': case EventUpdateType.ephemeral:
room.ephemerals[eventUpdate.eventType] = room.ephemerals[eventUpdate.eventType] =
BasicRoomEvent.fromJson(eventUpdate.content); BasicRoomEvent.fromJson(eventUpdate.content);
break; break;
case EventUpdateType.history:
break;
} }
room.onUpdate.add(room.id); room.onUpdate.add(room.id);
} }

View File

@ -6,7 +6,6 @@ import 'package:olm/olm.dart' as olm;
import '../../famedlysdk.dart' as sdk; import '../../famedlysdk.dart' as sdk;
import '../../matrix_api.dart' as api; import '../../matrix_api.dart' as api;
import '../../matrix_api.dart';
import '../client.dart'; import '../client.dart';
import '../room.dart'; import '../room.dart';
import '../utils/logs.dart'; import '../utils/logs.dart';
@ -266,13 +265,13 @@ class Database extends _$Database {
// let's see if we need any m.room.member events // let's see if we need any m.room.member events
final membersToPostload = <String>{}; final membersToPostload = <String>{};
// the lastEvent message preview might have an author we need to fetch, if it is a group chat // the lastEvent message preview might have an author we need to fetch, if it is a group chat
if (room.getState(EventTypes.Message) != null && !room.isDirectChat) { if (room.getState(api.EventTypes.Message) != null && !room.isDirectChat) {
membersToPostload.add(room.getState(EventTypes.Message).senderId); membersToPostload.add(room.getState(api.EventTypes.Message).senderId);
} }
// if the room has no name and no canonical alias, its name is calculated // if the room has no name and no canonical alias, its name is calculated
// based on the heroes of the room // based on the heroes of the room
if (room.getState(EventTypes.RoomName) == null && if (room.getState(api.EventTypes.RoomName) == null &&
room.getState(EventTypes.RoomCanonicalAlias) == null && room.getState(api.EventTypes.RoomCanonicalAlias) == null &&
room.mHeroes != null) { room.mHeroes != null) {
// we don't have a name and no canonical alias, so we'll need to // we don't have a name and no canonical alias, so we'll need to
// post-load the heroes // post-load the heroes
@ -430,7 +429,7 @@ class Database extends _$Database {
/// [transaction]. /// [transaction].
Future<void> storeEventUpdate( Future<void> storeEventUpdate(
int clientId, sdk.EventUpdate eventUpdate) async { int clientId, sdk.EventUpdate eventUpdate) async {
if (eventUpdate.type == 'ephemeral') return; if (eventUpdate.type == sdk.EventUpdateType.ephemeral) return;
final eventContent = eventUpdate.content; final eventContent = eventUpdate.content;
final type = eventUpdate.type; final type = eventUpdate.type;
final chatId = eventUpdate.roomID; final chatId = eventUpdate.roomID;
@ -441,11 +440,12 @@ class Database extends _$Database {
stateKey = eventContent['state_key']; stateKey = eventContent['state_key'];
} }
if (eventUpdate.eventType == EventTypes.Redaction) { if (eventUpdate.eventType == api.EventTypes.Redaction) {
await redactMessage(clientId, eventUpdate); await redactMessage(clientId, eventUpdate);
} }
if (type == 'timeline' || type == 'history') { if (type == sdk.EventUpdateType.timeline ||
type == sdk.EventUpdateType.history) {
// calculate the status // calculate the status
var status = 2; var status = 2;
if (eventContent['unsigned'] is Map<String, dynamic> && if (eventContent['unsigned'] is Map<String, dynamic> &&
@ -493,7 +493,7 @@ class Database extends _$Database {
} }
if (storeNewEvent) { if (storeNewEvent) {
DbEvent oldEvent; DbEvent oldEvent;
if (type == 'history') { if (type == sdk.EventUpdateType.history) {
final allOldEvents = final allOldEvents =
await getEvent(clientId, eventContent['event_id'], chatId).get(); await getEvent(clientId, eventContent['event_id'], chatId).get();
if (allOldEvents.isNotEmpty) { if (allOldEvents.isNotEmpty) {
@ -527,12 +527,15 @@ class Database extends _$Database {
} }
} }
if (type == 'history') return; if (type == sdk.EventUpdateType.history) return;
if (type != 'account_data' && if (type != sdk.EventUpdateType.accountData &&
((stateKey is String) || ((stateKey is String) ||
[EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted] [
.contains(eventUpdate.eventType))) { api.EventTypes.Message,
api.EventTypes.Sticker,
api.EventTypes.Encrypted
].contains(eventUpdate.eventType))) {
final now = DateTime.now(); final now = DateTime.now();
await storeRoomState( await storeRoomState(
clientId, clientId,
@ -547,7 +550,7 @@ class Database extends _$Database {
json.encode(eventContent['prev_content'] ?? ''), json.encode(eventContent['prev_content'] ?? ''),
stateKey ?? '', stateKey ?? '',
); );
} else if (type == 'account_data') { } else if (type == sdk.EventUpdateType.accountData) {
await storeRoomAccountData( await storeRoomAccountData(
clientId, clientId,
eventContent['type'], eventContent['type'],

View File

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

View File

@ -1190,7 +1190,7 @@ class Room {
EventUpdate( EventUpdate(
content: content, content: content,
roomID: id, roomID: id,
type: 'state', type: EventUpdateType.state,
eventType: EventTypes.RoomMember, eventType: EventTypes.RoomMember,
sortOrder: 0.0), sortOrder: 0.0),
); );

View File

@ -211,7 +211,8 @@ class Timeline {
try { try {
if (eventUpdate.roomID != room.id) return; if (eventUpdate.roomID != room.id) return;
if (eventUpdate.type == 'timeline' || eventUpdate.type == 'history') { if (eventUpdate.type == EventUpdateType.timeline ||
eventUpdate.type == EventUpdateType.history) {
var status = eventUpdate.content['status'] ?? var status = eventUpdate.content['status'] ??
(eventUpdate.content['unsigned'] is Map<String, dynamic> (eventUpdate.content['unsigned'] is Map<String, dynamic>
? eventUpdate.content['unsigned'][MessageSendingStatusKey] ? eventUpdate.content['unsigned'][MessageSendingStatusKey]
@ -252,7 +253,7 @@ class Timeline {
var newEvent = Event.fromJson( var newEvent = Event.fromJson(
eventUpdate.content, room, eventUpdate.sortOrder); eventUpdate.content, room, eventUpdate.sortOrder);
if (eventUpdate.type == 'history' && if (eventUpdate.type == EventUpdateType.history &&
events.indexWhere( events.indexWhere(
(e) => e.eventId == eventUpdate.content['event_id']) != (e) => e.eventId == eventUpdate.content['event_id']) !=
-1) return; -1) return;

View File

@ -20,11 +20,20 @@ import '../../famedlysdk.dart';
import '../../matrix_api.dart'; import '../../matrix_api.dart';
import 'logs.dart'; import 'logs.dart';
enum EventUpdateType {
timeline,
state,
history,
accountData,
ephemeral,
inviteState
}
/// Represents a new event (e.g. a message in a room) or an update for an /// Represents a new event (e.g. a message in a room) or an update for an
/// already known event. /// already known event.
class EventUpdate { class EventUpdate {
/// Usually 'timeline', 'state' or whatever. /// Usually 'timeline', 'state' or whatever.
final String type; final EventUpdateType type;
/// Most events belong to a room. If not, this equals to eventType. /// Most events belong to a room. If not, this equals to eventType.
final String roomID; final String roomID;

View File

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

View File

@ -54,7 +54,7 @@ EventUpdate getLastSentEvent(KeyVerification req) {
'sender': req.client.userID, 'sender': req.client.userID,
}, },
eventType: type, eventType: type,
type: 'timeline', type: EventUpdateType.timeline,
roomID: req.room.id, roomID: req.room.id,
); );
} }
@ -446,7 +446,7 @@ void main() {
'sender': client2.userID, 'sender': client2.userID,
}, },
eventType: 'm.key.verification.ready', eventType: 'm.key.verification.ready',
type: 'timeline', type: EventUpdateType.timeline,
roomID: req2.room.id, roomID: req2.room.id,
)); ));
expect(req2.state, KeyVerificationState.error); expect(req2.state, KeyVerificationState.error);

View File

@ -40,7 +40,7 @@ void main() {
test('storeEventUpdate', () async { test('storeEventUpdate', () async {
// store a simple update // store a simple update
var update = EventUpdate( var update = EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -58,7 +58,7 @@ void main() {
// insert a transaction id // insert a transaction id
update = EventUpdate( update = EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -75,7 +75,7 @@ void main() {
event = await database.getEventById(clientId, 'transaction-1', room); event = await database.getEventById(clientId, 'transaction-1', room);
expect(event.eventId, 'transaction-1'); expect(event.eventId, 'transaction-1');
update = EventUpdate( update = EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -98,7 +98,7 @@ void main() {
// insert a transaction id if the event id for it already exists // insert a transaction id if the event id for it already exists
update = EventUpdate( update = EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -115,7 +115,7 @@ void main() {
event = await database.getEventById(clientId, '\$event-3', room); event = await database.getEventById(clientId, '\$event-3', room);
expect(event.eventId, '\$event-3'); expect(event.eventId, '\$event-3');
update = EventUpdate( update = EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -140,7 +140,7 @@ void main() {
// insert transaction id and not update status // insert transaction id and not update status
update = EventUpdate( update = EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -157,7 +157,7 @@ void main() {
event = await database.getEventById(clientId, '\$event-4', room); event = await database.getEventById(clientId, '\$event-4', room);
expect(event.eventId, '\$event-4'); expect(event.eventId, '\$event-4');
update = EventUpdate( update = EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {

View File

@ -52,7 +52,7 @@ void main() {
await client.checkServer('https://fakeServer.notExisting'); await client.checkServer('https://fakeServer.notExisting');
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -65,7 +65,7 @@ void main() {
}, },
sortOrder: room.newSortOrder)); sortOrder: room.newSortOrder));
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -114,7 +114,7 @@ void main() {
expect(timeline.events[0].receipts[0].user.id, '@alice:example.com'); expect(timeline.events[0].receipts[0].user.id, '@alice:example.com');
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.redaction', eventType: 'm.room.redaction',
content: { content: {
@ -149,7 +149,7 @@ void main() {
expect(timeline.events[0].status, 1); expect(timeline.events[0].status, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -174,7 +174,7 @@ void main() {
test('Send message with error', () async { test('Send message with error', () async {
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -221,7 +221,7 @@ void main() {
test('Resend message', () async { test('Resend message', () async {
timeline.events.clear(); timeline.events.clear();
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -278,7 +278,7 @@ void main() {
test('sort errors on top', () async { test('sort errors on top', () async {
timeline.events.clear(); timeline.events.clear();
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -291,7 +291,7 @@ void main() {
}, },
sortOrder: room.newSortOrder)); sortOrder: room.newSortOrder));
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -311,7 +311,7 @@ void main() {
test('sending event to failed update', () async { test('sending event to failed update', () async {
timeline.events.clear(); timeline.events.clear();
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -327,7 +327,7 @@ void main() {
expect(timeline.events[0].status, 0); expect(timeline.events[0].status, 0);
expect(timeline.events.length, 1); expect(timeline.events.length, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -347,7 +347,7 @@ void main() {
() async { () async {
timeline.events.clear(); timeline.events.clear();
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -363,7 +363,7 @@ void main() {
expect(timeline.events[0].status, 0); expect(timeline.events[0].status, 0);
expect(timeline.events.length, 1); expect(timeline.events.length, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -380,7 +380,7 @@ void main() {
expect(timeline.events[0].status, 1); expect(timeline.events[0].status, 1);
expect(timeline.events.length, 1); expect(timeline.events.length, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -401,7 +401,7 @@ void main() {
() async { () async {
timeline.events.clear(); timeline.events.clear();
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -420,7 +420,7 @@ void main() {
expect(timeline.events[0].status, 0); expect(timeline.events[0].status, 0);
expect(timeline.events.length, 1); expect(timeline.events.length, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -439,7 +439,7 @@ void main() {
expect(timeline.events[0].status, 2); expect(timeline.events[0].status, 2);
expect(timeline.events.length, 1); expect(timeline.events.length, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -461,7 +461,7 @@ void main() {
test('sending an event 0 -> -1 -> 2', () async { test('sending an event 0 -> -1 -> 2', () async {
timeline.events.clear(); timeline.events.clear();
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -477,7 +477,7 @@ void main() {
expect(timeline.events[0].status, 0); expect(timeline.events[0].status, 0);
expect(timeline.events.length, 1); expect(timeline.events.length, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -493,7 +493,7 @@ void main() {
expect(timeline.events[0].status, -1); expect(timeline.events[0].status, -1);
expect(timeline.events.length, 1); expect(timeline.events.length, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -513,7 +513,7 @@ void main() {
test('sending an event 0 -> 2 -> -1', () async { test('sending an event 0 -> 2 -> -1', () async {
timeline.events.clear(); timeline.events.clear();
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -529,7 +529,7 @@ void main() {
expect(timeline.events[0].status, 0); expect(timeline.events[0].status, 0);
expect(timeline.events.length, 1); expect(timeline.events.length, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {
@ -546,7 +546,7 @@ void main() {
expect(timeline.events[0].status, 2); expect(timeline.events[0].status, 2);
expect(timeline.events.length, 1); expect(timeline.events.length, 1);
client.onEvent.add(EventUpdate( client.onEvent.add(EventUpdate(
type: 'timeline', type: EventUpdateType.timeline,
roomID: roomID, roomID: roomID,
eventType: 'm.room.message', eventType: 'm.room.message',
content: { content: {