Merge pull request #1867 from famedly/krille/automatic-cancel-typing-indicators-after-30-seconds

feat: Automatically cancel typing indicators after 30 seconds
This commit is contained in:
Krille-chan 2024-07-03 15:03:20 +02:00 committed by GitHub
commit ab24a25350
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -118,6 +118,9 @@ class Client extends MatrixApi {
final Duration sendTimelineEventTimeout;
/// The timeout until a typing indicator gets removed automatically.
final Duration typingIndicatorTimeout;
Future<MatrixImageFileResizedResponse?> Function(
MatrixImageFileResizeArguments)? customImageResizer;
@ -205,6 +208,7 @@ class Client extends MatrixApi {
/// lifetime to the server which overrides the default one. Needs server
/// support.
this.customRefreshTokenLifetime,
this.typingIndicatorTimeout = const Duration(seconds: 30),
}) : syncFilter = syncFilter ??
Filter(
room: RoomFilter(
@ -2474,8 +2478,7 @@ class Client extends MatrixApi {
BasicRoomEvent.fromJson(eventUpdate.content);
break;
case EventUpdateType.ephemeral:
room.ephemerals[eventUpdate.content['type']] =
BasicRoomEvent.fromJson(eventUpdate.content);
room.setEphemeral(BasicRoomEvent.fromJson(eventUpdate.content));
break;
case EventUpdateType.history:
case EventUpdateType.decryptedTimelineQueue:

View File

@ -74,6 +74,8 @@ class Room {
final _sendingQueue = <Completer>[];
Timer? _clearTypingIndicatorTimer;
Map<String, dynamic> toJson() => {
'id': id,
'membership': membership.toString().split('.').last,
@ -367,6 +369,16 @@ class Room {
Event? lastEvent;
void setEphemeral(BasicRoomEvent ephemeral) {
ephemerals[ephemeral.type] = ephemeral;
if (ephemeral.type == 'm.typing') {
_clearTypingIndicatorTimer?.cancel();
_clearTypingIndicatorTimer = Timer(client.typingIndicatorTimeout, () {
ephemerals.remove('m.typing');
});
}
}
/// Returns a list of all current typing users.
List<User> get typingUsers {
final typingMxid = ephemerals['m.typing']?.content['user_ids'];