refactor: Make most of the utils null safe
This commit is contained in:
parent
110d0506aa
commit
265ef0ebb2
23 changed files with 140 additions and 112 deletions
|
|
@ -1,3 +1,5 @@
|
|||
//@dart=2.12
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
extension ClientPresenceExtension on Client {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
|
@ -31,14 +33,14 @@ IconData _getIconFromName(String displayname) {
|
|||
|
||||
extension DeviceExtension on Device {
|
||||
String get displayname =>
|
||||
(displayName?.isNotEmpty ?? false) ? displayName : 'Unknown device';
|
||||
(displayName?.isNotEmpty ?? false) ? displayName! : 'Unknown device';
|
||||
|
||||
IconData get icon => _getIconFromName(displayname);
|
||||
}
|
||||
|
||||
extension DeviceKeysExtension on DeviceKeys {
|
||||
String get displayname => (deviceDisplayName?.isNotEmpty ?? false)
|
||||
? deviceDisplayName
|
||||
? deviceDisplayName!
|
||||
: 'Unknown device';
|
||||
|
||||
IconData get icon => _getIconFromName(displayname);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
|
@ -19,10 +21,10 @@ extension LocalizedBody on Event {
|
|||
|
||||
bool get isAttachmentSmallEnough =>
|
||||
infoMap['size'] is int &&
|
||||
infoMap['size'] < room.client.database.maxFileSize;
|
||||
infoMap['size'] < room.client.database!.maxFileSize;
|
||||
bool get isThumbnailSmallEnough =>
|
||||
thumbnailInfoMap['size'] is int &&
|
||||
thumbnailInfoMap['size'] < room.client.database.maxFileSize;
|
||||
thumbnailInfoMap['size'] < room.client.database!.maxFileSize;
|
||||
|
||||
bool get showThumbnail =>
|
||||
[MessageTypes.Image, MessageTypes.Sticker, MessageTypes.Video]
|
||||
|
|
@ -32,7 +34,7 @@ extension LocalizedBody on Event {
|
|||
isThumbnailSmallEnough ||
|
||||
(content['url'] is String));
|
||||
|
||||
String get sizeString {
|
||||
String? get sizeString {
|
||||
if (content['info'] is Map<String, dynamic> &&
|
||||
content['info'].containsKey('size')) {
|
||||
num size = content['info']['size'];
|
||||
|
|
@ -58,6 +60,7 @@ extension LocalizedBody on Event {
|
|||
|
||||
Future<bool> isAttachmentCached({bool getThumbnail = false}) async {
|
||||
final mxcUrl = attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail);
|
||||
if (mxcUrl == null) return false;
|
||||
// check if we have it in-memory
|
||||
if (_downloadAndDecryptFutures.containsKey(mxcUrl)) {
|
||||
return true;
|
||||
|
|
@ -72,7 +75,7 @@ extension LocalizedBody on Event {
|
|||
return file != null;
|
||||
}
|
||||
|
||||
Future<MatrixFile> downloadAndDecryptAttachmentCached(
|
||||
Future<MatrixFile?> downloadAndDecryptAttachmentCached(
|
||||
{bool getThumbnail = false}) async {
|
||||
final mxcUrl =
|
||||
attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail).toString();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//@dart=2.12
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../../config/app_config.dart';
|
||||
|
|
@ -30,13 +32,14 @@ extension FilteredTimelineExtension on Timeline {
|
|||
filteredEvents[i - 1].isState &&
|
||||
!unfolded.contains(filteredEvents[i - 1].eventId)) {
|
||||
counter++;
|
||||
filteredEvents[i].unsigned['im.fluffychat.collapsed_state_event'] =
|
||||
filteredEvents[i].unsigned ??= {};
|
||||
filteredEvents[i].unsigned!['im.fluffychat.collapsed_state_event'] =
|
||||
true;
|
||||
} else {
|
||||
filteredEvents[i].unsigned['im.fluffychat.collapsed_state_event'] =
|
||||
filteredEvents[i].unsigned!['im.fluffychat.collapsed_state_event'] =
|
||||
false;
|
||||
filteredEvents[i]
|
||||
.unsigned['im.fluffychat.collapsed_state_event_count'] = counter;
|
||||
.unsigned!['im.fluffychat.collapsed_state_event_count'] = counter;
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//@dart=2.12
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -16,14 +18,14 @@ extension MatrixFileExtension on MatrixFile {
|
|||
if (PlatformInfos.isMobile) {
|
||||
final tmpDirectory = PlatformInfos.isAndroid
|
||||
? (await getExternalStorageDirectories(
|
||||
type: StorageDirectory.downloads))
|
||||
type: StorageDirectory.downloads))!
|
||||
.first
|
||||
: await getTemporaryDirectory();
|
||||
final path = '${tmpDirectory.path}$fileName';
|
||||
await File(path).writeAsBytes(bytes);
|
||||
await Share.shareFiles([path]);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context).savedFileAs(path))),
|
||||
SnackBar(content: Text(L10n.of(context)!.savedFileAs(path))),
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//@dart=2.12
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
@ -8,25 +10,27 @@ import '../date_time_extension.dart';
|
|||
extension PresenceExtension on Presence {
|
||||
String getLocalizedLastActiveAgo(BuildContext context) {
|
||||
if (presence.lastActiveAgo != null && presence.lastActiveAgo != 0) {
|
||||
return L10n.of(context).lastActiveAgo(DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime.now().millisecondsSinceEpoch - presence.lastActiveAgo)
|
||||
.localizedTimeShort(context));
|
||||
return L10n.of(context)!.lastActiveAgo(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime.now().millisecondsSinceEpoch -
|
||||
presence.lastActiveAgo!)
|
||||
.localizedTimeShort(context));
|
||||
}
|
||||
return L10n.of(context).lastSeenLongTimeAgo;
|
||||
return L10n.of(context)!.lastSeenLongTimeAgo;
|
||||
}
|
||||
|
||||
String getLocalizedStatusMessage(BuildContext context) {
|
||||
if (presence.statusMsg?.isNotEmpty ?? false) {
|
||||
return presence.statusMsg;
|
||||
return presence.statusMsg!;
|
||||
}
|
||||
if (presence.currentlyActive ?? false) {
|
||||
return L10n.of(context).currentlyActive;
|
||||
return L10n.of(context)!.currentlyActive;
|
||||
}
|
||||
return getLocalizedLastActiveAgo(context);
|
||||
}
|
||||
|
||||
Color get color {
|
||||
switch (presence?.presence ?? PresenceType.offline) {
|
||||
switch (presence.presence) {
|
||||
case PresenceType.online:
|
||||
return Colors.green;
|
||||
case PresenceType.offline:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue