Minor refactoring

This commit is contained in:
Christian Pauly 2020-06-25 07:16:59 +00:00 committed by Sorunome
parent 802e3c3f4d
commit 52e57f8dc2
2 changed files with 8 additions and 23 deletions

View file

@ -722,11 +722,11 @@ class Client {
if (sync.presence != null) { if (sync.presence != null) {
for (final newPresence in sync.presence) { for (final newPresence in sync.presence) {
if (database != null) { if (database != null) {
await database.storeUserEventUpdate( await database.storePresence(
id, id,
'presence',
newPresence.type, newPresence.type,
newPresence.toJson(), newPresence.senderId,
jsonEncode(newPresence.toJson()),
); );
} }
presences[newPresence.senderId] = newPresence; presences[newPresence.senderId] = newPresence;
@ -736,15 +736,17 @@ class Client {
if (sync.accountData != null) { if (sync.accountData != null) {
for (final newAccountData in sync.accountData) { for (final newAccountData in sync.accountData) {
if (database != null) { if (database != null) {
await database.storeUserEventUpdate( await database.storeAccountData(
id, id,
'account_data',
newAccountData.type, newAccountData.type,
newAccountData.toJson(), jsonEncode(newAccountData.toJson()),
); );
} }
accountData[newAccountData.type] = newAccountData; accountData[newAccountData.type] = newAccountData;
if (onAccountData != null) onAccountData.add(newAccountData); if (onAccountData != null) onAccountData.add(newAccountData);
if (newAccountData.type == 'm.direct') {
_sortRooms();
}
} }
} }
if (sync.deviceLists != null) { if (sync.deviceLists != null) {

View file

@ -255,23 +255,6 @@ class Database extends _$Database {
} }
} }
/// Stores an UserUpdate object in the database. Must be called inside of
/// [transaction].
Future<void> storeUserEventUpdate(
int clientId,
String type,
String eventType,
Map<String, dynamic> content,
) async {
if (type == 'account_data') {
await storeAccountData(
clientId, eventType, json.encode(content['content']));
} else if (type == 'presence') {
await storePresence(clientId, eventType, content['sender'],
json.encode(content['content']));
}
}
/// Stores an EventUpdate object in the database. Must be called inside of /// Stores an EventUpdate object in the database. Must be called inside of
/// [transaction]. /// [transaction].
Future<void> storeEventUpdate( Future<void> storeEventUpdate(