fluffychat/lib/utils/matrix_sdk_extensions.dart/presence_extension.dart

41 lines
1.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-10-26 18:50:34 +02:00
import 'package:matrix/matrix.dart';
import '../date_time_extension.dart';
2022-05-14 09:51:21 +02:00
extension PresenceExtension on CachedPresence {
2020-10-28 07:23:50 +01:00
String getLocalizedLastActiveAgo(BuildContext context) {
2022-05-14 09:51:21 +02:00
final lastActiveTimestamp = this.lastActiveTimestamp;
if (lastActiveTimestamp != null) {
return L10n.of(context)!
.lastActiveAgo(lastActiveTimestamp.localizedTimeShort(context));
2020-10-28 07:23:50 +01:00
}
return L10n.of(context)!.lastSeenLongTimeAgo;
2020-10-28 07:23:50 +01:00
}
2020-10-03 15:53:08 +02:00
String getLocalizedStatusMessage(BuildContext context) {
2022-05-14 09:51:21 +02:00
final statusMsg = this.statusMsg;
if (statusMsg != null && statusMsg.isNotEmpty) {
return statusMsg;
}
2022-05-14 09:51:21 +02:00
if (currentlyActive ?? false) {
return L10n.of(context)!.currentlyActive;
2020-08-23 18:10:33 +02:00
}
2021-02-23 15:15:54 +01:00
return getLocalizedLastActiveAgo(context);
}
Color get color {
2022-05-14 09:51:21 +02:00
switch (presence) {
case PresenceType.online:
return Colors.green;
case PresenceType.offline:
2021-02-25 07:44:41 +01:00
return Colors.grey;
case PresenceType.unavailable:
default:
2021-02-25 07:44:41 +01:00
return Colors.red;
}
}
}