1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00

Send writing messages event

This commit is contained in:
Pierre HUBERT 2021-03-13 09:09:26 +01:00
parent dbb2a3f1a1
commit 1e0e2fca52
2 changed files with 25 additions and 1 deletions

View File

@ -404,6 +404,10 @@ class ConversationsHelper {
}
}
/// Send a notification to inform that the user is writing a message
static Future<void> sendWritingEvent(int convID) async =>
await ws("conversations/is_writing", {"convID": convID});
/// Turn an API response into a ConversationMessage object
static ConversationMessage apiToConversationMessage(
Map<String, dynamic> map,

View File

@ -66,6 +66,8 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
ScrollWatcher _scrollController;
_OlderMessagesLevel _loadingOlderMessages = _OlderMessagesLevel.NONE;
int _lastWritingEventSent = 0;
CancelToken _sendCancel;
double _sendProgress;
@ -533,7 +535,10 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
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<ConversationScreen> {
);
}
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)