From 7c0cf0c8beaf3f0f8a743a10e0e3963c94c14bd3 Mon Sep 17 00:00:00 2001
From: mathieui <mathieui@mathieui.net>
Date: Sat, 1 Feb 2014 19:10:50 +0100
Subject: =?UTF-8?q?Fix=20#2441=20(don=E2=80=99t=20send=20chatstates=20in?=
 =?UTF-8?q?=20a=20non-chatstate=20conv)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Also enable chatstates when we receive them from our contacts.
---
 src/core.py |  3 +++
 src/tabs.py | 12 +++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/core.py b/src/core.py
index 766061bd..169df31f 100644
--- a/src/core.py
+++ b/src/core.py
@@ -3272,6 +3272,7 @@ class Core(object):
                             identifier=message['id'],
                             jid=message['from'],
                             typ=1)
+
         if tab.remote_wants_chatstates is None:
             if message['chat_state']:
                 tab.remote_wants_chatstates = True
@@ -3317,6 +3318,7 @@ class Core(object):
         tab = self.get_conversation_by_jid(message['from'], False)
         if not tab:
             return False
+        tab.remote_wants_chatstates = True
         self.events.trigger('normal_chatstate', message, tab)
         tab.chatstate = state
         if state == 'gone' and isinstance(tab, tabs.DynamicConversationTab):
@@ -3333,6 +3335,7 @@ class Core(object):
         tab = self.get_tab_by_name(message['from'].full, tabs.PrivateTab)
         if not tab:
             return
+        tab.remote_wants_chatstates = True
         self.events.trigger('private_chatstate', message, tab)
         tab.chatstate = state
         if tab == self.current_tab():
diff --git a/src/tabs.py b/src/tabs.py
index c44b5bf0..12a3cd62 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -576,11 +576,13 @@ class ChatTab(Tab):
         if not isinstance(self, MucTab) or self.joined:
             if state in ('active', 'inactive', 'gone') and self.inactive and not always_send:
                 return
-            msg = self.core.xmpp.make_message(self.get_dest_jid())
-            msg['type'] = self.message_type
-            msg['chat_state'] = state
-            self.chat_state = state
-            msg.send()
+            if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) and \
+                    self.remote_wants_chatstates is not False:
+                msg = self.core.xmpp.make_message(self.get_dest_jid())
+                msg['type'] = self.message_type
+                msg['chat_state'] = state
+                self.chat_state = state
+                msg.send()
 
     def send_composing_chat_state(self, empty_after):
         """
-- 
cgit v1.2.3