Merge pull request #1973 from famedly/krille/fix-flutter-3-27-lints

refactor: Fix new lints from flutter 3.27
This commit is contained in:
Krille-chan 2024-12-17 13:05:49 +01:00 committed by GitHub
commit 5d7b802027
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 57 additions and 62 deletions

View File

@ -129,7 +129,7 @@ jobs:
- name: Run tests - name: Run tests
run: | run: |
dart pub get dart pub get
dart test test/box_test.dart --platform chrome dart test test/box_test.dart --platform chrome --fail-fast
pub-dev-dry-run: pub-dev-dry-run:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -1,2 +1,2 @@
flutter_version=3.24.3 flutter_version=3.27.1
dart_version=3.5.3 dart_version=3.6.0

View File

@ -193,7 +193,7 @@ class Encryption {
} }
} }
Event decryptRoomEventSync(String roomId, Event event) { Event decryptRoomEventSync(Event event) {
if (event.type != EventTypes.Encrypted || event.redacted) { if (event.type != EventTypes.Encrypted || event.redacted) {
return event; return event;
} }
@ -214,7 +214,7 @@ class Encryption {
} }
final inboundGroupSession = final inboundGroupSession =
keyManager.getInboundGroupSession(roomId, sessionId); keyManager.getInboundGroupSession(event.room.id, sessionId);
if (!(inboundGroupSession?.isValid ?? false)) { if (!(inboundGroupSession?.isValid ?? false)) {
canRequestSession = true; canRequestSession = true;
throw DecryptException(DecryptException.unknownSession); throw DecryptException(DecryptException.unknownSession);
@ -249,7 +249,7 @@ class Encryption {
// ignore: discarded_futures // ignore: discarded_futures
?.updateInboundGroupSessionIndexes( ?.updateInboundGroupSessionIndexes(
json.encode(inboundGroupSession.indexes), json.encode(inboundGroupSession.indexes),
roomId, event.room.id,
sessionId, sessionId,
) )
// ignore: discarded_futures // ignore: discarded_futures
@ -260,14 +260,16 @@ class Encryption {
// alright, if this was actually by our own outbound group session, we might as well clear it // alright, if this was actually by our own outbound group session, we might as well clear it
if (exception.toString() != DecryptException.unknownSession && if (exception.toString() != DecryptException.unknownSession &&
(keyManager (keyManager
.getOutboundGroupSession(roomId) .getOutboundGroupSession(event.room.id)
?.outboundGroupSession ?.outboundGroupSession
?.session_id() ?? ?.session_id() ??
'') == '') ==
content.sessionId) { content.sessionId) {
runInRoot( runInRoot(
() async => () async => keyManager.clearOrUseOutboundGroupSession(
keyManager.clearOrUseOutboundGroupSession(roomId, wipe: true), event.room.id,
wipe: true,
),
); );
} }
if (canRequestSession) { if (canRequestSession) {
@ -308,7 +310,6 @@ class Encryption {
} }
Future<Event> decryptRoomEvent( Future<Event> decryptRoomEvent(
String roomId,
Event event, { Event event, {
bool store = false, bool store = false,
EventUpdateType updateType = EventUpdateType.timeline, EventUpdateType updateType = EventUpdateType.timeline,
@ -323,22 +324,22 @@ class Encryption {
sessionId != null && sessionId != null &&
!(keyManager !(keyManager
.getInboundGroupSession( .getInboundGroupSession(
roomId, event.room.id,
sessionId, sessionId,
) )
?.isValid ?? ?.isValid ??
false)) { false)) {
await keyManager.loadInboundGroupSession( await keyManager.loadInboundGroupSession(
roomId, event.room.id,
sessionId, sessionId,
); );
} }
event = decryptRoomEventSync(roomId, event); event = decryptRoomEventSync(event);
if (event.type == EventTypes.Encrypted && if (event.type == EventTypes.Encrypted &&
event.content['can_request_session'] == true && event.content['can_request_session'] == true &&
sessionId != null) { sessionId != null) {
keyManager.maybeAutoRequest( keyManager.maybeAutoRequest(
roomId, event.room.id,
sessionId, sessionId,
content.senderKey, content.senderKey,
); );
@ -350,7 +351,7 @@ class Encryption {
await client.database?.storeEventUpdate( await client.database?.storeEventUpdate(
EventUpdate( EventUpdate(
content: event.toJson(), content: event.toJson(),
roomID: roomId, roomID: event.room.id,
type: updateType, type: updateType,
), ),
client, client,

View File

@ -192,7 +192,7 @@ class KeyManager {
if (event != null && if (event != null &&
event.type == EventTypes.Encrypted && event.type == EventTypes.Encrypted &&
event.content['session_id'] == sessionId) { event.content['session_id'] == sessionId) {
final decrypted = encryption.decryptRoomEventSync(roomId, event); final decrypted = encryption.decryptRoomEventSync(event);
if (decrypted.type != EventTypes.Encrypted) { if (decrypted.type != EventTypes.Encrypted) {
// Update the last event in memory first // Update the last event in memory first
room.lastEvent = decrypted; room.lastEvent = decrypted;

View File

@ -27,7 +27,9 @@ extension JsonSignatureCheckExtension on Map<String, dynamic> {
final signatures = this['signatures']; final signatures = this['signatures'];
if (signatures == null || if (signatures == null ||
signatures is! Map<String, dynamic> || signatures is! Map<String, dynamic> ||
!signatures.containsKey(userId)) return false; !signatures.containsKey(userId)) {
return false;
}
remove('unsigned'); remove('unsigned');
remove('signatures'); remove('signatures');
if (!signatures[userId].containsKey('ed25519:$deviceId')) return false; if (!signatures[userId].containsKey('ed25519:$deviceId')) return false;

View File

@ -54,7 +54,9 @@ extension DehydratedDeviceHandler on Client {
// Only handle devices we understand // Only handle devices we understand
// In the future we might want to migrate to a newer format here // In the future we might want to migrate to a newer format here
if (device.deviceData?.tryGet<String>('algorithm') != if (device.deviceData?.tryGet<String>('algorithm') !=
_dehydratedDeviceAlgorithm) return; _dehydratedDeviceAlgorithm) {
return;
}
// Verify that the device is cross-signed // Verify that the device is cross-signed
final dehydratedDeviceIdentity = final dehydratedDeviceIdentity =

View File

@ -1243,10 +1243,7 @@ class Client extends MatrixApi {
if (archivedRoom.encrypted && archivedRoom.client.encryptionEnabled) { if (archivedRoom.encrypted && archivedRoom.client.encryptionEnabled) {
if (timeline.events[i].type == EventTypes.Encrypted) { if (timeline.events[i].type == EventTypes.Encrypted) {
await archivedRoom.client.encryption! await archivedRoom.client.encryption!
.decryptRoomEvent( .decryptRoomEvent(timeline.events[i])
archivedRoom.id,
timeline.events[i],
)
.then( .then(
(decrypted) => timeline.events[i] = decrypted, (decrypted) => timeline.events[i] = decrypted,
); );
@ -1880,11 +1877,11 @@ class Client extends MatrixApi {
final encryption = this.encryption; final encryption = this.encryption;
if (event.type == EventTypes.Encrypted && encryption != null) { if (event.type == EventTypes.Encrypted && encryption != null) {
var decrypted = await encryption.decryptRoomEvent(roomId, event); var decrypted = await encryption.decryptRoomEvent(event);
if (decrypted.messageType == MessageTypes.BadEncrypted && if (decrypted.messageType == MessageTypes.BadEncrypted &&
prevBatch != null) { prevBatch != null) {
await oneShotSync(); await oneShotSync();
decrypted = await encryption.decryptRoomEvent(roomId, event); decrypted = await encryption.decryptRoomEvent(event);
} }
event = decrypted; event = decrypted;
} }
@ -2567,7 +2564,9 @@ class Client extends MatrixApi {
if (event.event.roomID != roomId) continue; if (event.event.roomID != roomId) continue;
if (!sessionIds.contains( if (!sessionIds.contains(
event.event.content['content']?['session_id'], event.event.content['content']?['session_id'],
)) continue; )) {
continue;
}
final decryptedEvent = await event.event.decrypt(room); final decryptedEvent = await event.event.decrypt(room);
if (decryptedEvent.content.tryGet<String>('type') != if (decryptedEvent.content.tryGet<String>('type') !=

View File

@ -115,7 +115,9 @@ class ReceiptEventContent {
if (userId is! String || if (userId is! String ||
!userId.isValidMatrixId || !userId.isValidMatrixId ||
receiptContent is! Map) continue; receiptContent is! Map) {
continue;
}
final ts = receiptContent['ts']; final ts = receiptContent['ts'];
final threadId = receiptContent['thread_id']; final threadId = receiptContent['thread_id'];

View File

@ -518,7 +518,9 @@ class Room {
// There is no known event or the last event is only a state fallback event, // There is no known event or the last event is only a state fallback event,
// we assume there is no new messages. // we assume there is no new messages.
if (lastEvent == null || if (lastEvent == null ||
!client.roomPreviewLastEvents.contains(lastEvent.type)) return false; !client.roomPreviewLastEvents.contains(lastEvent.type)) {
return false;
}
// Read marker is on the last event so no new messages. // Read marker is on the last event so no new messages.
if (lastEvent.receipts if (lastEvent.receipts
@ -1458,10 +1460,7 @@ class Room {
for (var i = 0; i < events.length; i++) { for (var i = 0; i < events.length; i++) {
if (events[i].type == EventTypes.Encrypted && if (events[i].type == EventTypes.Encrypted &&
events[i].content['can_request_session'] == true) { events[i].content['can_request_session'] == true) {
events[i] = await client.encryption!.decryptRoomEvent( events[i] = await client.encryption!.decryptRoomEvent(events[i]);
id,
events[i],
);
} }
} }
} }
@ -1527,10 +1526,7 @@ class Room {
// Try to decrypt encrypted events but don't update the database. // Try to decrypt encrypted events but don't update the database.
if (encrypted && client.encryptionEnabled) { if (encrypted && client.encryptionEnabled) {
if (events[i].type == EventTypes.Encrypted) { if (events[i].type == EventTypes.Encrypted) {
events[i] = await client.encryption!.decryptRoomEvent( events[i] = await client.encryption!.decryptRoomEvent(events[i]);
id,
events[i],
);
} }
} }
} }
@ -1574,7 +1570,6 @@ class Room {
// for the fragmented timeline, we don't cache the decrypted // for the fragmented timeline, we don't cache the decrypted
//message in the database //message in the database
chunk.events[i] = await client.encryption!.decryptRoomEvent( chunk.events[i] = await client.encryption!.decryptRoomEvent(
id,
chunk.events[i], chunk.events[i],
); );
} else if (client.database != null) { } else if (client.database != null) {
@ -1583,7 +1578,6 @@ class Room {
for (var i = 0; i < chunk.events.length; i++) { for (var i = 0; i < chunk.events.length; i++) {
if (chunk.events[i].content['can_request_session'] == true) { if (chunk.events[i].content['can_request_session'] == true) {
chunk.events[i] = await client.encryption!.decryptRoomEvent( chunk.events[i] = await client.encryption!.decryptRoomEvent(
id,
chunk.events[i], chunk.events[i],
store: !isArchived, store: !isArchived,
updateType: EventUpdateType.history, updateType: EventUpdateType.history,
@ -1911,10 +1905,7 @@ class Room {
final event = Event.fromMatrixEvent(matrixEvent, this); final event = Event.fromMatrixEvent(matrixEvent, this);
if (event.type == EventTypes.Encrypted && client.encryptionEnabled) { if (event.type == EventTypes.Encrypted && client.encryptionEnabled) {
// attempt decryption // attempt decryption
return await client.encryption?.decryptRoomEvent( return await client.encryption?.decryptRoomEvent(event);
id,
event,
);
} }
return event; return event;
} on MatrixException catch (err) { } on MatrixException catch (err) {

View File

@ -263,7 +263,9 @@ class Timeline {
if (!allowNewEvent) { if (!allowNewEvent) {
if (resp.start == resp.end || if (resp.start == resp.end ||
(resp.end == null && direction == Direction.f)) allowNewEvent = true; (resp.end == null && direction == Direction.f)) {
allowNewEvent = true;
}
if (allowNewEvent) { if (allowNewEvent) {
Logs().d('We now allow sync update into the timeline.'); Logs().d('We now allow sync update into the timeline.');
@ -279,7 +281,6 @@ class Timeline {
for (var i = 0; i < newEvents.length; i++) { for (var i = 0; i < newEvents.length; i++) {
if (newEvents[i].type == EventTypes.Encrypted) { if (newEvents[i].type == EventTypes.Encrypted) {
newEvents[i] = await room.client.encryption!.decryptRoomEvent( newEvents[i] = await room.client.encryption!.decryptRoomEvent(
room.id,
newEvents[i], newEvents[i],
); );
} }
@ -388,7 +389,6 @@ class Timeline {
events[i].messageType == MessageTypes.BadEncrypted && events[i].messageType == MessageTypes.BadEncrypted &&
events[i].content['session_id'] == sessionId) { events[i].content['session_id'] == sessionId) {
events[i] = await encryption.decryptRoomEvent( events[i] = await encryption.decryptRoomEvent(
room.id,
events[i], events[i],
store: true, store: true,
updateType: EventUpdateType.history, updateType: EventUpdateType.history,
@ -566,7 +566,9 @@ class Timeline {
events.indexWhere( events.indexWhere(
(e) => e.eventId == eventUpdate.content['event_id'], (e) => e.eventId == eventUpdate.content['event_id'],
) != ) !=
-1) return; -1) {
return;
}
var index = events.length; var index = events.length;
if (eventUpdate.type == EventUpdateType.history) { if (eventUpdate.type == EventUpdateType.history) {
events.add(newEvent); events.add(newEvent);
@ -703,7 +705,7 @@ class Timeline {
for (final matrixEvent in resp.chunk) { for (final matrixEvent in resp.chunk) {
var event = Event.fromMatrixEvent(matrixEvent, room); var event = Event.fromMatrixEvent(matrixEvent, room);
if (event.type == EventTypes.Encrypted && encryption != null) { if (event.type == EventTypes.Encrypted && encryption != null) {
event = await encryption.decryptRoomEvent(room.id, event); event = await encryption.decryptRoomEvent(event);
if (event.type == EventTypes.Encrypted && if (event.type == EventTypes.Encrypted &&
event.messageType == MessageTypes.BadEncrypted && event.messageType == MessageTypes.BadEncrypted &&
event.content['can_request_session'] == true) { event.content['can_request_session'] == true) {

View File

@ -203,7 +203,6 @@ abstract class EventLocalizations {
case RoomMemberChangeType.knock: case RoomMemberChangeType.knock:
return i18n.hasKnocked(targetName); return i18n.hasKnocked(targetName);
case RoomMemberChangeType.other: case RoomMemberChangeType.other:
default:
return userIsTarget return userIsTarget
? i18n.youJoinedTheChat ? i18n.youJoinedTheChat
: i18n.joinedTheChat(targetName); : i18n.joinedTheChat(targetName);

View File

@ -68,7 +68,6 @@ class EventUpdate {
} }
try { try {
final decrpytedEvent = await encryption.decryptRoomEvent( final decrpytedEvent = await encryption.decryptRoomEvent(
room.id,
Event.fromJson(content, room), Event.fromJson(content, room),
store: store, store: store,
updateType: type, updateType: type,

View File

@ -29,7 +29,7 @@ class PushNotification {
}); });
/// Generate a Push Notification object from JSON. It also supports a /// Generate a Push Notification object from JSON. It also supports a
/// <String, String> map which usually comes from Firebase Cloud Messaging. /// `map<String, String>` which usually comes from Firebase Cloud Messaging.
factory PushNotification.fromJson(Map<String, dynamic> json) => factory PushNotification.fromJson(Map<String, dynamic> json) =>
PushNotification( PushNotification(
content: json['content'] is Map content: json['content'] is Map

View File

@ -153,7 +153,6 @@ class _MemberCountCondition {
case _CountComparisonOp.lt: case _CountComparisonOp.lt:
return memberCount < count; return memberCount < count;
case _CountComparisonOp.eq: case _CountComparisonOp.eq:
default:
return memberCount == count; return memberCount == count;
} }
} }

View File

@ -13,11 +13,10 @@ bool isVersionGreaterThanOrEqualTo(String version, String target) {
} }
return true; return true;
} catch (e, s) { } catch (e) {
Logs().e( Logs().w(
'[_isVersionGreaterThanOrEqualTo] Failed to parse version $version', '[_isVersionGreaterThanOrEqualTo] Failed to parse version $version',
e, e,
s,
); );
return false; return false;
} }

View File

@ -650,7 +650,6 @@ class MeshBackend extends CallBackend {
await call.setLocalVideoMuted(muted); await call.setLocalVideoMuted(muted);
} }
break; break;
default:
} }
} }

View File

@ -1016,7 +1016,9 @@ class CallSession {
// when a call crash and this call is already terminated the currentCId is null. // when a call crash and this call is already terminated the currentCId is null.
// So don't return bc the hangup or reject will not proceed anymore. // So don't return bc the hangup or reject will not proceed anymore.
if (voip.currentCID != null && if (voip.currentCID != null &&
voip.currentCID != VoipId(roomId: room.id, callId: callId)) return; voip.currentCID != VoipId(roomId: room.id, callId: callId)) {
return;
}
voip.currentCID = null; voip.currentCID = null;
voip.incomingCallRoomId.removeWhere((key, value) => value == callId); voip.incomingCallRoomId.removeWhere((key, value) => value == callId);
} }

View File

@ -6,7 +6,7 @@ if [ -n "$NO_OLM" ]; then
tagFlag="-x olm" tagFlag="-x olm"
fi fi
dart test --concurrency=$thread_count --coverage=coverage_dir $tagFlag dart test --concurrency=$thread_count --coverage=coverage_dir $tagFlag --fail-fast
TEST_CODE=$? TEST_CODE=$?
# lets you do more stuff like reporton # lets you do more stuff like reporton

View File

@ -109,7 +109,7 @@ void main() {
}); });
test('Login', () async { test('Login', () async {
matrix = Client( final matrix = Client(
'testclient', 'testclient',
httpClient: FakeMatrixApi(), httpClient: FakeMatrixApi(),
databaseBuilder: getDatabase, databaseBuilder: getDatabase,

View File

@ -61,7 +61,7 @@ void main() {
senderId: client.userID!, senderId: client.userID!,
); );
final decryptedEvent = final decryptedEvent =
await client.encryption!.decryptRoomEvent(roomId, encryptedEvent); await client.encryption!.decryptRoomEvent(encryptedEvent);
expect(decryptedEvent.type, 'm.room.message'); expect(decryptedEvent.type, 'm.room.message');
expect(decryptedEvent.content['msgtype'], 'm.text'); expect(decryptedEvent.content['msgtype'], 'm.text');
expect(decryptedEvent.content['text'], 'Hello foxies!'); expect(decryptedEvent.content['text'], 'Hello foxies!');
@ -80,7 +80,7 @@ void main() {
senderId: client.userID!, senderId: client.userID!,
); );
final decryptedEvent = final decryptedEvent =
await client.encryption!.decryptRoomEvent(roomId, encryptedEvent); await client.encryption!.decryptRoomEvent(encryptedEvent);
expect(decryptedEvent.type, 'm.room.message'); expect(decryptedEvent.type, 'm.room.message');
expect(decryptedEvent.content['msgtype'], 'm.text'); expect(decryptedEvent.content['msgtype'], 'm.text');
expect(decryptedEvent.content['text'], 'Hello foxies!'); expect(decryptedEvent.content['text'], 'Hello foxies!');
@ -98,12 +98,11 @@ void main() {
senderId: '@alice:example.com', senderId: '@alice:example.com',
); );
final decryptedEvent = final decryptedEvent =
await client.encryption!.decryptRoomEvent(roomId, encryptedEvent); await client.encryption!.decryptRoomEvent(encryptedEvent);
expect(decryptedEvent.type, 'm.room.message'); expect(decryptedEvent.type, 'm.room.message');
expect(decryptedEvent.content['msgtype'], 'm.text'); expect(decryptedEvent.content['msgtype'], 'm.text');
expect(decryptedEvent.content['text'], 'Hello foxies!'); expect(decryptedEvent.content['text'], 'Hello foxies!');
await client.encryption! await client.encryption!.decryptRoomEvent(encryptedEvent, store: true);
.decryptRoomEvent(roomId, encryptedEvent, store: true);
}); });
test('dispose client', () async { test('dispose client', () async {