feat: Automatically cancel typing indicators after 30 seconds
This commit is contained in:
parent
b248d6382a
commit
0f5526e1b8
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
|
|
|
|||
Loading…
Reference in New Issue