summaryrefslogtreecommitdiff
blob: bc1ad87b2fc5261d7f459446d42606de2d6d549f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
commit 04a419887ba7102726ae4168294da613ea58a6e2
Author: Martin Klapetek <martin.klapetek@gmail.com>
Date:   Wed Jul 18 14:58:33 2012 +0200

    Don't spam the channel with Composing state if the state actually hasn't changed
    
    This fixes delays in messages with some accounts like ICQ/AIM, however if user sends quickly too many messages,
    they will still be delayed (by libpurple), just considerably less. Now we're on par with Empathy and Kopete,
    that's all we can do about it.
    
    Reviewed-by: George Kiagiadakis
    BUG: 300655
    FIXED-IN: 0.4.1

diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index e3439d8..e30d7b5 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -862,13 +862,21 @@ void ChatWidget::onChannelInvalidated()
 void ChatWidget::onInputBoxChanged()
 {
     //if the box is empty
-    bool textBoxEmpty = !d->ui.sendMessageBox->toPlainText().isEmpty();
+    bool textBoxEmpty = d->ui.sendMessageBox->toPlainText().isEmpty();
 
-    //FIXME buffer what we've sent to telepathy, make this more efficient.
-    if(textBoxEmpty) {
+    //if the timer is active, it means the user is continuously typing
+    if (d->pausedStateTimer->isActive()) {
+        //just restart the timer and don't spam with chat state changes
+        d->pausedStateTimer->start(5000);
+        return;
+    }
+
+    if(!textBoxEmpty) {
+        //if the user has typed some text, set state to Composing and start the timer
         d->channel->requestChatState(Tp::ChannelChatStateComposing);
         d->pausedStateTimer->start(5000);
     } else {
+        //if the user typed no text/cleared the input field, set Active and stop the timer
         d->channel->requestChatState(Tp::ChannelChatStateActive);
         d->pausedStateTimer->stop();
     }