def accept_friend_request(self, jid): if not isinstance(jid, JID): jid = JID(jid) stanza = Presence(stanza_type=ACCEPT_RESPONSES["subscribe"], to_jid=jid.bare()) self.send(stanza) self.request_add_friend(jid)
def get_name(self, jid): if isinstance(jid, str): jid = JID(jid) else: jid = jid.bare() try: return self.roster[jid].name or hashjid(jid) except KeyError: return hashjid(jid)
def del_roster(self, Jid): """ 删除好友 :param Jid: 删除的jid :return: """ if isinstance(Jid, str) or isinstance(Jid, unicode): Jid = JID(Jid) if not self.is_jid_in_roster(Jid): return UserService().del_roster(self.JID.local, Jid.bare().as_string()) UserService().del_roster(Jid.local, self.JID.as_string()) self.xmpp_client.stream._send(Presence(to_jid=Jid, stanza_type='unsubscribe'))
def del_roster(self, Jid): """ 删除好友 :param Jid: 删除的jid :return: """ if isinstance(Jid, str) or isinstance(Jid, unicode): Jid = JID(Jid) if not self.is_jid_in_roster(Jid): return UserService().del_roster(self.JID.local, Jid.bare().as_string()) UserService().del_roster(Jid.local, self.JID.as_string()) self.xmpp_client.stream._send( Presence(to_jid=Jid, stanza_type='unsubscribe'))
def deny_friend_request(self, jid): if not isinstance(jid, JID): jid = JID(jid) stanza = Presence(stanza_type=DENY_RESPONSES["subscribe"], to_jid=jid.bare()) self.send(stanza)
def generate_presence(self, jid, stanza_type): if not isinstance(jid, JID): jid = JID(jid) return Presence(to_jid=jid.bare(), stanza_type=stanza_type)