Commit f907ada8 authored by Philipp Hörist's avatar Philipp Hörist

Refactor around VCard events

parent 878f0458
......@@ -128,6 +128,9 @@ class MUC(BaseModule):
def _get_muc_state(self, room_jid):
return self._muc_data[room_jid].state
def get_mucs_with_state(self, states):
return [muc for muc in self._muc_data.values() if muc.state in states]
def join(self, room_jid, nick, password, rejoin=False):
if not app.account_is_connected(self._account):
return
......@@ -165,7 +168,13 @@ class MUC(BaseModule):
'%s/%s' % (room_jid, muc.nick),
typ='unavailable')
def send_muc_presence(self, room_jid, auto=False):
def update_presence(self, auto=False):
mucs = self.get_mucs_with_state([MUCJoinedState.JOINED,
MUCJoinedState.JOINING])
for muc in mucs:
self._send_presence(muc.jid, auto)
def _send_presence(self, room_jid, auto):
show = app.SHOW_LIST[self._con.connected]
if show in ('invisible', 'offline'):
# FIXME: Check if this
......
......@@ -23,7 +23,6 @@ import nbxmpp
from gajim.common import app
from gajim.common.const import RequestAvatar
from gajim.common.nec import NetworkEvent
from gajim.common.nec import NetworkIncomingEvent
from gajim.common.modules.base import BaseModule
from gajim.common.connection_handlers_events import InformationEvent
......@@ -158,12 +157,13 @@ class VCardTemp(BaseModule):
self._con.get_module('VCardAvatars').send_avatar_presence(
after_publish=True)
self._log.info('%s: Published: %s', self._account, sha)
self._con.get_module('MUC').update_presence()
app.nec.push_incoming_event(
VcardPublishedEvent(None, conn=self._con))
NetworkEvent('vcard-published', account=self._account))
elif stanza.getType() == 'error':
app.nec.push_incoming_event(
VcardNotPublishedEvent(None, conn=self._con))
NetworkEvent('vcard-not-published', account=self._account))
def _get_vcard_photo(self, vcard, jid):
try:
......@@ -216,10 +216,10 @@ class VCardTemp(BaseModule):
elif 'FN' in vcard:
app.nicks[self._account] = vcard['FN']
app.nec.push_incoming_event(
VcardReceivedEvent(None, conn=self._con,
vcard_dict=vcard,
jid=jid))
app.nec.push_incoming_event(NetworkEvent('vcard-received',
account=self._account,
jid=jid,
vcard_dict=vcard))
callback(jid, resource, room, vcard, expected_sha)
......@@ -309,17 +309,5 @@ class VCardTemp(BaseModule):
return name
class VcardPublishedEvent(NetworkIncomingEvent):
name = 'vcard-published'
class VcardNotPublishedEvent(NetworkIncomingEvent):
name = 'vcard-not-published'
class VcardReceivedEvent(NetworkIncomingEvent):
name = 'vcard-received'
def get_instance(*args, **kwargs):
return VCardTemp(*args, **kwargs), 'VCardTemp'
......@@ -328,7 +328,6 @@ class GroupchatControl(ChatControlBase):
('muc-voice-approval', ged.GUI1, self._on_voice_approval),
('gc-message-received', ged.GUI1, self._nec_gc_message_received),
('mam-decrypted-message-received', ged.GUI1, self._nec_mam_decrypted_message_received),
('vcard-published', ged.GUI1, self._nec_vcard_published),
('update-gc-avatar', ged.GUI1, self._nec_update_avatar),
('update-room-avatar', ged.GUI1, self._nec_update_room_avatar),
('signed-in', ged.GUI1, self._nec_signed_in),
......@@ -1122,12 +1121,6 @@ class GroupchatControl(ChatControlBase):
subject_text = self.urlfinder.sub(self.make_href, subject)
self.subject_button.get_popover().set_text(subject_text)
def _nec_vcard_published(self, obj):
if obj.conn.name != self.account:
return
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:
return
......
......@@ -29,6 +29,7 @@ from gajim.common import app
from gajim.common import ged
from gajim.common.i18n import _
from gajim.common.const import AvatarSize
from gajim.common.helpers import event_filter
from gajim import gtkgui_helpers
from gajim.gui_menu_builder import show_save_as_menu
......@@ -338,17 +339,15 @@ class ProfileWindow(Gtk.ApplicationWindow):
self.update_progressbar_timeout_id = GLib.timeout_add(
100, self.update_progressbar)
def _nec_vcard_published(self, obj):
if obj.conn.name != self.account:
return
@event_filter(['account'])
def _nec_vcard_published(self, _event):
if self.update_progressbar_timeout_id is not None:
GLib.source_remove(self.update_progressbar_timeout_id)
self.update_progressbar_timeout_id = None
self.destroy()
def _nec_vcard_not_published(self, obj):
if obj.conn.name != self.account:
return
@event_filter(['account'])
def _nec_vcard_not_published(self, _event):
if self.message_id:
self.statusbar.remove(self.context_id, self.message_id)
self.message_id = self.statusbar.push(
......
......@@ -386,7 +386,7 @@ class GajimRemote(Server):
self.raise_signal('NewAccount', (obj.conn.name, obj.account_info))
def on_vcard_received(self, obj):
self.raise_signal('VcardInfo', (obj.conn.name, obj.vcard_dict))
self.raise_signal('VcardInfo', (obj.account, obj.vcard_dict))
def raise_signal(self, event_name, data):
log.info('Send event %s', event_name)
......
......@@ -2109,14 +2109,7 @@ class RosterWindow:
self.delete_pep(app.get_jid_from_account(account), account)
was_invisible = app.is_invisible(account)
app.connections[account].change_status(status, txt, auto)
for gc_control in app.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC) + \
list(app.interface.minimized_controls[account].values()):
if gc_control.account == account:
if app.gc_connected[account][gc_control.room_jid]:
app.connections[account].get_module('MUC').send_muc_presence(
gc_control.room_jid, auto=auto)
app.connections[account].get_module('MUC').update_presence(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