[Link Mauve & I] store bookmarks in pubsub if server supports that.
This commit is contained in:
parent
66254bc47f
commit
4a0e5bc2b3
|
@ -1589,38 +1589,47 @@ class Connection(ConnectionHandlers):
|
|||
self.connection.send(iq)
|
||||
|
||||
def get_bookmarks(self):
|
||||
'''Get Bookmarks from storage as described in XEP 0048'''
|
||||
'''Get Bookmarks from storage or PubSub if supported as described in
|
||||
XEP 0048'''
|
||||
self.bookmarks = [] #avoid multiple bookmarks when re-connecting
|
||||
if not self.connection:
|
||||
return
|
||||
if self.pubsub_supported:
|
||||
self.send_pb_retrieve('', 'storage:bookmarks', self._PrivatePubsubCB)
|
||||
else:
|
||||
iq = common.xmpp.Iq(typ='get')
|
||||
iq2 = iq.addChild(name='query', namespace=common.xmpp.NS_PRIVATE)
|
||||
iq2.addChild(name='storage', namespace='storage:bookmarks')
|
||||
self.connection.send(iq)
|
||||
|
||||
def store_bookmarks(self):
|
||||
''' Send bookmarks to the storage namespace '''
|
||||
''' Send bookmarks to the storage namespace or PubSub if supported'''
|
||||
if not self.connection:
|
||||
return
|
||||
iq = common.xmpp.Iq(typ='set')
|
||||
iq2 = iq.addChild(name='query', namespace=common.xmpp.NS_PRIVATE)
|
||||
iq3 = iq2.addChild(name='storage', namespace='storage:bookmarks')
|
||||
iq = common.xmpp.Node(tag='storage', attrs={'xmlns': 'storage:bookmarks'})
|
||||
for bm in self.bookmarks:
|
||||
iq4 = iq3.addChild(name = "conference")
|
||||
iq4.setAttr('jid', bm['jid'])
|
||||
iq4.setAttr('autojoin', bm['autojoin'])
|
||||
iq4.setAttr('minimize', bm['minimize'])
|
||||
iq4.setAttr('name', bm['name'])
|
||||
iq2 = iq.addChild(name = "conference")
|
||||
iq2.setAttr('jid', bm['jid'])
|
||||
iq2.setAttr('autojoin', bm['autojoin'])
|
||||
iq2.setAttr('minimize', bm['minimize'])
|
||||
iq2.setAttr('name', bm['name'])
|
||||
# Only add optional elements if not empty
|
||||
# Note: need to handle both None and '' as empty
|
||||
# thus shouldn't use "is not None"
|
||||
if bm.get('nick', None):
|
||||
iq4.setTagData('nick', bm['nick'])
|
||||
iq2.setTagData('nick', bm['nick'])
|
||||
if bm.get('password', None):
|
||||
iq4.setTagData('password', bm['password'])
|
||||
iq2.setTagData('password', bm['password'])
|
||||
if bm.get('print_status', None):
|
||||
iq4.setTagData('print_status', bm['print_status'])
|
||||
self.connection.send(iq)
|
||||
iq2.setTagData('print_status', bm['print_status'])
|
||||
|
||||
if self.pubsub_supported:
|
||||
self.send_pb_publish('', 'storage:bookmarks', iq, 'current')
|
||||
else:
|
||||
iqA = common.xmpp.Iq(typ='set')
|
||||
iqB = iqA.addChild(name='query', namespace=common.xmpp.NS_PRIVATE)
|
||||
iqB.addChild(node=iq)
|
||||
self.connection.send(iqA)
|
||||
|
||||
def get_annotations(self):
|
||||
'''Get Annonations from storage as described in XEP 0048, and XEP 0145'''
|
||||
|
|
|
@ -1527,6 +1527,44 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
|||
if storage:
|
||||
ns = storage.getNamespace()
|
||||
if ns == 'storage:bookmarks':
|
||||
self._parse_bookmarks(storage)
|
||||
elif ns == 'gajim:prefs':
|
||||
# Preferences data
|
||||
# http://www.xmpp.org/extensions/xep-0049.html
|
||||
#TODO: implement this
|
||||
pass
|
||||
elif ns == 'storage:rosternotes':
|
||||
# Annotations
|
||||
# http://www.xmpp.org/extensions/xep-0145.html
|
||||
notes = storage.getTags('note')
|
||||
for note in notes:
|
||||
try:
|
||||
jid = helpers.parse_jid(note.getAttr('jid'))
|
||||
except common.helpers.InvalidFormat:
|
||||
log.warn('Invalid JID: %s, ignoring it' % note.getAttr('jid'))
|
||||
continue
|
||||
annotation = note.getData()
|
||||
self.annotations[jid] = annotation
|
||||
|
||||
def _PrivatePubsubCB(self, conn, request):
|
||||
'''Private data from PubSub'''
|
||||
gajim.log.debug('_PrivatePubsubCB')
|
||||
pubsub = request.getTag('pubsub')
|
||||
if not pubsub:
|
||||
return
|
||||
items = pubsub.getTag('items')
|
||||
if not items:
|
||||
return
|
||||
item = items.getTag('item')
|
||||
if not item:
|
||||
return
|
||||
storage = item.getTag('storage')
|
||||
if storage:
|
||||
ns = storage.getNamespace()
|
||||
if ns == 'storage:bookmarks':
|
||||
self._parse_bookmarks(storage)
|
||||
|
||||
def _parse_bookmarks(self, storage):
|
||||
# Bookmarked URLs and Conferences
|
||||
# http://www.xmpp.org/extensions/xep-0048.html
|
||||
confs = storage.getTags('conference')
|
||||
|
@ -1555,24 +1593,6 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
|||
self.bookmarks.append(bm)
|
||||
self.dispatch('BOOKMARKS', self.bookmarks)
|
||||
|
||||
elif ns == 'gajim:prefs':
|
||||
# Preferences data
|
||||
# http://www.xmpp.org/extensions/xep-0049.html
|
||||
#TODO: implement this
|
||||
pass
|
||||
elif ns == 'storage:rosternotes':
|
||||
# Annotations
|
||||
# http://www.xmpp.org/extensions/xep-0145.html
|
||||
notes = storage.getTags('note')
|
||||
for note in notes:
|
||||
try:
|
||||
jid = helpers.parse_jid(note.getAttr('jid'))
|
||||
except common.helpers.InvalidFormat:
|
||||
log.warn('Invalid JID: %s, ignoring it' % note.getAttr('jid'))
|
||||
continue
|
||||
annotation = note.getData()
|
||||
self.annotations[jid] = annotation
|
||||
|
||||
def _rosterSetCB(self, con, iq_obj):
|
||||
log.debug('rosterSetCB')
|
||||
version = iq_obj.getTagAttr('query', 'ver')
|
||||
|
|
|
@ -75,6 +75,17 @@ class ConnectionPubSub:
|
|||
|
||||
self.connection.send(query)
|
||||
|
||||
def send_pb_retrieve(self, jid, node, cb, *args, **kwargs):
|
||||
'''Get items from a node'''
|
||||
if not self.connection or self.connected < 2:
|
||||
return
|
||||
query = xmpp.Iq('get', to=jid)
|
||||
r = query.addChild('pubsub', namespace=xmpp.NS_PUBSUB)
|
||||
r = r.addChild('items', {'node': node})
|
||||
id_ = self.connection.send(query)
|
||||
|
||||
self.__callbacks[id_]=(cb, args, kwargs)
|
||||
|
||||
def send_pb_retract(self, jid, node, id_):
|
||||
'''Delete item from a node'''
|
||||
if not self.connection or self.connected < 2:
|
||||
|
|
Loading…
Reference in New Issue