Yann Leboulanger pushed to branch xep-0319 at gajim / gajim

Commits:
a5fa072f by Yann Leboulanger at 2017-07-28T14:42:23+02:00
correctly get autoaway config value
send XEP-0319 idle tag to groupchat presences
fix coming back from autoaway

- - - - -


3 changed files:

- gajim/common/connection.py
- gajim/gui_interface.py
- gajim/roster_window.py


Changes:

=====================================
gajim/common/connection.py
=====================================
--- a/gajim/common/connection.py
+++ b/gajim/common/connection.py
@@ -634,10 +634,10 @@ class CommonConnection:
             idle_time = None
             if auto:
                 global HAS_IDLE
-                if HAS_IDLE and gajim.config.get_per('accounts', self.name,
-                'autoaway'):
+                if HAS_IDLE and gajim.config.get('autoaway'):
                     idle_sec = int(self.sleeper.getIdleSec())
-                    idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', 
time.gmtime(time.time() - idle_sec))
+                    idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ',
+                        time.gmtime(time.time() - idle_sec))
             gajim.nec.push_incoming_event(BeforeChangeShowEvent(None,
                 conn=self, show=show, message=msg))
             if was_invisible:
@@ -2697,7 +2697,7 @@ class Connection(CommonConnection, ConnectionHandlers):
             destroy.setAttr('jid', jid)
         self.connection.send(iq)
 
-    def send_gc_status(self, nick, jid, show, status):
+    def send_gc_status(self, nick, jid, show, status, auto=False):
         if not gajim.account_is_connected(self.name):
             return
         if show == 'invisible':
@@ -2716,6 +2716,14 @@ class Connection(CommonConnection, ConnectionHandlers):
         if gajim.config.get('send_sha_in_gc_presence') and show != 'offline':
             p = self.add_sha(p, ptype != 'unavailable')
         self.add_lang(p)
+        if auto:
+            global HAS_IDLE
+            if HAS_IDLE and gajim.config.get('autoaway'):
+                idle_sec = int(self.sleeper.getIdleSec())
+                idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ',
+                    time.gmtime(time.time() - idle_sec))
+                idle = p.setTag('idle', namespace=nbxmpp.NS_IDLE)
+                idle.setAttr('since', idle_time)
         # send instantly so when we go offline, status is sent to gc before we
         # disconnect from jabber server
         self.connection.send(p)


=====================================
gajim/gui_interface.py
=====================================
--- a/gajim/gui_interface.py
+++ b/gajim/gui_interface.py
@@ -2262,10 +2262,10 @@ class Interface:
                     gajim.status_before_autoaway[account] = ''
                     gajim.sleeper_state[account] = 'off'
             elif state == sleepy.STATE_AWAY and gajim.config.get('autoaway'):
-                # we save out online status
-                gajim.status_before_autoaway[account] = \
-                    gajim.connections[account].status
                 if gajim.sleeper_state[account] == 'online':
+                    # we save out online status
+                    gajim.status_before_autoaway[account] = \
+                        gajim.connections[account].status
                     # we go away (no auto status) [we pass True to auto param]
                     auto_message = gajim.config.get('autoaway_message')
                     if not auto_message:
@@ -2279,11 +2279,15 @@ class Interface:
                         }
                     self.roster.send_status(account, 'away', auto_message,
                         auto=True)
-                if gajim.sleeper_state[account] == 'off':
+                    gajim.sleeper_state[account] = 'autoaway'
+                elif gajim.sleeper_state[account] == 'off':
+                    # we save out online status
+                    gajim.status_before_autoaway[account] = \
+                        gajim.connections[account].status
                     connected = gajim.connections[account].connected
                     self.roster.send_status(account, 
gajim.SHOW_LIST[connected],
                         gajim.status_before_autoaway[account], auto=True)
-                gajim.sleeper_state[account] = 'idle'
+                    gajim.sleeper_state[account] = 'idle'
             elif state == sleepy.STATE_XA and \
             gajim.sleeper_state[account] in ('online', 'autoaway',
             'autoaway-forced') and gajim.config.get('autoxa'):


=====================================
gajim/roster_window.py
=====================================
--- a/gajim/roster_window.py
+++ b/gajim/roster_window.py
@@ -2191,7 +2191,8 @@ class RosterWindow:
                 if gc_control.account == account:
                     if gajim.gc_connected[account][gc_control.room_jid]:
                         gajim.connections[account].send_gc_status(
-                            gc_control.nick, gc_control.room_jid, status, txt)
+                            gc_control.nick, gc_control.room_jid, status, txt,
+                            auto=auto)
             if was_invisible and status != 'offline':
                 # We come back from invisible, join bookmarks
                 gajim.interface.auto_join_bookmarks(account)



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/a5fa072f2b04fa834112ed468ad283cd3e06636e
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to