forked from sch/Slixfeed
Add __init__.py and split muc.py into bookmark.py
This commit is contained in:
parent
61bd792572
commit
08001eebf8
3 changed files with 63 additions and 49 deletions
0
slixfeed/__init__.py
Normal file
0
slixfeed/__init__.py
Normal file
60
slixfeed/xmpp/bookmark.py
Normal file
60
slixfeed/xmpp/bookmark.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
|
1) Function to list bookmarks
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from slixmpp.plugins.xep_0048.stanza import Bookmarks
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
bookmarks.add_conference(
|
||||||
|
muc,
|
||||||
|
self.nick,
|
||||||
|
autojoin=True
|
||||||
|
)
|
||||||
|
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())
|
||||||
|
|
||||||
|
# bm = BookmarkStorage()
|
||||||
|
# bm.conferences.append(Conference(muc_jid, autojoin=True, nick=self.nick))
|
||||||
|
# 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:
|
||||||
|
bookmarks.add_conference(
|
||||||
|
muc,
|
||||||
|
self.nick,
|
||||||
|
autojoin=True
|
||||||
|
)
|
||||||
|
await self.plugin['xep_0048'].set_bookmarks(bookmarks)
|
|
@ -13,7 +13,7 @@ TODO
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from slixmpp.plugins.xep_0048.stanza import Bookmarks
|
import slixfeed.xmpp.bookmark as bookmark
|
||||||
|
|
||||||
async def join_groupchat(self, inviter, muc_jid):
|
async def join_groupchat(self, inviter, muc_jid):
|
||||||
# token = await initdb(
|
# token = await initdb(
|
||||||
|
@ -42,7 +42,7 @@ async def join_groupchat(self, inviter, muc_jid):
|
||||||
# If a room password is needed, use:
|
# If a room password is needed, use:
|
||||||
# password=the_room_password,
|
# password=the_room_password,
|
||||||
)
|
)
|
||||||
await self.add_groupchat_to_bookmarks(muc_jid)
|
await bookmark.add(self, muc_jid)
|
||||||
messages = [
|
messages = [
|
||||||
"Greetings!",
|
"Greetings!",
|
||||||
"I'm {}, the news anchor.".format(self.nick),
|
"I'm {}, the news anchor.".format(self.nick),
|
||||||
|
@ -59,33 +59,6 @@ async def join_groupchat(self, inviter, muc_jid):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def add_groupchat_to_bookmarks(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:
|
|
||||||
bookmarks.add_conference(
|
|
||||||
muc,
|
|
||||||
self.nick,
|
|
||||||
autojoin=True
|
|
||||||
)
|
|
||||||
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())
|
|
||||||
|
|
||||||
# bm = BookmarkStorage()
|
|
||||||
# bm.conferences.append(Conference(muc_jid, autojoin=True, nick=self.nick))
|
|
||||||
# await self['xep_0402'].publish(bm)
|
|
||||||
|
|
||||||
|
|
||||||
async def close_groupchat(self, muc_jid):
|
async def close_groupchat(self, muc_jid):
|
||||||
messages = [
|
messages = [
|
||||||
"Whenever you need an RSS service again, "
|
"Whenever you need an RSS service again, "
|
||||||
|
@ -99,7 +72,7 @@ async def close_groupchat(self, muc_jid):
|
||||||
mbody=message,
|
mbody=message,
|
||||||
mtype="groupchat"
|
mtype="groupchat"
|
||||||
)
|
)
|
||||||
await self.remove_groupchat_from_bookmarks(muc_jid)
|
await bookmark.remove(self, muc_jid)
|
||||||
self.plugin['xep_0045'].leave_muc(
|
self.plugin['xep_0045'].leave_muc(
|
||||||
muc_jid,
|
muc_jid,
|
||||||
self.nick,
|
self.nick,
|
||||||
|
@ -107,22 +80,3 @@ async def close_groupchat(self, muc_jid):
|
||||||
self.boundjid.bare
|
self.boundjid.bare
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def remove_groupchat_from_bookmarks(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:
|
|
||||||
bookmarks.add_conference(
|
|
||||||
muc,
|
|
||||||
self.nick,
|
|
||||||
autojoin=True
|
|
||||||
)
|
|
||||||
await self.plugin['xep_0048'].set_bookmarks(bookmarks)
|
|
||||||
|
|
Loading…
Reference in a new issue