Ejemplo n.º 1
0
    def send_contacts(self, contacts, fjid, type_='message'):
        if not app.account_is_available(self._account):
            return

        if type_ == 'message':
            if len(contacts) == 1:
                msg = _('Sent contact: "%(jid)s" (%(name)s)') % {
                    'jid': contacts[0].get_full_jid(),
                    'name': contacts[0].get_shown_name()}
            else:
                msg = _('Sent contacts:')
                for contact in contacts:
                    msg += '\n "%s" (%s)' % (contact.get_full_jid(),
                                             contact.get_shown_name())
            stanza = nbxmpp.Message(to=app.get_jid_without_resource(fjid),
                                    body=msg)
        elif type_ == 'iq':
            stanza = nbxmpp.Iq(to=fjid, typ='set')
        xdata = stanza.addChild(name='x', namespace=Namespace.ROSTERX)
        for contact in contacts:
            name = contact.get_shown_name()
            xdata.addChild(name='item', attrs={'action': 'add',
                                               'jid': contact.jid,
                                               'name': name})
            self._log.info('Send contact: %s %s', contact.jid, name)
        self._con.connection.send(stanza)
Ejemplo n.º 2
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_available(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=Namespace.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.º 3
0
def allow_showing_notification(account):
    if not app.settings.get('show_notifications'):
        return False
    if app.settings.get('autopopupaway'):
        return True
    if app.account_is_available(account):
        return True
    return False
Ejemplo n.º 4
0
    def send_pb_subscription_query(self, jid, cb, **kwargs):
        if not app.account_is_available(self._account):
            return

        query = nbxmpp.Iq('get', to=jid)
        pb = query.addChild('pubsub', namespace=Namespace.PUBSUB)
        pb.addChild('subscriptions')

        self._con.connection.SendAndCallForResponse(query, cb, kwargs)
Ejemplo n.º 5
0
    def unsubscribe(self, agent):
        if not app.account_is_available(self._account):
            return
        iq = nbxmpp.Iq('set', Namespace.REGISTER, to=agent)
        iq.setQuery().setTag('remove')

        self._con.connection.SendAndCallForResponse(
            iq, self._on_unsubscribe_result)
        self._con.get_module('Roster').del_item(agent)
Ejemplo n.º 6
0
    def send_pb_unsubscribe(self, jid, node, cb, **kwargs):
        if not app.account_is_available(self._account):
            return

        our_jid = app.get_jid_from_account(self._account)
        query = nbxmpp.Iq('set', to=jid)
        pb = query.addChild('pubsub', namespace=Namespace.PUBSUB)
        pb.addChild('unsubscribe', {'node': node, 'jid': our_jid})

        self._con.connection.SendAndCallForResponse(query, cb, kwargs)
Ejemplo n.º 7
0
    def _send_single_message(self):
        if not app.account_is_available(self.account):
            # if offline or connecting
            ErrorDialog(_('Connection not available'),
                        _('Please make sure you are connected with "%s".') %
                        self.account)
            return True
        if isinstance(self._to, list):
            sender_list = []
            for i in self._to:
                if i[0].resource:
                    sender_list.append(i[0].jid + '/' + i[0].resource)
                else:
                    sender_list.append(i[0].jid)
        else:
            sender_list = [j.strip() for j
                           in self._ui.to_entry.get_text().split(',')]

        subject = self._ui.subject_entry.get_text()
        begin, end = self._message_tv_buffer.get_bounds()
        message = self._message_tv_buffer.get_text(begin, end, True)

        recipient_list = []

        for to_whom_jid in sender_list:
            if to_whom_jid in self._completion_dict:
                to_whom_jid = self._completion_dict[to_whom_jid].jid
            try:
                to_whom_jid = helpers.parse_jid(to_whom_jid)
            except helpers.InvalidFormat:
                ErrorDialog(
                    _('Invalid XMPP Address'),
                    _('It is not possible to send a message to %s, this '
                      'XMPP Address is not valid.') % to_whom_jid)
                return True

            if '/announce/' in to_whom_jid:
                con = app.connections[self.account]
                con.get_module('Announce').set_announce(
                    to_whom_jid, subject, message)
                continue

            recipient_list.append(to_whom_jid)

        message = OutgoingMessage(account=self.account,
                                  contact=None,
                                  message=message,
                                  type_='normal',
                                  subject=subject)
        con = app.connections[self.account]
        con.send_messages(recipient_list, message)

        self._ui.subject_entry.set_text('') # we sent ok, clear the subject
        self._message_tv_buffer.set_text('') # we sent ok, clear the textview
        return False
Ejemplo n.º 8
0
    def join(self, muc_data):
        if not app.account_is_available(self._account):
            return

        self._manager.add(muc_data)

        disco_info = app.storage.cache.get_last_disco_info(muc_data.jid,
                                                           max_age=60)
        if disco_info is None:
            self._con.get_module('Discovery').disco_muc(
                muc_data.jid, callback=self._on_disco_result)
        else:
            self._join(muc_data)
Ejemplo n.º 9
0
    def send_file_rejection(self, file_props):
        """
        Inform sender that we refuse to download the file

        typ is used when code = '400', in this case typ can be 'stream' for
        invalid stream or 'profile' for invalid profile
        """
        # user response to ConfirmationDialog may come after we've disconnected
        if not app.account_is_available(self._account):
            return

        for session in self._con.get_module('Jingle').get_jingle_sessions(
                None, file_props.sid):
            session.cancel_session()
Ejemplo n.º 10
0
 def _proxy_auth_ok(self, proxy):
     """
     Called after authentication to proxy server
     """
     if not app.account_is_available(self._account):
         return
     file_props = FilesProp.getFileProp(self._account, proxy['sid'])
     iq = nbxmpp.Iq(to=proxy['initiator'], typ='set')
     auth_id = "au_" + proxy['sid']
     iq.setID(auth_id)
     query = iq.setTag('query', namespace=Namespace.BYTESTREAM)
     query.setAttr('sid', proxy['sid'])
     activate = query.setTag('activate')
     activate.setData(file_props.proxy_receiver)
     iq.setID(auth_id)
     self._con.connection.send(iq)
Ejemplo n.º 11
0
 def send_success_connect_reply(self, streamhost):
     """
     Send reply to the initiator of FT that we made a connection
     """
     if not app.account_is_available(self._account):
         return
     if streamhost is None:
         return
     iq = nbxmpp.Iq(to=streamhost['initiator'],
                    typ='result',
                    frm=streamhost['target'])
     iq.setAttr('id', streamhost['id'])
     query = iq.setTag('query', namespace=Namespace.BYTESTREAM)
     stream_tag = query.setTag('streamhost-used')
     stream_tag.setAttr('jid', streamhost['jid'])
     self._con.connection.send(iq)
Ejemplo n.º 12
0
 def store_metacontacts(self, tags_list):
     if not app.account_is_available(self._account):
         return
     iq = nbxmpp.Iq('set', Namespace.PRIVATE)
     meta = iq.getQuery().addChild('storage',
                                   namespace='storage:metacontacts')
     for tag in tags_list:
         for data in tags_list[tag]:
             jid = data['jid']
             dict_ = {'jid': jid, 'tag': tag}
             if 'order' in data:
                 dict_['order'] = data['order']
             meta.addChild(name='meta', attrs=dict_)
     self._log.info('Store: %s', tags_list)
     self._con.connection.SendAndCallForResponse(
         iq, self._store_response_received)
Ejemplo n.º 13
0
 def _send_location(self):
     accounts = app.connections.keys()
     for acct in accounts:
         if not app.account_is_available(acct):
             continue
         if not app.settings.get_account_setting(acct, 'publish_location'):
             continue
         if self.location_info == self._data:
             continue
         if 'timestamp' in self.location_info and 'timestamp' in self._data:
             last_data = self.location_info.copy()
             del last_data['timestamp']
             new_data = self._data.copy()
             del new_data['timestamp']
             if last_data == new_data:
                 continue
         app.connections[acct].get_module('UserLocation').set_location(
             LocationData(**self._data))
         self.location_info = self._data.copy()