2024-01-02 12:42:41 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
1) remove_subscription (clean_roster)
|
|
|
|
Remove presence from contacts that don't share presence.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2024-02-07 01:26:42 +01:00
|
|
|
class XmppRoster:
|
2024-01-02 12:42:41 +01:00
|
|
|
|
2024-02-18 00:21:44 +01:00
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
async def add(self, jid):
|
2024-02-07 01:26:42 +01:00
|
|
|
"""
|
2024-02-10 18:53:53 +01:00
|
|
|
Add JID to roster.
|
|
|
|
|
|
|
|
Add JID to roster if it is not already in roster.
|
2024-01-24 19:11:39 +01:00
|
|
|
|
2024-02-07 01:26:42 +01:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
jid : str
|
|
|
|
Jabber ID.
|
2024-01-24 19:11:39 +01:00
|
|
|
|
2024-02-07 01:26:42 +01:00
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
None.
|
|
|
|
"""
|
2024-02-10 18:53:53 +01:00
|
|
|
await self.get_roster()
|
|
|
|
if jid not in self.client_roster.keys():
|
|
|
|
self.update_roster(jid, subscription='both')
|
2024-01-24 19:11:39 +01:00
|
|
|
|
|
|
|
|
2024-02-19 01:26:10 +01:00
|
|
|
async def get_contacts(self):
|
|
|
|
await self.get_roster()
|
|
|
|
contacts = self.client_roster
|
|
|
|
return contacts
|
|
|
|
|
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
def remove(self, jid):
|
2024-02-07 01:26:42 +01:00
|
|
|
"""
|
2024-02-10 18:53:53 +01:00
|
|
|
Remove JID from roster.
|
2024-01-02 12:42:41 +01:00
|
|
|
|
2024-02-07 01:26:42 +01:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
jid : str
|
|
|
|
Jabber ID.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
None.
|
|
|
|
"""
|
2024-02-10 18:53:53 +01:00
|
|
|
self.update_roster(jid, subscription='remove')
|
2024-02-19 01:26:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
def set_contact_name(self, jid, name):
|
|
|
|
self.client_roster[jid]['name'] = name
|
|
|
|
|
|
|
|
|
|
|
|
def get_contact_name(self, jid):
|
|
|
|
name = self.client_roster[jid]['name']
|
|
|
|
return name
|