fluffychat/lib/utils/room_status_extension.dart

59 lines
1.9 KiB
Dart
Raw Normal View History

2020-05-15 17:57:53 +00:00
import 'package:flutter/widgets.dart';
2021-10-26 16:50:34 +00:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-10-26 16:50:34 +00:00
import 'package:matrix/matrix.dart';
2021-04-09 14:29:48 +00:00
import '../config/app_config.dart';
2020-05-15 17:57:53 +00:00
extension RoomStatusExtension on Room {
2020-11-22 14:25:13 +00:00
String getLocalizedTypingText(BuildContext context) {
var typingText = '';
2021-04-14 08:37:15 +00:00
final typingUsers = this.typingUsers;
2020-11-22 14:25:13 +00:00
typingUsers.removeWhere((User u) => u.id == client.userID);
2020-12-12 16:01:59 +00:00
if (AppConfig.hideTypingUsernames) {
typingText = L10n.of(context)!.isTyping;
2020-12-12 16:01:59 +00:00
if (typingUsers.first.id != directChatMatrixID) {
typingText =
L10n.of(context)!.numUsersTyping(typingUsers.length.toString());
2020-12-12 16:01:59 +00:00
}
} else if (typingUsers.length == 1) {
typingText = L10n.of(context)!.isTyping;
2020-11-22 14:25:13 +00:00
if (typingUsers.first.id != directChatMatrixID) {
typingText =
L10n.of(context)!.userIsTyping(typingUsers.first.calcDisplayname());
2020-11-22 14:25:13 +00:00
}
} else if (typingUsers.length == 2) {
typingText = L10n.of(context)!.userAndUserAreTyping(
typingUsers.first.calcDisplayname(),
typingUsers[1].calcDisplayname(),
);
2020-11-22 14:25:13 +00:00
} else if (typingUsers.length > 2) {
typingText = L10n.of(context)!.userAndOthersAreTyping(
typingUsers.first.calcDisplayname(),
(typingUsers.length - 1).toString(),
);
2020-11-22 14:25:13 +00:00
}
return typingText;
}
2020-12-23 10:23:19 +00:00
List<User> getSeenByUsers(Timeline timeline, {String? eventId}) {
2021-11-13 12:06:36 +00:00
if (timeline.events.isEmpty) return [];
eventId ??= timeline.events.first.eventId;
2021-11-13 12:06:36 +00: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));
2021-12-26 08:59:34 +00:00
if (event.eventId == eventId) {
2021-11-13 12:06:36 +00:00
break;
2020-12-23 10:23:19 +00:00
}
}
lastReceipts.removeWhere(
(user) =>
user.id == client.userID || user.id == timeline.events.first.senderId,
);
2021-11-13 12:06:36 +00:00
return lastReceipts.toList();
2020-12-23 10:23:19 +00:00
}
2020-05-15 17:57:53 +00:00
}