Commit 26a80048 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Presence: Refactor sending presence

parent f72e98ea
......@@ -13,7 +13,6 @@
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
import logging
import time
import nbxmpp
from nbxmpp.client import Client as NBXMPPClient
......@@ -27,7 +26,6 @@
from gajim.common import app
from gajim.common import helpers
from gajim.common import idle
from gajim.common import modules
from gajim.common.const import ClientState
from gajim.common.helpers import get_encryption_method
......@@ -358,15 +356,20 @@ def change_status(self, show, msg, auto=False):
destroy_client=True)
return
idle_time = None
if auto:
if app.is_installed('IDLE') and app.config.get('autoaway'):
idle_sec = idle.Monitor.get_idle_sec()
idle_time = time.strftime(
'%Y-%m-%dT%H:%M:%SZ',
time.gmtime(time.time() - idle_sec))
priority = app.get_priority(self._account, show)
self.get_module('Presence').send_presence(
priority=priority,
show=show,
status=msg,
idle_time=auto)
self._update_status(show, msg, idle_time=idle_time)
self.priority = priority
self.get_module('MUC').update_presence(auto=auto)
app.nec.push_incoming_event(
OurShowEvent(None, conn=self, show=show))
def _register_new_handlers(self):
for handler in modules.get_handlers(self):
......@@ -418,22 +421,6 @@ def _send_first_presence(self):
app.nec.push_incoming_event(NetworkEvent('signed-in', conn=self))
modules.send_stored_publish(self._account)
def _update_status(self, show, msg, idle_time=None):
priority = app.get_priority(self._account, show)
self.get_module('Presence').send_presence(
priority=priority,
show=show,
status=msg,
idle_time=idle_time)
self.priority = priority
self.get_module('MUC').update_presence()
app.nec.push_incoming_event(
OurShowEvent(None, conn=self, show=show))
def send_stanza(self, stanza):
"""
Send a stanza untouched
......
......@@ -15,7 +15,6 @@
# XEP-0045: Multi-User Chat
# XEP-0249: Direct MUC Invitations
import time
import logging
import nbxmpp
......@@ -36,7 +35,6 @@
from gajim.common.helpers import get_default_muc_config
from gajim.common.helpers import to_user_string
from gajim.common.helpers import event_filter
from gajim.common import idle
from gajim.common.nec import NetworkEvent
from gajim.common.modules.bits_of_binary import store_bob_data
from gajim.common.modules.base import BaseModule
......@@ -301,28 +299,12 @@ def update_presence(self, auto=False):
mucs = self._manager.get_mucs_with_state([MUCJoinedState.JOINED,
MUCJoinedState.JOINING])
for muc_data in mucs:
self._send_presence(muc_data, auto)
def _send_presence(self, muc_data, auto):
message = self._con.status_message
idle_time = None
if auto and app.is_installed('IDLE') and app.config.get('autoaway'):
idle_sec = idle.Monitor.get_idle_sec()
idle_time = time.strftime('%Y-%m-%dT%H:%M:%SZ',
time.gmtime(time.time() - idle_sec))
self._log.info('Send presence: %s, show: %s, '
'message: %s, idle_time: %s',
muc_data.occupant_jid, self._con.status,
message, idle_time)
self._con.get_module('Presence').send_presence(
muc_data.occupant_jid,
show=self._con.status,
status=self._con.status_message,
caps=True,
idle_time=idle_time)
self._con.get_module('Presence').send_presence(
muc_data.occupant_jid,
show=self._con.status,
status=self._con.status_message,
caps=True,
idle_time=auto)
def change_nick(self, room_jid, new_nick):
self._con.get_module('Presence').send_presence(
......
......@@ -21,6 +21,7 @@
from nbxmpp.const import PresenceType
from gajim.common import app
from gajim.common import idle
from gajim.common.i18n import _
from gajim.common.nec import NetworkEvent
from gajim.common.const import KindConstant
......@@ -353,7 +354,7 @@ def subscribe(self, jid, msg=None, name='', groups=None, auto_auth=False):
def get_presence(self, to=None, typ=None, priority=None,
show=None, status=None, nick=None, caps=True,
idle_time=None):
idle_time=False):
if show not in ('chat', 'away', 'xa', 'dnd'):
# Gajim sometimes passes invalid show values here
# until this is fixed this is a workaround
......@@ -363,15 +364,21 @@ def get_presence(self, to=None, typ=None, priority=None,
nick_tag = presence.setTag('nick', namespace=nbxmpp.NS_NICK)
nick_tag.setData(nick)
if idle_time is not None:
idle_node = presence.setTag('idle', namespace=nbxmpp.NS_IDLE)
idle_node.setAttr('since', idle_time)
if not self._con.avatar_conversion:
# XEP-0398 not supported by server so
# we add the avatar sha to our presence
self._con.get_module('VCardAvatars').add_update_node(presence)
if (idle_time and
app.is_installed('IDLE') and
app.config.get('autoaway')):
idle_sec = idle.Monitor.get_idle_sec()
time_ = time.strftime('%Y-%m-%dT%H:%M:%SZ',
time.gmtime(time.time() - idle_sec))
idle_node = presence.setTag('idle', namespace=nbxmpp.NS_IDLE)
idle_node.setAttr('since', time_)
caps = self._con.get_module('Caps').caps
if caps is not None and typ != 'unavailable':
presence.setTag('c',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment