Browse Source

Implement composition state change method in parsers

Change-Id: Iece6afe9fba02126f203cb1aecd702bc9303b981
Depends-On: Ic893051d84bc4ab47274b2bf9c967db8ba951eea
Reviewed-on: http://gerrit.dmdirc.com/2132
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.7rc1
Chris Smith 13 years ago
parent
commit
20facb53f2

+ 7
- 0
src/com/dmdirc/addons/parser_msn/MSNParser.java View File

@@ -25,6 +25,7 @@ package com.dmdirc.addons.parser_msn;
25 25
 import com.dmdirc.parser.common.BaseParser;
26 26
 import com.dmdirc.parser.common.ChannelJoinRequest;
27 27
 import com.dmdirc.parser.common.ChildImplementations;
28
+import com.dmdirc.parser.common.CompositionState;
28 29
 import com.dmdirc.parser.common.DefaultStringConverter;
29 30
 import com.dmdirc.parser.common.QueuePriority;
30 31
 import com.dmdirc.parser.interfaces.ChannelInfo;
@@ -462,4 +463,10 @@ public class MSNParser extends BaseParser {
462 463
     public void removeClient(final MsnContact contact) {
463 464
         clients.remove(contact.getEmail().getEmailAddress());
464 465
     }
466
+
467
+    /** {@inheritDoc} */
468
+    @Override
469
+    public void setCompositionState(final String host, final CompositionState state) {
470
+        // Do nothing
471
+    }
465 472
 }

+ 7
- 0
src/com/dmdirc/addons/parser_twitter/Twitter.java View File

@@ -35,6 +35,7 @@ import com.dmdirc.interfaces.ConfigChangeListener;
35 35
 import com.dmdirc.logger.ErrorManager;
36 36
 import com.dmdirc.parser.common.CallbackManager;
37 37
 import com.dmdirc.parser.common.ChannelJoinRequest;
38
+import com.dmdirc.parser.common.CompositionState;
38 39
 import com.dmdirc.parser.common.DefaultStringConverter;
39 40
 import com.dmdirc.parser.common.IgnoreList;
40 41
 import com.dmdirc.parser.common.QueuePriority;
@@ -1649,4 +1650,10 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1649 1650
         return Arrays.asList(new String[]{"Twitter IRC parser: " + getServerName()});
1650 1651
     }
1651 1652
 
1653
+    /** {@inheritDoc} */
1654
+    @Override
1655
+    public void setCompositionState(final String host, final CompositionState state) {
1656
+        // Do nothing
1657
+    }
1658
+
1652 1659
 }

+ 33
- 1
src/com/dmdirc/addons/parser_xmpp/XmppParser.java View File

@@ -90,6 +90,9 @@ public class XmppParser extends BaseSocketAwareParser {
90 90
     /** The connection to use. */
91 91
     private XMPPConnection connection;
92 92
 
93
+    /** The state manager for the current connection. */
94
+    private ChatStateManager stateManager;
95
+
93 96
     /** A cache of known chats. */
94 97
     private final Map<String, Chat> chats = new HashMap<String, Chat>();
95 98
 
@@ -451,7 +454,7 @@ public class XmppParser extends BaseSocketAwareParser {
451 454
             connection.sendPacket(new Presence(Presence.Type.available, null, priority, Presence.Mode.available));
452 455
             connection.getRoster().addRosterListener(new RosterListenerImpl());
453 456
 
454
-            ChatStateManager.getInstance(connection);
457
+            stateManager = ChatStateManager.getInstance(connection);
455 458
 
456 459
             setServerName(connection.getServiceName());
457 460
 
@@ -522,6 +525,35 @@ public class XmppParser extends BaseSocketAwareParser {
522 525
                 AwayState.AWAY, AwayState.HERE, null);
523 526
     }
524 527
 
528
+    /** {@inheritDoc} */
529
+    @Override
530
+    public void setCompositionState(final String host, final CompositionState state) {
531
+        final Chat chat = chats.get(parseHostmask(host)[0]);
532
+
533
+        ChatState newState;
534
+
535
+        switch (state) {
536
+            case ENTERED_TEXT:
537
+                newState = ChatState.paused;
538
+                break;
539
+            case TYPING:
540
+                newState = ChatState.composing;
541
+                break;
542
+            case IDLE:
543
+            default:
544
+                newState = ChatState.active;
545
+                break;
546
+        }
547
+
548
+        if (chat != null && stateManager != null) {
549
+            try {
550
+                stateManager.setCurrentState(newState, chat);
551
+            } catch (XMPPException ex) {
552
+                // Can't set chat state... Oh well?
553
+            }
554
+        }
555
+    }
556
+
525 557
     private class ConnectionListenerImpl implements ConnectionListener {
526 558
 
527 559
         /** {@inheritDoc} */

Loading…
Cancel
Save