From 1d5b33166362291ccfe101b6f609e551ac03351b Mon Sep 17 00:00:00 2001
From: mathieui <mathieui@mathieui.net>
Date: Sat, 26 Nov 2011 23:07:31 +0100
Subject: [PATCH] Add get_ methods to retrieve bookmarks
 locally/w/pubsub/privatexml

---
 src/bookmark.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/src/bookmark.py b/src/bookmark.py
index 66a89830..5f1fe508 100644
--- a/src/bookmark.py
+++ b/src/bookmark.py
@@ -73,3 +73,58 @@ class Bookmark(object):
 
         return Bookmark(jid, name, autojoin, nick, password, method)
 
+
+bookmarks = []
+
+def get_pep(xmpp):
+    try:
+        iq = xmpp.plugin['xep_0048'].get_bookmarks()
+    except:
+        return False
+    for conf in iq.xml.iter('{storage:bookmarks}conference'):
+        b = Bookmark.parse_from_element(conf, method='pep')
+        if not get_by_jid(b.jid):
+            bookmarks.append(b)
+    return True
+
+def get_privatexml(xmpp):
+    try:
+        iq = xmpp.plugin['xep_0048'].get_bookmarks_old()
+    except:
+        return False
+    for conf in iq.xml.iter('{storage:bookmarks}conference'):
+        b = Bookmark.parse_from_element(conf, method='privatexml')
+        if not get_by_jid(b.jid):
+            bookmarks.append(b)
+    return True
+
+def get_remote(xmpp):
+    if xmpp.anon:
+        return
+    pep, privatexml = True, True
+    for method in methods[1:]:
+        if method == 'pep':
+            pep = get_pep(xmpp)
+        else:
+            privatexml = get_privatexml(xmpp)
+    if pep and not privatexml:
+        config.set_and_save('use_bookmarks_method', 'pep')
+    elif privatexml and not pep:
+        config.set_and_save('use_bookmarks_method', 'privatexml')
+
+def get_local():
+    rooms = config.get('rooms', '')
+    if not rooms:
+        return
+    rooms = rooms.split(':')
+    for room in rooms:
+        jid = JID(room)
+        if jid.bare == '':
+            continue
+        if jid.resource != '':
+            nick = jid.resource
+        else:
+            nick = None
+        b = Bookmark(jid.bare, autojoin=True, nick=nick, method='local')
+        if not get_by_jid(b.jid):
+            bookmarks.append(b)