mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Send writing messages event
This commit is contained in:
parent
dbb2a3f1a1
commit
1e0e2fca52
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user