mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 05:42:11 +00:00
improve typing indicator
This commit is contained in:
parent
2cb51d668a
commit
d32e319c49
2 changed files with 15 additions and 2 deletions
|
|
@ -146,7 +146,9 @@ class _ChatMessagesViewState extends State<ChatMessagesView>
|
|||
_nextTypingIndicator = Timer.periodic(const Duration(seconds: 2), (
|
||||
_,
|
||||
) async {
|
||||
if (_isViewActive()) {
|
||||
await sendTypingIndication(widget.groupId, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:audio_waveforms/audio_waveforms.dart';
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:drift/drift.dart' show Value;
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -51,6 +52,7 @@ class _MessageInputState extends State<MessageInput> {
|
|||
Offset _recordingOffset = Offset.zero;
|
||||
RecordingState _recordingState = RecordingState.none;
|
||||
Timer? _nextTypingIndicator;
|
||||
DateTime? _lastTextChangeTime;
|
||||
|
||||
Future<void> _sendMessage() async {
|
||||
if (_textFieldController.text == '') return;
|
||||
|
|
@ -70,6 +72,7 @@ class _MessageInputState extends State<MessageInput> {
|
|||
void initState() {
|
||||
super.initState();
|
||||
_textFieldController = TextEditingController();
|
||||
_textFieldController.addListener(_handleTextChange);
|
||||
if (widget.group.draftMessage != null) {
|
||||
_textFieldController.text = widget.group.draftMessage!;
|
||||
}
|
||||
|
|
@ -78,7 +81,10 @@ class _MessageInputState extends State<MessageInput> {
|
|||
_nextTypingIndicator = Timer.periodic(const Duration(seconds: 1), (
|
||||
_,
|
||||
) async {
|
||||
if (widget.textFieldFocus.hasFocus) {
|
||||
if (widget.textFieldFocus.hasFocus &&
|
||||
_lastTextChangeTime != null &&
|
||||
DateTime.now().difference(_lastTextChangeTime!) <=
|
||||
const Duration(seconds: 6)) {
|
||||
await sendTypingIndication(widget.group.groupId, true);
|
||||
}
|
||||
});
|
||||
|
|
@ -88,6 +94,7 @@ class _MessageInputState extends State<MessageInput> {
|
|||
|
||||
@override
|
||||
void dispose() {
|
||||
_textFieldController.removeListener(_handleTextChange);
|
||||
widget.textFieldFocus.removeListener(_handleTextFocusChange);
|
||||
widget.textFieldFocus.dispose();
|
||||
recorderController.dispose();
|
||||
|
|
@ -105,6 +112,10 @@ class _MessageInputState extends State<MessageInput> {
|
|||
});
|
||||
}
|
||||
|
||||
void _handleTextChange() {
|
||||
_lastTextChangeTime = clock.now();
|
||||
}
|
||||
|
||||
void _handleTextFocusChange() {
|
||||
if (widget.textFieldFocus.hasFocus) {
|
||||
setState(() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue