def subscribe(self, jid, msg='', name='', groups=None, auto_auth=False, user_nick=''): if not app.account_is_connected(self._account): return if groups is None: groups = [] log.info('Request Subscription to %s', jid) if auto_auth: self.jids_for_auto_auth.append(jid) infos = {'jid': jid} if name: infos['name'] = name iq = nbxmpp.Iq('set', nbxmpp.NS_ROSTER) query = iq.setQuery() item = query.addChild('item', attrs=infos) for group in groups: item.addChild('group').setData(group) self._con.connection.send(iq) presence = nbxmpp.Presence(jid, 'subscribe') if user_nick: nick = presence.setTag('nick', namespace=nbxmpp.NS_NICK) nick.setData(user_nick) presence = self._add_sha(presence) if msg: presence.setStatus(msg) self._con.connection.send(presence)
def get_presence(self, to=None, typ=None, priority=None, show=None, status=None, nick=None, caps=True, 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 show = None presence = nbxmpp.Presence(to, typ, priority, show, status) if nick is not None: nick_tag = presence.setTag('nick', namespace=Namespace.NICK) nick_tag.setData(nick) if (idle_time and app.is_installed('IDLE') and app.settings.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=Namespace.IDLE) idle_node.setAttr('since', time_) caps = self._con.get_module('Caps').caps if caps is not None and typ != 'unavailable': presence.setTag('c', namespace=Namespace.CAPS, attrs=caps._asdict()) return presence
def unsubscribed(self, jid): if not app.account_is_connected(self._account): return log.info('Unsubscribed: %s', jid) presence = nbxmpp.Presence(jid, 'unsubscribed') presence = self._add_sha(presence) self._con.connection.send(presence)
def send_avatar_presence(self, force=False): if self.avatar_advertised and not force: log.debug('Avatar already advertised') return show = helpers.get_xmpp_show(app.SHOW_LIST[self._con.connected]) pres = nbxmpp.Presence(typ=None, priority=self._con.priority, show=show, status=self._con.status) pres = self._con.add_sha(pres) self._con.connection.send(pres) self.avatar_advertised = True app.interface.update_avatar(self._account, self._con.get_own_jid().getStripped())
def _send_first_presence(self, signed=''): show = self.continue_connect_info[0] msg = self.continue_connect_info[1] sign_msg = self.continue_connect_info[2] if sign_msg and not signed: signed = self.get_signed_presence(msg) if signed is None: app.nec.push_incoming_event( BadGPGPassphraseEvent(None, conn=self)) self.USE_GPG = False signed = '' self.connected = app.SHOW_LIST.index(show) sshow = helpers.get_xmpp_show(show) # send our presence if show == 'invisible': self.send_invisible_presence(msg, signed, True) return if show not in ['offline', 'online', 'chat', 'away', 'xa', 'dnd']: return priority = app.get_priority(self.name, sshow) p = nbxmpp.Presence(typ=None, priority=priority, show=sshow) if msg: p.setStatus(msg) if signed: p.setTag(nbxmpp.NS_SIGNED + ' x').setData(signed) p = self.add_sha(p) if self.connection: self.connection.send(p) self.priority = priority app.nec.push_incoming_event(OurShowEvent(None, conn=self, show=show)) # ask our VCard self.get_module('VCardTemp').request_vcard() # Get bookmarks self.get_module('Bookmarks').get_bookmarks() # Get annotations from private namespace self.get_module('Annotations').get_annotations() # Inform GUI we just signed in app.nec.push_incoming_event(SignedInEvent(None, conn=self)) self.get_module('PEP').send_stored_publish() self.continue_connect_info = None
def get_presence(self, to=None, typ=None, priority=None, show=None, status=None, nick=None, caps=True, idle_time=None): if show not in ('chat', 'away', 'xa', 'dnd'): # Gajim sometimes passes invalid show values here # until this is fixed this is a workaround show = None presence = nbxmpp.Presence(to, typ, priority, show, status) if nick is not 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 caps: attrs = { 'hash': 'sha-1', 'node': 'http://gajim.org', 'ver': app.caps_hash[self._account] } presence.setTag('c', namespace=nbxmpp.NS_CAPS, attrs=attrs) return presence
def _subscribe_received(self, con, stanza): from_ = stanza.getFrom() jid = from_.getStripped() fjid = str(from_) status = stanza.getStatus() is_transport = app.jid_is_transport(fjid) auto_auth = app.config.get_per('accounts', self._account, 'autoauth') user_nick = parse_nickname(stanza) log.info( 'Received Subscribe: %s, transport: %s, auto_auth: %s, ' 'user_nick: %s', from_, is_transport, auto_auth, user_nick) if is_transport and fjid in self._con.agent_registrations: self._con.agent_registrations[fjid]['sub_received'] = True if not self.agent_registrations[fjid]['roster_push']: # We'll reply after roster push result raise nbxmpp.NodeProcessed if auto_auth or is_transport or jid in self.jids_for_auto_auth: presence = nbxmpp.Presence(fjid, 'subscribed') presence = self._add_sha(presence) self._con.connection.send(presence) if not status: status = _('I would like to add you to my roster.') app.nec.push_incoming_event( NetworkEvent('subscribe-presence-received', conn=self._con, jid=jid, fjid=fjid, status=status, user_nick=user_nick, is_transport=is_transport)) raise nbxmpp.NodeProcessed
def _presence_probe(self, jid): self._log.info('Presence probe: %s', jid) # Send a presence Probe to get the current Status probe = nbxmpp.Presence(jid, 'probe', frm=self._con.get_own_jid()) self._con.connection.send(probe)
def _on_connected(self, _client, _signal_name): print("connected") self.client.send(nbxmpp.Presence())
def unsubscribe(self, jid): """ Ask for removing our subscription for JID 'jid' """ self._con.connection.send(nbxmpp.Presence(jid, 'unsubscribe'))
def send_presence(self): presence = nbxmpp.Presence() self._client.send_stanza(presence)