From 86041513f8fa222fbabbfd9a19205b55b55bb84d Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 17 Aug 2021 10:11:59 +0200 Subject: [PATCH] refactor: Remove deprecated moor database We have used some data models which were only used in moor in the tests. I needed to rewrite them in the original data as well. Also now the "fake database" on native is the same like on web now with hive. --- lib/matrix.dart | 1 - lib/src/database/database.dart | 893 ---- lib/src/database/database.g.dart | 7554 ------------------------------ lib/src/database/database.moor | 261 -- pubspec.yaml | 3 - test/database_api_test.dart | 7 +- test/fake_database.dart | 27 +- test/fake_database_native.dart | 50 - test/fake_database_web.dart | 26 - test/room_test.dart | 71 +- 10 files changed, 56 insertions(+), 8837 deletions(-) delete mode 100644 lib/src/database/database.dart delete mode 100644 lib/src/database/database.g.dart delete mode 100644 lib/src/database/database.moor delete mode 100644 test/fake_database_native.dart delete mode 100644 test/fake_database_web.dart diff --git a/lib/matrix.dart b/lib/matrix.dart index 5a09bc14..01339c0b 100644 --- a/lib/matrix.dart +++ b/lib/matrix.dart @@ -39,6 +39,5 @@ export 'src/event.dart'; export 'src/room.dart'; export 'src/timeline.dart'; export 'src/user.dart'; -export 'src/database/database.dart' show Database; export 'src/database/database_api.dart'; export 'src/database/hive_database.dart'; diff --git a/lib/src/database/database.dart b/lib/src/database/database.dart deleted file mode 100644 index b29dcaeb..00000000 --- a/lib/src/database/database.dart +++ /dev/null @@ -1,893 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2020, 2021 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'dart:async'; -import 'dart:convert'; - -import 'package:matrix/encryption/utils/olm_session.dart'; -import 'package:matrix/encryption/utils/outbound_group_session.dart'; -import 'package:matrix/encryption/utils/ssss_cache.dart'; -import 'package:matrix/encryption/utils/stored_inbound_group_session.dart'; -import 'package:matrix/src/utils/QueuedToDeviceEvent.dart'; -import 'package:moor/moor.dart'; - -import '../../matrix.dart' as sdk; -import 'package:matrix_api_lite/matrix_api_lite.dart' as api; -import '../client.dart'; -import '../room.dart'; -import 'database_api.dart'; - -part 'database.g.dart'; - -extension MigratorExtension on Migrator { - Future createIndexIfNotExists(Index index) async { - try { - await createIndex(index); - } catch (err) { - if (!err.toString().toLowerCase().contains('already exists')) { - rethrow; - } - } - } - - Future createTableIfNotExists(TableInfo table) async { - try { - await createTable(table); - } catch (err) { - if (!err.toString().toLowerCase().contains('already exists')) { - rethrow; - } - } - } - - Future addColumnIfNotExists( - TableInfo table, GeneratedColumn column) async { - try { - await addColumn(table, column); - } catch (err) { - if (!err.toString().toLowerCase().contains('duplicate column name')) { - rethrow; - } - } - } -} - -@UseMoor( - include: {'database.moor'}, -) -class Database extends _$Database implements DatabaseApi { - Database(QueryExecutor e) : super(e); - - Database.connect(DatabaseConnection connection) : super.connect(connection); - - @override - bool get supportsFileStoring => true; - - @override - int get schemaVersion => 12; - - @override - int get maxFileSize => 1 * 1024 * 1024; - - /// Update errors are coming here. - final StreamController onError = StreamController.broadcast(); - - @override - MigrationStrategy get migration => MigrationStrategy( - onCreate: (Migrator m) async { - try { - await m.createAll(); - } catch (e, s) { - api.Logs().e('Create all failed in database migrator', e, s); - onError.add(SdkError(exception: e, stackTrace: s)); - rethrow; - } - }, - onUpgrade: (Migrator m, int from, int to) async { - try { - // this appears to be only called once, so multiple consecutive upgrades have to be handled appropriately in here - if (from == 1) { - await m.createIndexIfNotExists(userDeviceKeysIndex); - await m.createIndexIfNotExists(userDeviceKeysKeyIndex); - await m.createIndexIfNotExists(olmSessionsIndex); - await m.createIndexIfNotExists(outboundGroupSessionsIndex); - await m.createIndexIfNotExists(inboundGroupSessionsIndex); - await m.createIndexIfNotExists(roomsIndex); - await m.createIndexIfNotExists(eventsIndex); - await m.createIndexIfNotExists(roomStatesIndex); - await m.createIndexIfNotExists(accountDataIndex); - await m.createIndexIfNotExists(roomAccountDataIndex); - await m.createIndexIfNotExists(presencesIndex); - from++; - } - if (from == 2) { - await m.deleteTable('outbound_group_sessions'); - await m.createTable(outboundGroupSessions); - from++; - } - if (from == 3) { - await m.createTableIfNotExists(userCrossSigningKeys); - await m.createTableIfNotExists(ssssCache); - // mark all keys as outdated so that the cross signing keys will be fetched - await customStatement( - 'UPDATE user_device_keys SET outdated = true'); - from++; - } - if (from == 4) { - await m.addColumnIfNotExists( - olmSessions, olmSessions.lastReceived); - from++; - } - if (from == 5) { - await m.addColumnIfNotExists( - inboundGroupSessions, inboundGroupSessions.uploaded); - await m.addColumnIfNotExists( - inboundGroupSessions, inboundGroupSessions.senderKey); - await m.addColumnIfNotExists( - inboundGroupSessions, inboundGroupSessions.senderClaimedKeys); - from++; - } - if (from == 6) { - // DATETIME was internally an int, so we should be able to re-use the - // olm_sessions table. - await m.deleteTable('outbound_group_sessions'); - await m.createTable(outboundGroupSessions); - await m.deleteTable('events'); - await m.createTable(events); - await m.deleteTable('room_states'); - await m.createTable(roomStates); - await m.deleteTable('files'); - await m.createTable(files); - // and now clear cache - await delete(presences).go(); - await delete(roomAccountData).go(); - await delete(accountData).go(); - await delete(roomStates).go(); - await delete(events).go(); - await delete(rooms).go(); - await delete(outboundGroupSessions).go(); - await customStatement('UPDATE clients SET prev_batch = null'); - from++; - } - if (from == 7) { - await m.addColumnIfNotExists( - inboundGroupSessions, inboundGroupSessions.allowedAtIndex); - from++; - } - if (from == 8) { - await m.addColumnIfNotExists( - userDeviceKeysKey, userDeviceKeysKey.lastActive); - from++; - } - if (from == 9) { - await m.addColumnIfNotExists( - userDeviceKeysKey, userDeviceKeysKey.lastSentMessage); - await m.createIndexIfNotExists(olmSessionsIdentityIndex); - from++; - } - if (from == 10) { - await m.createTableIfNotExists(toDeviceQueue); - await m.createIndexIfNotExists(toDeviceQueueIndex); - from++; - } - if (from == 11) { - await m.addColumnIfNotExists(clients, clients.syncFilterId); - from++; - } - } catch (e, s) { - api.Logs().e('Database migration failed', e, s); - onError.add(SdkError(exception: e, stackTrace: s)); - rethrow; - } - }, - beforeOpen: (_) async { - try { - if (executor.dialect == SqlDialect.sqlite) { - final ret = await customSelect('PRAGMA journal_mode=WAL').get(); - if (ret.isNotEmpty) { - api.Logs().v('[Moor] Switched database to mode ' + - ret.first.data['journal_mode'].toString()); - } - } - } catch (e, s) { - api.Logs().e('Database before open failed', e, s); - onError.add(SdkError(exception: e, stackTrace: s)); - rethrow; - } - }, - ); - - @override - Future> getClient(String name) async { - final res = await dbGetClient(name).get(); - if (res.isEmpty) return null; - await markPendingEventsAsError(res.single.clientId); - return res.single.toJson(); - } - - @override - Future> getUserDeviceKeys( - sdk.Client client) async { - final deviceKeys = await getAllUserDeviceKeys(client.id).get(); - if (deviceKeys.isEmpty) { - return {}; - } - final deviceKeysKeys = await getAllUserDeviceKeysKeys(client.id).get(); - final crossSigningKeys = await getAllUserCrossSigningKeys(client.id).get(); - final res = {}; - for (final entry in deviceKeys) { - res[entry.userId] = sdk.DeviceKeysList.fromDbJson( - entry.toJson(), - deviceKeysKeys - .where((k) => k.userId == entry.userId) - .map((d) => d.toJson()) - .toList(), - crossSigningKeys - .where((k) => k.userId == entry.userId) - .map((d) => d.toJson()) - .toList(), - client); - } - return res; - } - - @override - Future getOutboundGroupSession( - int clientId, String roomId, String userId) async { - final res = await dbGetOutboundGroupSession(clientId, roomId).get(); - if (res.isEmpty) { - return null; - } - return OutboundGroupSession.fromJson(res.single.toJson(), userId); - } - - @override - Future> getAllInboundGroupSessions( - int clientId, - ) async { - final res = await dbGetAllInboundGroupSessions(clientId).get(); - if (res.isEmpty) { - return []; - } - return res - .map((res) => StoredInboundGroupSession.fromJson(res.toJson())) - .toList(); - } - - @override - Future getInboundGroupSession( - int clientId, - String roomId, - String sessionId, - ) async { - final res = - await dbGetInboundGroupSessionKey(clientId, roomId, sessionId).get(); - if (res.isEmpty) { - return null; - } - return StoredInboundGroupSession.fromJson(res.single.toJson()); - } - - @override - Future getSSSSCache(int clientId, String type) async { - final res = await dbGetSSSSCache(clientId, type).get(); - if (res.isEmpty) { - return null; - } - final dbCache = res.single; - return SSSSCache( - ciphertext: dbCache.ciphertext, - clientId: dbCache.clientId, - type: dbCache.type, - keyId: dbCache.keyId, - content: dbCache.content, - ); - } - - @override - Future> getRoomList(sdk.Client client) async { - final res = await select(rooms).get(); - final resStates = await getImportantRoomStates( - client.id, client.importantStateEvents.toList()) - .get(); - final resAccountData = await getAllRoomAccountData(client.id).get(); - final roomList = []; - final allMembersToPostload = >{}; - for (final r in res) { - final room = await getRoomFromTableRow( - r, - client, - states: resStates.where((rs) => rs.roomId == r.roomId), - roomAccountData: resAccountData.where((rs) => rs.roomId == r.roomId), - ); - roomList.add(room); - // let's see if we need any m.room.member events - // We always need the member event for ourself - final membersToPostload = {client.userID}; - // the lastEvent message preview might have an author we need to fetch, if it is a group chat - if (room.getState(api.EventTypes.Message) != null && !room.isDirectChat) { - membersToPostload.add(room.getState(api.EventTypes.Message).senderId); - } - // if the room has no name and no canonical alias, its name is calculated - // based on the heroes of the room - if (room.getState(api.EventTypes.RoomName) == null && - room.getState(api.EventTypes.RoomCanonicalAlias) == null && - room.summary.mHeroes != null) { - // we don't have a name and no canonical alias, so we'll need to - // post-load the heroes - membersToPostload - .addAll(room.summary.mHeroes.where((h) => h.isNotEmpty)); - } - // save it for loading later - allMembersToPostload[room.id] = membersToPostload; - } - // now we postload all members, if thre are any - if (allMembersToPostload.isNotEmpty) { - // we will generate a query to fetch as many events as possible at once, as that - // significantly improves performance. However, to prevent too large queries from being constructed, - // we limit to only fetching 500 rooms at once. - // This value might be fine-tune-able to be larger (and thus increase performance more for very large accounts), - // however this very conservative value should be on the safe side. - const maxRoomsPerQuery = 500; - // as we iterate over our entries in separate chunks one-by-one we use an iterator - // which persists accross the chunks, and thus we just re-sume iteration at the place - // we prreviously left off. - final entriesIterator = allMembersToPostload.entries.iterator; - // now we iterate over all our 500-room-chunks... - for (var i = 0; - i < allMembersToPostload.keys.length; - i += maxRoomsPerQuery) { - // query the current chunk and build the query - final membersRes = await (select(roomStates) - ..where((s) { - // all chunks have to have the reight client id and must be of type `m.room.member` - final basequery = s.clientId.equals(client.id) & - s.type.equals('m.room.member'); - // this is where the magic happens. Here we build a query with the form - // OR room_id = '!roomId1' AND state_key IN ('@member') OR room_id = '!roomId2' AND state_key IN ('@member') - // subqueries holds our query fragment - Expression subqueries; - // here we iterate over our chunk....we musn't forget to progress our iterator! - // we must check for if our chunk is done *before* progressing the - // iterator, else we might progress it twice around chunk edges, missing on rooms - for (var j = 0; - j < maxRoomsPerQuery && entriesIterator.moveNext(); - j++) { - final entry = entriesIterator.current; - // builds room_id = '!roomId1' AND state_key IN ('@member') - final q = - s.roomId.equals(entry.key) & s.stateKey.isIn(entry.value); - // adds it either as the start of subqueries or as a new OR condition to it - if (subqueries == null) { - subqueries = q; - } else { - subqueries = subqueries | q; - } - } - // combinde the basequery with the subquery together, giving our final query - return basequery & subqueries; - })) - .get(); - // now that we got all the entries from the database, set them as room states - for (final dbMember in membersRes) { - final room = roomList.firstWhere((r) => r.id == dbMember.roomId); - final event = getEventFromDb(dbMember, room); - room.setState(event); - } - } - } - return roomList; - } - - @override - Future> getAccountData(int clientId) async { - final newAccountData = {}; - final rawAccountData = await getAllAccountData(clientId).get(); - for (final d in rawAccountData) { - var content = sdk.Event.getMapFromPayload(d.content); - // there was a bug where it stored the entire event, not just the content - // in the databse. This is the temporary fix for those affected by the bug - if (content['content'] is Map && content['type'] is String) { - content = content['content']; - // and save - await storeAccountData(clientId, d.type, jsonEncode(content)); - } - newAccountData[d.type] = api.BasicEvent( - content: content, - type: d.type, - ); - } - return newAccountData; - } - - /// Stores a RoomUpdate object in the database. Must be called inside of - /// [transaction]. - final Set _ensuredRooms = {}; - @override - Future storeRoomUpdate(int clientId, sdk.RoomUpdate roomUpdate, - [sdk.Room oldRoom]) async { - final setKey = '$clientId;${roomUpdate.id}'; - if (roomUpdate.membership != api.Membership.leave) { - if (!_ensuredRooms.contains(setKey)) { - await ensureRoomExists(clientId, roomUpdate.id, - roomUpdate.membership.toString().split('.').last); - _ensuredRooms.add(setKey); - } - } else { - _ensuredRooms.remove(setKey); - await removeRoom(clientId, roomUpdate.id); - return; - } - - var doUpdate = oldRoom == null; - if (!doUpdate) { - doUpdate = roomUpdate.highlight_count != oldRoom.highlightCount || - roomUpdate.notification_count != oldRoom.notificationCount || - roomUpdate.membership.toString().split('.').last != - oldRoom.membership.toString().split('.').last || - (roomUpdate.summary?.mJoinedMemberCount != null && - roomUpdate.summary.mJoinedMemberCount != - oldRoom.summary.mInvitedMemberCount) || - (roomUpdate.summary?.mInvitedMemberCount != null && - roomUpdate.summary.mJoinedMemberCount != - oldRoom.summary.mJoinedMemberCount) || - (roomUpdate.summary?.mHeroes != null && - roomUpdate.summary.mHeroes.join(',') != - oldRoom.summary.mHeroes.join(',')); - } - - if (doUpdate) { - await (update(rooms) - ..where((r) => - r.roomId.equals(roomUpdate.id) & r.clientId.equals(clientId))) - .write(RoomsCompanion( - highlightCount: Value(roomUpdate.highlight_count), - notificationCount: Value(roomUpdate.notification_count), - membership: Value(roomUpdate.membership.toString().split('.').last), - joinedMemberCount: roomUpdate.summary?.mJoinedMemberCount != null - ? Value(roomUpdate.summary.mJoinedMemberCount) - : Value.absent(), - invitedMemberCount: roomUpdate.summary?.mInvitedMemberCount != null - ? Value(roomUpdate.summary.mInvitedMemberCount) - : Value.absent(), - heroes: roomUpdate.summary?.mHeroes != null - ? Value(roomUpdate.summary.mHeroes.join(',')) - : Value.absent(), - )); - } - - // Is the timeline limited? Then all previous messages should be - // removed from the database! - if (roomUpdate.limitedTimeline) { - await removeSuccessfulRoomEvents(clientId, roomUpdate.id); - await updateRoomSortOrder(0.0, 0.0, clientId, roomUpdate.id); - } - if (roomUpdate.prev_batch != null) { - await setRoomPrevBatch(roomUpdate.prev_batch, clientId, roomUpdate.id); - } - } - - /// Stores an EventUpdate object in the database. Must be called inside of - /// [transaction]. - @override - Future storeEventUpdate( - int clientId, sdk.EventUpdate eventUpdate) async { - if (eventUpdate.type == sdk.EventUpdateType.ephemeral) return; - final eventContent = eventUpdate.content; - final type = eventUpdate.type; - final chatId = eventUpdate.roomID; - - // Get the state_key for state events - String stateKey; - if (eventContent['state_key'] is String) { - stateKey = eventContent['state_key']; - } - - if (eventUpdate.content['type'] == api.EventTypes.Redaction) { - await redactMessage(clientId, eventUpdate); - } - - if (type == sdk.EventUpdateType.timeline || - type == sdk.EventUpdateType.history) { - // calculate the status - var status = 2; - if (eventContent['unsigned'] is Map && - eventContent['unsigned'][messageSendingStatusKey] is num) { - status = eventContent['unsigned'][messageSendingStatusKey]; - } - if (eventContent['status'] is num) status = eventContent['status']; - var storeNewEvent = !((status == 1 || status == -1) && - eventContent['unsigned'] is Map && - eventContent['unsigned']['transaction_id'] is String); - if (!storeNewEvent) { - final allOldEvents = - await getEvent(clientId, eventContent['event_id'], chatId).get(); - if (allOldEvents.isNotEmpty) { - // we were likely unable to change transaction_id -> event_id.....because the event ID already exists! - // So, we try to fetch the old event - // the transaction id event will automatically be deleted further down - final oldEvent = allOldEvents.first; - // do we update the status? We should allow 0 -> -1 updates and status increases - if (status > oldEvent.status || - (oldEvent.status == 0 && status == -1)) { - // update the status - await updateEventStatusOnly( - status, clientId, eventContent['event_id'], chatId); - } - } else { - // status changed and we have an old transaction id --> update event id and stuffs - try { - final updated = await updateEventStatus( - status, - eventContent['event_id'], - clientId, - eventContent['unsigned']['transaction_id'], - chatId); - if (updated == 0) { - storeNewEvent = true; - } - } catch (err) { - // we could not update the transaction id to the event id....so it already exists - // as we just tried to fetch the event previously this is a race condition if the event comes down sync in the mean time - // that means that the status we already have in the database is likely more accurate - // than our status. So, we just ignore this error - } - } - } - if (storeNewEvent) { - DbEvent oldEvent; - if (type == sdk.EventUpdateType.history) { - final allOldEvents = - await getEvent(clientId, eventContent['event_id'], chatId).get(); - if (allOldEvents.isNotEmpty) { - oldEvent = allOldEvents.first; - } - } - await storeEvent( - clientId, - eventContent['event_id'], - chatId, - oldEvent?.sortOrder ?? eventUpdate.sortOrder, - eventContent['origin_server_ts'] ?? - DateTime.now().millisecondsSinceEpoch, - eventContent['sender'], - eventContent['type'], - json.encode(eventContent['unsigned'] ?? ''), - json.encode(eventContent['content']), - json.encode(eventContent['prevContent']), - eventContent['state_key'], - status, - ); - } - - // is there a transaction id? Then delete the event with this id. - if (status != -1 && - status != 0 && - eventUpdate.content['unsigned'] is Map && - eventUpdate.content['unsigned']['transaction_id'] is String) { - await removeEvent(clientId, - eventUpdate.content['unsigned']['transaction_id'], chatId); - } - } - - if (type == sdk.EventUpdateType.history) return; - - if (type != sdk.EventUpdateType.accountData && - ((stateKey is String) || - [ - api.EventTypes.Message, - api.EventTypes.Sticker, - api.EventTypes.Encrypted - ].contains(eventUpdate.content['type']))) { - final now = DateTime.now(); - await storeRoomState( - clientId, - eventContent['event_id'] ?? now.millisecondsSinceEpoch.toString(), - chatId, - eventUpdate.sortOrder ?? 0.0, - eventContent['origin_server_ts'] ?? now.millisecondsSinceEpoch, - eventContent['sender'], - eventContent['type'], - json.encode(eventContent['unsigned'] ?? ''), - json.encode(eventContent['content']), - json.encode(eventContent['prev_content'] ?? ''), - stateKey ?? '', - ); - } else if (type == sdk.EventUpdateType.accountData) { - await storeRoomAccountData( - clientId, - eventContent['type'], - chatId, - json.encode(eventContent['content']), - ); - } - } - - @override - Future getEventById( - int clientId, String eventId, sdk.Room room) async { - final event = await getEvent(clientId, eventId, room.id).get(); - if (event.isEmpty) { - return null; - } - return getEventFromDb(event.single, room); - } - - Future redactMessage(int clientId, sdk.EventUpdate eventUpdate) async { - final events = await getEvent( - clientId, eventUpdate.content['redacts'], eventUpdate.roomID) - .get(); - var success = false; - for (final dbEvent in events) { - final event = getEventFromDb(dbEvent, null); - event.setRedactionEvent(sdk.Event.fromJson(eventUpdate.content, null)); - final changes1 = await updateEvent( - json.encode(event.unsigned ?? ''), - json.encode(event.content ?? ''), - json.encode(event.prevContent ?? ''), - clientId, - event.eventId, - eventUpdate.roomID, - ); - final changes2 = await updateEvent( - json.encode(event.unsigned ?? ''), - json.encode(event.content ?? ''), - json.encode(event.prevContent ?? ''), - clientId, - event.eventId, - eventUpdate.roomID, - ); - if (changes1 == 1 && changes2 == 1) success = true; - } - return success; - } - - @override - Future forgetRoom(int clientId, String roomId) async { - final setKey = '$clientId;$roomId'; - _ensuredRooms.remove(setKey); - await (delete(rooms) - ..where((r) => r.roomId.equals(roomId) & r.clientId.equals(clientId))) - .go(); - await (delete(events) - ..where((r) => r.roomId.equals(roomId) & r.clientId.equals(clientId))) - .go(); - await (delete(roomStates) - ..where((r) => r.roomId.equals(roomId) & r.clientId.equals(clientId))) - .go(); - await (delete(roomAccountData) - ..where((r) => r.roomId.equals(roomId) & r.clientId.equals(clientId))) - .go(); - } - - @override - Future clearCache(int clientId) async { - await (delete(presences)..where((r) => r.clientId.equals(clientId))).go(); - await (delete(roomAccountData)..where((r) => r.clientId.equals(clientId))) - .go(); - await (delete(accountData)..where((r) => r.clientId.equals(clientId))).go(); - await (delete(roomStates)..where((r) => r.clientId.equals(clientId))).go(); - await (delete(events)..where((r) => r.clientId.equals(clientId))).go(); - await (delete(rooms)..where((r) => r.clientId.equals(clientId))).go(); - await (delete(outboundGroupSessions) - ..where((r) => r.clientId.equals(clientId))) - .go(); - _ensuredRooms.clear(); - await storePrevBatch(null, clientId); - } - - @override - Future clear(int clientId) async { - await clearCache(clientId); - await (delete(inboundGroupSessions) - ..where((r) => r.clientId.equals(clientId))) - .go(); - await (delete(ssssCache)..where((r) => r.clientId.equals(clientId))).go(); - await (delete(olmSessions)..where((r) => r.clientId.equals(clientId))).go(); - await (delete(userCrossSigningKeys) - ..where((r) => r.clientId.equals(clientId))) - .go(); - await (delete(userDeviceKeysKey)..where((r) => r.clientId.equals(clientId))) - .go(); - await (delete(userDeviceKeys)..where((r) => r.clientId.equals(clientId))) - .go(); - await (delete(ssssCache)..where((r) => r.clientId.equals(clientId))).go(); - await (delete(clients)..where((r) => r.clientId.equals(clientId))).go(); - await (delete(toDeviceQueue)..where((r) => r.clientId.equals(clientId))) - .go(); - } - - @override - Future getUser(int clientId, String userId, sdk.Room room) async { - final res = await dbGetUser(clientId, userId, room.id).get(); - if (res.isEmpty) { - return null; - } - return getEventFromDb(res.single, room).asUser; - } - - @override - Future> getUsers(int clientId, sdk.Room room) async { - final res = await dbGetUsers(clientId, room.id).get(); - return res.map((r) => getEventFromDb(r, room).asUser).toList(); - } - - @override - Future> getEventList(int clientId, sdk.Room room) async { - final res = await dbGetEventList(clientId, room.id).get(); - return res.map((r) => getEventFromDb(r, room)).toList(); - } - - @override - Future getFile(String mxcUri) async { - final res = await dbGetFile(mxcUri).get(); - if (res.isEmpty) return null; - return res.single.bytes; - } - - @override - Future> getUnimportantRoomEventStatesForRoom( - int client_id, - List events, - Room room, - ) async { - final entries = await getUnimportantRoomStatesForRoom( - client_id, - room.id, - events, - ).get(); - return entries.map((dbEvent) => getEventFromDb(dbEvent, room)).toList(); - } - - @override - Future> getOlmSessions( - int client_id, - String identity_key, - String userId, - ) async { - final rows = await dbGetOlmSessions(client_id, identity_key).get(); - return rows - .map((row) => OlmSession.fromJson(row.toJson(), userId)) - .toList(); - } - - @override - Future> getOlmSessionsForDevices( - int client_id, - List identity_keys, - String userId, - ) async { - final rows = - await dbGetOlmSessionsForDevices(client_id, identity_keys).get(); - return rows - .map((row) => OlmSession.fromJson(row.toJson(), userId)) - .toList(); - } - - @override - Future> getToDeviceEventQueue(int client_id) async { - final rows = await getToDeviceQueue(client_id).get(); - return rows - .map((row) => QueuedToDeviceEvent( - id: row.id, - type: row.type, - txnId: row.txnId, - content: - (json.decode(row.content) as Map).copy(), - )) - .toList(); - } - - @override - Future> getLastSentMessageUserDeviceKey( - int client_id, - String user_id, - String device_id, - ) => - dbGetLastSentMessageUserDeviceKey(client_id, user_id, device_id).get(); - - @override - Future> - getInboundGroupSessionsToUpload() async { - final rows = await dbGetInboundGroupSessionsToUpload().get(); - return rows - .map((row) => StoredInboundGroupSession.fromJson(row.toJson())) - .toList(); - } -} - -/// Get an event from either DbRoomState or DbEvent -sdk.Event getEventFromDb(dynamic dbEntry, sdk.Room room) { - if (!(dbEntry is DbRoomState || dbEntry is DbEvent)) { - throw ('Unknown db type'); - } - final content = sdk.Event.getMapFromPayload(dbEntry.content); - final unsigned = sdk.Event.getMapFromPayload(dbEntry.unsigned); - final prevContent = sdk.Event.getMapFromPayload(dbEntry.prevContent); - return sdk.Event( - status: - (dbEntry is DbEvent ? dbEntry.status : null) ?? sdk.Event.defaultStatus, - stateKey: dbEntry.stateKey, - prevContent: prevContent, - content: content, - type: dbEntry.type, - eventId: dbEntry.eventId, - roomId: dbEntry.roomId, - senderId: dbEntry.sender, - originServerTs: dbEntry.originServerTs != null - ? DateTime.fromMillisecondsSinceEpoch(dbEntry.originServerTs) - : DateTime.now(), - unsigned: unsigned, - room: room, - sortOrder: dbEntry.sortOrder ?? 0.0, - ); -} - -/// Returns a Room from a json String which comes normally from the store. If the -/// state are also given, the method will await them. -Future getRoomFromTableRow( - // either Map or DbRoom - DbRoom row, - Client matrix, { - dynamic states, // DbRoomState, as iterator and optionally as future - dynamic - roomAccountData, // DbRoomAccountData, as iterator and optionally as future -}) async { - final newRoom = Room( - id: row.roomId, - membership: sdk.Membership.values - .firstWhere((e) => e.toString() == 'Membership.' + row.membership), - notificationCount: row.notificationCount, - highlightCount: row.highlightCount, - // TODO: do proper things - notificationSettings: 'mention', - prev_batch: row.prevBatch, - summary: sdk.RoomSummary.fromJson({ - 'm.heroes': row.heroes?.split(',') ?? [], - 'm.joined_member_count': row.joinedMemberCount, - 'm.invited_member_count': row.invitedMemberCount, - }), - client: matrix, - roomAccountData: {}, - newestSortOrder: row.newestSortOrder, - oldestSortOrder: row.oldestSortOrder, - ); - - if (states != null) { - for (final rawState in await states) { - final newState = getEventFromDb(rawState, newRoom); - newRoom.setState(newState); - } - } - - final newRoomAccountData = {}; - if (roomAccountData != null) { - for (final singleAccountData in await roomAccountData) { - final content = sdk.Event.getMapFromPayload(singleAccountData.content); - final newData = sdk.BasicRoomEvent( - content: content, - type: singleAccountData.type, - roomId: singleAccountData.roomId, - ); - newRoomAccountData[newData.type] = newData; - } - } - newRoom.roomAccountData = newRoomAccountData; - - return newRoom; -} diff --git a/lib/src/database/database.g.dart b/lib/src/database/database.g.dart deleted file mode 100644 index 14188033..00000000 --- a/lib/src/database/database.g.dart +++ /dev/null @@ -1,7554 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'database.dart'; - -// ************************************************************************** -// MoorGenerator -// ************************************************************************** - -// ignore_for_file: unnecessary_brace_in_string_interps, unnecessary_this -class DbClient extends DataClass implements Insertable { - final int clientId; - final String name; - final String homeserverUrl; - final String token; - final String userId; - final String deviceId; - final String deviceName; - final String prevBatch; - final String syncFilterId; - final String olmAccount; - DbClient( - {@required this.clientId, - @required this.name, - @required this.homeserverUrl, - @required this.token, - @required this.userId, - this.deviceId, - this.deviceName, - this.prevBatch, - this.syncFilterId, - this.olmAccount}); - factory DbClient.fromData(Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbClient( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - name: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}name']), - homeserverUrl: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}homeserver_url']), - token: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}token']), - userId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}user_id']), - deviceId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}device_id']), - deviceName: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}device_name']), - prevBatch: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}prev_batch']), - syncFilterId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}sync_filter_id']), - olmAccount: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}olm_account']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || name != null) { - map['name'] = Variable(name); - } - if (!nullToAbsent || homeserverUrl != null) { - map['homeserver_url'] = Variable(homeserverUrl); - } - if (!nullToAbsent || token != null) { - map['token'] = Variable(token); - } - if (!nullToAbsent || userId != null) { - map['user_id'] = Variable(userId); - } - if (!nullToAbsent || deviceId != null) { - map['device_id'] = Variable(deviceId); - } - if (!nullToAbsent || deviceName != null) { - map['device_name'] = Variable(deviceName); - } - if (!nullToAbsent || prevBatch != null) { - map['prev_batch'] = Variable(prevBatch); - } - if (!nullToAbsent || syncFilterId != null) { - map['sync_filter_id'] = Variable(syncFilterId); - } - if (!nullToAbsent || olmAccount != null) { - map['olm_account'] = Variable(olmAccount); - } - return map; - } - - ClientsCompanion toCompanion(bool nullToAbsent) { - return ClientsCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - name: name == null && nullToAbsent ? const Value.absent() : Value(name), - homeserverUrl: homeserverUrl == null && nullToAbsent - ? const Value.absent() - : Value(homeserverUrl), - token: - token == null && nullToAbsent ? const Value.absent() : Value(token), - userId: - userId == null && nullToAbsent ? const Value.absent() : Value(userId), - deviceId: deviceId == null && nullToAbsent - ? const Value.absent() - : Value(deviceId), - deviceName: deviceName == null && nullToAbsent - ? const Value.absent() - : Value(deviceName), - prevBatch: prevBatch == null && nullToAbsent - ? const Value.absent() - : Value(prevBatch), - syncFilterId: syncFilterId == null && nullToAbsent - ? const Value.absent() - : Value(syncFilterId), - olmAccount: olmAccount == null && nullToAbsent - ? const Value.absent() - : Value(olmAccount), - ); - } - - factory DbClient.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbClient( - clientId: serializer.fromJson(json['client_id']), - name: serializer.fromJson(json['name']), - homeserverUrl: serializer.fromJson(json['homeserver_url']), - token: serializer.fromJson(json['token']), - userId: serializer.fromJson(json['user_id']), - deviceId: serializer.fromJson(json['device_id']), - deviceName: serializer.fromJson(json['device_name']), - prevBatch: serializer.fromJson(json['prev_batch']), - syncFilterId: serializer.fromJson(json['sync_filter_id']), - olmAccount: serializer.fromJson(json['olm_account']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'name': serializer.toJson(name), - 'homeserver_url': serializer.toJson(homeserverUrl), - 'token': serializer.toJson(token), - 'user_id': serializer.toJson(userId), - 'device_id': serializer.toJson(deviceId), - 'device_name': serializer.toJson(deviceName), - 'prev_batch': serializer.toJson(prevBatch), - 'sync_filter_id': serializer.toJson(syncFilterId), - 'olm_account': serializer.toJson(olmAccount), - }; - } - - DbClient copyWith( - {int clientId, - String name, - String homeserverUrl, - String token, - String userId, - String deviceId, - String deviceName, - String prevBatch, - String syncFilterId, - String olmAccount}) => - DbClient( - clientId: clientId ?? this.clientId, - name: name ?? this.name, - homeserverUrl: homeserverUrl ?? this.homeserverUrl, - token: token ?? this.token, - userId: userId ?? this.userId, - deviceId: deviceId ?? this.deviceId, - deviceName: deviceName ?? this.deviceName, - prevBatch: prevBatch ?? this.prevBatch, - syncFilterId: syncFilterId ?? this.syncFilterId, - olmAccount: olmAccount ?? this.olmAccount, - ); - @override - String toString() { - return (StringBuffer('DbClient(') - ..write('clientId: $clientId, ') - ..write('name: $name, ') - ..write('homeserverUrl: $homeserverUrl, ') - ..write('token: $token, ') - ..write('userId: $userId, ') - ..write('deviceId: $deviceId, ') - ..write('deviceName: $deviceName, ') - ..write('prevBatch: $prevBatch, ') - ..write('syncFilterId: $syncFilterId, ') - ..write('olmAccount: $olmAccount') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - name.hashCode, - $mrjc( - homeserverUrl.hashCode, - $mrjc( - token.hashCode, - $mrjc( - userId.hashCode, - $mrjc( - deviceId.hashCode, - $mrjc( - deviceName.hashCode, - $mrjc( - prevBatch.hashCode, - $mrjc(syncFilterId.hashCode, - olmAccount.hashCode)))))))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbClient && - other.clientId == this.clientId && - other.name == this.name && - other.homeserverUrl == this.homeserverUrl && - other.token == this.token && - other.userId == this.userId && - other.deviceId == this.deviceId && - other.deviceName == this.deviceName && - other.prevBatch == this.prevBatch && - other.syncFilterId == this.syncFilterId && - other.olmAccount == this.olmAccount); -} - -class ClientsCompanion extends UpdateCompanion { - final Value clientId; - final Value name; - final Value homeserverUrl; - final Value token; - final Value userId; - final Value deviceId; - final Value deviceName; - final Value prevBatch; - final Value syncFilterId; - final Value olmAccount; - const ClientsCompanion({ - this.clientId = const Value.absent(), - this.name = const Value.absent(), - this.homeserverUrl = const Value.absent(), - this.token = const Value.absent(), - this.userId = const Value.absent(), - this.deviceId = const Value.absent(), - this.deviceName = const Value.absent(), - this.prevBatch = const Value.absent(), - this.syncFilterId = const Value.absent(), - this.olmAccount = const Value.absent(), - }); - ClientsCompanion.insert({ - this.clientId = const Value.absent(), - @required String name, - @required String homeserverUrl, - @required String token, - @required String userId, - this.deviceId = const Value.absent(), - this.deviceName = const Value.absent(), - this.prevBatch = const Value.absent(), - this.syncFilterId = const Value.absent(), - this.olmAccount = const Value.absent(), - }) : name = Value(name), - homeserverUrl = Value(homeserverUrl), - token = Value(token), - userId = Value(userId); - static Insertable custom({ - Expression clientId, - Expression name, - Expression homeserverUrl, - Expression token, - Expression userId, - Expression deviceId, - Expression deviceName, - Expression prevBatch, - Expression syncFilterId, - Expression olmAccount, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (name != null) 'name': name, - if (homeserverUrl != null) 'homeserver_url': homeserverUrl, - if (token != null) 'token': token, - if (userId != null) 'user_id': userId, - if (deviceId != null) 'device_id': deviceId, - if (deviceName != null) 'device_name': deviceName, - if (prevBatch != null) 'prev_batch': prevBatch, - if (syncFilterId != null) 'sync_filter_id': syncFilterId, - if (olmAccount != null) 'olm_account': olmAccount, - }); - } - - ClientsCompanion copyWith( - {Value clientId, - Value name, - Value homeserverUrl, - Value token, - Value userId, - Value deviceId, - Value deviceName, - Value prevBatch, - Value syncFilterId, - Value olmAccount}) { - return ClientsCompanion( - clientId: clientId ?? this.clientId, - name: name ?? this.name, - homeserverUrl: homeserverUrl ?? this.homeserverUrl, - token: token ?? this.token, - userId: userId ?? this.userId, - deviceId: deviceId ?? this.deviceId, - deviceName: deviceName ?? this.deviceName, - prevBatch: prevBatch ?? this.prevBatch, - syncFilterId: syncFilterId ?? this.syncFilterId, - olmAccount: olmAccount ?? this.olmAccount, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (name.present) { - map['name'] = Variable(name.value); - } - if (homeserverUrl.present) { - map['homeserver_url'] = Variable(homeserverUrl.value); - } - if (token.present) { - map['token'] = Variable(token.value); - } - if (userId.present) { - map['user_id'] = Variable(userId.value); - } - if (deviceId.present) { - map['device_id'] = Variable(deviceId.value); - } - if (deviceName.present) { - map['device_name'] = Variable(deviceName.value); - } - if (prevBatch.present) { - map['prev_batch'] = Variable(prevBatch.value); - } - if (syncFilterId.present) { - map['sync_filter_id'] = Variable(syncFilterId.value); - } - if (olmAccount.present) { - map['olm_account'] = Variable(olmAccount.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('ClientsCompanion(') - ..write('clientId: $clientId, ') - ..write('name: $name, ') - ..write('homeserverUrl: $homeserverUrl, ') - ..write('token: $token, ') - ..write('userId: $userId, ') - ..write('deviceId: $deviceId, ') - ..write('deviceName: $deviceName, ') - ..write('prevBatch: $prevBatch, ') - ..write('syncFilterId: $syncFilterId, ') - ..write('olmAccount: $olmAccount') - ..write(')')) - .toString(); - } -} - -class Clients extends Table with TableInfo { - final GeneratedDatabase _db; - final String _alias; - Clients(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - declaredAsPrimaryKey: true, - hasAutoIncrement: true, - $customConstraints: 'NOT NULL PRIMARY KEY AUTOINCREMENT'); - } - - final VerificationMeta _nameMeta = const VerificationMeta('name'); - GeneratedTextColumn _name; - GeneratedTextColumn get name => _name ??= _constructName(); - GeneratedTextColumn _constructName() { - return GeneratedTextColumn('name', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _homeserverUrlMeta = - const VerificationMeta('homeserverUrl'); - GeneratedTextColumn _homeserverUrl; - GeneratedTextColumn get homeserverUrl => - _homeserverUrl ??= _constructHomeserverUrl(); - GeneratedTextColumn _constructHomeserverUrl() { - return GeneratedTextColumn('homeserver_url', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _tokenMeta = const VerificationMeta('token'); - GeneratedTextColumn _token; - GeneratedTextColumn get token => _token ??= _constructToken(); - GeneratedTextColumn _constructToken() { - return GeneratedTextColumn('token', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _userIdMeta = const VerificationMeta('userId'); - GeneratedTextColumn _userId; - GeneratedTextColumn get userId => _userId ??= _constructUserId(); - GeneratedTextColumn _constructUserId() { - return GeneratedTextColumn('user_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _deviceIdMeta = const VerificationMeta('deviceId'); - GeneratedTextColumn _deviceId; - GeneratedTextColumn get deviceId => _deviceId ??= _constructDeviceId(); - GeneratedTextColumn _constructDeviceId() { - return GeneratedTextColumn('device_id', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _deviceNameMeta = const VerificationMeta('deviceName'); - GeneratedTextColumn _deviceName; - GeneratedTextColumn get deviceName => _deviceName ??= _constructDeviceName(); - GeneratedTextColumn _constructDeviceName() { - return GeneratedTextColumn('device_name', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _prevBatchMeta = const VerificationMeta('prevBatch'); - GeneratedTextColumn _prevBatch; - GeneratedTextColumn get prevBatch => _prevBatch ??= _constructPrevBatch(); - GeneratedTextColumn _constructPrevBatch() { - return GeneratedTextColumn('prev_batch', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _syncFilterIdMeta = - const VerificationMeta('syncFilterId'); - GeneratedTextColumn _syncFilterId; - GeneratedTextColumn get syncFilterId => - _syncFilterId ??= _constructSyncFilterId(); - GeneratedTextColumn _constructSyncFilterId() { - return GeneratedTextColumn('sync_filter_id', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _olmAccountMeta = const VerificationMeta('olmAccount'); - GeneratedTextColumn _olmAccount; - GeneratedTextColumn get olmAccount => _olmAccount ??= _constructOlmAccount(); - GeneratedTextColumn _constructOlmAccount() { - return GeneratedTextColumn('olm_account', $tableName, true, - $customConstraints: ''); - } - - @override - List get $columns => [ - clientId, - name, - homeserverUrl, - token, - userId, - deviceId, - deviceName, - prevBatch, - syncFilterId, - olmAccount - ]; - @override - Clients get asDslTable => this; - @override - String get $tableName => _alias ?? 'clients'; - @override - final String actualTableName = 'clients'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } - if (data.containsKey('name')) { - context.handle( - _nameMeta, name.isAcceptableOrUnknown(data['name'], _nameMeta)); - } else if (isInserting) { - context.missing(_nameMeta); - } - if (data.containsKey('homeserver_url')) { - context.handle( - _homeserverUrlMeta, - homeserverUrl.isAcceptableOrUnknown( - data['homeserver_url'], _homeserverUrlMeta)); - } else if (isInserting) { - context.missing(_homeserverUrlMeta); - } - if (data.containsKey('token')) { - context.handle( - _tokenMeta, token.isAcceptableOrUnknown(data['token'], _tokenMeta)); - } else if (isInserting) { - context.missing(_tokenMeta); - } - if (data.containsKey('user_id')) { - context.handle(_userIdMeta, - userId.isAcceptableOrUnknown(data['user_id'], _userIdMeta)); - } else if (isInserting) { - context.missing(_userIdMeta); - } - if (data.containsKey('device_id')) { - context.handle(_deviceIdMeta, - deviceId.isAcceptableOrUnknown(data['device_id'], _deviceIdMeta)); - } - if (data.containsKey('device_name')) { - context.handle( - _deviceNameMeta, - deviceName.isAcceptableOrUnknown( - data['device_name'], _deviceNameMeta)); - } - if (data.containsKey('prev_batch')) { - context.handle(_prevBatchMeta, - prevBatch.isAcceptableOrUnknown(data['prev_batch'], _prevBatchMeta)); - } - if (data.containsKey('sync_filter_id')) { - context.handle( - _syncFilterIdMeta, - syncFilterId.isAcceptableOrUnknown( - data['sync_filter_id'], _syncFilterIdMeta)); - } - if (data.containsKey('olm_account')) { - context.handle( - _olmAccountMeta, - olmAccount.isAcceptableOrUnknown( - data['olm_account'], _olmAccountMeta)); - } - return context; - } - - @override - Set get $primaryKey => {clientId}; - @override - DbClient map(Map data, {String tablePrefix}) { - return DbClient.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - Clients createAlias(String alias) { - return Clients(_db, alias); - } - - @override - List get customConstraints => const ['UNIQUE(name)']; - @override - bool get dontWriteConstraints => true; -} - -class DbUserDeviceKey extends DataClass implements Insertable { - final int clientId; - final String userId; - final bool outdated; - DbUserDeviceKey( - {@required this.clientId, @required this.userId, this.outdated}); - factory DbUserDeviceKey.fromData( - Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbUserDeviceKey( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - userId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}user_id']), - outdated: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}outdated']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || userId != null) { - map['user_id'] = Variable(userId); - } - if (!nullToAbsent || outdated != null) { - map['outdated'] = Variable(outdated); - } - return map; - } - - UserDeviceKeysCompanion toCompanion(bool nullToAbsent) { - return UserDeviceKeysCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - userId: - userId == null && nullToAbsent ? const Value.absent() : Value(userId), - outdated: outdated == null && nullToAbsent - ? const Value.absent() - : Value(outdated), - ); - } - - factory DbUserDeviceKey.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbUserDeviceKey( - clientId: serializer.fromJson(json['client_id']), - userId: serializer.fromJson(json['user_id']), - outdated: serializer.fromJson(json['outdated']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'user_id': serializer.toJson(userId), - 'outdated': serializer.toJson(outdated), - }; - } - - DbUserDeviceKey copyWith({int clientId, String userId, bool outdated}) => - DbUserDeviceKey( - clientId: clientId ?? this.clientId, - userId: userId ?? this.userId, - outdated: outdated ?? this.outdated, - ); - @override - String toString() { - return (StringBuffer('DbUserDeviceKey(') - ..write('clientId: $clientId, ') - ..write('userId: $userId, ') - ..write('outdated: $outdated') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf( - $mrjc(clientId.hashCode, $mrjc(userId.hashCode, outdated.hashCode))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbUserDeviceKey && - other.clientId == this.clientId && - other.userId == this.userId && - other.outdated == this.outdated); -} - -class UserDeviceKeysCompanion extends UpdateCompanion { - final Value clientId; - final Value userId; - final Value outdated; - const UserDeviceKeysCompanion({ - this.clientId = const Value.absent(), - this.userId = const Value.absent(), - this.outdated = const Value.absent(), - }); - UserDeviceKeysCompanion.insert({ - @required int clientId, - @required String userId, - this.outdated = const Value.absent(), - }) : clientId = Value(clientId), - userId = Value(userId); - static Insertable custom({ - Expression clientId, - Expression userId, - Expression outdated, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (userId != null) 'user_id': userId, - if (outdated != null) 'outdated': outdated, - }); - } - - UserDeviceKeysCompanion copyWith( - {Value clientId, Value userId, Value outdated}) { - return UserDeviceKeysCompanion( - clientId: clientId ?? this.clientId, - userId: userId ?? this.userId, - outdated: outdated ?? this.outdated, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (userId.present) { - map['user_id'] = Variable(userId.value); - } - if (outdated.present) { - map['outdated'] = Variable(outdated.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('UserDeviceKeysCompanion(') - ..write('clientId: $clientId, ') - ..write('userId: $userId, ') - ..write('outdated: $outdated') - ..write(')')) - .toString(); - } -} - -class UserDeviceKeys extends Table - with TableInfo { - final GeneratedDatabase _db; - final String _alias; - UserDeviceKeys(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _userIdMeta = const VerificationMeta('userId'); - GeneratedTextColumn _userId; - GeneratedTextColumn get userId => _userId ??= _constructUserId(); - GeneratedTextColumn _constructUserId() { - return GeneratedTextColumn('user_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _outdatedMeta = const VerificationMeta('outdated'); - GeneratedBoolColumn _outdated; - GeneratedBoolColumn get outdated => _outdated ??= _constructOutdated(); - GeneratedBoolColumn _constructOutdated() { - return GeneratedBoolColumn('outdated', $tableName, true, - $customConstraints: 'DEFAULT true', - defaultValue: const CustomExpression('true')); - } - - @override - List get $columns => [clientId, userId, outdated]; - @override - UserDeviceKeys get asDslTable => this; - @override - String get $tableName => _alias ?? 'user_device_keys'; - @override - final String actualTableName = 'user_device_keys'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('user_id')) { - context.handle(_userIdMeta, - userId.isAcceptableOrUnknown(data['user_id'], _userIdMeta)); - } else if (isInserting) { - context.missing(_userIdMeta); - } - if (data.containsKey('outdated')) { - context.handle(_outdatedMeta, - outdated.isAcceptableOrUnknown(data['outdated'], _outdatedMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbUserDeviceKey map(Map data, {String tablePrefix}) { - return DbUserDeviceKey.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - UserDeviceKeys createAlias(String alias) { - return UserDeviceKeys(_db, alias); - } - - @override - List get customConstraints => const ['UNIQUE(client_id, user_id)']; - @override - bool get dontWriteConstraints => true; -} - -class DbUserDeviceKeysKey extends DataClass - implements Insertable { - final int clientId; - final String userId; - final String deviceId; - final String content; - final bool verified; - final bool blocked; - final int lastActive; - final String lastSentMessage; - DbUserDeviceKeysKey( - {@required this.clientId, - @required this.userId, - @required this.deviceId, - @required this.content, - this.verified, - this.blocked, - this.lastActive, - this.lastSentMessage}); - factory DbUserDeviceKeysKey.fromData( - Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbUserDeviceKeysKey( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - userId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}user_id']), - deviceId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}device_id']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - verified: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}verified']), - blocked: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}blocked']), - lastActive: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}last_active']), - lastSentMessage: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}last_sent_message']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || userId != null) { - map['user_id'] = Variable(userId); - } - if (!nullToAbsent || deviceId != null) { - map['device_id'] = Variable(deviceId); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - if (!nullToAbsent || verified != null) { - map['verified'] = Variable(verified); - } - if (!nullToAbsent || blocked != null) { - map['blocked'] = Variable(blocked); - } - if (!nullToAbsent || lastActive != null) { - map['last_active'] = Variable(lastActive); - } - if (!nullToAbsent || lastSentMessage != null) { - map['last_sent_message'] = Variable(lastSentMessage); - } - return map; - } - - UserDeviceKeysKeyCompanion toCompanion(bool nullToAbsent) { - return UserDeviceKeysKeyCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - userId: - userId == null && nullToAbsent ? const Value.absent() : Value(userId), - deviceId: deviceId == null && nullToAbsent - ? const Value.absent() - : Value(deviceId), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - verified: verified == null && nullToAbsent - ? const Value.absent() - : Value(verified), - blocked: blocked == null && nullToAbsent - ? const Value.absent() - : Value(blocked), - lastActive: lastActive == null && nullToAbsent - ? const Value.absent() - : Value(lastActive), - lastSentMessage: lastSentMessage == null && nullToAbsent - ? const Value.absent() - : Value(lastSentMessage), - ); - } - - factory DbUserDeviceKeysKey.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbUserDeviceKeysKey( - clientId: serializer.fromJson(json['client_id']), - userId: serializer.fromJson(json['user_id']), - deviceId: serializer.fromJson(json['device_id']), - content: serializer.fromJson(json['content']), - verified: serializer.fromJson(json['verified']), - blocked: serializer.fromJson(json['blocked']), - lastActive: serializer.fromJson(json['last_active']), - lastSentMessage: serializer.fromJson(json['last_sent_message']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'user_id': serializer.toJson(userId), - 'device_id': serializer.toJson(deviceId), - 'content': serializer.toJson(content), - 'verified': serializer.toJson(verified), - 'blocked': serializer.toJson(blocked), - 'last_active': serializer.toJson(lastActive), - 'last_sent_message': serializer.toJson(lastSentMessage), - }; - } - - DbUserDeviceKeysKey copyWith( - {int clientId, - String userId, - String deviceId, - String content, - bool verified, - bool blocked, - int lastActive, - String lastSentMessage}) => - DbUserDeviceKeysKey( - clientId: clientId ?? this.clientId, - userId: userId ?? this.userId, - deviceId: deviceId ?? this.deviceId, - content: content ?? this.content, - verified: verified ?? this.verified, - blocked: blocked ?? this.blocked, - lastActive: lastActive ?? this.lastActive, - lastSentMessage: lastSentMessage ?? this.lastSentMessage, - ); - @override - String toString() { - return (StringBuffer('DbUserDeviceKeysKey(') - ..write('clientId: $clientId, ') - ..write('userId: $userId, ') - ..write('deviceId: $deviceId, ') - ..write('content: $content, ') - ..write('verified: $verified, ') - ..write('blocked: $blocked, ') - ..write('lastActive: $lastActive, ') - ..write('lastSentMessage: $lastSentMessage') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - userId.hashCode, - $mrjc( - deviceId.hashCode, - $mrjc( - content.hashCode, - $mrjc( - verified.hashCode, - $mrjc( - blocked.hashCode, - $mrjc(lastActive.hashCode, - lastSentMessage.hashCode)))))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbUserDeviceKeysKey && - other.clientId == this.clientId && - other.userId == this.userId && - other.deviceId == this.deviceId && - other.content == this.content && - other.verified == this.verified && - other.blocked == this.blocked && - other.lastActive == this.lastActive && - other.lastSentMessage == this.lastSentMessage); -} - -class UserDeviceKeysKeyCompanion extends UpdateCompanion { - final Value clientId; - final Value userId; - final Value deviceId; - final Value content; - final Value verified; - final Value blocked; - final Value lastActive; - final Value lastSentMessage; - const UserDeviceKeysKeyCompanion({ - this.clientId = const Value.absent(), - this.userId = const Value.absent(), - this.deviceId = const Value.absent(), - this.content = const Value.absent(), - this.verified = const Value.absent(), - this.blocked = const Value.absent(), - this.lastActive = const Value.absent(), - this.lastSentMessage = const Value.absent(), - }); - UserDeviceKeysKeyCompanion.insert({ - @required int clientId, - @required String userId, - @required String deviceId, - @required String content, - this.verified = const Value.absent(), - this.blocked = const Value.absent(), - this.lastActive = const Value.absent(), - this.lastSentMessage = const Value.absent(), - }) : clientId = Value(clientId), - userId = Value(userId), - deviceId = Value(deviceId), - content = Value(content); - static Insertable custom({ - Expression clientId, - Expression userId, - Expression deviceId, - Expression content, - Expression verified, - Expression blocked, - Expression lastActive, - Expression lastSentMessage, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (userId != null) 'user_id': userId, - if (deviceId != null) 'device_id': deviceId, - if (content != null) 'content': content, - if (verified != null) 'verified': verified, - if (blocked != null) 'blocked': blocked, - if (lastActive != null) 'last_active': lastActive, - if (lastSentMessage != null) 'last_sent_message': lastSentMessage, - }); - } - - UserDeviceKeysKeyCompanion copyWith( - {Value clientId, - Value userId, - Value deviceId, - Value content, - Value verified, - Value blocked, - Value lastActive, - Value lastSentMessage}) { - return UserDeviceKeysKeyCompanion( - clientId: clientId ?? this.clientId, - userId: userId ?? this.userId, - deviceId: deviceId ?? this.deviceId, - content: content ?? this.content, - verified: verified ?? this.verified, - blocked: blocked ?? this.blocked, - lastActive: lastActive ?? this.lastActive, - lastSentMessage: lastSentMessage ?? this.lastSentMessage, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (userId.present) { - map['user_id'] = Variable(userId.value); - } - if (deviceId.present) { - map['device_id'] = Variable(deviceId.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - if (verified.present) { - map['verified'] = Variable(verified.value); - } - if (blocked.present) { - map['blocked'] = Variable(blocked.value); - } - if (lastActive.present) { - map['last_active'] = Variable(lastActive.value); - } - if (lastSentMessage.present) { - map['last_sent_message'] = Variable(lastSentMessage.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('UserDeviceKeysKeyCompanion(') - ..write('clientId: $clientId, ') - ..write('userId: $userId, ') - ..write('deviceId: $deviceId, ') - ..write('content: $content, ') - ..write('verified: $verified, ') - ..write('blocked: $blocked, ') - ..write('lastActive: $lastActive, ') - ..write('lastSentMessage: $lastSentMessage') - ..write(')')) - .toString(); - } -} - -class UserDeviceKeysKey extends Table - with TableInfo { - final GeneratedDatabase _db; - final String _alias; - UserDeviceKeysKey(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _userIdMeta = const VerificationMeta('userId'); - GeneratedTextColumn _userId; - GeneratedTextColumn get userId => _userId ??= _constructUserId(); - GeneratedTextColumn _constructUserId() { - return GeneratedTextColumn('user_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _deviceIdMeta = const VerificationMeta('deviceId'); - GeneratedTextColumn _deviceId; - GeneratedTextColumn get deviceId => _deviceId ??= _constructDeviceId(); - GeneratedTextColumn _constructDeviceId() { - return GeneratedTextColumn('device_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _verifiedMeta = const VerificationMeta('verified'); - GeneratedBoolColumn _verified; - GeneratedBoolColumn get verified => _verified ??= _constructVerified(); - GeneratedBoolColumn _constructVerified() { - return GeneratedBoolColumn('verified', $tableName, true, - $customConstraints: 'DEFAULT false', - defaultValue: const CustomExpression('false')); - } - - final VerificationMeta _blockedMeta = const VerificationMeta('blocked'); - GeneratedBoolColumn _blocked; - GeneratedBoolColumn get blocked => _blocked ??= _constructBlocked(); - GeneratedBoolColumn _constructBlocked() { - return GeneratedBoolColumn('blocked', $tableName, true, - $customConstraints: 'DEFAULT false', - defaultValue: const CustomExpression('false')); - } - - final VerificationMeta _lastActiveMeta = const VerificationMeta('lastActive'); - GeneratedIntColumn _lastActive; - GeneratedIntColumn get lastActive => _lastActive ??= _constructLastActive(); - GeneratedIntColumn _constructLastActive() { - return GeneratedIntColumn('last_active', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _lastSentMessageMeta = - const VerificationMeta('lastSentMessage'); - GeneratedTextColumn _lastSentMessage; - GeneratedTextColumn get lastSentMessage => - _lastSentMessage ??= _constructLastSentMessage(); - GeneratedTextColumn _constructLastSentMessage() { - return GeneratedTextColumn('last_sent_message', $tableName, true, - $customConstraints: ''); - } - - @override - List get $columns => [ - clientId, - userId, - deviceId, - content, - verified, - blocked, - lastActive, - lastSentMessage - ]; - @override - UserDeviceKeysKey get asDslTable => this; - @override - String get $tableName => _alias ?? 'user_device_keys_key'; - @override - final String actualTableName = 'user_device_keys_key'; - @override - VerificationContext validateIntegrity( - Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('user_id')) { - context.handle(_userIdMeta, - userId.isAcceptableOrUnknown(data['user_id'], _userIdMeta)); - } else if (isInserting) { - context.missing(_userIdMeta); - } - if (data.containsKey('device_id')) { - context.handle(_deviceIdMeta, - deviceId.isAcceptableOrUnknown(data['device_id'], _deviceIdMeta)); - } else if (isInserting) { - context.missing(_deviceIdMeta); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } else if (isInserting) { - context.missing(_contentMeta); - } - if (data.containsKey('verified')) { - context.handle(_verifiedMeta, - verified.isAcceptableOrUnknown(data['verified'], _verifiedMeta)); - } - if (data.containsKey('blocked')) { - context.handle(_blockedMeta, - blocked.isAcceptableOrUnknown(data['blocked'], _blockedMeta)); - } - if (data.containsKey('last_active')) { - context.handle( - _lastActiveMeta, - lastActive.isAcceptableOrUnknown( - data['last_active'], _lastActiveMeta)); - } - if (data.containsKey('last_sent_message')) { - context.handle( - _lastSentMessageMeta, - lastSentMessage.isAcceptableOrUnknown( - data['last_sent_message'], _lastSentMessageMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbUserDeviceKeysKey map(Map data, {String tablePrefix}) { - return DbUserDeviceKeysKey.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - UserDeviceKeysKey createAlias(String alias) { - return UserDeviceKeysKey(_db, alias); - } - - @override - List get customConstraints => - const ['UNIQUE(client_id, user_id, device_id)']; - @override - bool get dontWriteConstraints => true; -} - -class DbUserCrossSigningKey extends DataClass - implements Insertable { - final int clientId; - final String userId; - final String publicKey; - final String content; - final bool verified; - final bool blocked; - DbUserCrossSigningKey( - {@required this.clientId, - @required this.userId, - @required this.publicKey, - @required this.content, - this.verified, - this.blocked}); - factory DbUserCrossSigningKey.fromData( - Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbUserCrossSigningKey( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - userId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}user_id']), - publicKey: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}public_key']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - verified: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}verified']), - blocked: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}blocked']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || userId != null) { - map['user_id'] = Variable(userId); - } - if (!nullToAbsent || publicKey != null) { - map['public_key'] = Variable(publicKey); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - if (!nullToAbsent || verified != null) { - map['verified'] = Variable(verified); - } - if (!nullToAbsent || blocked != null) { - map['blocked'] = Variable(blocked); - } - return map; - } - - UserCrossSigningKeysCompanion toCompanion(bool nullToAbsent) { - return UserCrossSigningKeysCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - userId: - userId == null && nullToAbsent ? const Value.absent() : Value(userId), - publicKey: publicKey == null && nullToAbsent - ? const Value.absent() - : Value(publicKey), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - verified: verified == null && nullToAbsent - ? const Value.absent() - : Value(verified), - blocked: blocked == null && nullToAbsent - ? const Value.absent() - : Value(blocked), - ); - } - - factory DbUserCrossSigningKey.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbUserCrossSigningKey( - clientId: serializer.fromJson(json['client_id']), - userId: serializer.fromJson(json['user_id']), - publicKey: serializer.fromJson(json['public_key']), - content: serializer.fromJson(json['content']), - verified: serializer.fromJson(json['verified']), - blocked: serializer.fromJson(json['blocked']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'user_id': serializer.toJson(userId), - 'public_key': serializer.toJson(publicKey), - 'content': serializer.toJson(content), - 'verified': serializer.toJson(verified), - 'blocked': serializer.toJson(blocked), - }; - } - - DbUserCrossSigningKey copyWith( - {int clientId, - String userId, - String publicKey, - String content, - bool verified, - bool blocked}) => - DbUserCrossSigningKey( - clientId: clientId ?? this.clientId, - userId: userId ?? this.userId, - publicKey: publicKey ?? this.publicKey, - content: content ?? this.content, - verified: verified ?? this.verified, - blocked: blocked ?? this.blocked, - ); - @override - String toString() { - return (StringBuffer('DbUserCrossSigningKey(') - ..write('clientId: $clientId, ') - ..write('userId: $userId, ') - ..write('publicKey: $publicKey, ') - ..write('content: $content, ') - ..write('verified: $verified, ') - ..write('blocked: $blocked') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - userId.hashCode, - $mrjc( - publicKey.hashCode, - $mrjc(content.hashCode, - $mrjc(verified.hashCode, blocked.hashCode)))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbUserCrossSigningKey && - other.clientId == this.clientId && - other.userId == this.userId && - other.publicKey == this.publicKey && - other.content == this.content && - other.verified == this.verified && - other.blocked == this.blocked); -} - -class UserCrossSigningKeysCompanion - extends UpdateCompanion { - final Value clientId; - final Value userId; - final Value publicKey; - final Value content; - final Value verified; - final Value blocked; - const UserCrossSigningKeysCompanion({ - this.clientId = const Value.absent(), - this.userId = const Value.absent(), - this.publicKey = const Value.absent(), - this.content = const Value.absent(), - this.verified = const Value.absent(), - this.blocked = const Value.absent(), - }); - UserCrossSigningKeysCompanion.insert({ - @required int clientId, - @required String userId, - @required String publicKey, - @required String content, - this.verified = const Value.absent(), - this.blocked = const Value.absent(), - }) : clientId = Value(clientId), - userId = Value(userId), - publicKey = Value(publicKey), - content = Value(content); - static Insertable custom({ - Expression clientId, - Expression userId, - Expression publicKey, - Expression content, - Expression verified, - Expression blocked, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (userId != null) 'user_id': userId, - if (publicKey != null) 'public_key': publicKey, - if (content != null) 'content': content, - if (verified != null) 'verified': verified, - if (blocked != null) 'blocked': blocked, - }); - } - - UserCrossSigningKeysCompanion copyWith( - {Value clientId, - Value userId, - Value publicKey, - Value content, - Value verified, - Value blocked}) { - return UserCrossSigningKeysCompanion( - clientId: clientId ?? this.clientId, - userId: userId ?? this.userId, - publicKey: publicKey ?? this.publicKey, - content: content ?? this.content, - verified: verified ?? this.verified, - blocked: blocked ?? this.blocked, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (userId.present) { - map['user_id'] = Variable(userId.value); - } - if (publicKey.present) { - map['public_key'] = Variable(publicKey.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - if (verified.present) { - map['verified'] = Variable(verified.value); - } - if (blocked.present) { - map['blocked'] = Variable(blocked.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('UserCrossSigningKeysCompanion(') - ..write('clientId: $clientId, ') - ..write('userId: $userId, ') - ..write('publicKey: $publicKey, ') - ..write('content: $content, ') - ..write('verified: $verified, ') - ..write('blocked: $blocked') - ..write(')')) - .toString(); - } -} - -class UserCrossSigningKeys extends Table - with TableInfo { - final GeneratedDatabase _db; - final String _alias; - UserCrossSigningKeys(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _userIdMeta = const VerificationMeta('userId'); - GeneratedTextColumn _userId; - GeneratedTextColumn get userId => _userId ??= _constructUserId(); - GeneratedTextColumn _constructUserId() { - return GeneratedTextColumn('user_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _publicKeyMeta = const VerificationMeta('publicKey'); - GeneratedTextColumn _publicKey; - GeneratedTextColumn get publicKey => _publicKey ??= _constructPublicKey(); - GeneratedTextColumn _constructPublicKey() { - return GeneratedTextColumn('public_key', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _verifiedMeta = const VerificationMeta('verified'); - GeneratedBoolColumn _verified; - GeneratedBoolColumn get verified => _verified ??= _constructVerified(); - GeneratedBoolColumn _constructVerified() { - return GeneratedBoolColumn('verified', $tableName, true, - $customConstraints: 'DEFAULT false', - defaultValue: const CustomExpression('false')); - } - - final VerificationMeta _blockedMeta = const VerificationMeta('blocked'); - GeneratedBoolColumn _blocked; - GeneratedBoolColumn get blocked => _blocked ??= _constructBlocked(); - GeneratedBoolColumn _constructBlocked() { - return GeneratedBoolColumn('blocked', $tableName, true, - $customConstraints: 'DEFAULT false', - defaultValue: const CustomExpression('false')); - } - - @override - List get $columns => - [clientId, userId, publicKey, content, verified, blocked]; - @override - UserCrossSigningKeys get asDslTable => this; - @override - String get $tableName => _alias ?? 'user_cross_signing_keys'; - @override - final String actualTableName = 'user_cross_signing_keys'; - @override - VerificationContext validateIntegrity( - Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('user_id')) { - context.handle(_userIdMeta, - userId.isAcceptableOrUnknown(data['user_id'], _userIdMeta)); - } else if (isInserting) { - context.missing(_userIdMeta); - } - if (data.containsKey('public_key')) { - context.handle(_publicKeyMeta, - publicKey.isAcceptableOrUnknown(data['public_key'], _publicKeyMeta)); - } else if (isInserting) { - context.missing(_publicKeyMeta); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } else if (isInserting) { - context.missing(_contentMeta); - } - if (data.containsKey('verified')) { - context.handle(_verifiedMeta, - verified.isAcceptableOrUnknown(data['verified'], _verifiedMeta)); - } - if (data.containsKey('blocked')) { - context.handle(_blockedMeta, - blocked.isAcceptableOrUnknown(data['blocked'], _blockedMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbUserCrossSigningKey map(Map data, {String tablePrefix}) { - return DbUserCrossSigningKey.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - UserCrossSigningKeys createAlias(String alias) { - return UserCrossSigningKeys(_db, alias); - } - - @override - List get customConstraints => - const ['UNIQUE(client_id, user_id, public_key)']; - @override - bool get dontWriteConstraints => true; -} - -class DbOlmSessions extends DataClass implements Insertable { - final int clientId; - final String identityKey; - final String sessionId; - final String pickle; - final int lastReceived; - DbOlmSessions( - {@required this.clientId, - @required this.identityKey, - @required this.sessionId, - @required this.pickle, - this.lastReceived}); - factory DbOlmSessions.fromData( - Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbOlmSessions( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - identityKey: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}identity_key']), - sessionId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}session_id']), - pickle: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}pickle']), - lastReceived: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}last_received']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || identityKey != null) { - map['identity_key'] = Variable(identityKey); - } - if (!nullToAbsent || sessionId != null) { - map['session_id'] = Variable(sessionId); - } - if (!nullToAbsent || pickle != null) { - map['pickle'] = Variable(pickle); - } - if (!nullToAbsent || lastReceived != null) { - map['last_received'] = Variable(lastReceived); - } - return map; - } - - OlmSessionsCompanion toCompanion(bool nullToAbsent) { - return OlmSessionsCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - identityKey: identityKey == null && nullToAbsent - ? const Value.absent() - : Value(identityKey), - sessionId: sessionId == null && nullToAbsent - ? const Value.absent() - : Value(sessionId), - pickle: - pickle == null && nullToAbsent ? const Value.absent() : Value(pickle), - lastReceived: lastReceived == null && nullToAbsent - ? const Value.absent() - : Value(lastReceived), - ); - } - - factory DbOlmSessions.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbOlmSessions( - clientId: serializer.fromJson(json['client_id']), - identityKey: serializer.fromJson(json['identity_key']), - sessionId: serializer.fromJson(json['session_id']), - pickle: serializer.fromJson(json['pickle']), - lastReceived: serializer.fromJson(json['last_received']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'identity_key': serializer.toJson(identityKey), - 'session_id': serializer.toJson(sessionId), - 'pickle': serializer.toJson(pickle), - 'last_received': serializer.toJson(lastReceived), - }; - } - - DbOlmSessions copyWith( - {int clientId, - String identityKey, - String sessionId, - String pickle, - int lastReceived}) => - DbOlmSessions( - clientId: clientId ?? this.clientId, - identityKey: identityKey ?? this.identityKey, - sessionId: sessionId ?? this.sessionId, - pickle: pickle ?? this.pickle, - lastReceived: lastReceived ?? this.lastReceived, - ); - @override - String toString() { - return (StringBuffer('DbOlmSessions(') - ..write('clientId: $clientId, ') - ..write('identityKey: $identityKey, ') - ..write('sessionId: $sessionId, ') - ..write('pickle: $pickle, ') - ..write('lastReceived: $lastReceived') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - identityKey.hashCode, - $mrjc(sessionId.hashCode, - $mrjc(pickle.hashCode, lastReceived.hashCode))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbOlmSessions && - other.clientId == this.clientId && - other.identityKey == this.identityKey && - other.sessionId == this.sessionId && - other.pickle == this.pickle && - other.lastReceived == this.lastReceived); -} - -class OlmSessionsCompanion extends UpdateCompanion { - final Value clientId; - final Value identityKey; - final Value sessionId; - final Value pickle; - final Value lastReceived; - const OlmSessionsCompanion({ - this.clientId = const Value.absent(), - this.identityKey = const Value.absent(), - this.sessionId = const Value.absent(), - this.pickle = const Value.absent(), - this.lastReceived = const Value.absent(), - }); - OlmSessionsCompanion.insert({ - @required int clientId, - @required String identityKey, - @required String sessionId, - @required String pickle, - this.lastReceived = const Value.absent(), - }) : clientId = Value(clientId), - identityKey = Value(identityKey), - sessionId = Value(sessionId), - pickle = Value(pickle); - static Insertable custom({ - Expression clientId, - Expression identityKey, - Expression sessionId, - Expression pickle, - Expression lastReceived, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (identityKey != null) 'identity_key': identityKey, - if (sessionId != null) 'session_id': sessionId, - if (pickle != null) 'pickle': pickle, - if (lastReceived != null) 'last_received': lastReceived, - }); - } - - OlmSessionsCompanion copyWith( - {Value clientId, - Value identityKey, - Value sessionId, - Value pickle, - Value lastReceived}) { - return OlmSessionsCompanion( - clientId: clientId ?? this.clientId, - identityKey: identityKey ?? this.identityKey, - sessionId: sessionId ?? this.sessionId, - pickle: pickle ?? this.pickle, - lastReceived: lastReceived ?? this.lastReceived, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (identityKey.present) { - map['identity_key'] = Variable(identityKey.value); - } - if (sessionId.present) { - map['session_id'] = Variable(sessionId.value); - } - if (pickle.present) { - map['pickle'] = Variable(pickle.value); - } - if (lastReceived.present) { - map['last_received'] = Variable(lastReceived.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('OlmSessionsCompanion(') - ..write('clientId: $clientId, ') - ..write('identityKey: $identityKey, ') - ..write('sessionId: $sessionId, ') - ..write('pickle: $pickle, ') - ..write('lastReceived: $lastReceived') - ..write(')')) - .toString(); - } -} - -class OlmSessions extends Table with TableInfo { - final GeneratedDatabase _db; - final String _alias; - OlmSessions(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _identityKeyMeta = - const VerificationMeta('identityKey'); - GeneratedTextColumn _identityKey; - GeneratedTextColumn get identityKey => - _identityKey ??= _constructIdentityKey(); - GeneratedTextColumn _constructIdentityKey() { - return GeneratedTextColumn('identity_key', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _sessionIdMeta = const VerificationMeta('sessionId'); - GeneratedTextColumn _sessionId; - GeneratedTextColumn get sessionId => _sessionId ??= _constructSessionId(); - GeneratedTextColumn _constructSessionId() { - return GeneratedTextColumn('session_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _pickleMeta = const VerificationMeta('pickle'); - GeneratedTextColumn _pickle; - GeneratedTextColumn get pickle => _pickle ??= _constructPickle(); - GeneratedTextColumn _constructPickle() { - return GeneratedTextColumn('pickle', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _lastReceivedMeta = - const VerificationMeta('lastReceived'); - GeneratedIntColumn _lastReceived; - GeneratedIntColumn get lastReceived => - _lastReceived ??= _constructLastReceived(); - GeneratedIntColumn _constructLastReceived() { - return GeneratedIntColumn('last_received', $tableName, true, - $customConstraints: ''); - } - - @override - List get $columns => - [clientId, identityKey, sessionId, pickle, lastReceived]; - @override - OlmSessions get asDslTable => this; - @override - String get $tableName => _alias ?? 'olm_sessions'; - @override - final String actualTableName = 'olm_sessions'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('identity_key')) { - context.handle( - _identityKeyMeta, - identityKey.isAcceptableOrUnknown( - data['identity_key'], _identityKeyMeta)); - } else if (isInserting) { - context.missing(_identityKeyMeta); - } - if (data.containsKey('session_id')) { - context.handle(_sessionIdMeta, - sessionId.isAcceptableOrUnknown(data['session_id'], _sessionIdMeta)); - } else if (isInserting) { - context.missing(_sessionIdMeta); - } - if (data.containsKey('pickle')) { - context.handle(_pickleMeta, - pickle.isAcceptableOrUnknown(data['pickle'], _pickleMeta)); - } else if (isInserting) { - context.missing(_pickleMeta); - } - if (data.containsKey('last_received')) { - context.handle( - _lastReceivedMeta, - lastReceived.isAcceptableOrUnknown( - data['last_received'], _lastReceivedMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbOlmSessions map(Map data, {String tablePrefix}) { - return DbOlmSessions.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - OlmSessions createAlias(String alias) { - return OlmSessions(_db, alias); - } - - @override - List get customConstraints => - const ['UNIQUE(client_id, identity_key, session_id)']; - @override - bool get dontWriteConstraints => true; -} - -class DbOutboundGroupSession extends DataClass - implements Insertable { - final int clientId; - final String roomId; - final String pickle; - final String deviceIds; - final int creationTime; - final int sentMessages; - DbOutboundGroupSession( - {@required this.clientId, - @required this.roomId, - @required this.pickle, - @required this.deviceIds, - @required this.creationTime, - @required this.sentMessages}); - factory DbOutboundGroupSession.fromData( - Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbOutboundGroupSession( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - roomId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}room_id']), - pickle: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}pickle']), - deviceIds: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}device_ids']), - creationTime: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}creation_time']), - sentMessages: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}sent_messages']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || roomId != null) { - map['room_id'] = Variable(roomId); - } - if (!nullToAbsent || pickle != null) { - map['pickle'] = Variable(pickle); - } - if (!nullToAbsent || deviceIds != null) { - map['device_ids'] = Variable(deviceIds); - } - if (!nullToAbsent || creationTime != null) { - map['creation_time'] = Variable(creationTime); - } - if (!nullToAbsent || sentMessages != null) { - map['sent_messages'] = Variable(sentMessages); - } - return map; - } - - OutboundGroupSessionsCompanion toCompanion(bool nullToAbsent) { - return OutboundGroupSessionsCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - roomId: - roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), - pickle: - pickle == null && nullToAbsent ? const Value.absent() : Value(pickle), - deviceIds: deviceIds == null && nullToAbsent - ? const Value.absent() - : Value(deviceIds), - creationTime: creationTime == null && nullToAbsent - ? const Value.absent() - : Value(creationTime), - sentMessages: sentMessages == null && nullToAbsent - ? const Value.absent() - : Value(sentMessages), - ); - } - - factory DbOutboundGroupSession.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbOutboundGroupSession( - clientId: serializer.fromJson(json['client_id']), - roomId: serializer.fromJson(json['room_id']), - pickle: serializer.fromJson(json['pickle']), - deviceIds: serializer.fromJson(json['device_ids']), - creationTime: serializer.fromJson(json['creation_time']), - sentMessages: serializer.fromJson(json['sent_messages']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'room_id': serializer.toJson(roomId), - 'pickle': serializer.toJson(pickle), - 'device_ids': serializer.toJson(deviceIds), - 'creation_time': serializer.toJson(creationTime), - 'sent_messages': serializer.toJson(sentMessages), - }; - } - - DbOutboundGroupSession copyWith( - {int clientId, - String roomId, - String pickle, - String deviceIds, - int creationTime, - int sentMessages}) => - DbOutboundGroupSession( - clientId: clientId ?? this.clientId, - roomId: roomId ?? this.roomId, - pickle: pickle ?? this.pickle, - deviceIds: deviceIds ?? this.deviceIds, - creationTime: creationTime ?? this.creationTime, - sentMessages: sentMessages ?? this.sentMessages, - ); - @override - String toString() { - return (StringBuffer('DbOutboundGroupSession(') - ..write('clientId: $clientId, ') - ..write('roomId: $roomId, ') - ..write('pickle: $pickle, ') - ..write('deviceIds: $deviceIds, ') - ..write('creationTime: $creationTime, ') - ..write('sentMessages: $sentMessages') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - roomId.hashCode, - $mrjc( - pickle.hashCode, - $mrjc(deviceIds.hashCode, - $mrjc(creationTime.hashCode, sentMessages.hashCode)))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbOutboundGroupSession && - other.clientId == this.clientId && - other.roomId == this.roomId && - other.pickle == this.pickle && - other.deviceIds == this.deviceIds && - other.creationTime == this.creationTime && - other.sentMessages == this.sentMessages); -} - -class OutboundGroupSessionsCompanion - extends UpdateCompanion { - final Value clientId; - final Value roomId; - final Value pickle; - final Value deviceIds; - final Value creationTime; - final Value sentMessages; - const OutboundGroupSessionsCompanion({ - this.clientId = const Value.absent(), - this.roomId = const Value.absent(), - this.pickle = const Value.absent(), - this.deviceIds = const Value.absent(), - this.creationTime = const Value.absent(), - this.sentMessages = const Value.absent(), - }); - OutboundGroupSessionsCompanion.insert({ - @required int clientId, - @required String roomId, - @required String pickle, - @required String deviceIds, - @required int creationTime, - this.sentMessages = const Value.absent(), - }) : clientId = Value(clientId), - roomId = Value(roomId), - pickle = Value(pickle), - deviceIds = Value(deviceIds), - creationTime = Value(creationTime); - static Insertable custom({ - Expression clientId, - Expression roomId, - Expression pickle, - Expression deviceIds, - Expression creationTime, - Expression sentMessages, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (roomId != null) 'room_id': roomId, - if (pickle != null) 'pickle': pickle, - if (deviceIds != null) 'device_ids': deviceIds, - if (creationTime != null) 'creation_time': creationTime, - if (sentMessages != null) 'sent_messages': sentMessages, - }); - } - - OutboundGroupSessionsCompanion copyWith( - {Value clientId, - Value roomId, - Value pickle, - Value deviceIds, - Value creationTime, - Value sentMessages}) { - return OutboundGroupSessionsCompanion( - clientId: clientId ?? this.clientId, - roomId: roomId ?? this.roomId, - pickle: pickle ?? this.pickle, - deviceIds: deviceIds ?? this.deviceIds, - creationTime: creationTime ?? this.creationTime, - sentMessages: sentMessages ?? this.sentMessages, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (roomId.present) { - map['room_id'] = Variable(roomId.value); - } - if (pickle.present) { - map['pickle'] = Variable(pickle.value); - } - if (deviceIds.present) { - map['device_ids'] = Variable(deviceIds.value); - } - if (creationTime.present) { - map['creation_time'] = Variable(creationTime.value); - } - if (sentMessages.present) { - map['sent_messages'] = Variable(sentMessages.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('OutboundGroupSessionsCompanion(') - ..write('clientId: $clientId, ') - ..write('roomId: $roomId, ') - ..write('pickle: $pickle, ') - ..write('deviceIds: $deviceIds, ') - ..write('creationTime: $creationTime, ') - ..write('sentMessages: $sentMessages') - ..write(')')) - .toString(); - } -} - -class OutboundGroupSessions extends Table - with TableInfo { - final GeneratedDatabase _db; - final String _alias; - OutboundGroupSessions(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _roomIdMeta = const VerificationMeta('roomId'); - GeneratedTextColumn _roomId; - GeneratedTextColumn get roomId => _roomId ??= _constructRoomId(); - GeneratedTextColumn _constructRoomId() { - return GeneratedTextColumn('room_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _pickleMeta = const VerificationMeta('pickle'); - GeneratedTextColumn _pickle; - GeneratedTextColumn get pickle => _pickle ??= _constructPickle(); - GeneratedTextColumn _constructPickle() { - return GeneratedTextColumn('pickle', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _deviceIdsMeta = const VerificationMeta('deviceIds'); - GeneratedTextColumn _deviceIds; - GeneratedTextColumn get deviceIds => _deviceIds ??= _constructDeviceIds(); - GeneratedTextColumn _constructDeviceIds() { - return GeneratedTextColumn('device_ids', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _creationTimeMeta = - const VerificationMeta('creationTime'); - GeneratedIntColumn _creationTime; - GeneratedIntColumn get creationTime => - _creationTime ??= _constructCreationTime(); - GeneratedIntColumn _constructCreationTime() { - return GeneratedIntColumn('creation_time', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _sentMessagesMeta = - const VerificationMeta('sentMessages'); - GeneratedIntColumn _sentMessages; - GeneratedIntColumn get sentMessages => - _sentMessages ??= _constructSentMessages(); - GeneratedIntColumn _constructSentMessages() { - return GeneratedIntColumn('sent_messages', $tableName, false, - $customConstraints: 'NOT NULL DEFAULT \'0\'', - defaultValue: const CustomExpression('\'0\'')); - } - - @override - List get $columns => - [clientId, roomId, pickle, deviceIds, creationTime, sentMessages]; - @override - OutboundGroupSessions get asDslTable => this; - @override - String get $tableName => _alias ?? 'outbound_group_sessions'; - @override - final String actualTableName = 'outbound_group_sessions'; - @override - VerificationContext validateIntegrity( - Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('room_id')) { - context.handle(_roomIdMeta, - roomId.isAcceptableOrUnknown(data['room_id'], _roomIdMeta)); - } else if (isInserting) { - context.missing(_roomIdMeta); - } - if (data.containsKey('pickle')) { - context.handle(_pickleMeta, - pickle.isAcceptableOrUnknown(data['pickle'], _pickleMeta)); - } else if (isInserting) { - context.missing(_pickleMeta); - } - if (data.containsKey('device_ids')) { - context.handle(_deviceIdsMeta, - deviceIds.isAcceptableOrUnknown(data['device_ids'], _deviceIdsMeta)); - } else if (isInserting) { - context.missing(_deviceIdsMeta); - } - if (data.containsKey('creation_time')) { - context.handle( - _creationTimeMeta, - creationTime.isAcceptableOrUnknown( - data['creation_time'], _creationTimeMeta)); - } else if (isInserting) { - context.missing(_creationTimeMeta); - } - if (data.containsKey('sent_messages')) { - context.handle( - _sentMessagesMeta, - sentMessages.isAcceptableOrUnknown( - data['sent_messages'], _sentMessagesMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbOutboundGroupSession map(Map data, {String tablePrefix}) { - return DbOutboundGroupSession.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - OutboundGroupSessions createAlias(String alias) { - return OutboundGroupSessions(_db, alias); - } - - @override - List get customConstraints => const ['UNIQUE(client_id, room_id)']; - @override - bool get dontWriteConstraints => true; -} - -class DbInboundGroupSession extends DataClass - implements Insertable { - final int clientId; - final String roomId; - final String sessionId; - final String pickle; - final String content; - final String indexes; - final String allowedAtIndex; - final bool uploaded; - final String senderKey; - final String senderClaimedKeys; - DbInboundGroupSession( - {@required this.clientId, - @required this.roomId, - @required this.sessionId, - @required this.pickle, - this.content, - this.indexes, - this.allowedAtIndex, - this.uploaded, - this.senderKey, - this.senderClaimedKeys}); - factory DbInboundGroupSession.fromData( - Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbInboundGroupSession( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - roomId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}room_id']), - sessionId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}session_id']), - pickle: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}pickle']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - indexes: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}indexes']), - allowedAtIndex: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}allowed_at_index']), - uploaded: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}uploaded']), - senderKey: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}sender_key']), - senderClaimedKeys: const StringType().mapFromDatabaseResponse( - data['${effectivePrefix}sender_claimed_keys']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || roomId != null) { - map['room_id'] = Variable(roomId); - } - if (!nullToAbsent || sessionId != null) { - map['session_id'] = Variable(sessionId); - } - if (!nullToAbsent || pickle != null) { - map['pickle'] = Variable(pickle); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - if (!nullToAbsent || indexes != null) { - map['indexes'] = Variable(indexes); - } - if (!nullToAbsent || allowedAtIndex != null) { - map['allowed_at_index'] = Variable(allowedAtIndex); - } - if (!nullToAbsent || uploaded != null) { - map['uploaded'] = Variable(uploaded); - } - if (!nullToAbsent || senderKey != null) { - map['sender_key'] = Variable(senderKey); - } - if (!nullToAbsent || senderClaimedKeys != null) { - map['sender_claimed_keys'] = Variable(senderClaimedKeys); - } - return map; - } - - InboundGroupSessionsCompanion toCompanion(bool nullToAbsent) { - return InboundGroupSessionsCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - roomId: - roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), - sessionId: sessionId == null && nullToAbsent - ? const Value.absent() - : Value(sessionId), - pickle: - pickle == null && nullToAbsent ? const Value.absent() : Value(pickle), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - indexes: indexes == null && nullToAbsent - ? const Value.absent() - : Value(indexes), - allowedAtIndex: allowedAtIndex == null && nullToAbsent - ? const Value.absent() - : Value(allowedAtIndex), - uploaded: uploaded == null && nullToAbsent - ? const Value.absent() - : Value(uploaded), - senderKey: senderKey == null && nullToAbsent - ? const Value.absent() - : Value(senderKey), - senderClaimedKeys: senderClaimedKeys == null && nullToAbsent - ? const Value.absent() - : Value(senderClaimedKeys), - ); - } - - factory DbInboundGroupSession.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbInboundGroupSession( - clientId: serializer.fromJson(json['client_id']), - roomId: serializer.fromJson(json['room_id']), - sessionId: serializer.fromJson(json['session_id']), - pickle: serializer.fromJson(json['pickle']), - content: serializer.fromJson(json['content']), - indexes: serializer.fromJson(json['indexes']), - allowedAtIndex: serializer.fromJson(json['allowed_at_index']), - uploaded: serializer.fromJson(json['uploaded']), - senderKey: serializer.fromJson(json['sender_key']), - senderClaimedKeys: - serializer.fromJson(json['sender_claimed_keys']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'room_id': serializer.toJson(roomId), - 'session_id': serializer.toJson(sessionId), - 'pickle': serializer.toJson(pickle), - 'content': serializer.toJson(content), - 'indexes': serializer.toJson(indexes), - 'allowed_at_index': serializer.toJson(allowedAtIndex), - 'uploaded': serializer.toJson(uploaded), - 'sender_key': serializer.toJson(senderKey), - 'sender_claimed_keys': serializer.toJson(senderClaimedKeys), - }; - } - - DbInboundGroupSession copyWith( - {int clientId, - String roomId, - String sessionId, - String pickle, - String content, - String indexes, - String allowedAtIndex, - bool uploaded, - String senderKey, - String senderClaimedKeys}) => - DbInboundGroupSession( - clientId: clientId ?? this.clientId, - roomId: roomId ?? this.roomId, - sessionId: sessionId ?? this.sessionId, - pickle: pickle ?? this.pickle, - content: content ?? this.content, - indexes: indexes ?? this.indexes, - allowedAtIndex: allowedAtIndex ?? this.allowedAtIndex, - uploaded: uploaded ?? this.uploaded, - senderKey: senderKey ?? this.senderKey, - senderClaimedKeys: senderClaimedKeys ?? this.senderClaimedKeys, - ); - @override - String toString() { - return (StringBuffer('DbInboundGroupSession(') - ..write('clientId: $clientId, ') - ..write('roomId: $roomId, ') - ..write('sessionId: $sessionId, ') - ..write('pickle: $pickle, ') - ..write('content: $content, ') - ..write('indexes: $indexes, ') - ..write('allowedAtIndex: $allowedAtIndex, ') - ..write('uploaded: $uploaded, ') - ..write('senderKey: $senderKey, ') - ..write('senderClaimedKeys: $senderClaimedKeys') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - roomId.hashCode, - $mrjc( - sessionId.hashCode, - $mrjc( - pickle.hashCode, - $mrjc( - content.hashCode, - $mrjc( - indexes.hashCode, - $mrjc( - allowedAtIndex.hashCode, - $mrjc( - uploaded.hashCode, - $mrjc(senderKey.hashCode, - senderClaimedKeys.hashCode)))))))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbInboundGroupSession && - other.clientId == this.clientId && - other.roomId == this.roomId && - other.sessionId == this.sessionId && - other.pickle == this.pickle && - other.content == this.content && - other.indexes == this.indexes && - other.allowedAtIndex == this.allowedAtIndex && - other.uploaded == this.uploaded && - other.senderKey == this.senderKey && - other.senderClaimedKeys == this.senderClaimedKeys); -} - -class InboundGroupSessionsCompanion - extends UpdateCompanion { - final Value clientId; - final Value roomId; - final Value sessionId; - final Value pickle; - final Value content; - final Value indexes; - final Value allowedAtIndex; - final Value uploaded; - final Value senderKey; - final Value senderClaimedKeys; - const InboundGroupSessionsCompanion({ - this.clientId = const Value.absent(), - this.roomId = const Value.absent(), - this.sessionId = const Value.absent(), - this.pickle = const Value.absent(), - this.content = const Value.absent(), - this.indexes = const Value.absent(), - this.allowedAtIndex = const Value.absent(), - this.uploaded = const Value.absent(), - this.senderKey = const Value.absent(), - this.senderClaimedKeys = const Value.absent(), - }); - InboundGroupSessionsCompanion.insert({ - @required int clientId, - @required String roomId, - @required String sessionId, - @required String pickle, - this.content = const Value.absent(), - this.indexes = const Value.absent(), - this.allowedAtIndex = const Value.absent(), - this.uploaded = const Value.absent(), - this.senderKey = const Value.absent(), - this.senderClaimedKeys = const Value.absent(), - }) : clientId = Value(clientId), - roomId = Value(roomId), - sessionId = Value(sessionId), - pickle = Value(pickle); - static Insertable custom({ - Expression clientId, - Expression roomId, - Expression sessionId, - Expression pickle, - Expression content, - Expression indexes, - Expression allowedAtIndex, - Expression uploaded, - Expression senderKey, - Expression senderClaimedKeys, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (roomId != null) 'room_id': roomId, - if (sessionId != null) 'session_id': sessionId, - if (pickle != null) 'pickle': pickle, - if (content != null) 'content': content, - if (indexes != null) 'indexes': indexes, - if (allowedAtIndex != null) 'allowed_at_index': allowedAtIndex, - if (uploaded != null) 'uploaded': uploaded, - if (senderKey != null) 'sender_key': senderKey, - if (senderClaimedKeys != null) 'sender_claimed_keys': senderClaimedKeys, - }); - } - - InboundGroupSessionsCompanion copyWith( - {Value clientId, - Value roomId, - Value sessionId, - Value pickle, - Value content, - Value indexes, - Value allowedAtIndex, - Value uploaded, - Value senderKey, - Value senderClaimedKeys}) { - return InboundGroupSessionsCompanion( - clientId: clientId ?? this.clientId, - roomId: roomId ?? this.roomId, - sessionId: sessionId ?? this.sessionId, - pickle: pickle ?? this.pickle, - content: content ?? this.content, - indexes: indexes ?? this.indexes, - allowedAtIndex: allowedAtIndex ?? this.allowedAtIndex, - uploaded: uploaded ?? this.uploaded, - senderKey: senderKey ?? this.senderKey, - senderClaimedKeys: senderClaimedKeys ?? this.senderClaimedKeys, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (roomId.present) { - map['room_id'] = Variable(roomId.value); - } - if (sessionId.present) { - map['session_id'] = Variable(sessionId.value); - } - if (pickle.present) { - map['pickle'] = Variable(pickle.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - if (indexes.present) { - map['indexes'] = Variable(indexes.value); - } - if (allowedAtIndex.present) { - map['allowed_at_index'] = Variable(allowedAtIndex.value); - } - if (uploaded.present) { - map['uploaded'] = Variable(uploaded.value); - } - if (senderKey.present) { - map['sender_key'] = Variable(senderKey.value); - } - if (senderClaimedKeys.present) { - map['sender_claimed_keys'] = Variable(senderClaimedKeys.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('InboundGroupSessionsCompanion(') - ..write('clientId: $clientId, ') - ..write('roomId: $roomId, ') - ..write('sessionId: $sessionId, ') - ..write('pickle: $pickle, ') - ..write('content: $content, ') - ..write('indexes: $indexes, ') - ..write('allowedAtIndex: $allowedAtIndex, ') - ..write('uploaded: $uploaded, ') - ..write('senderKey: $senderKey, ') - ..write('senderClaimedKeys: $senderClaimedKeys') - ..write(')')) - .toString(); - } -} - -class InboundGroupSessions extends Table - with TableInfo { - final GeneratedDatabase _db; - final String _alias; - InboundGroupSessions(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _roomIdMeta = const VerificationMeta('roomId'); - GeneratedTextColumn _roomId; - GeneratedTextColumn get roomId => _roomId ??= _constructRoomId(); - GeneratedTextColumn _constructRoomId() { - return GeneratedTextColumn('room_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _sessionIdMeta = const VerificationMeta('sessionId'); - GeneratedTextColumn _sessionId; - GeneratedTextColumn get sessionId => _sessionId ??= _constructSessionId(); - GeneratedTextColumn _constructSessionId() { - return GeneratedTextColumn('session_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _pickleMeta = const VerificationMeta('pickle'); - GeneratedTextColumn _pickle; - GeneratedTextColumn get pickle => _pickle ??= _constructPickle(); - GeneratedTextColumn _constructPickle() { - return GeneratedTextColumn('pickle', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _indexesMeta = const VerificationMeta('indexes'); - GeneratedTextColumn _indexes; - GeneratedTextColumn get indexes => _indexes ??= _constructIndexes(); - GeneratedTextColumn _constructIndexes() { - return GeneratedTextColumn('indexes', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _allowedAtIndexMeta = - const VerificationMeta('allowedAtIndex'); - GeneratedTextColumn _allowedAtIndex; - GeneratedTextColumn get allowedAtIndex => - _allowedAtIndex ??= _constructAllowedAtIndex(); - GeneratedTextColumn _constructAllowedAtIndex() { - return GeneratedTextColumn('allowed_at_index', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _uploadedMeta = const VerificationMeta('uploaded'); - GeneratedBoolColumn _uploaded; - GeneratedBoolColumn get uploaded => _uploaded ??= _constructUploaded(); - GeneratedBoolColumn _constructUploaded() { - return GeneratedBoolColumn('uploaded', $tableName, true, - $customConstraints: 'DEFAULT false', - defaultValue: const CustomExpression('false')); - } - - final VerificationMeta _senderKeyMeta = const VerificationMeta('senderKey'); - GeneratedTextColumn _senderKey; - GeneratedTextColumn get senderKey => _senderKey ??= _constructSenderKey(); - GeneratedTextColumn _constructSenderKey() { - return GeneratedTextColumn('sender_key', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _senderClaimedKeysMeta = - const VerificationMeta('senderClaimedKeys'); - GeneratedTextColumn _senderClaimedKeys; - GeneratedTextColumn get senderClaimedKeys => - _senderClaimedKeys ??= _constructSenderClaimedKeys(); - GeneratedTextColumn _constructSenderClaimedKeys() { - return GeneratedTextColumn('sender_claimed_keys', $tableName, true, - $customConstraints: ''); - } - - @override - List get $columns => [ - clientId, - roomId, - sessionId, - pickle, - content, - indexes, - allowedAtIndex, - uploaded, - senderKey, - senderClaimedKeys - ]; - @override - InboundGroupSessions get asDslTable => this; - @override - String get $tableName => _alias ?? 'inbound_group_sessions'; - @override - final String actualTableName = 'inbound_group_sessions'; - @override - VerificationContext validateIntegrity( - Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('room_id')) { - context.handle(_roomIdMeta, - roomId.isAcceptableOrUnknown(data['room_id'], _roomIdMeta)); - } else if (isInserting) { - context.missing(_roomIdMeta); - } - if (data.containsKey('session_id')) { - context.handle(_sessionIdMeta, - sessionId.isAcceptableOrUnknown(data['session_id'], _sessionIdMeta)); - } else if (isInserting) { - context.missing(_sessionIdMeta); - } - if (data.containsKey('pickle')) { - context.handle(_pickleMeta, - pickle.isAcceptableOrUnknown(data['pickle'], _pickleMeta)); - } else if (isInserting) { - context.missing(_pickleMeta); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } - if (data.containsKey('indexes')) { - context.handle(_indexesMeta, - indexes.isAcceptableOrUnknown(data['indexes'], _indexesMeta)); - } - if (data.containsKey('allowed_at_index')) { - context.handle( - _allowedAtIndexMeta, - allowedAtIndex.isAcceptableOrUnknown( - data['allowed_at_index'], _allowedAtIndexMeta)); - } - if (data.containsKey('uploaded')) { - context.handle(_uploadedMeta, - uploaded.isAcceptableOrUnknown(data['uploaded'], _uploadedMeta)); - } - if (data.containsKey('sender_key')) { - context.handle(_senderKeyMeta, - senderKey.isAcceptableOrUnknown(data['sender_key'], _senderKeyMeta)); - } - if (data.containsKey('sender_claimed_keys')) { - context.handle( - _senderClaimedKeysMeta, - senderClaimedKeys.isAcceptableOrUnknown( - data['sender_claimed_keys'], _senderClaimedKeysMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbInboundGroupSession map(Map data, {String tablePrefix}) { - return DbInboundGroupSession.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - InboundGroupSessions createAlias(String alias) { - return InboundGroupSessions(_db, alias); - } - - @override - List get customConstraints => - const ['UNIQUE(client_id, room_id, session_id)']; - @override - bool get dontWriteConstraints => true; -} - -class DbRoom extends DataClass implements Insertable { - final int clientId; - final String roomId; - final String membership; - final int highlightCount; - final int notificationCount; - final String prevBatch; - final int joinedMemberCount; - final int invitedMemberCount; - final double newestSortOrder; - final double oldestSortOrder; - final String heroes; - DbRoom( - {@required this.clientId, - @required this.roomId, - @required this.membership, - @required this.highlightCount, - @required this.notificationCount, - this.prevBatch, - @required this.joinedMemberCount, - @required this.invitedMemberCount, - @required this.newestSortOrder, - @required this.oldestSortOrder, - this.heroes}); - factory DbRoom.fromData(Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbRoom( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - roomId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}room_id']), - membership: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}membership']), - highlightCount: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}highlight_count']), - notificationCount: const IntType().mapFromDatabaseResponse( - data['${effectivePrefix}notification_count']), - prevBatch: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}prev_batch']), - joinedMemberCount: const IntType().mapFromDatabaseResponse( - data['${effectivePrefix}joined_member_count']), - invitedMemberCount: const IntType().mapFromDatabaseResponse( - data['${effectivePrefix}invited_member_count']), - newestSortOrder: const RealType() - .mapFromDatabaseResponse(data['${effectivePrefix}newest_sort_order']), - oldestSortOrder: const RealType() - .mapFromDatabaseResponse(data['${effectivePrefix}oldest_sort_order']), - heroes: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}heroes']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || roomId != null) { - map['room_id'] = Variable(roomId); - } - if (!nullToAbsent || membership != null) { - map['membership'] = Variable(membership); - } - if (!nullToAbsent || highlightCount != null) { - map['highlight_count'] = Variable(highlightCount); - } - if (!nullToAbsent || notificationCount != null) { - map['notification_count'] = Variable(notificationCount); - } - if (!nullToAbsent || prevBatch != null) { - map['prev_batch'] = Variable(prevBatch); - } - if (!nullToAbsent || joinedMemberCount != null) { - map['joined_member_count'] = Variable(joinedMemberCount); - } - if (!nullToAbsent || invitedMemberCount != null) { - map['invited_member_count'] = Variable(invitedMemberCount); - } - if (!nullToAbsent || newestSortOrder != null) { - map['newest_sort_order'] = Variable(newestSortOrder); - } - if (!nullToAbsent || oldestSortOrder != null) { - map['oldest_sort_order'] = Variable(oldestSortOrder); - } - if (!nullToAbsent || heroes != null) { - map['heroes'] = Variable(heroes); - } - return map; - } - - RoomsCompanion toCompanion(bool nullToAbsent) { - return RoomsCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - roomId: - roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), - membership: membership == null && nullToAbsent - ? const Value.absent() - : Value(membership), - highlightCount: highlightCount == null && nullToAbsent - ? const Value.absent() - : Value(highlightCount), - notificationCount: notificationCount == null && nullToAbsent - ? const Value.absent() - : Value(notificationCount), - prevBatch: prevBatch == null && nullToAbsent - ? const Value.absent() - : Value(prevBatch), - joinedMemberCount: joinedMemberCount == null && nullToAbsent - ? const Value.absent() - : Value(joinedMemberCount), - invitedMemberCount: invitedMemberCount == null && nullToAbsent - ? const Value.absent() - : Value(invitedMemberCount), - newestSortOrder: newestSortOrder == null && nullToAbsent - ? const Value.absent() - : Value(newestSortOrder), - oldestSortOrder: oldestSortOrder == null && nullToAbsent - ? const Value.absent() - : Value(oldestSortOrder), - heroes: - heroes == null && nullToAbsent ? const Value.absent() : Value(heroes), - ); - } - - factory DbRoom.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbRoom( - clientId: serializer.fromJson(json['client_id']), - roomId: serializer.fromJson(json['room_id']), - membership: serializer.fromJson(json['membership']), - highlightCount: serializer.fromJson(json['highlight_count']), - notificationCount: serializer.fromJson(json['notification_count']), - prevBatch: serializer.fromJson(json['prev_batch']), - joinedMemberCount: serializer.fromJson(json['joined_member_count']), - invitedMemberCount: - serializer.fromJson(json['invited_member_count']), - newestSortOrder: serializer.fromJson(json['newest_sort_order']), - oldestSortOrder: serializer.fromJson(json['oldest_sort_order']), - heroes: serializer.fromJson(json['heroes']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'room_id': serializer.toJson(roomId), - 'membership': serializer.toJson(membership), - 'highlight_count': serializer.toJson(highlightCount), - 'notification_count': serializer.toJson(notificationCount), - 'prev_batch': serializer.toJson(prevBatch), - 'joined_member_count': serializer.toJson(joinedMemberCount), - 'invited_member_count': serializer.toJson(invitedMemberCount), - 'newest_sort_order': serializer.toJson(newestSortOrder), - 'oldest_sort_order': serializer.toJson(oldestSortOrder), - 'heroes': serializer.toJson(heroes), - }; - } - - DbRoom copyWith( - {int clientId, - String roomId, - String membership, - int highlightCount, - int notificationCount, - String prevBatch, - int joinedMemberCount, - int invitedMemberCount, - double newestSortOrder, - double oldestSortOrder, - String heroes}) => - DbRoom( - clientId: clientId ?? this.clientId, - roomId: roomId ?? this.roomId, - membership: membership ?? this.membership, - highlightCount: highlightCount ?? this.highlightCount, - notificationCount: notificationCount ?? this.notificationCount, - prevBatch: prevBatch ?? this.prevBatch, - joinedMemberCount: joinedMemberCount ?? this.joinedMemberCount, - invitedMemberCount: invitedMemberCount ?? this.invitedMemberCount, - newestSortOrder: newestSortOrder ?? this.newestSortOrder, - oldestSortOrder: oldestSortOrder ?? this.oldestSortOrder, - heroes: heroes ?? this.heroes, - ); - @override - String toString() { - return (StringBuffer('DbRoom(') - ..write('clientId: $clientId, ') - ..write('roomId: $roomId, ') - ..write('membership: $membership, ') - ..write('highlightCount: $highlightCount, ') - ..write('notificationCount: $notificationCount, ') - ..write('prevBatch: $prevBatch, ') - ..write('joinedMemberCount: $joinedMemberCount, ') - ..write('invitedMemberCount: $invitedMemberCount, ') - ..write('newestSortOrder: $newestSortOrder, ') - ..write('oldestSortOrder: $oldestSortOrder, ') - ..write('heroes: $heroes') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - roomId.hashCode, - $mrjc( - membership.hashCode, - $mrjc( - highlightCount.hashCode, - $mrjc( - notificationCount.hashCode, - $mrjc( - prevBatch.hashCode, - $mrjc( - joinedMemberCount.hashCode, - $mrjc( - invitedMemberCount.hashCode, - $mrjc( - newestSortOrder.hashCode, - $mrjc(oldestSortOrder.hashCode, - heroes.hashCode))))))))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbRoom && - other.clientId == this.clientId && - other.roomId == this.roomId && - other.membership == this.membership && - other.highlightCount == this.highlightCount && - other.notificationCount == this.notificationCount && - other.prevBatch == this.prevBatch && - other.joinedMemberCount == this.joinedMemberCount && - other.invitedMemberCount == this.invitedMemberCount && - other.newestSortOrder == this.newestSortOrder && - other.oldestSortOrder == this.oldestSortOrder && - other.heroes == this.heroes); -} - -class RoomsCompanion extends UpdateCompanion { - final Value clientId; - final Value roomId; - final Value membership; - final Value highlightCount; - final Value notificationCount; - final Value prevBatch; - final Value joinedMemberCount; - final Value invitedMemberCount; - final Value newestSortOrder; - final Value oldestSortOrder; - final Value heroes; - const RoomsCompanion({ - this.clientId = const Value.absent(), - this.roomId = const Value.absent(), - this.membership = const Value.absent(), - this.highlightCount = const Value.absent(), - this.notificationCount = const Value.absent(), - this.prevBatch = const Value.absent(), - this.joinedMemberCount = const Value.absent(), - this.invitedMemberCount = const Value.absent(), - this.newestSortOrder = const Value.absent(), - this.oldestSortOrder = const Value.absent(), - this.heroes = const Value.absent(), - }); - RoomsCompanion.insert({ - @required int clientId, - @required String roomId, - @required String membership, - this.highlightCount = const Value.absent(), - this.notificationCount = const Value.absent(), - this.prevBatch = const Value.absent(), - this.joinedMemberCount = const Value.absent(), - this.invitedMemberCount = const Value.absent(), - this.newestSortOrder = const Value.absent(), - this.oldestSortOrder = const Value.absent(), - this.heroes = const Value.absent(), - }) : clientId = Value(clientId), - roomId = Value(roomId), - membership = Value(membership); - static Insertable custom({ - Expression clientId, - Expression roomId, - Expression membership, - Expression highlightCount, - Expression notificationCount, - Expression prevBatch, - Expression joinedMemberCount, - Expression invitedMemberCount, - Expression newestSortOrder, - Expression oldestSortOrder, - Expression heroes, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (roomId != null) 'room_id': roomId, - if (membership != null) 'membership': membership, - if (highlightCount != null) 'highlight_count': highlightCount, - if (notificationCount != null) 'notification_count': notificationCount, - if (prevBatch != null) 'prev_batch': prevBatch, - if (joinedMemberCount != null) 'joined_member_count': joinedMemberCount, - if (invitedMemberCount != null) - 'invited_member_count': invitedMemberCount, - if (newestSortOrder != null) 'newest_sort_order': newestSortOrder, - if (oldestSortOrder != null) 'oldest_sort_order': oldestSortOrder, - if (heroes != null) 'heroes': heroes, - }); - } - - RoomsCompanion copyWith( - {Value clientId, - Value roomId, - Value membership, - Value highlightCount, - Value notificationCount, - Value prevBatch, - Value joinedMemberCount, - Value invitedMemberCount, - Value newestSortOrder, - Value oldestSortOrder, - Value heroes}) { - return RoomsCompanion( - clientId: clientId ?? this.clientId, - roomId: roomId ?? this.roomId, - membership: membership ?? this.membership, - highlightCount: highlightCount ?? this.highlightCount, - notificationCount: notificationCount ?? this.notificationCount, - prevBatch: prevBatch ?? this.prevBatch, - joinedMemberCount: joinedMemberCount ?? this.joinedMemberCount, - invitedMemberCount: invitedMemberCount ?? this.invitedMemberCount, - newestSortOrder: newestSortOrder ?? this.newestSortOrder, - oldestSortOrder: oldestSortOrder ?? this.oldestSortOrder, - heroes: heroes ?? this.heroes, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (roomId.present) { - map['room_id'] = Variable(roomId.value); - } - if (membership.present) { - map['membership'] = Variable(membership.value); - } - if (highlightCount.present) { - map['highlight_count'] = Variable(highlightCount.value); - } - if (notificationCount.present) { - map['notification_count'] = Variable(notificationCount.value); - } - if (prevBatch.present) { - map['prev_batch'] = Variable(prevBatch.value); - } - if (joinedMemberCount.present) { - map['joined_member_count'] = Variable(joinedMemberCount.value); - } - if (invitedMemberCount.present) { - map['invited_member_count'] = Variable(invitedMemberCount.value); - } - if (newestSortOrder.present) { - map['newest_sort_order'] = Variable(newestSortOrder.value); - } - if (oldestSortOrder.present) { - map['oldest_sort_order'] = Variable(oldestSortOrder.value); - } - if (heroes.present) { - map['heroes'] = Variable(heroes.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('RoomsCompanion(') - ..write('clientId: $clientId, ') - ..write('roomId: $roomId, ') - ..write('membership: $membership, ') - ..write('highlightCount: $highlightCount, ') - ..write('notificationCount: $notificationCount, ') - ..write('prevBatch: $prevBatch, ') - ..write('joinedMemberCount: $joinedMemberCount, ') - ..write('invitedMemberCount: $invitedMemberCount, ') - ..write('newestSortOrder: $newestSortOrder, ') - ..write('oldestSortOrder: $oldestSortOrder, ') - ..write('heroes: $heroes') - ..write(')')) - .toString(); - } -} - -class Rooms extends Table with TableInfo { - final GeneratedDatabase _db; - final String _alias; - Rooms(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _roomIdMeta = const VerificationMeta('roomId'); - GeneratedTextColumn _roomId; - GeneratedTextColumn get roomId => _roomId ??= _constructRoomId(); - GeneratedTextColumn _constructRoomId() { - return GeneratedTextColumn('room_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _membershipMeta = const VerificationMeta('membership'); - GeneratedTextColumn _membership; - GeneratedTextColumn get membership => _membership ??= _constructMembership(); - GeneratedTextColumn _constructMembership() { - return GeneratedTextColumn('membership', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _highlightCountMeta = - const VerificationMeta('highlightCount'); - GeneratedIntColumn _highlightCount; - GeneratedIntColumn get highlightCount => - _highlightCount ??= _constructHighlightCount(); - GeneratedIntColumn _constructHighlightCount() { - return GeneratedIntColumn('highlight_count', $tableName, false, - $customConstraints: 'NOT NULL DEFAULT \'0\'', - defaultValue: const CustomExpression('\'0\'')); - } - - final VerificationMeta _notificationCountMeta = - const VerificationMeta('notificationCount'); - GeneratedIntColumn _notificationCount; - GeneratedIntColumn get notificationCount => - _notificationCount ??= _constructNotificationCount(); - GeneratedIntColumn _constructNotificationCount() { - return GeneratedIntColumn('notification_count', $tableName, false, - $customConstraints: 'NOT NULL DEFAULT \'0\'', - defaultValue: const CustomExpression('\'0\'')); - } - - final VerificationMeta _prevBatchMeta = const VerificationMeta('prevBatch'); - GeneratedTextColumn _prevBatch; - GeneratedTextColumn get prevBatch => _prevBatch ??= _constructPrevBatch(); - GeneratedTextColumn _constructPrevBatch() { - return GeneratedTextColumn('prev_batch', $tableName, true, - $customConstraints: 'DEFAULT \'\'', - defaultValue: const CustomExpression('\'\'')); - } - - final VerificationMeta _joinedMemberCountMeta = - const VerificationMeta('joinedMemberCount'); - GeneratedIntColumn _joinedMemberCount; - GeneratedIntColumn get joinedMemberCount => - _joinedMemberCount ??= _constructJoinedMemberCount(); - GeneratedIntColumn _constructJoinedMemberCount() { - return GeneratedIntColumn('joined_member_count', $tableName, false, - $customConstraints: 'NOT NULL DEFAULT \'0\'', - defaultValue: const CustomExpression('\'0\'')); - } - - final VerificationMeta _invitedMemberCountMeta = - const VerificationMeta('invitedMemberCount'); - GeneratedIntColumn _invitedMemberCount; - GeneratedIntColumn get invitedMemberCount => - _invitedMemberCount ??= _constructInvitedMemberCount(); - GeneratedIntColumn _constructInvitedMemberCount() { - return GeneratedIntColumn('invited_member_count', $tableName, false, - $customConstraints: 'NOT NULL DEFAULT \'0\'', - defaultValue: const CustomExpression('\'0\'')); - } - - final VerificationMeta _newestSortOrderMeta = - const VerificationMeta('newestSortOrder'); - GeneratedRealColumn _newestSortOrder; - GeneratedRealColumn get newestSortOrder => - _newestSortOrder ??= _constructNewestSortOrder(); - GeneratedRealColumn _constructNewestSortOrder() { - return GeneratedRealColumn('newest_sort_order', $tableName, false, - $customConstraints: 'NOT NULL DEFAULT \'0\'', - defaultValue: const CustomExpression('\'0\'')); - } - - final VerificationMeta _oldestSortOrderMeta = - const VerificationMeta('oldestSortOrder'); - GeneratedRealColumn _oldestSortOrder; - GeneratedRealColumn get oldestSortOrder => - _oldestSortOrder ??= _constructOldestSortOrder(); - GeneratedRealColumn _constructOldestSortOrder() { - return GeneratedRealColumn('oldest_sort_order', $tableName, false, - $customConstraints: 'NOT NULL DEFAULT \'0\'', - defaultValue: const CustomExpression('\'0\'')); - } - - final VerificationMeta _heroesMeta = const VerificationMeta('heroes'); - GeneratedTextColumn _heroes; - GeneratedTextColumn get heroes => _heroes ??= _constructHeroes(); - GeneratedTextColumn _constructHeroes() { - return GeneratedTextColumn('heroes', $tableName, true, - $customConstraints: 'DEFAULT \'\'', - defaultValue: const CustomExpression('\'\'')); - } - - @override - List get $columns => [ - clientId, - roomId, - membership, - highlightCount, - notificationCount, - prevBatch, - joinedMemberCount, - invitedMemberCount, - newestSortOrder, - oldestSortOrder, - heroes - ]; - @override - Rooms get asDslTable => this; - @override - String get $tableName => _alias ?? 'rooms'; - @override - final String actualTableName = 'rooms'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('room_id')) { - context.handle(_roomIdMeta, - roomId.isAcceptableOrUnknown(data['room_id'], _roomIdMeta)); - } else if (isInserting) { - context.missing(_roomIdMeta); - } - if (data.containsKey('membership')) { - context.handle( - _membershipMeta, - membership.isAcceptableOrUnknown( - data['membership'], _membershipMeta)); - } else if (isInserting) { - context.missing(_membershipMeta); - } - if (data.containsKey('highlight_count')) { - context.handle( - _highlightCountMeta, - highlightCount.isAcceptableOrUnknown( - data['highlight_count'], _highlightCountMeta)); - } - if (data.containsKey('notification_count')) { - context.handle( - _notificationCountMeta, - notificationCount.isAcceptableOrUnknown( - data['notification_count'], _notificationCountMeta)); - } - if (data.containsKey('prev_batch')) { - context.handle(_prevBatchMeta, - prevBatch.isAcceptableOrUnknown(data['prev_batch'], _prevBatchMeta)); - } - if (data.containsKey('joined_member_count')) { - context.handle( - _joinedMemberCountMeta, - joinedMemberCount.isAcceptableOrUnknown( - data['joined_member_count'], _joinedMemberCountMeta)); - } - if (data.containsKey('invited_member_count')) { - context.handle( - _invitedMemberCountMeta, - invitedMemberCount.isAcceptableOrUnknown( - data['invited_member_count'], _invitedMemberCountMeta)); - } - if (data.containsKey('newest_sort_order')) { - context.handle( - _newestSortOrderMeta, - newestSortOrder.isAcceptableOrUnknown( - data['newest_sort_order'], _newestSortOrderMeta)); - } - if (data.containsKey('oldest_sort_order')) { - context.handle( - _oldestSortOrderMeta, - oldestSortOrder.isAcceptableOrUnknown( - data['oldest_sort_order'], _oldestSortOrderMeta)); - } - if (data.containsKey('heroes')) { - context.handle(_heroesMeta, - heroes.isAcceptableOrUnknown(data['heroes'], _heroesMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbRoom map(Map data, {String tablePrefix}) { - return DbRoom.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - Rooms createAlias(String alias) { - return Rooms(_db, alias); - } - - @override - List get customConstraints => const ['UNIQUE(client_id, room_id)']; - @override - bool get dontWriteConstraints => true; -} - -class DbEvent extends DataClass implements Insertable { - final int clientId; - final String eventId; - final String roomId; - final double sortOrder; - final int originServerTs; - final String sender; - final String type; - final String unsigned; - final String content; - final String prevContent; - final String stateKey; - final int status; - DbEvent( - {@required this.clientId, - @required this.eventId, - @required this.roomId, - @required this.sortOrder, - @required this.originServerTs, - @required this.sender, - @required this.type, - this.unsigned, - this.content, - this.prevContent, - this.stateKey, - this.status}); - factory DbEvent.fromData(Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbEvent( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - eventId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}event_id']), - roomId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}room_id']), - sortOrder: const RealType() - .mapFromDatabaseResponse(data['${effectivePrefix}sort_order']), - originServerTs: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}origin_server_ts']), - sender: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}sender']), - type: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}type']), - unsigned: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}unsigned']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - prevContent: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}prev_content']), - stateKey: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}state_key']), - status: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}status']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || eventId != null) { - map['event_id'] = Variable(eventId); - } - if (!nullToAbsent || roomId != null) { - map['room_id'] = Variable(roomId); - } - if (!nullToAbsent || sortOrder != null) { - map['sort_order'] = Variable(sortOrder); - } - if (!nullToAbsent || originServerTs != null) { - map['origin_server_ts'] = Variable(originServerTs); - } - if (!nullToAbsent || sender != null) { - map['sender'] = Variable(sender); - } - if (!nullToAbsent || type != null) { - map['type'] = Variable(type); - } - if (!nullToAbsent || unsigned != null) { - map['unsigned'] = Variable(unsigned); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - if (!nullToAbsent || prevContent != null) { - map['prev_content'] = Variable(prevContent); - } - if (!nullToAbsent || stateKey != null) { - map['state_key'] = Variable(stateKey); - } - if (!nullToAbsent || status != null) { - map['status'] = Variable(status); - } - return map; - } - - EventsCompanion toCompanion(bool nullToAbsent) { - return EventsCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - eventId: eventId == null && nullToAbsent - ? const Value.absent() - : Value(eventId), - roomId: - roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), - sortOrder: sortOrder == null && nullToAbsent - ? const Value.absent() - : Value(sortOrder), - originServerTs: originServerTs == null && nullToAbsent - ? const Value.absent() - : Value(originServerTs), - sender: - sender == null && nullToAbsent ? const Value.absent() : Value(sender), - type: type == null && nullToAbsent ? const Value.absent() : Value(type), - unsigned: unsigned == null && nullToAbsent - ? const Value.absent() - : Value(unsigned), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - prevContent: prevContent == null && nullToAbsent - ? const Value.absent() - : Value(prevContent), - stateKey: stateKey == null && nullToAbsent - ? const Value.absent() - : Value(stateKey), - status: - status == null && nullToAbsent ? const Value.absent() : Value(status), - ); - } - - factory DbEvent.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbEvent( - clientId: serializer.fromJson(json['client_id']), - eventId: serializer.fromJson(json['event_id']), - roomId: serializer.fromJson(json['room_id']), - sortOrder: serializer.fromJson(json['sort_order']), - originServerTs: serializer.fromJson(json['origin_server_ts']), - sender: serializer.fromJson(json['sender']), - type: serializer.fromJson(json['type']), - unsigned: serializer.fromJson(json['unsigned']), - content: serializer.fromJson(json['content']), - prevContent: serializer.fromJson(json['prev_content']), - stateKey: serializer.fromJson(json['state_key']), - status: serializer.fromJson(json['status']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'event_id': serializer.toJson(eventId), - 'room_id': serializer.toJson(roomId), - 'sort_order': serializer.toJson(sortOrder), - 'origin_server_ts': serializer.toJson(originServerTs), - 'sender': serializer.toJson(sender), - 'type': serializer.toJson(type), - 'unsigned': serializer.toJson(unsigned), - 'content': serializer.toJson(content), - 'prev_content': serializer.toJson(prevContent), - 'state_key': serializer.toJson(stateKey), - 'status': serializer.toJson(status), - }; - } - - DbEvent copyWith( - {int clientId, - String eventId, - String roomId, - double sortOrder, - int originServerTs, - String sender, - String type, - String unsigned, - String content, - String prevContent, - String stateKey, - int status}) => - DbEvent( - clientId: clientId ?? this.clientId, - eventId: eventId ?? this.eventId, - roomId: roomId ?? this.roomId, - sortOrder: sortOrder ?? this.sortOrder, - originServerTs: originServerTs ?? this.originServerTs, - sender: sender ?? this.sender, - type: type ?? this.type, - unsigned: unsigned ?? this.unsigned, - content: content ?? this.content, - prevContent: prevContent ?? this.prevContent, - stateKey: stateKey ?? this.stateKey, - status: status ?? this.status, - ); - @override - String toString() { - return (StringBuffer('DbEvent(') - ..write('clientId: $clientId, ') - ..write('eventId: $eventId, ') - ..write('roomId: $roomId, ') - ..write('sortOrder: $sortOrder, ') - ..write('originServerTs: $originServerTs, ') - ..write('sender: $sender, ') - ..write('type: $type, ') - ..write('unsigned: $unsigned, ') - ..write('content: $content, ') - ..write('prevContent: $prevContent, ') - ..write('stateKey: $stateKey, ') - ..write('status: $status') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - eventId.hashCode, - $mrjc( - roomId.hashCode, - $mrjc( - sortOrder.hashCode, - $mrjc( - originServerTs.hashCode, - $mrjc( - sender.hashCode, - $mrjc( - type.hashCode, - $mrjc( - unsigned.hashCode, - $mrjc( - content.hashCode, - $mrjc( - prevContent.hashCode, - $mrjc(stateKey.hashCode, - status.hashCode)))))))))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbEvent && - other.clientId == this.clientId && - other.eventId == this.eventId && - other.roomId == this.roomId && - other.sortOrder == this.sortOrder && - other.originServerTs == this.originServerTs && - other.sender == this.sender && - other.type == this.type && - other.unsigned == this.unsigned && - other.content == this.content && - other.prevContent == this.prevContent && - other.stateKey == this.stateKey && - other.status == this.status); -} - -class EventsCompanion extends UpdateCompanion { - final Value clientId; - final Value eventId; - final Value roomId; - final Value sortOrder; - final Value originServerTs; - final Value sender; - final Value type; - final Value unsigned; - final Value content; - final Value prevContent; - final Value stateKey; - final Value status; - const EventsCompanion({ - this.clientId = const Value.absent(), - this.eventId = const Value.absent(), - this.roomId = const Value.absent(), - this.sortOrder = const Value.absent(), - this.originServerTs = const Value.absent(), - this.sender = const Value.absent(), - this.type = const Value.absent(), - this.unsigned = const Value.absent(), - this.content = const Value.absent(), - this.prevContent = const Value.absent(), - this.stateKey = const Value.absent(), - this.status = const Value.absent(), - }); - EventsCompanion.insert({ - @required int clientId, - @required String eventId, - @required String roomId, - @required double sortOrder, - @required int originServerTs, - @required String sender, - @required String type, - this.unsigned = const Value.absent(), - this.content = const Value.absent(), - this.prevContent = const Value.absent(), - this.stateKey = const Value.absent(), - this.status = const Value.absent(), - }) : clientId = Value(clientId), - eventId = Value(eventId), - roomId = Value(roomId), - sortOrder = Value(sortOrder), - originServerTs = Value(originServerTs), - sender = Value(sender), - type = Value(type); - static Insertable custom({ - Expression clientId, - Expression eventId, - Expression roomId, - Expression sortOrder, - Expression originServerTs, - Expression sender, - Expression type, - Expression unsigned, - Expression content, - Expression prevContent, - Expression stateKey, - Expression status, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (eventId != null) 'event_id': eventId, - if (roomId != null) 'room_id': roomId, - if (sortOrder != null) 'sort_order': sortOrder, - if (originServerTs != null) 'origin_server_ts': originServerTs, - if (sender != null) 'sender': sender, - if (type != null) 'type': type, - if (unsigned != null) 'unsigned': unsigned, - if (content != null) 'content': content, - if (prevContent != null) 'prev_content': prevContent, - if (stateKey != null) 'state_key': stateKey, - if (status != null) 'status': status, - }); - } - - EventsCompanion copyWith( - {Value clientId, - Value eventId, - Value roomId, - Value sortOrder, - Value originServerTs, - Value sender, - Value type, - Value unsigned, - Value content, - Value prevContent, - Value stateKey, - Value status}) { - return EventsCompanion( - clientId: clientId ?? this.clientId, - eventId: eventId ?? this.eventId, - roomId: roomId ?? this.roomId, - sortOrder: sortOrder ?? this.sortOrder, - originServerTs: originServerTs ?? this.originServerTs, - sender: sender ?? this.sender, - type: type ?? this.type, - unsigned: unsigned ?? this.unsigned, - content: content ?? this.content, - prevContent: prevContent ?? this.prevContent, - stateKey: stateKey ?? this.stateKey, - status: status ?? this.status, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (eventId.present) { - map['event_id'] = Variable(eventId.value); - } - if (roomId.present) { - map['room_id'] = Variable(roomId.value); - } - if (sortOrder.present) { - map['sort_order'] = Variable(sortOrder.value); - } - if (originServerTs.present) { - map['origin_server_ts'] = Variable(originServerTs.value); - } - if (sender.present) { - map['sender'] = Variable(sender.value); - } - if (type.present) { - map['type'] = Variable(type.value); - } - if (unsigned.present) { - map['unsigned'] = Variable(unsigned.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - if (prevContent.present) { - map['prev_content'] = Variable(prevContent.value); - } - if (stateKey.present) { - map['state_key'] = Variable(stateKey.value); - } - if (status.present) { - map['status'] = Variable(status.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('EventsCompanion(') - ..write('clientId: $clientId, ') - ..write('eventId: $eventId, ') - ..write('roomId: $roomId, ') - ..write('sortOrder: $sortOrder, ') - ..write('originServerTs: $originServerTs, ') - ..write('sender: $sender, ') - ..write('type: $type, ') - ..write('unsigned: $unsigned, ') - ..write('content: $content, ') - ..write('prevContent: $prevContent, ') - ..write('stateKey: $stateKey, ') - ..write('status: $status') - ..write(')')) - .toString(); - } -} - -class Events extends Table with TableInfo { - final GeneratedDatabase _db; - final String _alias; - Events(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _eventIdMeta = const VerificationMeta('eventId'); - GeneratedTextColumn _eventId; - GeneratedTextColumn get eventId => _eventId ??= _constructEventId(); - GeneratedTextColumn _constructEventId() { - return GeneratedTextColumn('event_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _roomIdMeta = const VerificationMeta('roomId'); - GeneratedTextColumn _roomId; - GeneratedTextColumn get roomId => _roomId ??= _constructRoomId(); - GeneratedTextColumn _constructRoomId() { - return GeneratedTextColumn('room_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _sortOrderMeta = const VerificationMeta('sortOrder'); - GeneratedRealColumn _sortOrder; - GeneratedRealColumn get sortOrder => _sortOrder ??= _constructSortOrder(); - GeneratedRealColumn _constructSortOrder() { - return GeneratedRealColumn('sort_order', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _originServerTsMeta = - const VerificationMeta('originServerTs'); - GeneratedIntColumn _originServerTs; - GeneratedIntColumn get originServerTs => - _originServerTs ??= _constructOriginServerTs(); - GeneratedIntColumn _constructOriginServerTs() { - return GeneratedIntColumn('origin_server_ts', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _senderMeta = const VerificationMeta('sender'); - GeneratedTextColumn _sender; - GeneratedTextColumn get sender => _sender ??= _constructSender(); - GeneratedTextColumn _constructSender() { - return GeneratedTextColumn('sender', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _typeMeta = const VerificationMeta('type'); - GeneratedTextColumn _type; - GeneratedTextColumn get type => _type ??= _constructType(); - GeneratedTextColumn _constructType() { - return GeneratedTextColumn('type', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _unsignedMeta = const VerificationMeta('unsigned'); - GeneratedTextColumn _unsigned; - GeneratedTextColumn get unsigned => _unsigned ??= _constructUnsigned(); - GeneratedTextColumn _constructUnsigned() { - return GeneratedTextColumn('unsigned', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _prevContentMeta = - const VerificationMeta('prevContent'); - GeneratedTextColumn _prevContent; - GeneratedTextColumn get prevContent => - _prevContent ??= _constructPrevContent(); - GeneratedTextColumn _constructPrevContent() { - return GeneratedTextColumn('prev_content', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _stateKeyMeta = const VerificationMeta('stateKey'); - GeneratedTextColumn _stateKey; - GeneratedTextColumn get stateKey => _stateKey ??= _constructStateKey(); - GeneratedTextColumn _constructStateKey() { - return GeneratedTextColumn('state_key', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _statusMeta = const VerificationMeta('status'); - GeneratedIntColumn _status; - GeneratedIntColumn get status => _status ??= _constructStatus(); - GeneratedIntColumn _constructStatus() { - return GeneratedIntColumn('status', $tableName, true, - $customConstraints: ''); - } - - @override - List get $columns => [ - clientId, - eventId, - roomId, - sortOrder, - originServerTs, - sender, - type, - unsigned, - content, - prevContent, - stateKey, - status - ]; - @override - Events get asDslTable => this; - @override - String get $tableName => _alias ?? 'events'; - @override - final String actualTableName = 'events'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('event_id')) { - context.handle(_eventIdMeta, - eventId.isAcceptableOrUnknown(data['event_id'], _eventIdMeta)); - } else if (isInserting) { - context.missing(_eventIdMeta); - } - if (data.containsKey('room_id')) { - context.handle(_roomIdMeta, - roomId.isAcceptableOrUnknown(data['room_id'], _roomIdMeta)); - } else if (isInserting) { - context.missing(_roomIdMeta); - } - if (data.containsKey('sort_order')) { - context.handle(_sortOrderMeta, - sortOrder.isAcceptableOrUnknown(data['sort_order'], _sortOrderMeta)); - } else if (isInserting) { - context.missing(_sortOrderMeta); - } - if (data.containsKey('origin_server_ts')) { - context.handle( - _originServerTsMeta, - originServerTs.isAcceptableOrUnknown( - data['origin_server_ts'], _originServerTsMeta)); - } else if (isInserting) { - context.missing(_originServerTsMeta); - } - if (data.containsKey('sender')) { - context.handle(_senderMeta, - sender.isAcceptableOrUnknown(data['sender'], _senderMeta)); - } else if (isInserting) { - context.missing(_senderMeta); - } - if (data.containsKey('type')) { - context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type'], _typeMeta)); - } else if (isInserting) { - context.missing(_typeMeta); - } - if (data.containsKey('unsigned')) { - context.handle(_unsignedMeta, - unsigned.isAcceptableOrUnknown(data['unsigned'], _unsignedMeta)); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } - if (data.containsKey('prev_content')) { - context.handle( - _prevContentMeta, - prevContent.isAcceptableOrUnknown( - data['prev_content'], _prevContentMeta)); - } - if (data.containsKey('state_key')) { - context.handle(_stateKeyMeta, - stateKey.isAcceptableOrUnknown(data['state_key'], _stateKeyMeta)); - } - if (data.containsKey('status')) { - context.handle(_statusMeta, - status.isAcceptableOrUnknown(data['status'], _statusMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbEvent map(Map data, {String tablePrefix}) { - return DbEvent.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - Events createAlias(String alias) { - return Events(_db, alias); - } - - @override - List get customConstraints => - const ['UNIQUE(client_id, event_id, room_id)']; - @override - bool get dontWriteConstraints => true; -} - -class DbRoomState extends DataClass implements Insertable { - final int clientId; - final String eventId; - final String roomId; - final double sortOrder; - final int originServerTs; - final String sender; - final String type; - final String unsigned; - final String content; - final String prevContent; - final String stateKey; - DbRoomState( - {@required this.clientId, - @required this.eventId, - @required this.roomId, - @required this.sortOrder, - @required this.originServerTs, - @required this.sender, - @required this.type, - this.unsigned, - this.content, - this.prevContent, - @required this.stateKey}); - factory DbRoomState.fromData(Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbRoomState( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - eventId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}event_id']), - roomId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}room_id']), - sortOrder: const RealType() - .mapFromDatabaseResponse(data['${effectivePrefix}sort_order']), - originServerTs: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}origin_server_ts']), - sender: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}sender']), - type: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}type']), - unsigned: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}unsigned']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - prevContent: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}prev_content']), - stateKey: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}state_key']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || eventId != null) { - map['event_id'] = Variable(eventId); - } - if (!nullToAbsent || roomId != null) { - map['room_id'] = Variable(roomId); - } - if (!nullToAbsent || sortOrder != null) { - map['sort_order'] = Variable(sortOrder); - } - if (!nullToAbsent || originServerTs != null) { - map['origin_server_ts'] = Variable(originServerTs); - } - if (!nullToAbsent || sender != null) { - map['sender'] = Variable(sender); - } - if (!nullToAbsent || type != null) { - map['type'] = Variable(type); - } - if (!nullToAbsent || unsigned != null) { - map['unsigned'] = Variable(unsigned); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - if (!nullToAbsent || prevContent != null) { - map['prev_content'] = Variable(prevContent); - } - if (!nullToAbsent || stateKey != null) { - map['state_key'] = Variable(stateKey); - } - return map; - } - - RoomStatesCompanion toCompanion(bool nullToAbsent) { - return RoomStatesCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - eventId: eventId == null && nullToAbsent - ? const Value.absent() - : Value(eventId), - roomId: - roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), - sortOrder: sortOrder == null && nullToAbsent - ? const Value.absent() - : Value(sortOrder), - originServerTs: originServerTs == null && nullToAbsent - ? const Value.absent() - : Value(originServerTs), - sender: - sender == null && nullToAbsent ? const Value.absent() : Value(sender), - type: type == null && nullToAbsent ? const Value.absent() : Value(type), - unsigned: unsigned == null && nullToAbsent - ? const Value.absent() - : Value(unsigned), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - prevContent: prevContent == null && nullToAbsent - ? const Value.absent() - : Value(prevContent), - stateKey: stateKey == null && nullToAbsent - ? const Value.absent() - : Value(stateKey), - ); - } - - factory DbRoomState.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbRoomState( - clientId: serializer.fromJson(json['client_id']), - eventId: serializer.fromJson(json['event_id']), - roomId: serializer.fromJson(json['room_id']), - sortOrder: serializer.fromJson(json['sort_order']), - originServerTs: serializer.fromJson(json['origin_server_ts']), - sender: serializer.fromJson(json['sender']), - type: serializer.fromJson(json['type']), - unsigned: serializer.fromJson(json['unsigned']), - content: serializer.fromJson(json['content']), - prevContent: serializer.fromJson(json['prev_content']), - stateKey: serializer.fromJson(json['state_key']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'event_id': serializer.toJson(eventId), - 'room_id': serializer.toJson(roomId), - 'sort_order': serializer.toJson(sortOrder), - 'origin_server_ts': serializer.toJson(originServerTs), - 'sender': serializer.toJson(sender), - 'type': serializer.toJson(type), - 'unsigned': serializer.toJson(unsigned), - 'content': serializer.toJson(content), - 'prev_content': serializer.toJson(prevContent), - 'state_key': serializer.toJson(stateKey), - }; - } - - DbRoomState copyWith( - {int clientId, - String eventId, - String roomId, - double sortOrder, - int originServerTs, - String sender, - String type, - String unsigned, - String content, - String prevContent, - String stateKey}) => - DbRoomState( - clientId: clientId ?? this.clientId, - eventId: eventId ?? this.eventId, - roomId: roomId ?? this.roomId, - sortOrder: sortOrder ?? this.sortOrder, - originServerTs: originServerTs ?? this.originServerTs, - sender: sender ?? this.sender, - type: type ?? this.type, - unsigned: unsigned ?? this.unsigned, - content: content ?? this.content, - prevContent: prevContent ?? this.prevContent, - stateKey: stateKey ?? this.stateKey, - ); - @override - String toString() { - return (StringBuffer('DbRoomState(') - ..write('clientId: $clientId, ') - ..write('eventId: $eventId, ') - ..write('roomId: $roomId, ') - ..write('sortOrder: $sortOrder, ') - ..write('originServerTs: $originServerTs, ') - ..write('sender: $sender, ') - ..write('type: $type, ') - ..write('unsigned: $unsigned, ') - ..write('content: $content, ') - ..write('prevContent: $prevContent, ') - ..write('stateKey: $stateKey') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - eventId.hashCode, - $mrjc( - roomId.hashCode, - $mrjc( - sortOrder.hashCode, - $mrjc( - originServerTs.hashCode, - $mrjc( - sender.hashCode, - $mrjc( - type.hashCode, - $mrjc( - unsigned.hashCode, - $mrjc( - content.hashCode, - $mrjc(prevContent.hashCode, - stateKey.hashCode))))))))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbRoomState && - other.clientId == this.clientId && - other.eventId == this.eventId && - other.roomId == this.roomId && - other.sortOrder == this.sortOrder && - other.originServerTs == this.originServerTs && - other.sender == this.sender && - other.type == this.type && - other.unsigned == this.unsigned && - other.content == this.content && - other.prevContent == this.prevContent && - other.stateKey == this.stateKey); -} - -class RoomStatesCompanion extends UpdateCompanion { - final Value clientId; - final Value eventId; - final Value roomId; - final Value sortOrder; - final Value originServerTs; - final Value sender; - final Value type; - final Value unsigned; - final Value content; - final Value prevContent; - final Value stateKey; - const RoomStatesCompanion({ - this.clientId = const Value.absent(), - this.eventId = const Value.absent(), - this.roomId = const Value.absent(), - this.sortOrder = const Value.absent(), - this.originServerTs = const Value.absent(), - this.sender = const Value.absent(), - this.type = const Value.absent(), - this.unsigned = const Value.absent(), - this.content = const Value.absent(), - this.prevContent = const Value.absent(), - this.stateKey = const Value.absent(), - }); - RoomStatesCompanion.insert({ - @required int clientId, - @required String eventId, - @required String roomId, - @required double sortOrder, - @required int originServerTs, - @required String sender, - @required String type, - this.unsigned = const Value.absent(), - this.content = const Value.absent(), - this.prevContent = const Value.absent(), - @required String stateKey, - }) : clientId = Value(clientId), - eventId = Value(eventId), - roomId = Value(roomId), - sortOrder = Value(sortOrder), - originServerTs = Value(originServerTs), - sender = Value(sender), - type = Value(type), - stateKey = Value(stateKey); - static Insertable custom({ - Expression clientId, - Expression eventId, - Expression roomId, - Expression sortOrder, - Expression originServerTs, - Expression sender, - Expression type, - Expression unsigned, - Expression content, - Expression prevContent, - Expression stateKey, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (eventId != null) 'event_id': eventId, - if (roomId != null) 'room_id': roomId, - if (sortOrder != null) 'sort_order': sortOrder, - if (originServerTs != null) 'origin_server_ts': originServerTs, - if (sender != null) 'sender': sender, - if (type != null) 'type': type, - if (unsigned != null) 'unsigned': unsigned, - if (content != null) 'content': content, - if (prevContent != null) 'prev_content': prevContent, - if (stateKey != null) 'state_key': stateKey, - }); - } - - RoomStatesCompanion copyWith( - {Value clientId, - Value eventId, - Value roomId, - Value sortOrder, - Value originServerTs, - Value sender, - Value type, - Value unsigned, - Value content, - Value prevContent, - Value stateKey}) { - return RoomStatesCompanion( - clientId: clientId ?? this.clientId, - eventId: eventId ?? this.eventId, - roomId: roomId ?? this.roomId, - sortOrder: sortOrder ?? this.sortOrder, - originServerTs: originServerTs ?? this.originServerTs, - sender: sender ?? this.sender, - type: type ?? this.type, - unsigned: unsigned ?? this.unsigned, - content: content ?? this.content, - prevContent: prevContent ?? this.prevContent, - stateKey: stateKey ?? this.stateKey, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (eventId.present) { - map['event_id'] = Variable(eventId.value); - } - if (roomId.present) { - map['room_id'] = Variable(roomId.value); - } - if (sortOrder.present) { - map['sort_order'] = Variable(sortOrder.value); - } - if (originServerTs.present) { - map['origin_server_ts'] = Variable(originServerTs.value); - } - if (sender.present) { - map['sender'] = Variable(sender.value); - } - if (type.present) { - map['type'] = Variable(type.value); - } - if (unsigned.present) { - map['unsigned'] = Variable(unsigned.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - if (prevContent.present) { - map['prev_content'] = Variable(prevContent.value); - } - if (stateKey.present) { - map['state_key'] = Variable(stateKey.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('RoomStatesCompanion(') - ..write('clientId: $clientId, ') - ..write('eventId: $eventId, ') - ..write('roomId: $roomId, ') - ..write('sortOrder: $sortOrder, ') - ..write('originServerTs: $originServerTs, ') - ..write('sender: $sender, ') - ..write('type: $type, ') - ..write('unsigned: $unsigned, ') - ..write('content: $content, ') - ..write('prevContent: $prevContent, ') - ..write('stateKey: $stateKey') - ..write(')')) - .toString(); - } -} - -class RoomStates extends Table with TableInfo { - final GeneratedDatabase _db; - final String _alias; - RoomStates(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _eventIdMeta = const VerificationMeta('eventId'); - GeneratedTextColumn _eventId; - GeneratedTextColumn get eventId => _eventId ??= _constructEventId(); - GeneratedTextColumn _constructEventId() { - return GeneratedTextColumn('event_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _roomIdMeta = const VerificationMeta('roomId'); - GeneratedTextColumn _roomId; - GeneratedTextColumn get roomId => _roomId ??= _constructRoomId(); - GeneratedTextColumn _constructRoomId() { - return GeneratedTextColumn('room_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _sortOrderMeta = const VerificationMeta('sortOrder'); - GeneratedRealColumn _sortOrder; - GeneratedRealColumn get sortOrder => _sortOrder ??= _constructSortOrder(); - GeneratedRealColumn _constructSortOrder() { - return GeneratedRealColumn('sort_order', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _originServerTsMeta = - const VerificationMeta('originServerTs'); - GeneratedIntColumn _originServerTs; - GeneratedIntColumn get originServerTs => - _originServerTs ??= _constructOriginServerTs(); - GeneratedIntColumn _constructOriginServerTs() { - return GeneratedIntColumn('origin_server_ts', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _senderMeta = const VerificationMeta('sender'); - GeneratedTextColumn _sender; - GeneratedTextColumn get sender => _sender ??= _constructSender(); - GeneratedTextColumn _constructSender() { - return GeneratedTextColumn('sender', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _typeMeta = const VerificationMeta('type'); - GeneratedTextColumn _type; - GeneratedTextColumn get type => _type ??= _constructType(); - GeneratedTextColumn _constructType() { - return GeneratedTextColumn('type', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _unsignedMeta = const VerificationMeta('unsigned'); - GeneratedTextColumn _unsigned; - GeneratedTextColumn get unsigned => _unsigned ??= _constructUnsigned(); - GeneratedTextColumn _constructUnsigned() { - return GeneratedTextColumn('unsigned', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _prevContentMeta = - const VerificationMeta('prevContent'); - GeneratedTextColumn _prevContent; - GeneratedTextColumn get prevContent => - _prevContent ??= _constructPrevContent(); - GeneratedTextColumn _constructPrevContent() { - return GeneratedTextColumn('prev_content', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _stateKeyMeta = const VerificationMeta('stateKey'); - GeneratedTextColumn _stateKey; - GeneratedTextColumn get stateKey => _stateKey ??= _constructStateKey(); - GeneratedTextColumn _constructStateKey() { - return GeneratedTextColumn('state_key', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - @override - List get $columns => [ - clientId, - eventId, - roomId, - sortOrder, - originServerTs, - sender, - type, - unsigned, - content, - prevContent, - stateKey - ]; - @override - RoomStates get asDslTable => this; - @override - String get $tableName => _alias ?? 'room_states'; - @override - final String actualTableName = 'room_states'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('event_id')) { - context.handle(_eventIdMeta, - eventId.isAcceptableOrUnknown(data['event_id'], _eventIdMeta)); - } else if (isInserting) { - context.missing(_eventIdMeta); - } - if (data.containsKey('room_id')) { - context.handle(_roomIdMeta, - roomId.isAcceptableOrUnknown(data['room_id'], _roomIdMeta)); - } else if (isInserting) { - context.missing(_roomIdMeta); - } - if (data.containsKey('sort_order')) { - context.handle(_sortOrderMeta, - sortOrder.isAcceptableOrUnknown(data['sort_order'], _sortOrderMeta)); - } else if (isInserting) { - context.missing(_sortOrderMeta); - } - if (data.containsKey('origin_server_ts')) { - context.handle( - _originServerTsMeta, - originServerTs.isAcceptableOrUnknown( - data['origin_server_ts'], _originServerTsMeta)); - } else if (isInserting) { - context.missing(_originServerTsMeta); - } - if (data.containsKey('sender')) { - context.handle(_senderMeta, - sender.isAcceptableOrUnknown(data['sender'], _senderMeta)); - } else if (isInserting) { - context.missing(_senderMeta); - } - if (data.containsKey('type')) { - context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type'], _typeMeta)); - } else if (isInserting) { - context.missing(_typeMeta); - } - if (data.containsKey('unsigned')) { - context.handle(_unsignedMeta, - unsigned.isAcceptableOrUnknown(data['unsigned'], _unsignedMeta)); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } - if (data.containsKey('prev_content')) { - context.handle( - _prevContentMeta, - prevContent.isAcceptableOrUnknown( - data['prev_content'], _prevContentMeta)); - } - if (data.containsKey('state_key')) { - context.handle(_stateKeyMeta, - stateKey.isAcceptableOrUnknown(data['state_key'], _stateKeyMeta)); - } else if (isInserting) { - context.missing(_stateKeyMeta); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbRoomState map(Map data, {String tablePrefix}) { - return DbRoomState.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - RoomStates createAlias(String alias) { - return RoomStates(_db, alias); - } - - @override - List get customConstraints => const [ - 'UNIQUE(client_id, event_id, room_id)', - 'UNIQUE(client_id, room_id, state_key, type)' - ]; - @override - bool get dontWriteConstraints => true; -} - -class DbAccountData extends DataClass implements Insertable { - final int clientId; - final String type; - final String content; - DbAccountData({@required this.clientId, @required this.type, this.content}); - factory DbAccountData.fromData( - Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbAccountData( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - type: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}type']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || type != null) { - map['type'] = Variable(type); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - return map; - } - - AccountDataCompanion toCompanion(bool nullToAbsent) { - return AccountDataCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - type: type == null && nullToAbsent ? const Value.absent() : Value(type), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - ); - } - - factory DbAccountData.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbAccountData( - clientId: serializer.fromJson(json['client_id']), - type: serializer.fromJson(json['type']), - content: serializer.fromJson(json['content']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'type': serializer.toJson(type), - 'content': serializer.toJson(content), - }; - } - - DbAccountData copyWith({int clientId, String type, String content}) => - DbAccountData( - clientId: clientId ?? this.clientId, - type: type ?? this.type, - content: content ?? this.content, - ); - @override - String toString() { - return (StringBuffer('DbAccountData(') - ..write('clientId: $clientId, ') - ..write('type: $type, ') - ..write('content: $content') - ..write(')')) - .toString(); - } - - @override - int get hashCode => - $mrjf($mrjc(clientId.hashCode, $mrjc(type.hashCode, content.hashCode))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbAccountData && - other.clientId == this.clientId && - other.type == this.type && - other.content == this.content); -} - -class AccountDataCompanion extends UpdateCompanion { - final Value clientId; - final Value type; - final Value content; - const AccountDataCompanion({ - this.clientId = const Value.absent(), - this.type = const Value.absent(), - this.content = const Value.absent(), - }); - AccountDataCompanion.insert({ - @required int clientId, - @required String type, - this.content = const Value.absent(), - }) : clientId = Value(clientId), - type = Value(type); - static Insertable custom({ - Expression clientId, - Expression type, - Expression content, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (type != null) 'type': type, - if (content != null) 'content': content, - }); - } - - AccountDataCompanion copyWith( - {Value clientId, Value type, Value content}) { - return AccountDataCompanion( - clientId: clientId ?? this.clientId, - type: type ?? this.type, - content: content ?? this.content, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (type.present) { - map['type'] = Variable(type.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('AccountDataCompanion(') - ..write('clientId: $clientId, ') - ..write('type: $type, ') - ..write('content: $content') - ..write(')')) - .toString(); - } -} - -class AccountData extends Table with TableInfo { - final GeneratedDatabase _db; - final String _alias; - AccountData(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _typeMeta = const VerificationMeta('type'); - GeneratedTextColumn _type; - GeneratedTextColumn get type => _type ??= _constructType(); - GeneratedTextColumn _constructType() { - return GeneratedTextColumn('type', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, true, - $customConstraints: ''); - } - - @override - List get $columns => [clientId, type, content]; - @override - AccountData get asDslTable => this; - @override - String get $tableName => _alias ?? 'account_data'; - @override - final String actualTableName = 'account_data'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('type')) { - context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type'], _typeMeta)); - } else if (isInserting) { - context.missing(_typeMeta); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbAccountData map(Map data, {String tablePrefix}) { - return DbAccountData.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - AccountData createAlias(String alias) { - return AccountData(_db, alias); - } - - @override - List get customConstraints => const ['UNIQUE(client_id, type)']; - @override - bool get dontWriteConstraints => true; -} - -class DbRoomAccountData extends DataClass - implements Insertable { - final int clientId; - final String type; - final String roomId; - final String content; - DbRoomAccountData( - {@required this.clientId, - @required this.type, - @required this.roomId, - this.content}); - factory DbRoomAccountData.fromData( - Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbRoomAccountData( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - type: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}type']), - roomId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}room_id']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || type != null) { - map['type'] = Variable(type); - } - if (!nullToAbsent || roomId != null) { - map['room_id'] = Variable(roomId); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - return map; - } - - RoomAccountDataCompanion toCompanion(bool nullToAbsent) { - return RoomAccountDataCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - type: type == null && nullToAbsent ? const Value.absent() : Value(type), - roomId: - roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - ); - } - - factory DbRoomAccountData.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbRoomAccountData( - clientId: serializer.fromJson(json['client_id']), - type: serializer.fromJson(json['type']), - roomId: serializer.fromJson(json['room_id']), - content: serializer.fromJson(json['content']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'type': serializer.toJson(type), - 'room_id': serializer.toJson(roomId), - 'content': serializer.toJson(content), - }; - } - - DbRoomAccountData copyWith( - {int clientId, String type, String roomId, String content}) => - DbRoomAccountData( - clientId: clientId ?? this.clientId, - type: type ?? this.type, - roomId: roomId ?? this.roomId, - content: content ?? this.content, - ); - @override - String toString() { - return (StringBuffer('DbRoomAccountData(') - ..write('clientId: $clientId, ') - ..write('type: $type, ') - ..write('roomId: $roomId, ') - ..write('content: $content') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc(clientId.hashCode, - $mrjc(type.hashCode, $mrjc(roomId.hashCode, content.hashCode)))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbRoomAccountData && - other.clientId == this.clientId && - other.type == this.type && - other.roomId == this.roomId && - other.content == this.content); -} - -class RoomAccountDataCompanion extends UpdateCompanion { - final Value clientId; - final Value type; - final Value roomId; - final Value content; - const RoomAccountDataCompanion({ - this.clientId = const Value.absent(), - this.type = const Value.absent(), - this.roomId = const Value.absent(), - this.content = const Value.absent(), - }); - RoomAccountDataCompanion.insert({ - @required int clientId, - @required String type, - @required String roomId, - this.content = const Value.absent(), - }) : clientId = Value(clientId), - type = Value(type), - roomId = Value(roomId); - static Insertable custom({ - Expression clientId, - Expression type, - Expression roomId, - Expression content, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (type != null) 'type': type, - if (roomId != null) 'room_id': roomId, - if (content != null) 'content': content, - }); - } - - RoomAccountDataCompanion copyWith( - {Value clientId, - Value type, - Value roomId, - Value content}) { - return RoomAccountDataCompanion( - clientId: clientId ?? this.clientId, - type: type ?? this.type, - roomId: roomId ?? this.roomId, - content: content ?? this.content, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (type.present) { - map['type'] = Variable(type.value); - } - if (roomId.present) { - map['room_id'] = Variable(roomId.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('RoomAccountDataCompanion(') - ..write('clientId: $clientId, ') - ..write('type: $type, ') - ..write('roomId: $roomId, ') - ..write('content: $content') - ..write(')')) - .toString(); - } -} - -class RoomAccountData extends Table - with TableInfo { - final GeneratedDatabase _db; - final String _alias; - RoomAccountData(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _typeMeta = const VerificationMeta('type'); - GeneratedTextColumn _type; - GeneratedTextColumn get type => _type ??= _constructType(); - GeneratedTextColumn _constructType() { - return GeneratedTextColumn('type', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _roomIdMeta = const VerificationMeta('roomId'); - GeneratedTextColumn _roomId; - GeneratedTextColumn get roomId => _roomId ??= _constructRoomId(); - GeneratedTextColumn _constructRoomId() { - return GeneratedTextColumn('room_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, true, - $customConstraints: ''); - } - - @override - List get $columns => [clientId, type, roomId, content]; - @override - RoomAccountData get asDslTable => this; - @override - String get $tableName => _alias ?? 'room_account_data'; - @override - final String actualTableName = 'room_account_data'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('type')) { - context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type'], _typeMeta)); - } else if (isInserting) { - context.missing(_typeMeta); - } - if (data.containsKey('room_id')) { - context.handle(_roomIdMeta, - roomId.isAcceptableOrUnknown(data['room_id'], _roomIdMeta)); - } else if (isInserting) { - context.missing(_roomIdMeta); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbRoomAccountData map(Map data, {String tablePrefix}) { - return DbRoomAccountData.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - RoomAccountData createAlias(String alias) { - return RoomAccountData(_db, alias); - } - - @override - List get customConstraints => - const ['UNIQUE(client_id, type, room_id)']; - @override - bool get dontWriteConstraints => true; -} - -class DbPresence extends DataClass implements Insertable { - final int clientId; - final String type; - final String sender; - final String content; - DbPresence( - {@required this.clientId, - @required this.type, - @required this.sender, - this.content}); - factory DbPresence.fromData(Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbPresence( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - type: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}type']), - sender: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}sender']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || type != null) { - map['type'] = Variable(type); - } - if (!nullToAbsent || sender != null) { - map['sender'] = Variable(sender); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - return map; - } - - PresencesCompanion toCompanion(bool nullToAbsent) { - return PresencesCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - type: type == null && nullToAbsent ? const Value.absent() : Value(type), - sender: - sender == null && nullToAbsent ? const Value.absent() : Value(sender), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - ); - } - - factory DbPresence.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbPresence( - clientId: serializer.fromJson(json['client_id']), - type: serializer.fromJson(json['type']), - sender: serializer.fromJson(json['sender']), - content: serializer.fromJson(json['content']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'type': serializer.toJson(type), - 'sender': serializer.toJson(sender), - 'content': serializer.toJson(content), - }; - } - - DbPresence copyWith( - {int clientId, String type, String sender, String content}) => - DbPresence( - clientId: clientId ?? this.clientId, - type: type ?? this.type, - sender: sender ?? this.sender, - content: content ?? this.content, - ); - @override - String toString() { - return (StringBuffer('DbPresence(') - ..write('clientId: $clientId, ') - ..write('type: $type, ') - ..write('sender: $sender, ') - ..write('content: $content') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc(clientId.hashCode, - $mrjc(type.hashCode, $mrjc(sender.hashCode, content.hashCode)))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbPresence && - other.clientId == this.clientId && - other.type == this.type && - other.sender == this.sender && - other.content == this.content); -} - -class PresencesCompanion extends UpdateCompanion { - final Value clientId; - final Value type; - final Value sender; - final Value content; - const PresencesCompanion({ - this.clientId = const Value.absent(), - this.type = const Value.absent(), - this.sender = const Value.absent(), - this.content = const Value.absent(), - }); - PresencesCompanion.insert({ - @required int clientId, - @required String type, - @required String sender, - this.content = const Value.absent(), - }) : clientId = Value(clientId), - type = Value(type), - sender = Value(sender); - static Insertable custom({ - Expression clientId, - Expression type, - Expression sender, - Expression content, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (type != null) 'type': type, - if (sender != null) 'sender': sender, - if (content != null) 'content': content, - }); - } - - PresencesCompanion copyWith( - {Value clientId, - Value type, - Value sender, - Value content}) { - return PresencesCompanion( - clientId: clientId ?? this.clientId, - type: type ?? this.type, - sender: sender ?? this.sender, - content: content ?? this.content, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (type.present) { - map['type'] = Variable(type.value); - } - if (sender.present) { - map['sender'] = Variable(sender.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('PresencesCompanion(') - ..write('clientId: $clientId, ') - ..write('type: $type, ') - ..write('sender: $sender, ') - ..write('content: $content') - ..write(')')) - .toString(); - } -} - -class Presences extends Table with TableInfo { - final GeneratedDatabase _db; - final String _alias; - Presences(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _typeMeta = const VerificationMeta('type'); - GeneratedTextColumn _type; - GeneratedTextColumn get type => _type ??= _constructType(); - GeneratedTextColumn _constructType() { - return GeneratedTextColumn('type', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _senderMeta = const VerificationMeta('sender'); - GeneratedTextColumn _sender; - GeneratedTextColumn get sender => _sender ??= _constructSender(); - GeneratedTextColumn _constructSender() { - return GeneratedTextColumn('sender', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, true, - $customConstraints: ''); - } - - @override - List get $columns => [clientId, type, sender, content]; - @override - Presences get asDslTable => this; - @override - String get $tableName => _alias ?? 'presences'; - @override - final String actualTableName = 'presences'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('type')) { - context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type'], _typeMeta)); - } else if (isInserting) { - context.missing(_typeMeta); - } - if (data.containsKey('sender')) { - context.handle(_senderMeta, - sender.isAcceptableOrUnknown(data['sender'], _senderMeta)); - } else if (isInserting) { - context.missing(_senderMeta); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbPresence map(Map data, {String tablePrefix}) { - return DbPresence.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - Presences createAlias(String alias) { - return Presences(_db, alias); - } - - @override - List get customConstraints => - const ['UNIQUE(client_id, type, sender)']; - @override - bool get dontWriteConstraints => true; -} - -class DbToDeviceQueue extends DataClass implements Insertable { - final int clientId; - final int id; - final String type; - final String txnId; - final String content; - DbToDeviceQueue( - {@required this.clientId, - @required this.id, - @required this.type, - @required this.txnId, - @required this.content}); - factory DbToDeviceQueue.fromData( - Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbToDeviceQueue( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - id: const IntType().mapFromDatabaseResponse(data['${effectivePrefix}id']), - type: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}type']), - txnId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}txn_id']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || id != null) { - map['id'] = Variable(id); - } - if (!nullToAbsent || type != null) { - map['type'] = Variable(type); - } - if (!nullToAbsent || txnId != null) { - map['txn_id'] = Variable(txnId); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - return map; - } - - ToDeviceQueueCompanion toCompanion(bool nullToAbsent) { - return ToDeviceQueueCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - id: id == null && nullToAbsent ? const Value.absent() : Value(id), - type: type == null && nullToAbsent ? const Value.absent() : Value(type), - txnId: - txnId == null && nullToAbsent ? const Value.absent() : Value(txnId), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - ); - } - - factory DbToDeviceQueue.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbToDeviceQueue( - clientId: serializer.fromJson(json['client_id']), - id: serializer.fromJson(json['id']), - type: serializer.fromJson(json['type']), - txnId: serializer.fromJson(json['txn_id']), - content: serializer.fromJson(json['content']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'id': serializer.toJson(id), - 'type': serializer.toJson(type), - 'txn_id': serializer.toJson(txnId), - 'content': serializer.toJson(content), - }; - } - - DbToDeviceQueue copyWith( - {int clientId, int id, String type, String txnId, String content}) => - DbToDeviceQueue( - clientId: clientId ?? this.clientId, - id: id ?? this.id, - type: type ?? this.type, - txnId: txnId ?? this.txnId, - content: content ?? this.content, - ); - @override - String toString() { - return (StringBuffer('DbToDeviceQueue(') - ..write('clientId: $clientId, ') - ..write('id: $id, ') - ..write('type: $type, ') - ..write('txnId: $txnId, ') - ..write('content: $content') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc(id.hashCode, - $mrjc(type.hashCode, $mrjc(txnId.hashCode, content.hashCode))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbToDeviceQueue && - other.clientId == this.clientId && - other.id == this.id && - other.type == this.type && - other.txnId == this.txnId && - other.content == this.content); -} - -class ToDeviceQueueCompanion extends UpdateCompanion { - final Value clientId; - final Value id; - final Value type; - final Value txnId; - final Value content; - const ToDeviceQueueCompanion({ - this.clientId = const Value.absent(), - this.id = const Value.absent(), - this.type = const Value.absent(), - this.txnId = const Value.absent(), - this.content = const Value.absent(), - }); - ToDeviceQueueCompanion.insert({ - @required int clientId, - this.id = const Value.absent(), - @required String type, - @required String txnId, - @required String content, - }) : clientId = Value(clientId), - type = Value(type), - txnId = Value(txnId), - content = Value(content); - static Insertable custom({ - Expression clientId, - Expression id, - Expression type, - Expression txnId, - Expression content, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (id != null) 'id': id, - if (type != null) 'type': type, - if (txnId != null) 'txn_id': txnId, - if (content != null) 'content': content, - }); - } - - ToDeviceQueueCompanion copyWith( - {Value clientId, - Value id, - Value type, - Value txnId, - Value content}) { - return ToDeviceQueueCompanion( - clientId: clientId ?? this.clientId, - id: id ?? this.id, - type: type ?? this.type, - txnId: txnId ?? this.txnId, - content: content ?? this.content, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (id.present) { - map['id'] = Variable(id.value); - } - if (type.present) { - map['type'] = Variable(type.value); - } - if (txnId.present) { - map['txn_id'] = Variable(txnId.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('ToDeviceQueueCompanion(') - ..write('clientId: $clientId, ') - ..write('id: $id, ') - ..write('type: $type, ') - ..write('txnId: $txnId, ') - ..write('content: $content') - ..write(')')) - .toString(); - } -} - -class ToDeviceQueue extends Table - with TableInfo { - final GeneratedDatabase _db; - final String _alias; - ToDeviceQueue(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _idMeta = const VerificationMeta('id'); - GeneratedIntColumn _id; - GeneratedIntColumn get id => _id ??= _constructId(); - GeneratedIntColumn _constructId() { - return GeneratedIntColumn('id', $tableName, false, - declaredAsPrimaryKey: true, - hasAutoIncrement: true, - $customConstraints: 'NOT NULL PRIMARY KEY AUTOINCREMENT'); - } - - final VerificationMeta _typeMeta = const VerificationMeta('type'); - GeneratedTextColumn _type; - GeneratedTextColumn get type => _type ??= _constructType(); - GeneratedTextColumn _constructType() { - return GeneratedTextColumn('type', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _txnIdMeta = const VerificationMeta('txnId'); - GeneratedTextColumn _txnId; - GeneratedTextColumn get txnId => _txnId ??= _constructTxnId(); - GeneratedTextColumn _constructTxnId() { - return GeneratedTextColumn('txn_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - @override - List get $columns => [clientId, id, type, txnId, content]; - @override - ToDeviceQueue get asDslTable => this; - @override - String get $tableName => _alias ?? 'to_device_queue'; - @override - final String actualTableName = 'to_device_queue'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('id')) { - context.handle(_idMeta, id.isAcceptableOrUnknown(data['id'], _idMeta)); - } - if (data.containsKey('type')) { - context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type'], _typeMeta)); - } else if (isInserting) { - context.missing(_typeMeta); - } - if (data.containsKey('txn_id')) { - context.handle( - _txnIdMeta, txnId.isAcceptableOrUnknown(data['txn_id'], _txnIdMeta)); - } else if (isInserting) { - context.missing(_txnIdMeta); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } else if (isInserting) { - context.missing(_contentMeta); - } - return context; - } - - @override - Set get $primaryKey => {id}; - @override - DbToDeviceQueue map(Map data, {String tablePrefix}) { - return DbToDeviceQueue.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - ToDeviceQueue createAlias(String alias) { - return ToDeviceQueue(_db, alias); - } - - @override - bool get dontWriteConstraints => true; -} - -class DbSSSSCache extends DataClass implements Insertable { - final int clientId; - final String type; - final String keyId; - final String ciphertext; - final String content; - DbSSSSCache( - {@required this.clientId, - @required this.type, - @required this.keyId, - @required this.ciphertext, - @required this.content}); - factory DbSSSSCache.fromData(Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbSSSSCache( - clientId: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}client_id']), - type: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}type']), - keyId: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}key_id']), - ciphertext: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}ciphertext']), - content: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}content']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || clientId != null) { - map['client_id'] = Variable(clientId); - } - if (!nullToAbsent || type != null) { - map['type'] = Variable(type); - } - if (!nullToAbsent || keyId != null) { - map['key_id'] = Variable(keyId); - } - if (!nullToAbsent || ciphertext != null) { - map['ciphertext'] = Variable(ciphertext); - } - if (!nullToAbsent || content != null) { - map['content'] = Variable(content); - } - return map; - } - - SsssCacheCompanion toCompanion(bool nullToAbsent) { - return SsssCacheCompanion( - clientId: clientId == null && nullToAbsent - ? const Value.absent() - : Value(clientId), - type: type == null && nullToAbsent ? const Value.absent() : Value(type), - keyId: - keyId == null && nullToAbsent ? const Value.absent() : Value(keyId), - ciphertext: ciphertext == null && nullToAbsent - ? const Value.absent() - : Value(ciphertext), - content: content == null && nullToAbsent - ? const Value.absent() - : Value(content), - ); - } - - factory DbSSSSCache.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbSSSSCache( - clientId: serializer.fromJson(json['client_id']), - type: serializer.fromJson(json['type']), - keyId: serializer.fromJson(json['key_id']), - ciphertext: serializer.fromJson(json['ciphertext']), - content: serializer.fromJson(json['content']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'client_id': serializer.toJson(clientId), - 'type': serializer.toJson(type), - 'key_id': serializer.toJson(keyId), - 'ciphertext': serializer.toJson(ciphertext), - 'content': serializer.toJson(content), - }; - } - - DbSSSSCache copyWith( - {int clientId, - String type, - String keyId, - String ciphertext, - String content}) => - DbSSSSCache( - clientId: clientId ?? this.clientId, - type: type ?? this.type, - keyId: keyId ?? this.keyId, - ciphertext: ciphertext ?? this.ciphertext, - content: content ?? this.content, - ); - @override - String toString() { - return (StringBuffer('DbSSSSCache(') - ..write('clientId: $clientId, ') - ..write('type: $type, ') - ..write('keyId: $keyId, ') - ..write('ciphertext: $ciphertext, ') - ..write('content: $content') - ..write(')')) - .toString(); - } - - @override - int get hashCode => $mrjf($mrjc( - clientId.hashCode, - $mrjc( - type.hashCode, - $mrjc( - keyId.hashCode, $mrjc(ciphertext.hashCode, content.hashCode))))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbSSSSCache && - other.clientId == this.clientId && - other.type == this.type && - other.keyId == this.keyId && - other.ciphertext == this.ciphertext && - other.content == this.content); -} - -class SsssCacheCompanion extends UpdateCompanion { - final Value clientId; - final Value type; - final Value keyId; - final Value ciphertext; - final Value content; - const SsssCacheCompanion({ - this.clientId = const Value.absent(), - this.type = const Value.absent(), - this.keyId = const Value.absent(), - this.ciphertext = const Value.absent(), - this.content = const Value.absent(), - }); - SsssCacheCompanion.insert({ - @required int clientId, - @required String type, - @required String keyId, - @required String ciphertext, - @required String content, - }) : clientId = Value(clientId), - type = Value(type), - keyId = Value(keyId), - ciphertext = Value(ciphertext), - content = Value(content); - static Insertable custom({ - Expression clientId, - Expression type, - Expression keyId, - Expression ciphertext, - Expression content, - }) { - return RawValuesInsertable({ - if (clientId != null) 'client_id': clientId, - if (type != null) 'type': type, - if (keyId != null) 'key_id': keyId, - if (ciphertext != null) 'ciphertext': ciphertext, - if (content != null) 'content': content, - }); - } - - SsssCacheCompanion copyWith( - {Value clientId, - Value type, - Value keyId, - Value ciphertext, - Value content}) { - return SsssCacheCompanion( - clientId: clientId ?? this.clientId, - type: type ?? this.type, - keyId: keyId ?? this.keyId, - ciphertext: ciphertext ?? this.ciphertext, - content: content ?? this.content, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (clientId.present) { - map['client_id'] = Variable(clientId.value); - } - if (type.present) { - map['type'] = Variable(type.value); - } - if (keyId.present) { - map['key_id'] = Variable(keyId.value); - } - if (ciphertext.present) { - map['ciphertext'] = Variable(ciphertext.value); - } - if (content.present) { - map['content'] = Variable(content.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('SsssCacheCompanion(') - ..write('clientId: $clientId, ') - ..write('type: $type, ') - ..write('keyId: $keyId, ') - ..write('ciphertext: $ciphertext, ') - ..write('content: $content') - ..write(')')) - .toString(); - } -} - -class SsssCache extends Table with TableInfo { - final GeneratedDatabase _db; - final String _alias; - SsssCache(this._db, [this._alias]); - final VerificationMeta _clientIdMeta = const VerificationMeta('clientId'); - GeneratedIntColumn _clientId; - GeneratedIntColumn get clientId => _clientId ??= _constructClientId(); - GeneratedIntColumn _constructClientId() { - return GeneratedIntColumn('client_id', $tableName, false, - $customConstraints: 'NOT NULL REFERENCES clients(client_id)'); - } - - final VerificationMeta _typeMeta = const VerificationMeta('type'); - GeneratedTextColumn _type; - GeneratedTextColumn get type => _type ??= _constructType(); - GeneratedTextColumn _constructType() { - return GeneratedTextColumn('type', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _keyIdMeta = const VerificationMeta('keyId'); - GeneratedTextColumn _keyId; - GeneratedTextColumn get keyId => _keyId ??= _constructKeyId(); - GeneratedTextColumn _constructKeyId() { - return GeneratedTextColumn('key_id', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _ciphertextMeta = const VerificationMeta('ciphertext'); - GeneratedTextColumn _ciphertext; - GeneratedTextColumn get ciphertext => _ciphertext ??= _constructCiphertext(); - GeneratedTextColumn _constructCiphertext() { - return GeneratedTextColumn('ciphertext', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - final VerificationMeta _contentMeta = const VerificationMeta('content'); - GeneratedTextColumn _content; - GeneratedTextColumn get content => _content ??= _constructContent(); - GeneratedTextColumn _constructContent() { - return GeneratedTextColumn('content', $tableName, false, - $customConstraints: 'NOT NULL'); - } - - @override - List get $columns => - [clientId, type, keyId, ciphertext, content]; - @override - SsssCache get asDslTable => this; - @override - String get $tableName => _alias ?? 'ssss_cache'; - @override - final String actualTableName = 'ssss_cache'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('client_id')) { - context.handle(_clientIdMeta, - clientId.isAcceptableOrUnknown(data['client_id'], _clientIdMeta)); - } else if (isInserting) { - context.missing(_clientIdMeta); - } - if (data.containsKey('type')) { - context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type'], _typeMeta)); - } else if (isInserting) { - context.missing(_typeMeta); - } - if (data.containsKey('key_id')) { - context.handle( - _keyIdMeta, keyId.isAcceptableOrUnknown(data['key_id'], _keyIdMeta)); - } else if (isInserting) { - context.missing(_keyIdMeta); - } - if (data.containsKey('ciphertext')) { - context.handle( - _ciphertextMeta, - ciphertext.isAcceptableOrUnknown( - data['ciphertext'], _ciphertextMeta)); - } else if (isInserting) { - context.missing(_ciphertextMeta); - } - if (data.containsKey('content')) { - context.handle(_contentMeta, - content.isAcceptableOrUnknown(data['content'], _contentMeta)); - } else if (isInserting) { - context.missing(_contentMeta); - } - return context; - } - - @override - Set get $primaryKey => {}; - @override - DbSSSSCache map(Map data, {String tablePrefix}) { - return DbSSSSCache.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - SsssCache createAlias(String alias) { - return SsssCache(_db, alias); - } - - @override - List get customConstraints => const ['UNIQUE(client_id, type)']; - @override - bool get dontWriteConstraints => true; -} - -class DbFile extends DataClass implements Insertable { - final String mxcUri; - final Uint8List bytes; - final int savedAt; - DbFile({@required this.mxcUri, this.bytes, this.savedAt}); - factory DbFile.fromData(Map data, GeneratedDatabase db, - {String prefix}) { - final effectivePrefix = prefix ?? ''; - return DbFile( - mxcUri: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}mxc_uri']), - bytes: const BlobType() - .mapFromDatabaseResponse(data['${effectivePrefix}bytes']), - savedAt: const IntType() - .mapFromDatabaseResponse(data['${effectivePrefix}saved_at']), - ); - } - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (!nullToAbsent || mxcUri != null) { - map['mxc_uri'] = Variable(mxcUri); - } - if (!nullToAbsent || bytes != null) { - map['bytes'] = Variable(bytes); - } - if (!nullToAbsent || savedAt != null) { - map['saved_at'] = Variable(savedAt); - } - return map; - } - - FilesCompanion toCompanion(bool nullToAbsent) { - return FilesCompanion( - mxcUri: - mxcUri == null && nullToAbsent ? const Value.absent() : Value(mxcUri), - bytes: - bytes == null && nullToAbsent ? const Value.absent() : Value(bytes), - savedAt: savedAt == null && nullToAbsent - ? const Value.absent() - : Value(savedAt), - ); - } - - factory DbFile.fromJson(Map json, - {ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return DbFile( - mxcUri: serializer.fromJson(json['mxc_uri']), - bytes: serializer.fromJson(json['bytes']), - savedAt: serializer.fromJson(json['saved_at']), - ); - } - @override - Map toJson({ValueSerializer serializer}) { - serializer ??= moorRuntimeOptions.defaultSerializer; - return { - 'mxc_uri': serializer.toJson(mxcUri), - 'bytes': serializer.toJson(bytes), - 'saved_at': serializer.toJson(savedAt), - }; - } - - DbFile copyWith({String mxcUri, Uint8List bytes, int savedAt}) => DbFile( - mxcUri: mxcUri ?? this.mxcUri, - bytes: bytes ?? this.bytes, - savedAt: savedAt ?? this.savedAt, - ); - @override - String toString() { - return (StringBuffer('DbFile(') - ..write('mxcUri: $mxcUri, ') - ..write('bytes: $bytes, ') - ..write('savedAt: $savedAt') - ..write(')')) - .toString(); - } - - @override - int get hashCode => - $mrjf($mrjc(mxcUri.hashCode, $mrjc(bytes.hashCode, savedAt.hashCode))); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is DbFile && - other.mxcUri == this.mxcUri && - other.bytes == this.bytes && - other.savedAt == this.savedAt); -} - -class FilesCompanion extends UpdateCompanion { - final Value mxcUri; - final Value bytes; - final Value savedAt; - const FilesCompanion({ - this.mxcUri = const Value.absent(), - this.bytes = const Value.absent(), - this.savedAt = const Value.absent(), - }); - FilesCompanion.insert({ - @required String mxcUri, - this.bytes = const Value.absent(), - this.savedAt = const Value.absent(), - }) : mxcUri = Value(mxcUri); - static Insertable custom({ - Expression mxcUri, - Expression bytes, - Expression savedAt, - }) { - return RawValuesInsertable({ - if (mxcUri != null) 'mxc_uri': mxcUri, - if (bytes != null) 'bytes': bytes, - if (savedAt != null) 'saved_at': savedAt, - }); - } - - FilesCompanion copyWith( - {Value mxcUri, Value bytes, Value savedAt}) { - return FilesCompanion( - mxcUri: mxcUri ?? this.mxcUri, - bytes: bytes ?? this.bytes, - savedAt: savedAt ?? this.savedAt, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (mxcUri.present) { - map['mxc_uri'] = Variable(mxcUri.value); - } - if (bytes.present) { - map['bytes'] = Variable(bytes.value); - } - if (savedAt.present) { - map['saved_at'] = Variable(savedAt.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('FilesCompanion(') - ..write('mxcUri: $mxcUri, ') - ..write('bytes: $bytes, ') - ..write('savedAt: $savedAt') - ..write(')')) - .toString(); - } -} - -class Files extends Table with TableInfo { - final GeneratedDatabase _db; - final String _alias; - Files(this._db, [this._alias]); - final VerificationMeta _mxcUriMeta = const VerificationMeta('mxcUri'); - GeneratedTextColumn _mxcUri; - GeneratedTextColumn get mxcUri => _mxcUri ??= _constructMxcUri(); - GeneratedTextColumn _constructMxcUri() { - return GeneratedTextColumn('mxc_uri', $tableName, false, - $customConstraints: 'NOT NULL PRIMARY KEY'); - } - - final VerificationMeta _bytesMeta = const VerificationMeta('bytes'); - GeneratedBlobColumn _bytes; - GeneratedBlobColumn get bytes => _bytes ??= _constructBytes(); - GeneratedBlobColumn _constructBytes() { - return GeneratedBlobColumn('bytes', $tableName, true, - $customConstraints: ''); - } - - final VerificationMeta _savedAtMeta = const VerificationMeta('savedAt'); - GeneratedIntColumn _savedAt; - GeneratedIntColumn get savedAt => _savedAt ??= _constructSavedAt(); - GeneratedIntColumn _constructSavedAt() { - return GeneratedIntColumn('saved_at', $tableName, true, - $customConstraints: ''); - } - - @override - List get $columns => [mxcUri, bytes, savedAt]; - @override - Files get asDslTable => this; - @override - String get $tableName => _alias ?? 'files'; - @override - final String actualTableName = 'files'; - @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('mxc_uri')) { - context.handle(_mxcUriMeta, - mxcUri.isAcceptableOrUnknown(data['mxc_uri'], _mxcUriMeta)); - } else if (isInserting) { - context.missing(_mxcUriMeta); - } - if (data.containsKey('bytes')) { - context.handle( - _bytesMeta, bytes.isAcceptableOrUnknown(data['bytes'], _bytesMeta)); - } - if (data.containsKey('saved_at')) { - context.handle(_savedAtMeta, - savedAt.isAcceptableOrUnknown(data['saved_at'], _savedAtMeta)); - } - return context; - } - - @override - Set get $primaryKey => {mxcUri}; - @override - DbFile map(Map data, {String tablePrefix}) { - return DbFile.fromData(data, _db, - prefix: tablePrefix != null ? '$tablePrefix.' : null); - } - - @override - Files createAlias(String alias) { - return Files(_db, alias); - } - - @override - List get customConstraints => const ['UNIQUE(mxc_uri)']; - @override - bool get dontWriteConstraints => true; -} - -abstract class _$Database extends GeneratedDatabase { - _$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e); - _$Database.connect(DatabaseConnection c) : super.connect(c); - Clients _clients; - Clients get clients => _clients ??= Clients(this); - UserDeviceKeys _userDeviceKeys; - UserDeviceKeys get userDeviceKeys => _userDeviceKeys ??= UserDeviceKeys(this); - Index _userDeviceKeysIndex; - Index get userDeviceKeysIndex => _userDeviceKeysIndex ??= Index( - 'user_device_keys_index', - 'CREATE INDEX user_device_keys_index ON user_device_keys(client_id);'); - UserDeviceKeysKey _userDeviceKeysKey; - UserDeviceKeysKey get userDeviceKeysKey => - _userDeviceKeysKey ??= UserDeviceKeysKey(this); - Index _userDeviceKeysKeyIndex; - Index get userDeviceKeysKeyIndex => _userDeviceKeysKeyIndex ??= Index( - 'user_device_keys_key_index', - 'CREATE INDEX user_device_keys_key_index ON user_device_keys_key(client_id);'); - UserCrossSigningKeys _userCrossSigningKeys; - UserCrossSigningKeys get userCrossSigningKeys => - _userCrossSigningKeys ??= UserCrossSigningKeys(this); - Index _userCrossSigningKeysIndex; - Index get userCrossSigningKeysIndex => _userCrossSigningKeysIndex ??= Index( - 'user_cross_signing_keys_index', - 'CREATE INDEX user_cross_signing_keys_index ON user_cross_signing_keys(client_id);'); - OlmSessions _olmSessions; - OlmSessions get olmSessions => _olmSessions ??= OlmSessions(this); - Index _olmSessionsIndex; - Index get olmSessionsIndex => _olmSessionsIndex ??= Index( - 'olm_sessions_index', - 'CREATE INDEX olm_sessions_index ON olm_sessions(client_id);'); - Index _olmSessionsIdentityIndex; - Index get olmSessionsIdentityIndex => _olmSessionsIdentityIndex ??= Index( - 'olm_sessions_identity_index', - 'CREATE INDEX olm_sessions_identity_index ON olm_sessions(client_id, identity_key);'); - OutboundGroupSessions _outboundGroupSessions; - OutboundGroupSessions get outboundGroupSessions => - _outboundGroupSessions ??= OutboundGroupSessions(this); - Index _outboundGroupSessionsIndex; - Index get outboundGroupSessionsIndex => _outboundGroupSessionsIndex ??= Index( - 'outbound_group_sessions_index', - 'CREATE INDEX outbound_group_sessions_index ON outbound_group_sessions(client_id);'); - InboundGroupSessions _inboundGroupSessions; - InboundGroupSessions get inboundGroupSessions => - _inboundGroupSessions ??= InboundGroupSessions(this); - Index _inboundGroupSessionsIndex; - Index get inboundGroupSessionsIndex => _inboundGroupSessionsIndex ??= Index( - 'inbound_group_sessions_index', - 'CREATE INDEX inbound_group_sessions_index ON inbound_group_sessions(client_id);'); - Rooms _rooms; - Rooms get rooms => _rooms ??= Rooms(this); - Index _roomsIndex; - Index get roomsIndex => _roomsIndex ??= - Index('rooms_index', 'CREATE INDEX rooms_index ON rooms(client_id);'); - Events _events; - Events get events => _events ??= Events(this); - Index _eventsIndex; - Index get eventsIndex => _eventsIndex ??= Index('events_index', - 'CREATE INDEX events_index ON events(client_id, room_id);'); - RoomStates _roomStates; - RoomStates get roomStates => _roomStates ??= RoomStates(this); - Index _roomStatesIndex; - Index get roomStatesIndex => _roomStatesIndex ??= Index('room_states_index', - 'CREATE INDEX room_states_index ON room_states(client_id);'); - AccountData _accountData; - AccountData get accountData => _accountData ??= AccountData(this); - Index _accountDataIndex; - Index get accountDataIndex => _accountDataIndex ??= Index( - 'account_data_index', - 'CREATE INDEX account_data_index ON account_data(client_id);'); - RoomAccountData _roomAccountData; - RoomAccountData get roomAccountData => - _roomAccountData ??= RoomAccountData(this); - Index _roomAccountDataIndex; - Index get roomAccountDataIndex => _roomAccountDataIndex ??= Index( - 'room_account_data_index', - 'CREATE INDEX room_account_data_index ON room_account_data(client_id);'); - Presences _presences; - Presences get presences => _presences ??= Presences(this); - Index _presencesIndex; - Index get presencesIndex => _presencesIndex ??= Index('presences_index', - 'CREATE INDEX presences_index ON presences(client_id);'); - ToDeviceQueue _toDeviceQueue; - ToDeviceQueue get toDeviceQueue => _toDeviceQueue ??= ToDeviceQueue(this); - Index _toDeviceQueueIndex; - Index get toDeviceQueueIndex => _toDeviceQueueIndex ??= Index( - 'to_device_queue_index', - 'CREATE INDEX to_device_queue_index ON to_device_queue(client_id);'); - SsssCache _ssssCache; - SsssCache get ssssCache => _ssssCache ??= SsssCache(this); - Files _files; - Files get files => _files ??= Files(this); - Selectable dbGetClient(String name) { - return customSelect('SELECT * FROM clients WHERE name = :name', - variables: [Variable(name)], - readsFrom: {clients}).map(clients.mapFromRow); - } - - Future updateClient( - String homeserver_url, - String token, - String user_id, - String device_id, - String device_name, - String prev_batch, - String olm_account, - int client_id) { - return customUpdate( - 'UPDATE clients SET homeserver_url = :homeserver_url, token = :token, user_id = :user_id, device_id = :device_id, device_name = :device_name, prev_batch = :prev_batch, olm_account = :olm_account WHERE client_id = :client_id', - variables: [ - Variable(homeserver_url), - Variable(token), - Variable(user_id), - Variable(device_id), - Variable(device_name), - Variable(prev_batch), - Variable(olm_account), - Variable(client_id) - ], - updates: {clients}, - updateKind: UpdateKind.update, - ); - } - - Future updateClientKeys(String olm_account, int client_id) { - return customUpdate( - 'UPDATE clients SET olm_account = :olm_account WHERE client_id = :client_id', - variables: [Variable(olm_account), Variable(client_id)], - updates: {clients}, - updateKind: UpdateKind.update, - ); - } - - Future storePrevBatch(String prev_batch, int client_id) { - return customUpdate( - 'UPDATE clients SET prev_batch = :prev_batch WHERE client_id = :client_id', - variables: [Variable(prev_batch), Variable(client_id)], - updates: {clients}, - updateKind: UpdateKind.update, - ); - } - - Future storeSyncFilterId(String sync_filter_id, int client_id) { - return customUpdate( - 'UPDATE clients SET sync_filter_id = :sync_filter_id WHERE client_id = :client_id', - variables: [Variable(sync_filter_id), Variable(client_id)], - updates: {clients}, - updateKind: UpdateKind.update, - ); - } - - Selectable getAllUserDeviceKeys(int client_id) { - return customSelect( - 'SELECT * FROM user_device_keys WHERE client_id = :client_id', - variables: [Variable(client_id)], - readsFrom: {userDeviceKeys}).map(userDeviceKeys.mapFromRow); - } - - Selectable getAllUserDeviceKeysKeys(int client_id) { - return customSelect( - 'SELECT * FROM user_device_keys_key WHERE client_id = :client_id', - variables: [Variable(client_id)], - readsFrom: {userDeviceKeysKey}).map(userDeviceKeysKey.mapFromRow); - } - - Selectable getAllUserCrossSigningKeys(int client_id) { - return customSelect( - 'SELECT * FROM user_cross_signing_keys WHERE client_id = :client_id', - variables: [Variable(client_id)], - readsFrom: {userCrossSigningKeys}).map(userCrossSigningKeys.mapFromRow); - } - - Selectable getAllOlmSessions(int client_id) { - return customSelect( - 'SELECT * FROM olm_sessions WHERE client_id = :client_id', - variables: [Variable(client_id)], - readsFrom: {olmSessions}).map(olmSessions.mapFromRow); - } - - Selectable dbGetOlmSessions( - int client_id, String identity_key) { - return customSelect( - 'SELECT * FROM olm_sessions WHERE client_id = :client_id AND identity_key = :identity_key', - variables: [Variable(client_id), Variable(identity_key)], - readsFrom: {olmSessions}).map(olmSessions.mapFromRow); - } - - Selectable dbGetOlmSessionsForDevices( - int client_id, List identity_keys) { - var $arrayStartIndex = 2; - final expandedidentity_keys = - $expandVar($arrayStartIndex, identity_keys.length); - $arrayStartIndex += identity_keys.length; - return customSelect( - 'SELECT * FROM olm_sessions WHERE client_id = :client_id AND identity_key IN ($expandedidentity_keys)', - variables: [ - Variable(client_id), - for (var $ in identity_keys) Variable($) - ], - readsFrom: { - olmSessions - }).map(olmSessions.mapFromRow); - } - - Future storeOlmSession(int client_id, String identitiy_key, - String session_id, String pickle, int last_received) { - return customInsert( - 'INSERT OR REPLACE INTO olm_sessions (client_id, identity_key, session_id, pickle, last_received) VALUES (:client_id, :identitiy_key, :session_id, :pickle, :last_received)', - variables: [ - Variable(client_id), - Variable(identitiy_key), - Variable(session_id), - Variable(pickle), - Variable(last_received) - ], - updates: {olmSessions}, - ); - } - - Selectable getAllOutboundGroupSessions( - int client_id) { - return customSelect( - 'SELECT * FROM outbound_group_sessions WHERE client_id = :client_id', - variables: [ - Variable(client_id) - ], - readsFrom: { - outboundGroupSessions - }).map(outboundGroupSessions.mapFromRow); - } - - Selectable dbGetOutboundGroupSession( - int client_id, String room_id) { - return customSelect( - 'SELECT * FROM outbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id', - variables: [ - Variable(client_id), - Variable(room_id) - ], - readsFrom: { - outboundGroupSessions - }).map(outboundGroupSessions.mapFromRow); - } - - Future storeOutboundGroupSession(int client_id, String room_id, - String pickle, String device_ids, int creation_time, int sent_messages) { - return customInsert( - 'INSERT OR REPLACE INTO outbound_group_sessions (client_id, room_id, pickle, device_ids, creation_time, sent_messages) VALUES (:client_id, :room_id, :pickle, :device_ids, :creation_time, :sent_messages)', - variables: [ - Variable(client_id), - Variable(room_id), - Variable(pickle), - Variable(device_ids), - Variable(creation_time), - Variable(sent_messages) - ], - updates: {outboundGroupSessions}, - ); - } - - Future removeOutboundGroupSession(int client_id, String room_id) { - return customUpdate( - 'DELETE FROM outbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id', - variables: [Variable(client_id), Variable(room_id)], - updates: {outboundGroupSessions}, - updateKind: UpdateKind.delete, - ); - } - - Selectable dbGetInboundGroupSessionKey( - int client_id, String room_id, String session_id) { - return customSelect( - 'SELECT * FROM inbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id', - variables: [ - Variable(client_id), - Variable(room_id), - Variable(session_id) - ], - readsFrom: { - inboundGroupSessions - }).map(inboundGroupSessions.mapFromRow); - } - - Selectable dbGetInboundGroupSessionKeys( - int client_id, String room_id) { - return customSelect( - 'SELECT * FROM inbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id', - variables: [Variable(client_id), Variable(room_id)], - readsFrom: {inboundGroupSessions}).map(inboundGroupSessions.mapFromRow); - } - - Selectable dbGetAllInboundGroupSessions( - int client_id) { - return customSelect( - 'SELECT * FROM inbound_group_sessions WHERE client_id = :client_id', - variables: [Variable(client_id)], - readsFrom: {inboundGroupSessions}).map(inboundGroupSessions.mapFromRow); - } - - Future storeInboundGroupSession( - int client_id, - String room_id, - String session_id, - String pickle, - String content, - String indexes, - String allowed_at_index, - String sender_key, - String sender_claimed_keys) { - return customInsert( - 'INSERT OR REPLACE INTO inbound_group_sessions (client_id, room_id, session_id, pickle, content, indexes, allowed_at_index, sender_key, sender_claimed_keys) VALUES (:client_id, :room_id, :session_id, :pickle, :content, :indexes, :allowed_at_index, :sender_key, :sender_claimed_keys)', - variables: [ - Variable(client_id), - Variable(room_id), - Variable(session_id), - Variable(pickle), - Variable(content), - Variable(indexes), - Variable(allowed_at_index), - Variable(sender_key), - Variable(sender_claimed_keys) - ], - updates: {inboundGroupSessions}, - ); - } - - Future updateInboundGroupSessionIndexes( - String indexes, int client_id, String room_id, String session_id) { - return customUpdate( - 'UPDATE inbound_group_sessions SET indexes = :indexes WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id', - variables: [ - Variable(indexes), - Variable(client_id), - Variable(room_id), - Variable(session_id) - ], - updates: {inboundGroupSessions}, - updateKind: UpdateKind.update, - ); - } - - Future updateInboundGroupSessionAllowedAtIndex(String allowed_at_index, - int client_id, String room_id, String session_id) { - return customUpdate( - 'UPDATE inbound_group_sessions SET allowed_at_index = :allowed_at_index WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id', - variables: [ - Variable(allowed_at_index), - Variable(client_id), - Variable(room_id), - Variable(session_id) - ], - updates: {inboundGroupSessions}, - updateKind: UpdateKind.update, - ); - } - - Selectable dbGetInboundGroupSessionsToUpload() { - return customSelect( - 'SELECT * FROM inbound_group_sessions WHERE uploaded = false LIMIT 500', - variables: [], - readsFrom: {inboundGroupSessions}).map(inboundGroupSessions.mapFromRow); - } - - Future markInboundGroupSessionAsUploaded( - int client_id, String room_id, String session_id) { - return customUpdate( - 'UPDATE inbound_group_sessions SET uploaded = true WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id', - variables: [ - Variable(client_id), - Variable(room_id), - Variable(session_id) - ], - updates: {inboundGroupSessions}, - updateKind: UpdateKind.update, - ); - } - - Future markInboundGroupSessionsAsNeedingUpload(int client_id) { - return customUpdate( - 'UPDATE inbound_group_sessions SET uploaded = false WHERE client_id = :client_id', - variables: [Variable(client_id)], - updates: {inboundGroupSessions}, - updateKind: UpdateKind.update, - ); - } - - Future storeUserDeviceKeysInfo( - int client_id, String user_id, bool outdated) { - return customInsert( - 'INSERT OR REPLACE INTO user_device_keys (client_id, user_id, outdated) VALUES (:client_id, :user_id, :outdated)', - variables: [ - Variable(client_id), - Variable(user_id), - Variable(outdated) - ], - updates: {userDeviceKeys}, - ); - } - - Future setVerifiedUserDeviceKey( - bool verified, int client_id, String user_id, String device_id) { - return customUpdate( - 'UPDATE user_device_keys_key SET verified = :verified WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id', - variables: [ - Variable(verified), - Variable(client_id), - Variable(user_id), - Variable(device_id) - ], - updates: {userDeviceKeysKey}, - updateKind: UpdateKind.update, - ); - } - - Future setBlockedUserDeviceKey( - bool blocked, int client_id, String user_id, String device_id) { - return customUpdate( - 'UPDATE user_device_keys_key SET blocked = :blocked WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id', - variables: [ - Variable(blocked), - Variable(client_id), - Variable(user_id), - Variable(device_id) - ], - updates: {userDeviceKeysKey}, - updateKind: UpdateKind.update, - ); - } - - Future storeUserDeviceKey( - int client_id, - String user_id, - String device_id, - String content, - bool verified, - bool blocked, - int last_active) { - return customInsert( - 'INSERT OR REPLACE INTO user_device_keys_key (client_id, user_id, device_id, content, verified, blocked, last_active) VALUES (:client_id, :user_id, :device_id, :content, :verified, :blocked, :last_active)', - variables: [ - Variable(client_id), - Variable(user_id), - Variable(device_id), - Variable(content), - Variable(verified), - Variable(blocked), - Variable(last_active) - ], - updates: {userDeviceKeysKey}, - ); - } - - Future removeUserDeviceKey( - int client_id, String user_id, String device_id) { - return customUpdate( - 'DELETE FROM user_device_keys_key WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id', - variables: [ - Variable(client_id), - Variable(user_id), - Variable(device_id) - ], - updates: {userDeviceKeysKey}, - updateKind: UpdateKind.delete, - ); - } - - Future setLastActiveUserDeviceKey( - int last_active, int client_id, String user_id, String device_id) { - return customUpdate( - 'UPDATE user_device_keys_key SET last_active = :last_active WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id', - variables: [ - Variable(last_active), - Variable(client_id), - Variable(user_id), - Variable(device_id) - ], - updates: {userDeviceKeysKey}, - updateKind: UpdateKind.update, - ); - } - - Future setLastSentMessageUserDeviceKey(String last_sent_message, - int client_id, String user_id, String device_id) { - return customUpdate( - 'UPDATE user_device_keys_key SET last_sent_message = :last_sent_message WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id', - variables: [ - Variable(last_sent_message), - Variable(client_id), - Variable(user_id), - Variable(device_id) - ], - updates: {userDeviceKeysKey}, - updateKind: UpdateKind.update, - ); - } - - Selectable dbGetLastSentMessageUserDeviceKey( - int client_id, String user_id, String device_id) { - return customSelect( - 'SELECT last_sent_message FROM user_device_keys_key WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id', - variables: [ - Variable(client_id), - Variable(user_id), - Variable(device_id) - ], - readsFrom: { - userDeviceKeysKey - }).map((QueryRow row) => row.read('last_sent_message')); - } - - Future setVerifiedUserCrossSigningKey( - bool verified, int client_id, String user_id, String public_key) { - return customUpdate( - 'UPDATE user_cross_signing_keys SET verified = :verified WHERE client_id = :client_id AND user_id = :user_id AND public_key = :public_key', - variables: [ - Variable(verified), - Variable(client_id), - Variable(user_id), - Variable(public_key) - ], - updates: {userCrossSigningKeys}, - updateKind: UpdateKind.update, - ); - } - - Future setBlockedUserCrossSigningKey( - bool blocked, int client_id, String user_id, String public_key) { - return customUpdate( - 'UPDATE user_cross_signing_keys SET blocked = :blocked WHERE client_id = :client_id AND user_id = :user_id AND public_key = :public_key', - variables: [ - Variable(blocked), - Variable(client_id), - Variable(user_id), - Variable(public_key) - ], - updates: {userCrossSigningKeys}, - updateKind: UpdateKind.update, - ); - } - - Future storeUserCrossSigningKey(int client_id, String user_id, - String public_key, String content, bool verified, bool blocked) { - return customInsert( - 'INSERT OR REPLACE INTO user_cross_signing_keys (client_id, user_id, public_key, content, verified, blocked) VALUES (:client_id, :user_id, :public_key, :content, :verified, :blocked)', - variables: [ - Variable(client_id), - Variable(user_id), - Variable(public_key), - Variable(content), - Variable(verified), - Variable(blocked) - ], - updates: {userCrossSigningKeys}, - ); - } - - Future removeUserCrossSigningKey( - int client_id, String user_id, String public_key) { - return customUpdate( - 'DELETE FROM user_cross_signing_keys WHERE client_id = :client_id AND user_id = :user_id AND public_key = :public_key', - variables: [ - Variable(client_id), - Variable(user_id), - Variable(public_key) - ], - updates: {userCrossSigningKeys}, - updateKind: UpdateKind.delete, - ); - } - - Future storeSSSSCache(int client_id, String type, String key_id, - String ciphertext, String content) { - return customInsert( - 'INSERT OR REPLACE INTO ssss_cache (client_id, type, key_id, ciphertext, content) VALUES (:client_id, :type, :key_id, :ciphertext, :content)', - variables: [ - Variable(client_id), - Variable(type), - Variable(key_id), - Variable(ciphertext), - Variable(content) - ], - updates: {ssssCache}, - ); - } - - Selectable dbGetSSSSCache(int client_id, String type) { - return customSelect( - 'SELECT * FROM ssss_cache WHERE client_id = :client_id AND type = :type', - variables: [Variable(client_id), Variable(type)], - readsFrom: {ssssCache}).map(ssssCache.mapFromRow); - } - - Future clearSSSSCache(int client_id) { - return customUpdate( - 'DELETE FROM ssss_cache WHERE client_id = :client_id', - variables: [Variable(client_id)], - updates: {ssssCache}, - updateKind: UpdateKind.delete, - ); - } - - Future insertClient( - String name, - String homeserver_url, - String token, - String user_id, - String device_id, - String device_name, - String prev_batch, - String olm_account) { - return customInsert( - 'INSERT INTO clients (name, homeserver_url, token, user_id, device_id, device_name, prev_batch, olm_account) VALUES (:name, :homeserver_url, :token, :user_id, :device_id, :device_name, :prev_batch, :olm_account)', - variables: [ - Variable(name), - Variable(homeserver_url), - Variable(token), - Variable(user_id), - Variable(device_id), - Variable(device_name), - Variable(prev_batch), - Variable(olm_account) - ], - updates: {clients}, - ); - } - - Future ensureRoomExists( - int client_id, String room_id, String membership) { - return customInsert( - 'INSERT OR IGNORE INTO rooms (client_id, room_id, membership) VALUES (:client_id, :room_id, :membership)', - variables: [ - Variable(client_id), - Variable(room_id), - Variable(membership) - ], - updates: {rooms}, - ); - } - - Future setRoomPrevBatch( - String prev_batch, int client_id, String room_id) { - return customUpdate( - 'UPDATE rooms SET prev_batch = :prev_batch WHERE client_id = :client_id AND room_id = :room_id', - variables: [ - Variable(prev_batch), - Variable(client_id), - Variable(room_id) - ], - updates: {rooms}, - updateKind: UpdateKind.update, - ); - } - - Future updateRoomSortOrder(double oldest_sort_order, - double newest_sort_order, int client_id, String room_id) { - return customUpdate( - 'UPDATE rooms SET oldest_sort_order = :oldest_sort_order, newest_sort_order = :newest_sort_order WHERE client_id = :client_id AND room_id = :room_id', - variables: [ - Variable(oldest_sort_order), - Variable(newest_sort_order), - Variable(client_id), - Variable(room_id) - ], - updates: {rooms}, - updateKind: UpdateKind.update, - ); - } - - Selectable getAllAccountData(int client_id) { - return customSelect( - 'SELECT * FROM account_data WHERE client_id = :client_id', - variables: [Variable(client_id)], - readsFrom: {accountData}).map(accountData.mapFromRow); - } - - Future storeAccountData(int client_id, String type, String content) { - return customInsert( - 'INSERT OR REPLACE INTO account_data (client_id, type, content) VALUES (:client_id, :type, :content)', - variables: [ - Variable(client_id), - Variable(type), - Variable(content) - ], - updates: {accountData}, - ); - } - - Future updateEvent(String unsigned, String content, String prev_content, - int client_id, String event_id, String room_id) { - return customUpdate( - 'UPDATE events SET unsigned = :unsigned, content = :content, prev_content = :prev_content WHERE client_id = :client_id AND event_id = :event_id AND room_id = :room_id', - variables: [ - Variable(unsigned), - Variable(content), - Variable(prev_content), - Variable(client_id), - Variable(event_id), - Variable(room_id) - ], - updates: {events}, - updateKind: UpdateKind.update, - ); - } - - Future updateEventStatus(int status, String new_event_id, int client_id, - String old_event_id, String room_id) { - return customUpdate( - 'UPDATE events SET status = :status, event_id = :new_event_id WHERE client_id = :client_id AND event_id = :old_event_id AND room_id = :room_id', - variables: [ - Variable(status), - Variable(new_event_id), - Variable(client_id), - Variable(old_event_id), - Variable(room_id) - ], - updates: {events}, - updateKind: UpdateKind.update, - ); - } - - Future updateEventStatusOnly( - int status, int client_id, String event_id, String room_id) { - return customUpdate( - 'UPDATE events SET status = :status WHERE client_id = :client_id AND event_id = :event_id AND room_id = :room_id', - variables: [ - Variable(status), - Variable(client_id), - Variable(event_id), - Variable(room_id) - ], - updates: {events}, - updateKind: UpdateKind.update, - ); - } - - Selectable getImportantRoomStates( - int client_id, List events) { - var $arrayStartIndex = 2; - final expandedevents = $expandVar($arrayStartIndex, events.length); - $arrayStartIndex += events.length; - return customSelect( - 'SELECT * FROM room_states WHERE client_id = :client_id AND type IN ($expandedevents)', - variables: [ - Variable(client_id), - for (var $ in events) Variable($) - ], - readsFrom: { - roomStates - }).map(roomStates.mapFromRow); - } - - Selectable getAllRoomStates(int client_id) { - return customSelect( - 'SELECT * FROM room_states WHERE client_id = :client_id', - variables: [Variable(client_id)], - readsFrom: {roomStates}).map(roomStates.mapFromRow); - } - - Selectable getUnimportantRoomStatesForRoom( - int client_id, String room_id, List events) { - var $arrayStartIndex = 3; - final expandedevents = $expandVar($arrayStartIndex, events.length); - $arrayStartIndex += events.length; - return customSelect( - 'SELECT * FROM room_states WHERE client_id = :client_id AND room_id = :room_id AND type NOT IN ($expandedevents)', - variables: [ - Variable(client_id), - Variable(room_id), - for (var $ in events) Variable($) - ], - readsFrom: { - roomStates - }).map(roomStates.mapFromRow); - } - - Future storeEvent( - int client_id, - String event_id, - String room_id, - double sort_order, - int origin_server_ts, - String sender, - String type, - String unsigned, - String content, - String prev_content, - String state_key, - int status) { - return customInsert( - 'INSERT OR REPLACE INTO events (client_id, event_id, room_id, sort_order, origin_server_ts, sender, type, unsigned, content, prev_content, state_key, status) VALUES (:client_id, :event_id, :room_id, :sort_order, :origin_server_ts, :sender, :type, :unsigned, :content, :prev_content, :state_key, :status)', - variables: [ - Variable(client_id), - Variable(event_id), - Variable(room_id), - Variable(sort_order), - Variable(origin_server_ts), - Variable(sender), - Variable(type), - Variable(unsigned), - Variable(content), - Variable(prev_content), - Variable(state_key), - Variable(status) - ], - updates: {events}, - ); - } - - Future storeRoomState( - int client_id, - String event_id, - String room_id, - double sort_order, - int origin_server_ts, - String sender, - String type, - String unsigned, - String content, - String prev_content, - String state_key) { - return customInsert( - 'INSERT OR REPLACE INTO room_states (client_id, event_id, room_id, sort_order, origin_server_ts, sender, type, unsigned, content, prev_content, state_key) VALUES (:client_id, :event_id, :room_id, :sort_order, :origin_server_ts, :sender, :type, :unsigned, :content, :prev_content, :state_key)', - variables: [ - Variable(client_id), - Variable(event_id), - Variable(room_id), - Variable(sort_order), - Variable(origin_server_ts), - Variable(sender), - Variable(type), - Variable(unsigned), - Variable(content), - Variable(prev_content), - Variable(state_key) - ], - updates: {roomStates}, - ); - } - - Selectable getAllRoomAccountData(int client_id) { - return customSelect( - 'SELECT * FROM room_account_data WHERE client_id = :client_id', - variables: [Variable(client_id)], - readsFrom: {roomAccountData}).map(roomAccountData.mapFromRow); - } - - Future storeRoomAccountData( - int client_id, String type, String room_id, String content) { - return customInsert( - 'INSERT OR REPLACE INTO room_account_data (client_id, type, room_id, content) VALUES (:client_id, :type, :room_id, :content)', - variables: [ - Variable(client_id), - Variable(type), - Variable(room_id), - Variable(content) - ], - updates: {roomAccountData}, - ); - } - - Selectable dbGetUser( - int client_id, String state_key, String room_id) { - return customSelect( - 'SELECT * FROM room_states WHERE client_id = :client_id AND type = \'m.room.member\' AND state_key = :state_key AND room_id = :room_id', - variables: [ - Variable(client_id), - Variable(state_key), - Variable(room_id) - ], - readsFrom: { - roomStates - }).map(roomStates.mapFromRow); - } - - Selectable dbGetUsers(int client_id, String room_id) { - return customSelect( - 'SELECT * FROM room_states WHERE client_id = :client_id AND type = \'m.room.member\' AND room_id = :room_id', - variables: [Variable(client_id), Variable(room_id)], - readsFrom: {roomStates}).map(roomStates.mapFromRow); - } - - Selectable dbGetEventList(int client_id, String room_id) { - return customSelect( - 'SELECT * FROM events WHERE client_id = :client_id AND room_id = :room_id GROUP BY event_id ORDER BY sort_order DESC', - variables: [Variable(client_id), Variable(room_id)], - readsFrom: {events}).map(events.mapFromRow); - } - - Selectable getStates(int client_id, String room_id) { - return customSelect( - 'SELECT * FROM room_states WHERE client_id = :client_id AND room_id = :room_id', - variables: [Variable(client_id), Variable(room_id)], - readsFrom: {roomStates}).map(roomStates.mapFromRow); - } - - Future resetNotificationCount(int client_id, String room_id) { - return customUpdate( - 'UPDATE rooms SET notification_count = 0, highlight_count = 0 WHERE client_id = :client_id AND room_id = :room_id', - variables: [Variable(client_id), Variable(room_id)], - updates: {rooms}, - updateKind: UpdateKind.update, - ); - } - - Selectable getRoom(int client_id, String room_id) { - return customSelect( - 'SELECT * FROM rooms WHERE client_id = :client_id AND room_id = :room_id', - variables: [Variable(client_id), Variable(room_id)], - readsFrom: {rooms}).map(rooms.mapFromRow); - } - - Selectable getEvent(int client_id, String event_id, String room_id) { - return customSelect( - 'SELECT * FROM events WHERE client_id = :client_id AND event_id = :event_id AND room_id = :room_id', - variables: [ - Variable(client_id), - Variable(event_id), - Variable(room_id) - ], - readsFrom: { - events - }).map(events.mapFromRow); - } - - Future removeEvent(int client_id, String event_id, String room_id) { - return customUpdate( - 'DELETE FROM events WHERE client_id = :client_id AND event_id = :event_id AND room_id = :room_id', - variables: [ - Variable(client_id), - Variable(event_id), - Variable(room_id) - ], - updates: {events}, - updateKind: UpdateKind.delete, - ); - } - - Future removeRoom(int client_id, String room_id) { - return customUpdate( - 'DELETE FROM rooms WHERE client_id = :client_id AND room_id = :room_id', - variables: [Variable(client_id), Variable(room_id)], - updates: {rooms}, - updateKind: UpdateKind.delete, - ); - } - - Future removeSuccessfulRoomEvents(int client_id, String room_id) { - return customUpdate( - 'DELETE FROM events WHERE client_id = :client_id AND room_id = :room_id AND status <> -1 AND status <> 0', - variables: [Variable(client_id), Variable(room_id)], - updates: {events}, - updateKind: UpdateKind.delete, - ); - } - - Future storeFile(String mxc_uri, Uint8List bytes, int time) { - return customInsert( - 'INSERT OR REPLACE INTO files (mxc_uri, bytes, saved_at) VALUES (:mxc_uri, :bytes, :time)', - variables: [ - Variable(mxc_uri), - Variable(bytes), - Variable(time) - ], - updates: {files}, - ); - } - - Selectable dbGetFile(String mxc_uri) { - return customSelect('SELECT * FROM files WHERE mxc_uri = :mxc_uri', - variables: [Variable(mxc_uri)], - readsFrom: {files}).map(files.mapFromRow); - } - - Future markPendingEventsAsError(int client_id) { - return customUpdate( - 'UPDATE events SET status = -1 WHERE client_id = :client_id AND status = 0', - variables: [Variable(client_id)], - updates: {events}, - updateKind: UpdateKind.update, - ); - } - - Future deleteOldFiles(int saved_at) { - return customUpdate( - 'DELETE FROM files WHERE saved_at < :saved_at', - variables: [Variable(saved_at)], - updates: {files}, - updateKind: UpdateKind.delete, - ); - } - - Future insertIntoToDeviceQueue( - int client_id, String type, String txn_id, String content) { - return customInsert( - 'INSERT INTO to_device_queue (client_id, type, txn_id, content) VALUES (:client_id, :type, :txn_id, :content)', - variables: [ - Variable(client_id), - Variable(type), - Variable(txn_id), - Variable(content) - ], - updates: {toDeviceQueue}, - ); - } - - Selectable getToDeviceQueue(int client_id) { - return customSelect( - 'SELECT * FROM to_device_queue WHERE client_id = :client_id', - variables: [Variable(client_id)], - readsFrom: {toDeviceQueue}).map(toDeviceQueue.mapFromRow); - } - - Future deleteFromToDeviceQueue(int client_id, int id) { - return customUpdate( - 'DELETE FROM to_device_queue WHERE client_id = :client_id AND id = :id', - variables: [Variable(client_id), Variable(id)], - updates: {toDeviceQueue}, - updateKind: UpdateKind.delete, - ); - } - - @override - Iterable get allTables => allSchemaEntities.whereType(); - @override - List get allSchemaEntities => [ - clients, - userDeviceKeys, - userDeviceKeysIndex, - userDeviceKeysKey, - userDeviceKeysKeyIndex, - userCrossSigningKeys, - userCrossSigningKeysIndex, - olmSessions, - olmSessionsIndex, - olmSessionsIdentityIndex, - outboundGroupSessions, - outboundGroupSessionsIndex, - inboundGroupSessions, - inboundGroupSessionsIndex, - rooms, - roomsIndex, - events, - eventsIndex, - roomStates, - roomStatesIndex, - accountData, - accountDataIndex, - roomAccountData, - roomAccountDataIndex, - presences, - presencesIndex, - toDeviceQueue, - toDeviceQueueIndex, - ssssCache, - files - ]; -} diff --git a/lib/src/database/database.moor b/lib/src/database/database.moor deleted file mode 100644 index 0a57fd46..00000000 --- a/lib/src/database/database.moor +++ /dev/null @@ -1,261 +0,0 @@ --- Table definitions - -CREATE TABLE clients ( - client_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - homeserver_url TEXT NOT NULL, - token TEXT NOT NULL, - user_id TEXT NOT NULL, - device_id TEXT, - device_name TEXT, - prev_batch TEXT, - sync_filter_id TEXT, - olm_account TEXT, - UNIQUE(name) -) AS DbClient; - -CREATE TABLE user_device_keys ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - user_id TEXT NOT NULL, - outdated BOOLEAN DEFAULT true, - UNIQUE(client_id, user_id) -) as DbUserDeviceKey; -CREATE INDEX user_device_keys_index ON user_device_keys(client_id); - -CREATE TABLE user_device_keys_key ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - user_id TEXT NOT NULL, - device_id TEXT NOT NULL, - content TEXT NOT NULL, - verified BOOLEAN DEFAULT false, - blocked BOOLEAN DEFAULT false, - last_active BIGINT, - last_sent_message TEXT, - UNIQUE(client_id, user_id, device_id) -) as DbUserDeviceKeysKey; -CREATE INDEX user_device_keys_key_index ON user_device_keys_key(client_id); - -CREATE TABLE user_cross_signing_keys ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - user_id TEXT NOT NULL, - public_key TEXT NOT NULL, - content TEXT NOT NULL, - verified BOOLEAN DEFAULT false, - blocked BOOLEAN DEFAULT false, - UNIQUE(client_id, user_id, public_key) -) as DbUserCrossSigningKey; -CREATE INDEX user_cross_signing_keys_index ON user_cross_signing_keys(client_id); - -CREATE TABLE olm_sessions ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - identity_key TEXT NOT NULL, - session_id TEXT NOT NULL, - pickle TEXT NOT NULL, - last_received BIGINT, - UNIQUE(client_id, identity_key, session_id) -) AS DbOlmSessions; -CREATE INDEX olm_sessions_index ON olm_sessions(client_id); -CREATE INDEX olm_sessions_identity_index ON olm_sessions(client_id, identity_key); - -CREATE TABLE outbound_group_sessions ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - room_id TEXT NOT NULL, - pickle TEXT NOT NULL, - device_ids TEXT NOT NULL, - creation_time BIGINT NOT NULL, - sent_messages INTEGER NOT NULL DEFAULT '0', - UNIQUE(client_id, room_id) -) AS DbOutboundGroupSession; -CREATE INDEX outbound_group_sessions_index ON outbound_group_sessions(client_id); - -CREATE TABLE inbound_group_sessions ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - room_id TEXT NOT NULL, - session_id TEXT NOT NULL, - pickle TEXT NOT NULL, - content TEXT, - indexes TEXT, - allowed_at_index TEXT, - uploaded BOOLEAN DEFAULT false, - sender_key TEXT, - sender_claimed_keys TEXT, - UNIQUE(client_id, room_id, session_id) -) AS DbInboundGroupSession; -CREATE INDEX inbound_group_sessions_index ON inbound_group_sessions(client_id); - -CREATE TABLE ssss_cache ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - type TEXT NOT NULL, - key_id TEXT NOT NULL, - ciphertext TEXT NOT NULL, - content TEXT NOT NULL, - UNIQUE(client_id, type) -) AS DbSSSSCache; - -CREATE TABLE rooms ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - room_id TEXT NOT NULL, - membership TEXT NOT NULL, - highlight_count INTEGER NOT NULL DEFAULT '0', - notification_count INTEGER NOT NULL DEFAULT '0', - prev_batch TEXT DEFAULT '', - joined_member_count INTEGER NOT NULL DEFAULT '0', - invited_member_count INTEGER NOT NULL DEFAULT '0', - newest_sort_order DOUBLE NOT NULL DEFAULT '0', - oldest_sort_order DOUBLE NOT NULL DEFAULT '0', - heroes TEXT DEFAULT '', - UNIQUE(client_id, room_id) -) AS DbRoom; -CREATE INDEX rooms_index ON rooms(client_id); - -CREATE TABLE events ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - event_id TEXT NOT NULL, - room_id TEXT NOT NULL, - sort_order DOUBLE NOT NULL, - origin_server_ts BIGINT NOT NULL, - sender TEXT NOT NULL, - type TEXT NOT NULL, - unsigned TEXT, - content TEXT, - prev_content TEXT, - state_key TEXT, - status INTEGER, - UNIQUE(client_id, event_id, room_id) -) AS DbEvent; -CREATE INDEX events_index ON events(client_id, room_id); - -CREATE TABLE room_states ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - event_id TEXT NOT NULL, - room_id TEXT NOT NULL, - sort_order DOUBLE NOT NULL, - origin_server_ts BIGINT NOT NULL, - sender TEXT NOT NULL, - type TEXT NOT NULL, - unsigned TEXT, - content TEXT, - prev_content TEXT, - state_key TEXT NOT NULL, - UNIQUE(client_id, event_id, room_id), - UNIQUE(client_id, room_id, state_key, type) -) AS DbRoomState; -CREATE INDEX room_states_index ON room_states(client_id); - -CREATE TABLE account_data ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - type TEXT NOT NULL, - content TEXT, - UNIQUE(client_id, type) -) AS DbAccountData; -CREATE INDEX account_data_index ON account_data(client_id); - -CREATE TABLE room_account_data ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - type TEXT NOT NULL, - room_id TEXT NOT NULL, - content TEXT, - UNIQUE(client_id, type, room_id) -) AS DbRoomAccountData; -CREATE INDEX room_account_data_index ON room_account_data(client_id); - -CREATE TABLE presences ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - type TEXT NOT NULL, - sender TEXT NOT NULL, - content TEXT, - UNIQUE(client_id, type, sender) -) AS DbPresence; -CREATE INDEX presences_index ON presences(client_id); - -CREATE TABLE files ( - mxc_uri TEXT NOT NULL PRIMARY KEY, - bytes BLOB, - saved_at BIGINT, - UNIQUE(mxc_uri) -) AS DbFile; - -CREATE TABLE to_device_queue ( - client_id INTEGER NOT NULL REFERENCES clients(client_id), - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - type TEXT NOT NULL, - txn_id TEXT NOT NULL, - content TEXT NOT NULL -) as DbToDeviceQueue; -CREATE INDEX to_device_queue_index ON to_device_queue(client_id); - --- named queries - -dbGetClient: SELECT * FROM clients WHERE name = :name; -updateClient: UPDATE clients SET homeserver_url = :homeserver_url, token = :token, user_id = :user_id, device_id = :device_id, device_name = :device_name, prev_batch = :prev_batch, olm_account = :olm_account WHERE client_id = :client_id; -updateClientKeys: UPDATE clients SET olm_account = :olm_account WHERE client_id = :client_id; -storePrevBatch: UPDATE clients SET prev_batch = :prev_batch WHERE client_id = :client_id; -storeSyncFilterId: UPDATE clients SET sync_filter_id = :sync_filter_id WHERE client_id = :client_id; -getAllUserDeviceKeys: SELECT * FROM user_device_keys WHERE client_id = :client_id; -getAllUserDeviceKeysKeys: SELECT * FROM user_device_keys_key WHERE client_id = :client_id; -getAllUserCrossSigningKeys: SELECT * FROM user_cross_signing_keys WHERE client_id = :client_id; -getAllOlmSessions: SELECT * FROM olm_sessions WHERE client_id = :client_id; -dbGetOlmSessions: SELECT * FROM olm_sessions WHERE client_id = :client_id AND identity_key = :identity_key; -dbGetOlmSessionsForDevices: SELECT * FROM olm_sessions WHERE client_id = :client_id AND identity_key IN :identity_keys; -storeOlmSession: INSERT OR REPLACE INTO olm_sessions (client_id, identity_key, session_id, pickle, last_received) VALUES (:client_id, :identitiy_key, :session_id, :pickle, :last_received); -getAllOutboundGroupSessions: SELECT * FROM outbound_group_sessions WHERE client_id = :client_id; -dbGetOutboundGroupSession: SELECT * FROM outbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id; -storeOutboundGroupSession: INSERT OR REPLACE INTO outbound_group_sessions (client_id, room_id, pickle, device_ids, creation_time, sent_messages) VALUES (:client_id, :room_id, :pickle, :device_ids, :creation_time, :sent_messages); -removeOutboundGroupSession: DELETE FROM outbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id; -dbGetInboundGroupSessionKey: SELECT * FROM inbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id; -dbGetInboundGroupSessionKeys: SELECT * FROM inbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id; -dbGetAllInboundGroupSessions: SELECT * FROM inbound_group_sessions WHERE client_id = :client_id; -storeInboundGroupSession: INSERT OR REPLACE INTO inbound_group_sessions (client_id, room_id, session_id, pickle, content, indexes, allowed_at_index, sender_key, sender_claimed_keys) VALUES (:client_id, :room_id, :session_id, :pickle, :content, :indexes, :allowed_at_index, :sender_key, :sender_claimed_keys); -updateInboundGroupSessionIndexes: UPDATE inbound_group_sessions SET indexes = :indexes WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id; -updateInboundGroupSessionAllowedAtIndex: UPDATE inbound_group_sessions SET allowed_at_index = :allowed_at_index WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id; -dbGetInboundGroupSessionsToUpload: SELECT * FROM inbound_group_sessions WHERE uploaded = false LIMIT 500; -markInboundGroupSessionAsUploaded: UPDATE inbound_group_sessions SET uploaded = true WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id; -markInboundGroupSessionsAsNeedingUpload: UPDATE inbound_group_sessions SET uploaded = false WHERE client_id = :client_id; -storeUserDeviceKeysInfo: INSERT OR REPLACE INTO user_device_keys (client_id, user_id, outdated) VALUES (:client_id, :user_id, :outdated); -setVerifiedUserDeviceKey: UPDATE user_device_keys_key SET verified = :verified WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id; -setBlockedUserDeviceKey: UPDATE user_device_keys_key SET blocked = :blocked WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id; -storeUserDeviceKey: INSERT OR REPLACE INTO user_device_keys_key (client_id, user_id, device_id, content, verified, blocked, last_active) VALUES (:client_id, :user_id, :device_id, :content, :verified, :blocked, :last_active); -removeUserDeviceKey: DELETE FROM user_device_keys_key WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id; -setLastActiveUserDeviceKey: UPDATE user_device_keys_key SET last_active = :last_active WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id; -setLastSentMessageUserDeviceKey: UPDATE user_device_keys_key SET last_sent_message = :last_sent_message WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id; -dbGetLastSentMessageUserDeviceKey: SELECT last_sent_message FROM user_device_keys_key WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id; -setVerifiedUserCrossSigningKey: UPDATE user_cross_signing_keys SET verified = :verified WHERE client_id = :client_id AND user_id = :user_id AND public_key = :public_key; -setBlockedUserCrossSigningKey: UPDATE user_cross_signing_keys SET blocked = :blocked WHERE client_id = :client_id AND user_id = :user_id AND public_key = :public_key; -storeUserCrossSigningKey: INSERT OR REPLACE INTO user_cross_signing_keys (client_id, user_id, public_key, content, verified, blocked) VALUES (:client_id, :user_id, :public_key, :content, :verified, :blocked); -removeUserCrossSigningKey: DELETE FROM user_cross_signing_keys WHERE client_id = :client_id AND user_id = :user_id AND public_key = :public_key; -storeSSSSCache: INSERT OR REPLACE INTO ssss_cache (client_id, type, key_id, ciphertext, content) VALUES (:client_id, :type, :key_id, :ciphertext, :content); -dbGetSSSSCache: SELECT * FROM ssss_cache WHERE client_id = :client_id AND type = :type; -clearSSSSCache: DELETE FROM ssss_cache WHERE client_id = :client_id; -insertClient: INSERT INTO clients (name, homeserver_url, token, user_id, device_id, device_name, prev_batch, olm_account) VALUES (:name, :homeserver_url, :token, :user_id, :device_id, :device_name, :prev_batch, :olm_account); -ensureRoomExists: INSERT OR IGNORE INTO rooms (client_id, room_id, membership) VALUES (:client_id, :room_id, :membership); -setRoomPrevBatch: UPDATE rooms SET prev_batch = :prev_batch WHERE client_id = :client_id AND room_id = :room_id; -updateRoomSortOrder: UPDATE rooms SET oldest_sort_order = :oldest_sort_order, newest_sort_order = :newest_sort_order WHERE client_id = :client_id AND room_id = :room_id; -getAllAccountData: SELECT * FROM account_data WHERE client_id = :client_id; -storeAccountData: INSERT OR REPLACE INTO account_data (client_id, type, content) VALUES (:client_id, :type, :content); -updateEvent: UPDATE events SET unsigned = :unsigned, content = :content, prev_content = :prev_content WHERE client_id = :client_id AND event_id = :event_id AND room_id = :room_id; -updateEventStatus: UPDATE events SET status = :status, event_id = :new_event_id WHERE client_id = :client_id AND event_id = :old_event_id AND room_id = :room_id; -updateEventStatusOnly: UPDATE events SET status = :status WHERE client_id = :client_id AND event_id = :event_id AND room_id = :room_id; -getImportantRoomStates: SELECT * FROM room_states WHERE client_id = :client_id AND type IN :events; -getAllRoomStates: SELECT * FROM room_states WHERE client_id = :client_id; -getUnimportantRoomStatesForRoom: SELECT * FROM room_states WHERE client_id = :client_id AND room_id = :room_id AND type NOT IN :events; -storeEvent: INSERT OR REPLACE INTO events (client_id, event_id, room_id, sort_order, origin_server_ts, sender, type, unsigned, content, prev_content, state_key, status) VALUES (:client_id, :event_id, :room_id, :sort_order, :origin_server_ts, :sender, :type, :unsigned, :content, :prev_content, :state_key, :status); -storeRoomState: INSERT OR REPLACE INTO room_states (client_id, event_id, room_id, sort_order, origin_server_ts, sender, type, unsigned, content, prev_content, state_key) VALUES (:client_id, :event_id, :room_id, :sort_order, :origin_server_ts, :sender, :type, :unsigned, :content, :prev_content, :state_key); -getAllRoomAccountData: SELECT * FROM room_account_data WHERE client_id = :client_id; -storeRoomAccountData: INSERT OR REPLACE INTO room_account_data (client_id, type, room_id, content) VALUES (:client_id, :type, :room_id, :content); -dbGetUser: SELECT * FROM room_states WHERE client_id = :client_id AND type = 'm.room.member' AND state_key = :state_key AND room_id = :room_id; -dbGetUsers: SELECT * FROM room_states WHERE client_id = :client_id AND type = 'm.room.member' AND room_id = :room_id; -dbGetEventList: SELECT * FROM events WHERE client_id = :client_id AND room_id = :room_id GROUP BY event_id ORDER BY sort_order DESC; -getStates: SELECT * FROM room_states WHERE client_id = :client_id AND room_id = :room_id; -resetNotificationCount: UPDATE rooms SET notification_count = 0, highlight_count = 0 WHERE client_id = :client_id AND room_id = :room_id; -getRoom: SELECT * FROM rooms WHERE client_id = :client_id AND room_id = :room_id; -getEvent: SELECT * FROM events WHERE client_id = :client_id AND event_id = :event_id AND room_id = :room_id; -removeEvent: DELETE FROM events WHERE client_id = :client_id AND event_id = :event_id AND room_id = :room_id; -removeRoom: DELETE FROM rooms WHERE client_id = :client_id AND room_id = :room_id; -removeSuccessfulRoomEvents: DELETE FROM events WHERE client_id = :client_id AND room_id = :room_id AND status <> -1 AND status <> 0; -storeFile: INSERT OR REPLACE INTO files (mxc_uri, bytes, saved_at) VALUES (:mxc_uri, :bytes, :time); -dbGetFile: SELECT * FROM files WHERE mxc_uri = :mxc_uri; -markPendingEventsAsError: UPDATE events SET status = -1 WHERE client_id = :client_id AND status = 0; -deleteOldFiles: DELETE FROM files WHERE saved_at < :saved_at; -insertIntoToDeviceQueue: INSERT INTO to_device_queue (client_id, type, txn_id, content) VALUES (:client_id, :type, :txn_id, :content); -getToDeviceQueue: SELECT * FROM to_device_queue WHERE client_id = :client_id; -deleteFromToDeviceQueue: DELETE FROM to_device_queue WHERE client_id = :client_id AND id = :id; diff --git a/pubspec.yaml b/pubspec.yaml index 642e3ae6..1b7c4142 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,6 @@ dependencies: canonical_json: ^1.0.0 markdown: ^4.0.0 html_unescape: ^2.0.0 - moor: ">=4.0.0 <=4.3.2" random_string: ^2.1.0 crypto: ^3.0.0 base58check: ^2.0.0 @@ -27,7 +26,5 @@ dev_dependencies: pedantic: ^1.11.0 test: ^1.15.7 coverage: ">=0.15.0 <2.0.0" - moor_generator: ^4.0.0 - build_runner: ^1.11.1 file: ^6.1.1 #flutter_test: {sdk: flutter} diff --git a/test/database_api_test.dart b/test/database_api_test.dart index 111c6a65..7c18f415 100644 --- a/test/database_api_test.dart +++ b/test/database_api_test.dart @@ -16,19 +16,16 @@ * along with this program. If not, see . */ import 'dart:convert'; +import 'dart:typed_data'; import 'package:matrix/matrix.dart'; -import 'package:moor/moor.dart'; import 'package:test/test.dart'; import 'package:olm/olm.dart' as olm; -import 'fake_database_native.dart'; +import 'fake_database.dart'; void main() { /// All Tests related to the ChatTime - group('Moor Database Test', () { - testDatabase(getMoorDatabase(null), 0); - }); group('Hive Database Test', () { testDatabase(getHiveDatabase(null), 0); }); diff --git a/test/fake_database.dart b/test/fake_database.dart index f6f09d8e..182dede9 100644 --- a/test/fake_database.dart +++ b/test/fake_database.dart @@ -16,5 +16,28 @@ * along with this program. If not, see . */ -export 'fake_database_native.dart' - if (dart.library.js) 'fake_database_web.dart'; +import 'dart:io'; +import 'dart:math'; + +import 'package:matrix/matrix.dart'; +import 'package:matrix/src/database/hive_database.dart'; +import 'package:file/memory.dart'; +import 'package:hive/hive.dart'; + +Future getDatabase(Client _) => getHiveDatabase(_); + +bool hiveInitialized = false; + +Future getHiveDatabase(Client c) async { + if (!hiveInitialized) { + final fileSystem = MemoryFileSystem(); + final testHivePath = + '${fileSystem.path}/build/.test_store/${Random().nextDouble()}'; + Directory(testHivePath).createSync(recursive: true); + Hive.init(testHivePath); + hiveInitialized = true; + } + final db = FamedlySdkHiveDatabase('unit_test.${c.hashCode}'); + await db.open(); + return db; +} diff --git a/test/fake_database_native.dart b/test/fake_database_native.dart deleted file mode 100644 index 564b8065..00000000 --- a/test/fake_database_native.dart +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'dart:io'; -import 'dart:math'; - -import 'package:matrix/matrix.dart'; -import 'package:matrix/src/database/hive_database.dart'; -import 'package:file/memory.dart'; -import 'package:hive/hive.dart'; -import 'package:moor/moor.dart'; -import 'package:moor/ffi.dart' as moor; - -Future getDatabase(Client _) => getHiveDatabase(_); - -Future getMoorDatabase(Client _) async { - moorRuntimeOptions.dontWarnAboutMultipleDatabases = true; - return Database(moor.VmDatabase.memory()); -} - -bool hiveInitialized = false; - -Future getHiveDatabase(Client c) async { - if (!hiveInitialized) { - final fileSystem = MemoryFileSystem(); - final testHivePath = - '${fileSystem.path}/build/.test_store/${Random().nextDouble()}'; - Directory(testHivePath).createSync(recursive: true); - Hive.init(testHivePath); - hiveInitialized = true; - } - final db = FamedlySdkHiveDatabase('unit_test.${c.hashCode}'); - await db.open(); - return db; -} diff --git a/test/fake_database_web.dart b/test/fake_database_web.dart deleted file mode 100644 index ed3d610f..00000000 --- a/test/fake_database_web.dart +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Famedly Matrix SDK - * Copyright (C) 2019, 2020 Famedly GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'package:matrix/matrix.dart'; -import 'package:moor/moor.dart'; -import 'package:moor/moor_web.dart' as moor; - -Future getDatabase(Client _) async { - moorRuntimeOptions.dontWarnAboutMultipleDatabases = true; - return Database(moor.WebDatabase('test')); -} diff --git a/test/room_test.dart b/test/room_test.dart index e9142ab4..8623b34a 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -21,8 +21,6 @@ import 'dart:typed_data'; import 'package:matrix/matrix.dart'; import 'package:matrix/src/client.dart'; -import 'package:matrix/src/database/database.dart' - show DbRoom, DbRoomAccountData, DbRoomState, getRoomFromTableRow; import 'package:matrix/src/event.dart'; import 'package:matrix/src/room.dart'; import 'package:matrix/src/user.dart'; @@ -55,51 +53,40 @@ void main() { '@charley:example.org' ]; - final dbRoom = DbRoom( - clientId: 1, - roomId: id, - membership: membership.toString().split('.').last, + room = Room( + client: matrix, + id: id, + membership: membership, highlightCount: highlightCount, notificationCount: notificationCount, - prevBatch: '', - joinedMemberCount: notificationCount, - invitedMemberCount: notificationCount, + prev_batch: '', newestSortOrder: 0.0, oldestSortOrder: 0.0, - heroes: heroes.join(','), - ); - - final states = [ - DbRoomState( - clientId: 1, - eventId: '143273582443PhrSn:example.org', - roomId: id, - sortOrder: 0.0, - originServerTs: 1432735824653, - sender: '@example:example.org', - type: 'm.room.join_rules', - unsigned: '{"age": 1234}', - content: '{"join_rule": "public"}', - prevContent: '', - stateKey: '', - ), - ]; - - final roomAccountData = [ - DbRoomAccountData( - clientId: 1, - type: 'com.test.foo', - roomId: id, - content: '{"foo": "bar"}', - ), - ]; - - room = await getRoomFromTableRow( - dbRoom, - matrix, - states: states, - roomAccountData: roomAccountData, + summary: RoomSummary.fromJson({ + 'm.joined_member_count': 2, + 'm.invited_member_count': 2, + 'm.heroes': heroes, + }), + roomAccountData: { + 'com.test.foo': BasicRoomEvent( + type: 'com.test.foo', + roomId: id, + content: {'foo': 'bar'}, + ), + }, ); + room.setState(Event( + room: room, + eventId: '143273582443PhrSn:example.org', + roomId: id, + sortOrder: 0.0, + originServerTs: DateTime.fromMillisecondsSinceEpoch(1432735824653), + senderId: '@example:example.org', + type: 'm.room.join_rules', + unsigned: {'age': 1234}, + content: {'join_rule': 'public'}, + stateKey: '', + )); expect(room.id, id); expect(room.membership, membership);