Commit 4e47062a authored by Philipp Hörist's avatar Philipp Hörist

MUC: Refactor sending status presence

parent 501b993b
......@@ -1690,30 +1690,6 @@ class Connection(CommonConnection, ConnectionHandlers):
automatic_message=obj.automatic_message,
stanza_id=obj.stanza_id, additional_data=obj.additional_data))
def send_gc_status(self, nick, jid, show, status, auto=False):
if not app.account_is_connected(self.name):
return
if show == 'invisible':
show = 'offline'
ptype = None
if show == 'offline':
ptype = 'unavailable'
xmpp_show = helpers.get_xmpp_show(show)
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.get_module('Presence').send_presence(
'%s/%s' % (jid, nick),
typ=ptype,
show=xmpp_show,
status=status,
caps=ptype != 'unavailable',
idle_time=idle_time)
def unregister_account(self, on_remove_success):
self._unregister_account = True
self._unregister_account_cb = on_remove_success
......
......@@ -32,6 +32,7 @@ from gajim.common.const import KindConstant
from gajim.common.const import MUCJoinedState
from gajim.common.structs import MUCData
from gajim.common.helpers import AdditionalDataDict
from gajim.common import idle
from gajim.common.caps_cache import muc_caps_cache
from gajim.common.nec import NetworkEvent
from gajim.common.modules.bits_of_binary import store_bob_data
......@@ -158,11 +159,41 @@ class MUC(BaseModule):
def leave(self, room_jid):
self._log.info('Leave MUC: %s', room_jid)
nick = self._get_muc_data(room_jid)
self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
muc = self._get_muc_data(room_jid)
self._con.get_module('Presence').send_presence(
'%s/%s' % (room_jid, nick),
'%s/%s' % (room_jid, muc.nick),
typ='unavailable')
def send_muc_presence(self, room_jid, auto=False):
show = app.SHOW_LIST[self._con.connected]
if show in ('invisible', 'offline'):
# FIXME: Check if this
return
muc = self._get_muc_data(room_jid)
status = self._con.status
xmpp_show = helpers.get_xmpp_show(show)
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))
full_jid = '%s/%s' % (room_jid, muc.nick)
self._log.info('Send presence: %s, show: %s, status: %s, idle_time: %s',
full_jid, xmpp_show, status, idle_time)
self._con.get_module('Presence').send_presence(
full_jid,
show=xmpp_show,
status=status,
caps=True,
idle_time=idle_time)
def change_nick(self, room_jid, new_nick):
show = helpers.get_xmpp_show(app.SHOW_LIST[self._con.connected])
self._con.get_module('Presence').send_presence(
......
......@@ -1123,9 +1123,8 @@ class GroupchatControl(ChatControlBase):
def _nec_vcard_published(self, obj):
if obj.conn.name != self.account:
return
show = app.SHOW_LIST[obj.conn.connected]
status = obj.conn.status
obj.conn.send_gc_status(self.nick, self.room_jid, show, status)
obj.conn.get_module('MUC').send_muc_presence(self.room_jid)
def _nec_update_avatar(self, obj):
if obj.contact.room_jid != self.room_jid:
......
......@@ -2120,9 +2120,8 @@ class RosterWindow:
list(app.interface.minimized_controls[account].values()):
if gc_control.account == account:
if app.gc_connected[account][gc_control.room_jid]:
app.connections[account].send_gc_status(
gc_control.nick, gc_control.room_jid, status, txt,
auto=auto)
app.connections[account].get_module('MUC').send_muc_presence(
gc_control.room_jid, auto=auto)
if was_invisible and status != 'offline':
# We come back from invisible, join bookmarks
con = app.connections[account]
......
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