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