Skip to content

Commit 0dcec55

Browse files
committed
refactor: event-getter
1 parent 9af1c56 commit 0dcec55

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

lib/src/event.dart

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,13 @@ class Event extends MatrixEvent {
534534
}
535535

536536
/// Gets the info map of file events, or a blank map if none present
537-
Map get infoMap =>
537+
Map<String, Object?> get infoMap =>
538538
content.tryGetMap<String, Object?>('info') ?? <String, Object?>{};
539539

540540
/// Gets the thumbnail info map of file events, or a blank map if nonepresent
541-
Map get thumbnailInfoMap => infoMap['thumbnail_info'] is Map
542-
? infoMap['thumbnail_info']
543-
: <String, dynamic>{};
541+
Map<String, Object?> get thumbnailInfoMap => infoMap['thumbnail_info'] is Map
542+
? (infoMap['thumbnail_info'] as Map).cast<String, Object?>()
543+
: <String, Object?>{};
544544

545545
/// Returns if a file event has an attachment
546546
bool get hasAttachment => content['url'] is String || content['file'] is Map;
@@ -557,18 +557,18 @@ class Event extends MatrixEvent {
557557

558558
/// Gets the mimetype of the attachment of a file event, or a blank string if not present
559559
String get attachmentMimetype => infoMap['mimetype'] is String
560-
? infoMap['mimetype'].toLowerCase()
560+
? (infoMap['mimetype'] as String).toLowerCase()
561561
: (content
562562
.tryGetMap<String, Object?>('file')
563563
?.tryGet<String>('mimetype') ??
564564
'');
565565

566566
/// Gets the mimetype of the thumbnail of a file event, or a blank string if not present
567567
String get thumbnailMimetype => thumbnailInfoMap['mimetype'] is String
568-
? thumbnailInfoMap['mimetype'].toLowerCase()
568+
? (thumbnailInfoMap['mimetype'] as String).toLowerCase()
569569
: (infoMap['thumbnail_file'] is Map &&
570-
infoMap['thumbnail_file']['mimetype'] is String
571-
? infoMap['thumbnail_file']['mimetype']
570+
(infoMap['thumbnail_file'] as Map)['mimetype'] is String
571+
? (infoMap['thumbnail_file'] as Map)['mimetype'] as String
572572
: '');
573573

574574
/// Gets the underlying mxc url of an attachment of a file event, or null if not present
@@ -582,7 +582,7 @@ class Event extends MatrixEvent {
582582
/// Gets the underlying mxc url of a thumbnail of a file event, or null if not present
583583
Uri? get thumbnailMxcUrl {
584584
final url = isThumbnailEncrypted
585-
? infoMap['thumbnail_file']['url']
585+
? (infoMap['thumbnail_file'] as Map)['url']
586586
: infoMap['thumbnail_url'];
587587
return url is String ? Uri.tryParse(url) : null;
588588
}
@@ -592,7 +592,7 @@ class Event extends MatrixEvent {
592592
if (getThumbnail &&
593593
infoMap['size'] is int &&
594594
thumbnailInfoMap['size'] is int &&
595-
infoMap['size'] <= thumbnailInfoMap['size']) {
595+
(infoMap['size'] as int) <= (thumbnailInfoMap['size'] as int)) {
596596
getThumbnail = false;
597597
}
598598
if (getThumbnail && !hasThumbnail) {
@@ -641,20 +641,20 @@ class Event extends MatrixEvent {
641641
if (getThumbnail &&
642642
method == ThumbnailMethod.scale &&
643643
thisInfoMap['size'] is int &&
644-
thisInfoMap['size'] < minNoThumbSize) {
644+
(thisInfoMap['size'] as int) < minNoThumbSize) {
645645
getThumbnail = false;
646646
}
647647
// now generate the actual URLs
648648
if (getThumbnail) {
649-
return await Uri.parse(thisMxcUrl).getThumbnailUri(
649+
return await Uri.parse(thisMxcUrl as String).getThumbnailUri(
650650
room.client,
651651
width: width,
652652
height: height,
653653
method: method,
654654
animated: animated,
655655
);
656656
} else {
657-
return await Uri.parse(thisMxcUrl).getDownloadUri(room.client);
657+
return await Uri.parse(thisMxcUrl as String).getDownloadUri(room.client);
658658
}
659659
}
660660

@@ -696,20 +696,20 @@ class Event extends MatrixEvent {
696696
if (getThumbnail &&
697697
method == ThumbnailMethod.scale &&
698698
thisInfoMap['size'] is int &&
699-
thisInfoMap['size'] < minNoThumbSize) {
699+
(thisInfoMap['size'] as int) < minNoThumbSize) {
700700
getThumbnail = false;
701701
}
702702
// now generate the actual URLs
703703
if (getThumbnail) {
704-
return Uri.parse(thisMxcUrl).getThumbnail(
704+
return Uri.parse(thisMxcUrl as String).getThumbnail(
705705
room.client,
706706
width: width,
707707
height: height,
708708
method: method,
709709
animated: animated,
710710
);
711711
} else {
712-
return Uri.parse(thisMxcUrl).getDownloadLink(room.client);
712+
return Uri.parse(thisMxcUrl as String).getDownloadLink(room.client);
713713
}
714714
}
715715

@@ -731,7 +731,7 @@ class Event extends MatrixEvent {
731731
}
732732

733733
final storeable = thisInfoMap['size'] is int &&
734-
thisInfoMap['size'] <= database.maxFileSize;
734+
(thisInfoMap['size'] as int) <= database.maxFileSize;
735735

736736
Uint8List? uint8list;
737737
if (storeable) {
@@ -774,7 +774,7 @@ class Event extends MatrixEvent {
774774
final thisInfoMap = getThumbnail ? thumbnailInfoMap : infoMap;
775775
var storeable = database != null &&
776776
thisInfoMap['size'] is int &&
777-
thisInfoMap['size'] <= database.maxFileSize;
777+
(thisInfoMap['size'] as int) <= database.maxFileSize;
778778

779779
Uint8List? uint8list;
780780
if (storeable) {
@@ -808,16 +808,17 @@ class Event extends MatrixEvent {
808808

809809
// Decrypt the file
810810
if (isEncrypted) {
811-
final fileMap =
812-
getThumbnail ? infoMap['thumbnail_file'] : content['file'];
813-
if (!fileMap['key']['key_ops'].contains('decrypt')) {
811+
final fileMap = getThumbnail
812+
? infoMap['thumbnail_file'] as Map
813+
: content['file'] as Map;
814+
if (!(fileMap['key'] as Map)['key_ops'].contains('decrypt')) {
814815
throw ("Missing 'decrypt' in 'key_ops'.");
815816
}
816817
final encryptedFile = EncryptedFile(
817818
data: uint8list,
818-
iv: fileMap['iv'],
819-
k: fileMap['key']['k'],
820-
sha256: fileMap['hashes']['sha256'],
819+
iv: fileMap['iv'] as String,
820+
k: (fileMap['key'] as Map)['k'] as String,
821+
sha256: (fileMap['hashes'] as Map)['sha256'] as String,
821822
);
822823
uint8list =
823824
await room.client.nativeImplementations.decryptFile(encryptedFile);

0 commit comments

Comments
 (0)