2023-12-28 17:22:32 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
1) Save groupchat name instead of jid in field name.
|
|
|
|
|
|
|
|
"""
|
2023-12-28 17:22:32 +01:00
|
|
|
|
|
|
|
from slixmpp.plugins.xep_0048.stanza import Bookmarks
|
|
|
|
|
|
|
|
|
2024-02-06 04:04:43 +01:00
|
|
|
class XmppBookmark:
|
2024-02-04 18:08:12 +01:00
|
|
|
|
|
|
|
|
2024-02-06 04:04:43 +01:00
|
|
|
async def get(self):
|
|
|
|
result = await self.plugin['xep_0048'].get_bookmarks()
|
|
|
|
bookmarks = result['private']['bookmarks']
|
2024-02-13 20:34:37 +01:00
|
|
|
conferences = bookmarks['conferences'] # We might not want this here
|
|
|
|
# conferences = bookmarks
|
2024-02-06 04:04:43 +01:00
|
|
|
return conferences
|
2023-12-28 17:22:32 +01:00
|
|
|
|
|
|
|
|
2024-02-13 20:34:37 +01:00
|
|
|
async def properties(self, jid):
|
|
|
|
result = await self.plugin['xep_0048'].get_bookmarks()
|
|
|
|
groupchats = result['private']['bookmarks']['conferences']
|
|
|
|
for groupchat in groupchats:
|
|
|
|
if jid == groupchat['jid']:
|
|
|
|
properties = {'password': groupchat['password'],
|
|
|
|
'jid': groupchat['jid'],
|
|
|
|
'name': groupchat['name'],
|
|
|
|
'nick': groupchat['nick'],
|
|
|
|
'autojoin': groupchat['autojoin'],
|
|
|
|
'lang': groupchat['lang']}
|
|
|
|
break
|
|
|
|
return properties
|
|
|
|
|
|
|
|
|
2024-02-06 04:04:43 +01:00
|
|
|
async def add(self, muc_jid):
|
|
|
|
result = await self.plugin['xep_0048'].get_bookmarks()
|
|
|
|
bookmarks = result['private']['bookmarks']
|
|
|
|
conferences = bookmarks['conferences']
|
|
|
|
mucs = []
|
|
|
|
for conference in conferences:
|
|
|
|
jid = conference['jid']
|
|
|
|
mucs.extend([jid])
|
|
|
|
if muc_jid not in mucs:
|
|
|
|
bookmarks = Bookmarks()
|
|
|
|
mucs.extend([muc_jid])
|
|
|
|
for muc in mucs:
|
2024-02-07 01:26:42 +01:00
|
|
|
bookmarks.add_conference(muc,
|
|
|
|
self.alias,
|
|
|
|
autojoin=True)
|
2024-02-06 04:04:43 +01:00
|
|
|
await self.plugin['xep_0048'].set_bookmarks(bookmarks)
|
|
|
|
# bookmarks = Bookmarks()
|
|
|
|
# await self.plugin['xep_0048'].set_bookmarks(bookmarks)
|
|
|
|
# print(await self.plugin['xep_0048'].get_bookmarks())
|
2023-12-28 17:22:32 +01:00
|
|
|
|
2024-02-06 04:04:43 +01:00
|
|
|
# bm = BookmarkStorage()
|
|
|
|
# bm.conferences.append(Conference(muc_jid, autojoin=True, nick=self.alias))
|
|
|
|
# await self['xep_0402'].publish(bm)
|
|
|
|
|
|
|
|
|
|
|
|
async def remove(self, muc_jid):
|
|
|
|
result = await self.plugin['xep_0048'].get_bookmarks()
|
|
|
|
bookmarks = result['private']['bookmarks']
|
|
|
|
conferences = bookmarks['conferences']
|
|
|
|
mucs = []
|
|
|
|
for conference in conferences:
|
|
|
|
jid = conference['jid']
|
|
|
|
mucs.extend([jid])
|
|
|
|
if muc_jid in mucs:
|
|
|
|
bookmarks = Bookmarks()
|
|
|
|
mucs.remove(muc_jid)
|
|
|
|
for muc in mucs:
|
2024-02-07 01:26:42 +01:00
|
|
|
bookmarks.add_conference(muc,
|
|
|
|
self.alias,
|
|
|
|
autojoin=True)
|
2024-02-06 04:04:43 +01:00
|
|
|
await self.plugin['xep_0048'].set_bookmarks(bookmarks)
|