Merge branch 'master' into soru/cross-signing

This commit is contained in:
Sorunome 2020-06-24 09:26:22 +02:00
commit f79a85ca71
No known key found for this signature in database
GPG key ID: B19471D07FC9BE9C
7 changed files with 56 additions and 22 deletions

View file

@ -404,6 +404,18 @@ class OlmManager {
String type,
Map<String, dynamic> payload) async {
var data = <String, Map<String, Map<String, dynamic>>>{};
// first check if any of our sessions we want to encrypt for are in the database
if (client.database != null) {
for (final device in deviceKeys) {
if (!olmSessions.containsKey(device.curve25519Key)) {
final sessions = await client.database.getSingleOlmSessions(
client.id, device.curve25519Key, client.userID);
if (sessions.isNotEmpty) {
_olmSessions[device.curve25519Key] = sessions;
}
}
}
}
final deviceKeysWithoutSession = List<DeviceKeys>.from(deviceKeys);
deviceKeysWithoutSession.removeWhere((DeviceKeys deviceKeys) =>
olmSessions.containsKey(deviceKeys.curve25519Key));

View file

@ -181,13 +181,12 @@ class Client {
if (accountData['m.direct'] != null &&
accountData['m.direct'].content[userId] is List<dynamic> &&
accountData['m.direct'].content[userId].length > 0) {
if (getRoomById(accountData['m.direct'].content[userId][0]) != null) {
return accountData['m.direct'].content[userId][0];
for (final roomId in accountData['m.direct'].content[userId]) {
final room = getRoomById(roomId);
if (room != null && room.membership == Membership.join) {
return roomId;
}
}
(accountData['m.direct'].content[userId] as List<dynamic>)
.remove(accountData['m.direct'].content[userId][0]);
api.setAccountData(userId, 'm.direct', directChats);
return getDirectChatFromUserId(userId);
}
for (var i = 0; i < rooms.length; i++) {
if (rooms[i].membership == Membership.invite &&

View file

@ -4,7 +4,6 @@ import 'dart:convert';
import 'package:famedlysdk/famedlysdk.dart' as sdk;
import 'package:famedlysdk/matrix_api.dart' as api;
import 'package:olm/olm.dart' as olm;
import 'package:pedantic/pedantic.dart';
import '../../matrix_api.dart';
@ -21,20 +20,6 @@ class Database extends _$Database {
int get maxFileSize => 1 * 1024 * 1024;
@override
Future<void> beforeOpen(
QueryExecutor executor, OpeningDetails details) async {
await super.beforeOpen(executor, details);
if (executor.dialect == SqlDialect.sqlite) {
unawaited(customSelect('PRAGMA journal_mode=WAL').get().then((ret) {
if (ret.isNotEmpty) {
print('[Moor] Switched database to mode ' +
ret.first.data['journal_mode'].toString());
}
}));
}
}
@override
MigrationStrategy get migration => MigrationStrategy(
onCreate: (Migrator m) {
@ -71,6 +56,15 @@ class Database extends _$Database {
from++;
}
},
beforeOpen: (_) async {
if (executor.dialect == SqlDialect.sqlite) {
final ret = await customSelect('PRAGMA journal_mode=WAL').get();
if (ret.isNotEmpty) {
print('[Moor] Switched database to mode ' +
ret.first.data['journal_mode'].toString());
}
}
},
);
Future<DbClient> getClient(String name) async {

View file

@ -6186,6 +6186,29 @@ abstract class _$Database extends GeneratedDatabase {
);
}
DbRoom _rowToDbRoom(QueryRow row) {
return DbRoom(
clientId: row.readInt('client_id'),
roomId: row.readString('room_id'),
membership: row.readString('membership'),
highlightCount: row.readInt('highlight_count'),
notificationCount: row.readInt('notification_count'),
prevBatch: row.readString('prev_batch'),
joinedMemberCount: row.readInt('joined_member_count'),
invitedMemberCount: row.readInt('invited_member_count'),
newestSortOrder: row.readDouble('newest_sort_order'),
oldestSortOrder: row.readDouble('oldest_sort_order'),
heroes: row.readString('heroes'),
);
}
Selectable<DbRoom> getRoom(int client_id, String room_id) {
return customSelect(
'SELECT * FROM rooms WHERE client_id = :client_id AND room_id = :room_id',
variables: [Variable.withInt(client_id), Variable.withString(room_id)],
readsFrom: {rooms}).map(_rowToDbRoom);
}
Selectable<DbEvent> 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',

View file

@ -218,6 +218,7 @@ dbGetUser: SELECT * FROM room_states WHERE client_id = :client_id AND type = 'm.
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;

View file

@ -307,7 +307,10 @@ class Event extends MatrixEvent {
Future<String> sendAgain({String txid}) async {
if (status != -1) return null;
await remove();
final eventID = await room.sendTextEvent(text, txid: txid);
final eventID = await room.sendEvent(
content,
txid: txid ?? unsigned['transaction_id'],
);
return eventID;
}

View file

@ -156,8 +156,10 @@ class Timeline {
: null);
if (i < events.length) {
final tempSortOrder = events[i].sortOrder;
events[i] = Event.fromJson(
eventUpdate.content, room, eventUpdate.sortOrder);
events[i].sortOrder = tempSortOrder;
}
} else {
Event newEvent;