Ejemplo n.º 1
0
    def send_ping(self, contact: ContactsT) -> Generator:
        _task = yield

        if not app.account_is_available(self._account):
            return

        jid = contact.get_full_jid()

        self._log.info('Send ping to %s', jid)

        app.nec.push_incoming_event(
            NetworkEvent('ping-sent', account=self._account, contact=contact))

        ping_time = time.time()

        response = yield self.ping(jid, timeout=10)
        if is_error(response):
            app.nec.push_incoming_event(
                NetworkEvent('ping-error',
                             account=self._account,
                             contact=contact,
                             error=str(response)))
            return

        diff = round(time.time() - ping_time, 2)
        self._log.info('Received pong from %s after %s seconds', response.jid,
                       diff)

        app.nec.push_incoming_event(
            NetworkEvent('ping-reply',
                         account=self._account,
                         contact=contact,
                         seconds=diff))
Ejemplo n.º 2
0
    def _on_invite_or_decline(self, _con, _stanza, properties):
        if properties.muc_decline is not None:
            data = properties.muc_decline
            if helpers.ignore_contact(self._account, data.from_):
                raise nbxmpp.NodeProcessed

            self._log.info('Invite declined from: %s, reason: %s', data.from_,
                           data.reason)

            app.nec.push_incoming_event(
                NetworkEvent('muc-decline',
                             account=self._account,
                             **data._asdict()))
            raise nbxmpp.NodeProcessed

        if properties.muc_invite is not None:
            data = properties.muc_invite
            if helpers.ignore_contact(self._account, data.from_):
                raise nbxmpp.NodeProcessed

            self._log.info('Invite from: %s, to: %s', data.from_, data.muc)

            if app.in_groupchat(self._account, data.muc):
                # We are already in groupchat. Ignore invitation
                self._log.info('We are already in this room')
                raise nbxmpp.NodeProcessed

            app.nec.push_incoming_event(
                NetworkEvent('muc-invitation',
                             account=self._account,
                             **data._asdict()))
            raise nbxmpp.NodeProcessed
Ejemplo n.º 3
0
Archivo: roster.py Proyecto: bj-h/gajim
    def load_roster(self):
        self._log.info('Load from database')
        account_jid = self._con.get_own_jid().getStripped()
        data = app.logger.get_roster(account_jid)
        if data:
            self.set_raw(data)
            for jid, item in self._data.items():
                app.nec.push_incoming_event(NetworkEvent(
                    'roster-info',
                    conn=self._con,
                    jid=jid,
                    nickname=item['name'],
                    sub=item['subscription'],
                    ask=item['ask'],
                    groups=item['groups'],
                    avatar_sha=item['avatar_sha']))
        else:
            self._log.info('Database empty, reset roster version')
            app.config.set_per(
                'accounts', self._account, 'roster_version', '')

        app.nec.push_incoming_event(NetworkEvent(
            'roster-received',
            conn=self._con,
            roster=self._data.copy(),
            received_from_server=False))
Ejemplo n.º 4
0
    def load_roster(self):
        self._log.info('Load from database')
        data = app.storage.cache.load_roster(self._account)
        if data:
            self.set_raw(data)
            for jid, item in self._data.items():
                self._log.debug('%s: %s', jid, item)
                app.nec.push_incoming_event(
                    NetworkEvent('roster-info',
                                 conn=self._con,
                                 jid=jid,
                                 nickname=item['name'],
                                 sub=item['subscription'],
                                 ask=item['ask'],
                                 groups=item['groups'],
                                 avatar_sha=item.get('avatar_sha')))
        else:
            self._log.info('Database empty, reset roster version')
            app.settings.set_account_setting(self._account, 'roster_version',
                                             '')

        app.nec.push_incoming_event(
            NetworkEvent('roster-received',
                         conn=self._con,
                         roster=self._data.copy(),
                         received_from_server=False))
Ejemplo n.º 5
0
 def _event_dispatcher(self, realm, event, data):
     if realm == '':
         if event == 'STANZA RECEIVED':
             app.nec.push_incoming_event(
                 NetworkEvent('stanza-received',
                              conn=self,
                              stanza_str=str(data)))
         elif event == 'DATA SENT':
             app.nec.push_incoming_event(
                 NetworkEvent('stanza-sent',
                              conn=self,
                              stanza_str=str(data)))
Ejemplo n.º 6
0
    def _presence_received(self, con, stanza):
        hash_method = node = caps_hash = None

        caps = stanza.getTag('c', namespace=nbxmpp.NS_CAPS)
        if caps is not None:
            hash_method = caps['hash']
            node = caps['node']
            caps_hash = caps['ver']

        from_ = stanza.getFrom()
        full_jid = str(from_)
        show = parse_show(stanza)
        type_ = parse_type(stanza)

        log.info('Received from %s, type: %s, method: %s, node: %s, hash: %s',
                 from_, stanza.getType(), hash_method, node, caps_hash)

        client_caps = self._create_suitable_client_caps(
            node, caps_hash, hash_method, full_jid)

        # Type is None means 'available'
        if stanza.getType() is None and client_caps._hash_method == 'no':
            self._capscache.forget_caps(client_caps)
            client_caps = self._create_suitable_client_caps(
                node, caps_hash, hash_method)
        else:
            self._capscache.query_client_of_jid_if_unknown(
                self._con, full_jid, client_caps)

        self._update_client_caps_of_contact(from_, client_caps)

        # Event is only used by ClientIcons Plugin
        app.nec.push_incoming_event(
            NetworkEvent('caps-presence-received',
                         conn=self._con,
                         fjid=full_jid,
                         jid=from_.getStripped(),
                         resource=from_.getResource(),
                         hash_method=hash_method,
                         node=node,
                         caps_hash=caps_hash,
                         client_caps=client_caps,
                         show=show,
                         ptype=type_,
                         stanza=stanza))

        app.nec.push_incoming_event(
            NetworkEvent('caps-update',
                         conn=self._con,
                         fjid=full_jid,
                         jid=from_.getStripped()))
Ejemplo n.º 7
0
    def connect(self, show='online', msg=''):
        self.get_config_values_or_default()
        if not self.connection:
            self.connection = client_zeroconf.ClientZeroconf(self)
            if not zeroconf.test_zeroconf():
                app.nec.push_incoming_event(OurShowEvent(None, conn=self,
                    show='offline'))
                self.status = 'offline'
                app.nec.push_incoming_event(ConnectionLostEvent(None,
                    conn=self, title=_('Could not connect to "%s"') % self.name,
                    msg=_('Please check if Avahi or Bonjour is installed.')))
                self.disconnect()
                return
            result = self.connection.connect(show, msg)
            if not result:
                app.nec.push_incoming_event(OurShowEvent(None, conn=self,
                    show='offline'))
                self.status = 'offline'
                if result is False:
                    app.nec.push_incoming_event(ConnectionLostEvent(None,
                        conn=self, title=_('Could not start local service'),
                        msg=_('Unable to bind to port %d.' % self.port)))
                else: # result is None
                    app.nec.push_incoming_event(ConnectionLostEvent(None,
                        conn=self, title=_('Could not start local service'),
                        msg=_('Please check if avahi/bonjour-daemon is running.')))
                self.disconnect()
                return
        else:
            self.connection.announce()
        self.roster = self.connection.getRoster()
        app.nec.push_incoming_event(NetworkEvent('roster-received', conn=self,
            roster=self.roster.copy(), received_from_server=True))

        # display contacts already detected and resolved
        for jid in self.roster.keys():
            app.nec.push_incoming_event(NetworkEvent(
                'roster-info', conn=self, jid=jid,
                nickname=self.roster.getName(jid), sub='both',
                ask='no', groups=self.roster.getGroups(jid),
                avatar_sha=None))
            self._on_presence(jid)

        self.connected = STATUS_LIST.index(show)

        # refresh all contacts data every five seconds
        self.call_resolve_timeout = True
        GLib.timeout_add_seconds(5, self._on_resolve_timeout)
        return True
Ejemplo n.º 8
0
    def _on_error_presence(self, _con, _stanza, properties):
        room_jid = properties.jid.getBare()
        muc_data = self._manager.get(room_jid)
        if muc_data is None:
            return

        if muc_data.state == MUCJoinedState.JOINING:
            if properties.error.condition == 'conflict':
                self._remove_rejoin_timeout(room_jid)
                muc_data.nick += '_'
                self._log.info('Nickname conflict: %s change to %s',
                               muc_data.jid, muc_data.nick)
                self._join(muc_data)
            elif properties.error.condition == 'not-authorized':
                self._remove_rejoin_timeout(room_jid)
                self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
                self._raise_muc_event('muc-password-required', properties)
            else:
                self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
                if room_jid not in self._rejoin_muc:
                    app.nec.push_incoming_event(
                        NetworkEvent('muc-join-failed',
                                     account=self._account,
                                     room_jid=room_jid,
                                     error=properties.error))

        elif muc_data.state == MUCJoinedState.CREATING:
            self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
            app.nec.push_incoming_event(
                NetworkEvent('muc-creation-failed',
                             account=self._account,
                             room_jid=room_jid,
                             error=properties.error))

        elif muc_data.state == MUCJoinedState.CAPTCHA_REQUEST:
            app.nec.push_incoming_event(
                NetworkEvent('muc-captcha-error',
                             account=self._account,
                             room_jid=room_jid,
                             error_text=to_user_string(properties.error)))
            self._manager.set_state(room_jid, MUCJoinedState.CAPTCHA_FAILED)
            self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)

        elif muc_data.state == MUCJoinedState.CAPTCHA_FAILED:
            self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)

        else:
            self._raise_muc_event('muc-presence-error', properties)
Ejemplo n.º 9
0
    def _subscribe_received(self, _con, _stanza, properties):
        jid = properties.jid.getBare()
        fjid = str(properties.jid)

        is_transport = app.jid_is_transport(fjid)
        auto_auth = app.config.get_per('accounts', self._account, 'autoauth')

        self._log.info(
            'Received Subscribe: %s, transport: %s, '
            'auto_auth: %s, user_nick: %s', properties.jid, is_transport,
            auto_auth, properties.nickname)

        if is_transport and fjid in self._con.agent_registrations:
            self._con.agent_registrations[fjid]['sub_received'] = True
            if not self._con.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:
            self.send_presence(fjid, 'subscribed')

        status = (properties.status
                  or _('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=properties.nickname,
                         is_transport=is_transport))

        raise nbxmpp.NodeProcessed
Ejemplo n.º 10
0
    def _mood_received(self, _con, _stanza, properties):
        if properties.pubsub_event.retracted:
            return

        data = properties.pubsub_event.data
        for contact in app.contacts.get_contacts(self._account,
                                                 str(properties.jid)):
            if data is not None:
                contact.pep[PEPEventType.MOOD] = data
            else:
                contact.pep.pop(PEPEventType.MOOD, None)

        if properties.is_self_message:
            if data is not None:
                self._con.pep[PEPEventType.MOOD] = data
            else:
                self._con.pep.pop(PEPEventType.MOOD, None)
            self._current_mood = data

        app.nec.push_incoming_event(
            NetworkEvent('mood-received',
                         account=self._account,
                         jid=properties.jid.bare,
                         mood=data,
                         is_self_message=properties.is_self_message))
Ejemplo n.º 11
0
    def add_plugin(self, plugin, activate=False):
        plugin_class = plugin.load_module()
        if plugin_class is None:
            return None

        if plugin in self.plugins:
            log.info('Not loading plugin %s v %s. Plugin already loaded.',
                     plugin.short_name, plugin.version)
            return None

        try:
            plugin_obj = plugin_class()
        except Exception:
            log.exception('Error while loading a plugin')
            return None

        if plugin.short_name not in app.settings.get_plugins():
            app.settings.set_plugin_setting(plugin.short_name, 'active',
                                            plugin.shipped)

        self.plugins.append(plugin_obj)
        plugin_obj.active = False

        if activate:
            self.activate_plugin(plugin_obj)

        app.nec.push_incoming_event(
            NetworkEvent('plugin-added', plugin=plugin_obj))

        return plugin_obj
Ejemplo n.º 12
0
    def _blocking_push_received(self, _con, _stanza, properties):
        if not properties.is_blocking:
            return

        changed_list = []

        if properties.blocking.unblock_all:
            self.blocked = []
            for jid in self.blocked:
                self._presence_probe(jid)
            self._log.info('Unblock all Push')

        for jid in properties.blocking.unblock:
            changed_list.append(jid)
            if jid not in self.blocked:
                continue
            self.blocked.remove(jid)
            self._presence_probe(jid)
            self._log.info('Unblock Push: %s', jid)

        for jid in properties.blocking.block:
            if jid in self.blocked:
                continue
            changed_list.append(jid)
            self.blocked.append(jid)
            self._set_contact_offline(str(jid))
            self._log.info('Block Push: %s', jid)

        app.nec.push_incoming_event(NetworkEvent('blocking',
                                                 conn=self._con,
                                                 changed=changed_list))

        raise nbxmpp.NodeProcessed
Ejemplo n.º 13
0
    def encrypt_message(self, obj, callback):
        keys = self._contacts.get_keys(obj.jid)
        if not keys:
            log.error('Droping stanza to %s, because we have no key', obj.jid)
            return

        keys += self._contacts.get_keys(self.own_jid)
        keys += [Key(self._fingerprint, None)]

        payload = create_signcrypt_node(obj.msg_iq, NOT_ENCRYPTED_TAGS)

        encrypted_payload, error = self._pgp.encrypt(payload, keys)
        if error:
            log.error('Error: %s', error)
            app.nec.push_incoming_event(
                NetworkEvent('message-not-sent',
                             conn=self._con,
                             jid=obj.jid,
                             message=obj.message,
                             error=error,
                             time_=time.time(),
                             session=None))
            return

        create_message_stanza(obj.msg_iq, encrypted_payload, bool(obj.message))
        add_additional_data(obj.additional_data, self._fingerprint)

        obj.encrypted = ENCRYPTION_NAME
        callback(obj)
Ejemplo n.º 14
0
    def _entity_caps(self, _con, _stanza, properties):
        if properties.type.is_error or properties.type.is_unavailable:
            return

        if properties.is_self_presence:
            return

        if properties.entity_caps is None:
            return

        task = EntityCapsTask(self._account, properties, self._execute_task)

        self._log.info('Received %s', task.entity)

        disco_info = app.storage.cache.get_caps_entry(task.entity.method,
                                                      task.entity.hash)
        if disco_info is None:
            self._queue_task(task)
            return

        jid = str(properties.jid)
        app.storage.cache.set_last_disco_info(jid, disco_info, cache_only=True)
        app.nec.push_incoming_event(
            NetworkEvent('caps-update',
                         account=self._account,
                         fjid=jid,
                         jid=properties.jid.bare))
Ejemplo n.º 15
0
    def connect_and_init(self, show, msg):
        # to check for errors from zeroconf
        check = True
        if not self.connect(show, msg):
            return

        check = self.connection.announce()

        # stay offline when zeroconf does something wrong
        if check:
            self._set_state(ClientState.CONNECTED)
            app.nec.push_incoming_event(NetworkEvent('signed-in', conn=self))
            app.nec.push_incoming_event(
                OurShowEvent(None, conn=self, show=show))
        else:
            # show notification that avahi or system bus is down
            self._set_state(ClientState.DISCONNECTED)
            app.nec.push_incoming_event(
                OurShowEvent(None, conn=self, show='offline'))
            self._status = 'offline'
            app.nec.push_incoming_event(
                ConnectionLostEvent(
                    None,
                    conn=self,
                    title=_('Could not change status of account "%s"') %
                    self.name,
                    msg=_('Please check if avahi-daemon is running.')))
Ejemplo n.º 16
0
Archivo: roster.py Proyecto: bj-h/gajim
    def _roster_push_received(self, _con, stanza, _properties):
        self._log.info('Push received')

        sender = stanza.getFrom()
        if sender is not None:
            if not self._con.get_own_jid().bareMatch(sender):
                self._log.warning('Wrong JID %s', stanza.getFrom())
                return

        push_items, version = self._parse_push(stanza)

        self._ack_roster_push(stanza)

        for item in push_items:
            attrs = item.data
            app.nec.push_incoming_event(NetworkEvent(
                'roster-info',
                conn=self._con,
                jid=item.jid,
                nickname=attrs['name'],
                sub=attrs['subscription'],
                ask=attrs['ask'],
                groups=attrs['groups'],
                avatar_sha=None))
            account_jid = self._con.get_own_jid().getStripped()
            app.logger.add_or_update_contact(
                account_jid, item.jid, attrs['name'],
                attrs['subscription'], attrs['ask'], attrs['groups'])

        self._log.info('New version: %s', version)
        app.config.set_per(
            'accounts', self._account, 'roster_version', version)

        raise nbxmpp.NodeProcessed
Ejemplo n.º 17
0
    def _on_config_result(self, result):
        if is_error_result(result):
            self._log.info(result)
            app.nec.push_incoming_event(
                NetworkEvent('muc-configuration-failed',
                             account=self._account,
                             room_jid=result.jid,
                             error=result))
            return

        self._con.get_module('Discovery').disco_muc(
            result.jid, callback=self._on_disco_result_after_config)

        # If this is an automatic room creation
        try:
            invites = app.automatic_rooms[self._account][
                result.jid]['invities']
        except KeyError:
            return

        user_list = {}
        for jid in invites:
            user_list[jid] = {'affiliation': 'member'}
        self.set_affiliation(result.jid, user_list)

        for jid in invites:
            self.invite(result.jid, jid)
Ejemplo n.º 18
0
    def _on_prompt_result(self, _nbxmpp_client, stanza):
        jid = str(stanza.getFrom())
        fjid = stanza.getFrom().bare
        resource = stanza.getFrom().resource

        query = stanza.getTag('query')
        if query is not None:
            desc = query.getTagData('desc')
            prompt = query.getTagData('prompt')
            prompt_jid = query.getTagData('jid')
        else:
            desc = None
            prompt = None
            prompt_jid = None

        app.nec.push_incoming_event(
            NetworkEvent('gateway-prompt-received',
                         conn=self._con,
                         fjid=fjid,
                         jid=jid,
                         resource=resource,
                         desc=desc,
                         prompt=prompt,
                         prompt_jid=prompt_jid,
                         stanza=stanza))
Ejemplo n.º 19
0
    def _subscribe_received(self, _con, _stanza, properties):
        jid = properties.jid.bare
        fjid = str(properties.jid)

        is_transport = app.jid_is_transport(fjid)
        auto_auth = app.settings.get_account_setting(self._account, 'autoauth')

        self._log.info(
            'Received Subscribe: %s, transport: %s, '
            'auto_auth: %s, user_nick: %s', properties.jid, is_transport,
            auto_auth, properties.nickname)

        if auto_auth or jid in self._jids_for_auto_auth:
            self.send_presence(fjid, 'subscribed')
            self._jids_for_auto_auth.discard(jid)
            self._log.info('Auto respond with subscribed: %s', jid)
            return

        status = (properties.status
                  or _('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=properties.nickname,
                         is_transport=is_transport))

        raise nbxmpp.NodeProcessed
Ejemplo n.º 20
0
    def _process_chatstate(self, _con, _stanza, properties):
        if not properties.has_chatstate:
            return

        if (properties.is_self_message or properties.type.is_groupchat
                or properties.is_mam_message
                or properties.is_carbon_message and properties.carbon.is_sent):
            return

        if properties.is_muc_pm:
            contact = app.contacts.get_gc_contact(self._account,
                                                  properties.jid.getBare(),
                                                  properties.jid.getResource())
        else:
            contact = app.contacts.get_contact_from_full_jid(
                self._account, str(properties.jid))
        if contact is None:
            return

        contact.chatstate = properties.chatstate
        self._log.info('Recv: %-10s - %s', properties.chatstate,
                       properties.jid)
        app.nec.push_outgoing_event(
            NetworkEvent('chatstate-received',
                         account=self._account,
                         contact=contact))
Ejemplo n.º 21
0
 def on_send_not_ok(reason):
     reason += ' ' + _('Your message could not be sent.')
     app.nec.push_incoming_event(
         NetworkEvent('zeroconf-error',
                      account=self.name,
                      jid=message.jid,
                      message=reason))
Ejemplo n.º 22
0
    def _send_message(self, message):
        def on_send_ok(stanza_id):
            app.nec.push_incoming_event(
                MessageSentEvent(None, jid=message.jid, **vars(message)))
            self.get_module('Message').log_message(message)

        def on_send_not_ok(reason):
            reason += ' ' + _('Your message could not be sent.')
            app.nec.push_incoming_event(
                NetworkEvent('zeroconf-error',
                             account=self.name,
                             jid=message.jid,
                             message=reason))

        ret = self.connection.send(message.stanza,
                                   message.message is not None,
                                   on_ok=on_send_ok,
                                   on_not_ok=on_send_not_ok)
        message.timestamp = time.time()

        if ret == -1:
            # Contact Offline
            error_message = _(
                'Contact is offline. Your message could not be sent.')
            app.nec.push_incoming_event(
                NetworkEvent('zeroconf-error',
                             account=self.name,
                             jid=message.jid,
                             message=error_message))
            return
Ejemplo n.º 23
0
 def _on_remove(self, *args):
     self.get_parent().remove(self)
     app.css_config.remove_value(self.option.selector,
                                 self.option.attr,
                                 pre=True)
     app.nec.push_incoming_event(NetworkEvent('style-changed'))
     self.destroy()
Ejemplo n.º 24
0
    def _nec_stanza_message_outgoing(self, obj):
        if obj.conn.name != self.name:
            return

        def on_send_ok(stanza_id):
            app.nec.push_incoming_event(MessageSentEvent(None, **vars(obj)))
            self.log_message(obj, obj.jid)

        def on_send_not_ok(reason):
            reason += ' ' + _('Your message could not be sent.')
            app.nec.push_incoming_event(NetworkEvent(
                'zeroconf-error',
                account=self.name,
                jid=obj.jid,
                message=reason))
            # Dont propagate event
            return True

        obj.timestamp = time.time()
        ret = self.connection.send(
            obj.msg_iq, obj.message is not None,
            on_ok=on_send_ok, on_not_ok=on_send_not_ok)

        if ret == -1:
            # Contact Offline
            error_message = _(
                'Contact is offline. Your message could not be sent.')
            app.nec.push_incoming_event(NetworkEvent(
                'zeroconf-error',
                account=self.name,
                jid=obj.jid,
                message=error_message))
            # Dont propagate event
            return True
Ejemplo n.º 25
0
 def _connect_error(self, sid, error, error_type, msg=None):
     """
     Called when there is an error establishing BS connection, or when
     connection is rejected
     """
     if not app.account_is_connected(self._account):
         return
     file_props = FilesProp.getFileProp(self._account, sid)
     if file_props is None:
         log.error('can not send iq error on failed transfer')
         return
     if file_props.type_ == 's':
         to = file_props.receiver
     else:
         to = file_props.sender
     iq = nbxmpp.Iq(to=to, typ='error')
     iq.setAttr('id', file_props.request_id)
     err = iq.setTag('error')
     err.setAttr('type', error_type)
     err.setTag(error, namespace=nbxmpp.NS_STANZAS)
     self._con.connection.send(iq)
     if msg:
         self.disconnect_transfer(file_props)
         file_props.error = -3
         app.nec.push_incoming_event(
             NetworkEvent('file-request-error',
                          conn=self._con,
                          jid=app.get_jid_without_resource(to),
                          file_props=file_props,
                          error_msg=msg))
Ejemplo n.º 26
0
 def _raise_muc_event(self, event_name, properties):
     app.nec.push_incoming_event(
         NetworkEvent(event_name,
                      account=self._account,
                      room_jid=properties.jid.getBare(),
                      properties=properties))
     self._log_muc_event(event_name, properties)
Ejemplo n.º 27
0
    def delegate(self, event: Any) -> None:
        if self._con.get_own_jid().bareMatch(event.jid) or event.sent:
            # Dont show chatstates from our own resources
            return

        if event.mtype == 'groupchat':
            # Not implemented yet
            return

        chatstate = parse_chatstate(event.stanza)
        if chatstate is None:
            return

        if event.muc_pm:
            contact = app.contacts.get_gc_contact(
                self._account, event.jid, event.resource)
        else:
            contact = app.contacts.get_contact_from_full_jid(
                self._account, event.fjid)
        if contact is None:
            return

        contact.chatstate = chatstate
        self._log.info('Recv: %-10s - %s', chatstate, event.fjid)
        app.nec.push_outgoing_event(
            NetworkEvent('chatstate-received',
                         account=self._account,
                         contact=contact))
Ejemplo n.º 28
0
    def _on_presence(self, jid, show=None, status=None):
        if status is None:
            status = self.roster.getMessage(jid)
        if show is None:
            show = self.roster.getStatus(jid)

        ptype = 'unavailable' if show == 'offline' else None

        event_attrs = {
            'conn': self,
            'prio': 0,
            'need_add_in_roster': False,
            'popup': False,
            'ptype': ptype,
            'jid': jid,
            'resource': 'local',
            'id_': None,
            'fjid': jid,
            'timestamp': 0,
            'avatar_sha': None,
            'user_nick': '',
            'idle_time': None,
            'show': show,
            'new_show': show,
            'old_show': 0,
            'status': status,
            'contact_list': [],
            'contact': None,
        }

        event_ = NetworkEvent('presence-received', **event_attrs)

        self._update_contact(event_)

        app.nec.push_incoming_event(event_)
Ejemplo n.º 29
0
 def _unsubscribed_received(self, _con, _stanza, properties):
     self._log.info('Received Unsubscribed: %s', properties.jid)
     app.nec.push_incoming_event(
         NetworkEvent('unsubscribed-presence-received',
                      conn=self._con,
                      jid=properties.jid.bare))
     raise nbxmpp.NodeProcessed
Ejemplo n.º 30
0
    def _bookmark_1_event_received(self, _con, _stanza, properties):
        if not properties.is_self_message:
            self._log.warning('%s has an open access bookmarks node',
                              properties.jid)
            return

        if not self.nativ_bookmarks_used:
            return

        if self._request_in_progress:
            self._log.info('Ignore update, pubsub request in progress')
            return

        old_bookmarks = self._bookmarks.copy()

        if properties.pubsub_event.deleted or properties.pubsub_event.purged:
            self._log.info('Bookmark node deleted/purged')
            self._bookmarks = {}

        elif properties.pubsub_event.retracted:
            jid = properties.pubsub_event.id
            self._log.info('Retract: %s', jid)
            bookmark = self._bookmarks.get(jid)
            if bookmark is not None:
                self._bookmarks.pop(bookmark, None)

        else:
            new_bookmark = properties.pubsub_event.data
            self._bookmarks[new_bookmark.jid] = properties.pubsub_event.data

        self._act_on_changed_bookmarks(old_bookmarks)
        app.nec.push_incoming_event(
            NetworkEvent('bookmarks-received', account=self._account))