fluffychat/lib/utils/presence_extension.dart

39 lines
1.2 KiB
Dart
Raw Normal View History

import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2020-05-06 18:31:38 +02:00
import 'date_time_extension.dart';
extension PresenceExtension on Presence {
2020-10-28 07:23:50 +01:00
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).lastSeenLongTimeAgo;
}
2020-10-03 15:53:08 +02:00
String getLocalizedStatusMessage(BuildContext context) {
2020-06-10 10:07:01 +02:00
if (presence.statusMsg?.isNotEmpty ?? false) {
return presence.statusMsg;
}
2020-10-28 15:01:16 +01:00
if (presence.currentlyActive ?? false) {
2020-08-23 18:10:33 +02:00
return L10n.of(context).currentlyActive;
}
2021-02-23 15:15:54 +01:00
return getLocalizedLastActiveAgo(context);
}
Color get color {
switch (presence?.presence ?? PresenceType.offline) {
case PresenceType.online:
return Colors.green;
case PresenceType.offline:
return Colors.red;
case PresenceType.unavailable:
default:
return Colors.grey;
}
}
}