def replace_roster(self, account_name, roster_version, roster): """ Replace current roster in DB by a new one accout_name is the name of the account to change. roster_version is the version of the new roster. roster is the new version. """ # First we must reset roster_version value to ensure that the server # sends back all the roster at the next connexion if the replacement # didn't work properly. gajim.config.set_per('accounts', account_name, 'roster_version', '') account_jid = gajim.get_jid_from_account(account_name) account_jid_id = self.get_jid_id(account_jid) # Delete old roster self.remove_roster(account_jid) # Fill roster tables with the new roster for jid in roster: self.add_or_update_contact(account_jid, jid, roster[jid]['name'], roster[jid]['subscription'], roster[jid]['ask'], roster[jid]['groups'], commit=False) self._timeout_commit() # At this point, we are sure the replacement works properly so we can # set the new roster_version value. gajim.config.set_per('accounts', account_name, 'roster_version', roster_version)
def send_pb_unsubscribe(self, jid, node, cb, *args, **kwargs): our_jid = gajim.get_jid_from_account(self.name) query = xmpp.Iq('set', to=jid) pb = query.addChild('pubsub', namespace=xmpp.NS_PUBSUB) pb.addChild('unsubscribe', {'node': node, 'jid': our_jid}) id = self.connection.send(query) self.__callbacks[id] = (cb, args, kwargs)
def send_pb_unsubscribe(self, jid, node, cb, *args, **kwargs): our_jid = gajim.get_jid_from_account(self.name) query = xmpp.Iq('set', to=jid) pb = query.addChild('pubsub', namespace=xmpp.NS_PUBSUB) pb.addChild('unsubscribe', {'node': node, 'jid': our_jid}) id = self.connection.send(query) self.__callbacks[id]=(cb, args, kwargs)
def __init__(self, con, weinitiate, jid, iq_id=None, sid=None, werequest=False): """ con -- connection object, weinitiate -- boolean, are we the initiator? jid - jid of the other entity """ self.contents = {} # negotiated contents self.connection = con # connection to use # our full jid #FIXME: Get rid of gajim here? self.ourjid = gajim.get_jid_from_account(self.connection.name) if con.server_resource: self.ourjid = self.ourjid + '/' + con.server_resource self.peerjid = jid # jid we connect to # jid we use as the initiator self.initiator = weinitiate and self.ourjid or self.peerjid # jid we use as the responder self.responder = weinitiate and self.peerjid or self.ourjid # are we an initiator? self.weinitiate = weinitiate # Are we requesting or offering a file? self.werequest = werequest self.request = False # what state is session in? (one from JingleStates) self.state = JingleStates.ended if not sid: sid = con.connection.getAnID() self.sid = sid # sessionid # iq stanza id, used to determine which sessions to summon callback # later on when iq-result stanza arrives if iq_id is not None: self.iq_ids = [iq_id] else: self.iq_ids = [] self.accepted = True # is this session accepted by user # Tells whether this session is a file transfer or not self.session_type_FT = False # callbacks to call on proper contents # use .prepend() to add new callbacks, especially when you're going # to send error instead of ack self.callbacks = { 'content-accept': [self.__ack, self.__on_content_accept, self.__broadcast], 'content-add': [self.__ack, self.__on_content_add, self.__broadcast ], #TODO 'content-modify': [self.__ack], #TODO 'content-reject': [self.__ack, self.__on_content_remove], 'content-remove': [self.__ack, self.__on_content_remove], 'description-info': [self.__ack, self.__broadcast], #TODO 'security-info': [self.__ack], #TODO 'session-accept': [self.__ack, self.__on_session_accept, self.__on_content_accept, self.__broadcast], 'session-info': [self.__ack, self.__broadcast, self.__on_session_info ], 'session-initiate': [self.__ack, self.__on_session_initiate, self.__broadcast], 'session-terminate': [self.__ack,self.__on_session_terminate, self.__broadcast_all], 'transport-info': [self.__ack, self.__broadcast], 'transport-replace': [self.__ack, self.__broadcast, self.__on_transport_replace], #TODO 'transport-accept': [self.__ack], #TODO 'transport-reject': [self.__ack], #TODO 'iq-result': [self.__broadcast], 'iq-error': [self.__on_error], }
def getOurBareJID(self): return gajim.get_jid_from_account(self.name)