refactor: high-level loops
This commit is contained in:
parent
71fdd28a8a
commit
b4f755388a
|
|
@ -115,19 +115,11 @@ class CrossSigning {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool signable(List<SignableKey> keys) {
|
bool signable(List<SignableKey> keys) => keys.any((key) =>
|
||||||
for (final key in keys) {
|
key is CrossSigningKey && key.usage.contains('master') ||
|
||||||
if (key is CrossSigningKey && key.usage.contains('master')) {
|
key is DeviceKeys &&
|
||||||
return true;
|
key.userId == client.userID &&
|
||||||
}
|
key.identifier != client.deviceID);
|
||||||
if (key.userId == client.userID &&
|
|
||||||
(key is DeviceKeys) &&
|
|
||||||
key.identifier != client.deviceID) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> sign(List<SignableKey> keys) async {
|
Future<void> sign(List<SignableKey> keys) async {
|
||||||
Uint8List selfSigningKey;
|
Uint8List selfSigningKey;
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,7 @@ class KeyVerificationManager {
|
||||||
entriesToDispose.add(entry.key);
|
entriesToDispose.add(entry.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final k in entriesToDispose) {
|
entriesToDispose.forEach(_requests.remove);
|
||||||
_requests.remove(k);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addRequest(KeyVerification request) {
|
void addRequest(KeyVerification request) {
|
||||||
|
|
|
||||||
|
|
@ -74,18 +74,8 @@ enum KeyVerificationState {
|
||||||
|
|
||||||
enum KeyVerificationMethod { emoji, numbers }
|
enum KeyVerificationMethod { emoji, numbers }
|
||||||
|
|
||||||
List<String> _intersect(List<String> a, List<dynamic> b) {
|
List<String> _intersect(List<String> a, List<dynamic> b) =>
|
||||||
if (b == null || a == null) {
|
(b == null || a == null) ? [] : a.where(b.contains).toList();
|
||||||
return [];
|
|
||||||
}
|
|
||||||
final res = <String>[];
|
|
||||||
for (final v in a) {
|
|
||||||
if (b.contains(v)) {
|
|
||||||
res.add(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<int> _bytesToInt(Uint8List bytes, int totalBits) {
|
List<int> _bytesToInt(Uint8List bytes, int totalBits) {
|
||||||
final ret = <int>[];
|
final ret = <int>[];
|
||||||
|
|
|
||||||
|
|
@ -249,13 +249,11 @@ class Client extends MatrixApi {
|
||||||
if (accountData['m.direct'] != null &&
|
if (accountData['m.direct'] != null &&
|
||||||
accountData['m.direct'].content[userId] is List<dynamic> &&
|
accountData['m.direct'].content[userId] is List<dynamic> &&
|
||||||
accountData['m.direct'].content[userId].length > 0) {
|
accountData['m.direct'].content[userId].length > 0) {
|
||||||
final potentialRooms = <Room>{};
|
final potentialRooms = accountData['m.direct']
|
||||||
for (final roomId in accountData['m.direct'].content[userId]) {
|
.content[userId]
|
||||||
final room = getRoomById(roomId);
|
.cast<String>()
|
||||||
if (room != null && room.membership == Membership.join) {
|
.map(getRoomById)
|
||||||
potentialRooms.add(room);
|
.where((room) => room != null && room.membership == Membership.join);
|
||||||
}
|
|
||||||
}
|
|
||||||
if (potentialRooms.isNotEmpty) {
|
if (potentialRooms.isNotEmpty) {
|
||||||
return potentialRooms
|
return potentialRooms
|
||||||
.fold(
|
.fold(
|
||||||
|
|
|
||||||
|
|
@ -295,14 +295,11 @@ class Event extends MatrixEvent {
|
||||||
/// Returns a list of [Receipt] instances for this event.
|
/// Returns a list of [Receipt] instances for this event.
|
||||||
List<Receipt> get receipts {
|
List<Receipt> get receipts {
|
||||||
if (!(room.roomAccountData.containsKey('m.receipt'))) return [];
|
if (!(room.roomAccountData.containsKey('m.receipt'))) return [];
|
||||||
final receiptsList = <Receipt>[];
|
return room.roomAccountData['m.receipt'].content.entries
|
||||||
for (final entry in room.roomAccountData['m.receipt'].content.entries) {
|
.where((entry) => entry.value['event_id'] == eventId)
|
||||||
if (entry.value['event_id'] == eventId) {
|
.map((entry) => Receipt(room.getUserByMXIDSync(entry.key),
|
||||||
receiptsList.add(Receipt(room.getUserByMXIDSync(entry.key),
|
DateTime.fromMillisecondsSinceEpoch(entry.value['ts'])))
|
||||||
DateTime.fromMillisecondsSinceEpoch(entry.value['ts'])));
|
.toList();
|
||||||
}
|
|
||||||
}
|
|
||||||
return receiptsList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes this event if the status is < 1. This event will just be removed
|
/// Removes this event if the status is < 1. This event will just be removed
|
||||||
|
|
|
||||||
|
|
@ -285,9 +285,8 @@ class Room {
|
||||||
// perfect, it is only used for the room preview in the room list and sorting
|
// perfect, it is only used for the room preview in the room list and sorting
|
||||||
// said room list, so it should be good enough.
|
// said room list, so it should be good enough.
|
||||||
var lastTime = DateTime.fromMillisecondsSinceEpoch(0);
|
var lastTime = DateTime.fromMillisecondsSinceEpoch(0);
|
||||||
final lastEvents = <Event>[
|
final lastEvents =
|
||||||
for (var type in client.roomPreviewLastEvents) getState(type)
|
client.roomPreviewLastEvents.map(getState).where((e) => e != null);
|
||||||
]..removeWhere((e) => e == null);
|
|
||||||
|
|
||||||
var lastEvent = lastEvents.isEmpty
|
var lastEvent = lastEvents.isEmpty
|
||||||
? null
|
? null
|
||||||
|
|
@ -375,12 +374,10 @@ class Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (heroes.isNotEmpty) {
|
if (heroes.isNotEmpty) {
|
||||||
var displayname = '';
|
return heroes
|
||||||
for (final hero in heroes) {
|
.where((hero) => hero.isNotEmpty)
|
||||||
if (hero.isEmpty) continue;
|
.map((hero) => getUserByMXIDSync(hero).calcDisplayname())
|
||||||
displayname += getUserByMXIDSync(hero).calcDisplayname() + ', ';
|
.join(', ');
|
||||||
}
|
|
||||||
return displayname.substring(0, displayname.length - 2);
|
|
||||||
}
|
}
|
||||||
if (membership == Membership.invite &&
|
if (membership == Membership.invite &&
|
||||||
getState(EventTypes.RoomMember, client.userID) != null) {
|
getState(EventTypes.RoomMember, client.userID) != null) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue