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;
|
final Duration sendTimelineEventTimeout;
|
||||||
|
|
||||||
|
/// The timeout until a typing indicator gets removed automatically.
|
||||||
|
final Duration typingIndicatorTimeout;
|
||||||
|
|
||||||
Future<MatrixImageFileResizedResponse?> Function(
|
Future<MatrixImageFileResizedResponse?> Function(
|
||||||
MatrixImageFileResizeArguments)? customImageResizer;
|
MatrixImageFileResizeArguments)? customImageResizer;
|
||||||
|
|
||||||
|
|
@ -205,6 +208,7 @@ class Client extends MatrixApi {
|
||||||
/// lifetime to the server which overrides the default one. Needs server
|
/// lifetime to the server which overrides the default one. Needs server
|
||||||
/// support.
|
/// support.
|
||||||
this.customRefreshTokenLifetime,
|
this.customRefreshTokenLifetime,
|
||||||
|
this.typingIndicatorTimeout = const Duration(seconds: 30),
|
||||||
}) : syncFilter = syncFilter ??
|
}) : syncFilter = syncFilter ??
|
||||||
Filter(
|
Filter(
|
||||||
room: RoomFilter(
|
room: RoomFilter(
|
||||||
|
|
@ -2474,8 +2478,7 @@ class Client extends MatrixApi {
|
||||||
BasicRoomEvent.fromJson(eventUpdate.content);
|
BasicRoomEvent.fromJson(eventUpdate.content);
|
||||||
break;
|
break;
|
||||||
case EventUpdateType.ephemeral:
|
case EventUpdateType.ephemeral:
|
||||||
room.ephemerals[eventUpdate.content['type']] =
|
room.setEphemeral(BasicRoomEvent.fromJson(eventUpdate.content));
|
||||||
BasicRoomEvent.fromJson(eventUpdate.content);
|
|
||||||
break;
|
break;
|
||||||
case EventUpdateType.history:
|
case EventUpdateType.history:
|
||||||
case EventUpdateType.decryptedTimelineQueue:
|
case EventUpdateType.decryptedTimelineQueue:
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,8 @@ class Room {
|
||||||
|
|
||||||
final _sendingQueue = <Completer>[];
|
final _sendingQueue = <Completer>[];
|
||||||
|
|
||||||
|
Timer? _clearTypingIndicatorTimer;
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
'id': id,
|
'id': id,
|
||||||
'membership': membership.toString().split('.').last,
|
'membership': membership.toString().split('.').last,
|
||||||
|
|
@ -367,6 +369,16 @@ class Room {
|
||||||
|
|
||||||
Event? lastEvent;
|
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.
|
/// Returns a list of all current typing users.
|
||||||
List<User> get typingUsers {
|
List<User> get typingUsers {
|
||||||
final typingMxid = ephemerals['m.typing']?.content['user_ids'];
|
final typingMxid = ephemerals['m.typing']?.content['user_ids'];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue