diff --git a/lib/helpers/conversations_helper.dart b/lib/helpers/conversations_helper.dart index 54342b7..c42ce31 100644 --- a/lib/helpers/conversations_helper.dart +++ b/lib/helpers/conversations_helper.dart @@ -404,6 +404,10 @@ class ConversationsHelper { } } + /// Send a notification to inform that the user is writing a message + static Future sendWritingEvent(int convID) async => + await ws("conversations/is_writing", {"convID": convID}); + /// Turn an API response into a ConversationMessage object static ConversationMessage apiToConversationMessage( Map map, diff --git a/lib/ui/screens/conversation_screen.dart b/lib/ui/screens/conversation_screen.dart index fc37fa4..52f7465 100644 --- a/lib/ui/screens/conversation_screen.dart +++ b/lib/ui/screens/conversation_screen.dart @@ -66,6 +66,8 @@ class _ConversationScreenState extends SafeState { ScrollWatcher _scrollController; _OlderMessagesLevel _loadingOlderMessages = _OlderMessagesLevel.NONE; + int _lastWritingEventSent = 0; + CancelToken _sendCancel; double _sendProgress; @@ -533,7 +535,10 @@ class _ConversationScreenState extends SafeState { style: TextStyle( color: darkTheme() ? Colors.white : Colors.black, ), - onChanged: (s) => setState(() {}), + onChanged: (s) { + _sendWritingEvent(); + setState(() {}); + }, decoration: InputDecoration( hintText: tr("New message..."), hintStyle: TextStyle( @@ -650,6 +655,21 @@ class _ConversationScreenState extends SafeState { ); } + void _sendWritingEvent() async { + try { + if (textMessage.isEmpty) return; + final t = time(); + + if (t - _lastWritingEventSent < + srvConfig.conversationsPolicy.writingEventInterval) return; + + _lastWritingEventSent = t; + await ConversationsHelper.sendWritingEvent(_conversation.id); + } catch (e, s) { + logError(e, s); + } + } + /// Request message statistics void _requestMessageStats(ConversationMessage message) async { MainController.of(context)