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