2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2020-05-15 19:57:53 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-05-22 09:24:39 +02:00
|
|
|
import 'matrix_sdk_extensions.dart/filtered_timeline_extension.dart';
|
2021-04-09 16:29:48 +02:00
|
|
|
import '../config/app_config.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;
|
|
|
|
}
|
2021-06-11 11:40:38 +02:00
|
|
|
return L10n.of(context)
|
|
|
|
.countParticipants(summary.mJoinedMemberCount.toString());
|
2020-05-15 19:57:53 +02:00
|
|
|
}
|
2020-11-22 15:25:13 +01:00
|
|
|
|
|
|
|
String getLocalizedTypingText(BuildContext context) {
|
|
|
|
var typingText = '';
|
2021-04-14 10:37:15 +02:00
|
|
|
final typingUsers = this.typingUsers;
|
2020-11-22 15:25:13 +01:00
|
|
|
typingUsers.removeWhere((User u) => u.id == client.userID);
|
|
|
|
|
2020-12-12 17:01:59 +01:00
|
|
|
if (AppConfig.hideTypingUsernames) {
|
|
|
|
typingText = L10n.of(context).isTyping;
|
|
|
|
if (typingUsers.first.id != directChatMatrixID) {
|
|
|
|
typingText =
|
|
|
|
L10n.of(context).numUsersTyping(typingUsers.length.toString());
|
|
|
|
}
|
|
|
|
} else if (typingUsers.length == 1) {
|
2020-11-22 15:25:13 +01:00
|
|
|
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-12-23 11:23:19 +01:00
|
|
|
|
|
|
|
String getLocalizedSeenByText(
|
2021-02-25 09:11:17 +01:00
|
|
|
BuildContext context,
|
|
|
|
Timeline timeline,
|
|
|
|
List<Event> filteredEvents,
|
|
|
|
Set<String> unfolded,
|
|
|
|
) {
|
2020-12-23 11:23:19 +01:00
|
|
|
var seenByText = '';
|
|
|
|
if (timeline.events.isNotEmpty) {
|
2021-02-25 09:11:17 +01:00
|
|
|
final filteredEvents = timeline.getFilteredEvents(unfolded: unfolded);
|
2021-07-23 09:13:24 +02:00
|
|
|
if (filteredEvents.isEmpty) return '';
|
2020-12-23 11:23:19 +01:00
|
|
|
final lastReceipts = <User>{};
|
|
|
|
// now we iterate the timeline events until we hit the first rendered event
|
|
|
|
for (final event in timeline.events) {
|
|
|
|
lastReceipts.addAll(event.receipts.map((r) => r.user));
|
|
|
|
if (event.eventId == filteredEvents.first.eventId) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastReceipts.removeWhere((user) =>
|
|
|
|
user.id == client.userID || user.id == filteredEvents.first.senderId);
|
|
|
|
if (lastReceipts.length == 1) {
|
|
|
|
seenByText =
|
|
|
|
L10n.of(context).seenByUser(lastReceipts.first.calcDisplayname());
|
|
|
|
} else if (lastReceipts.length == 2) {
|
|
|
|
seenByText = seenByText = L10n.of(context).seenByUserAndUser(
|
|
|
|
lastReceipts.first.calcDisplayname(),
|
|
|
|
lastReceipts.last.calcDisplayname());
|
|
|
|
} else if (lastReceipts.length > 2) {
|
|
|
|
seenByText = L10n.of(context).seenByUserAndCountOthers(
|
2021-08-14 12:35:45 +02:00
|
|
|
lastReceipts.first.calcDisplayname(), lastReceipts.length - 1);
|
2020-12-23 11:23:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return seenByText;
|
|
|
|
}
|
2020-05-15 19:57:53 +02:00
|
|
|
}
|