fluffychat/lib/utils/room_status_extension.dart

58 lines
2.2 KiB
Dart
Raw Normal View History

2020-05-15 19:57:53 +02:00
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2020-05-15 19:57:53 +02:00
import 'date_time_extension.dart';
extension RoomStatusExtension on Room {
Presence get directChatPresence => client.presences[directChatMatrixID];
String getLocalizedStatus(BuildContext context) {
if (isDirectChat) {
2020-06-19 15:10:26 +02:00
if (directChatPresence != null &&
directChatPresence.presence != null &&
(directChatPresence.presence.lastActiveAgo != null ||
directChatPresence.presence.currentlyActive != null)) {
2020-12-06 12:51:40 +01:00
if (directChatPresence.presence.statusMsg?.isNotEmpty ?? false) {
return directChatPresence.presence.statusMsg;
}
2020-06-10 10:07:01 +02:00
if (directChatPresence.presence.currentlyActive == true) {
2020-05-15 19:57:53 +02:00
return L10n.of(context).currentlyActive;
}
2020-06-25 16:29:06 +02:00
if (directChatPresence.presence.lastActiveAgo == null) {
return L10n.of(context).lastSeenLongTimeAgo;
}
final time = DateTime.fromMillisecondsSinceEpoch(
DateTime.now().millisecondsSinceEpoch -
directChatPresence.presence.lastActiveAgo);
return L10n.of(context).lastActiveAgo(time.localizedTimeShort(context));
2020-05-15 19:57:53 +02:00
}
return L10n.of(context).lastSeenLongTimeAgo;
}
return L10n.of(context).countParticipants(mJoinedMemberCount.toString());
}
2020-11-22 15:25:13 +01:00
String getLocalizedTypingText(BuildContext context) {
var typingText = '';
var typingUsers = this.typingUsers;
typingUsers.removeWhere((User u) => u.id == client.userID);
if (typingUsers.length == 1) {
typingText = L10n.of(context).isTyping;
if (typingUsers.first.id != directChatMatrixID) {
typingText =
L10n.of(context).userIsTyping(typingUsers.first.calcDisplayname());
}
} else if (typingUsers.length == 2) {
typingText = L10n.of(context).userAndUserAreTyping(
typingUsers.first.calcDisplayname(),
typingUsers[1].calcDisplayname());
} else if (typingUsers.length > 2) {
typingText = L10n.of(context).userAndOthersAreTyping(
typingUsers.first.calcDisplayname(),
(typingUsers.length - 1).toString());
}
return typingText;
}
2020-05-15 19:57:53 +02:00
}