Store optional fields correctly in Bookmarks
This commit is contained in:
parent
e5b69fae5c
commit
4c482cbfe8
|
@ -2474,7 +2474,8 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
"""
|
||||
if not gajim.account_is_connected(self.name):
|
||||
return
|
||||
if self.pubsub_supported and storage_type != 'xml':
|
||||
if self.pubsub_supported and self.pubsub_publish_options_supported \
|
||||
and storage_type != 'xml':
|
||||
self.send_pb_retrieve('', 'storage:bookmarks')
|
||||
# some server (ejabberd) are so slow to answer that we request via XML
|
||||
# if we don't get answer in the next 30 seconds
|
||||
|
@ -2489,15 +2490,17 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
storage_type can be set to 'pubsub' or 'xml' so store in only one method
|
||||
else it will be stored on both
|
||||
"""
|
||||
NS_GAJIM_BM = 'xmpp:gajim.org/bookmarks'
|
||||
if not gajim.account_is_connected(self.name):
|
||||
return
|
||||
iq = nbxmpp.Node(tag='storage', attrs={'xmlns': 'storage:bookmarks'})
|
||||
for bm in self.bookmarks:
|
||||
iq2 = iq.addChild(name = "conference")
|
||||
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'])
|
||||
iq2.setTag('minimize', namespace=NS_GAJIM_BM). \
|
||||
setData(bm['minimize'])
|
||||
# Only add optional elements if not empty
|
||||
# Note: need to handle both None and '' as empty
|
||||
# thus shouldn't use "is not None"
|
||||
|
@ -2506,21 +2509,23 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
if bm.get('password', None):
|
||||
iq2.setTagData('password', bm['password'])
|
||||
if bm.get('print_status', None):
|
||||
iq2.setTagData('print_status', bm['print_status'])
|
||||
iq2.setTag('print_status', namespace=NS_GAJIM_BM). \
|
||||
setData(bm['print_status'])
|
||||
|
||||
if self.pubsub_supported and self.pubsub_publish_options_supported and \
|
||||
storage_type != 'xml':
|
||||
if self.pubsub_supported and self.pubsub_publish_options_supported and\
|
||||
storage_type != 'xml':
|
||||
options = nbxmpp.Node(nbxmpp.NS_DATA + ' x',
|
||||
attrs={'type': 'submit'})
|
||||
f = options.addChild('field', attrs={'var': 'FORM_TYPE',
|
||||
'type': 'hidden'})
|
||||
attrs={'type': 'submit'})
|
||||
f = options.addChild('field',
|
||||
attrs={'var': 'FORM_TYPE', 'type': 'hidden'})
|
||||
f.setTagData('value', nbxmpp.NS_PUBSUB_PUBLISH_OPTIONS)
|
||||
f = options.addChild('field', attrs={'var': 'pubsub#persist_items'})
|
||||
f = options.addChild('field',
|
||||
attrs={'var': 'pubsub#persist_items'})
|
||||
f.setTagData('value', 'true')
|
||||
f = options.addChild('field', attrs={'var': 'pubsub#access_model'})
|
||||
f.setTagData('value', 'whitelist')
|
||||
self.send_pb_publish('', 'storage:bookmarks', iq, 'current',
|
||||
options=options)
|
||||
options=options)
|
||||
if storage_type != 'pubsub':
|
||||
iqA = nbxmpp.Iq(typ='set')
|
||||
iqB = iqA.addChild(name='query', namespace=nbxmpp.NS_PRIVATE)
|
||||
|
|
|
@ -499,33 +499,44 @@ class PrivateStorageReceivedEvent(nec.NetworkIncomingEvent):
|
|||
self.namespace = self.storage_node.getNamespace()
|
||||
return True
|
||||
|
||||
|
||||
class BookmarksHelper:
|
||||
def parse_bookmarks(self):
|
||||
self.bookmarks = []
|
||||
NS_GAJIM_BM = 'xmpp:gajim.org/bookmarks'
|
||||
confs = self.storage_node.getTags('conference')
|
||||
for conf in confs:
|
||||
autojoin_val = conf.getAttr('autojoin')
|
||||
if autojoin_val is None: # not there (it's optional)
|
||||
if not autojoin_val: # not there (it's optional)
|
||||
autojoin_val = False
|
||||
minimize_val = conf.getAttr('minimize')
|
||||
if minimize_val is None: # not there (it's optional)
|
||||
minimize_val = False
|
||||
print_status = conf.getTagData('print_status')
|
||||
minimize_val = conf.getTag('minimize', namespace=NS_GAJIM_BM)
|
||||
if not minimize_val: # not there, try old Gajim behaviour
|
||||
minimize_val = conf.getAttr('minimize')
|
||||
if not minimize_val: # not there (it's optional)
|
||||
minimize_val = False
|
||||
else:
|
||||
minimize_val = minimize_val.getData()
|
||||
|
||||
print_status = conf.getTag('print_status', namespace=NS_GAJIM_BM)
|
||||
if not print_status:
|
||||
print_status = conf.getTagData('show_status')
|
||||
else:
|
||||
print_status = print_status.getData()
|
||||
|
||||
try:
|
||||
jid = helpers.parse_jid(conf.getAttr('jid'))
|
||||
except helpers.InvalidFormat:
|
||||
log.warning('Invalid JID: %s, ignoring it' % conf.getAttr('jid'))
|
||||
log.warning('Invalid JID: %s, ignoring it'
|
||||
% conf.getAttr('jid'))
|
||||
continue
|
||||
bm = {'name': conf.getAttr('name'),
|
||||
'jid': jid,
|
||||
'autojoin': autojoin_val,
|
||||
'minimize': minimize_val,
|
||||
'password': conf.getTagData('password'),
|
||||
'nick': conf.getTagData('nick'),
|
||||
'print_status': print_status}
|
||||
|
||||
bm = {'name': conf.getAttr('name'),
|
||||
'jid': jid,
|
||||
'autojoin': autojoin_val,
|
||||
'minimize': minimize_val,
|
||||
'password': conf.getTagData('password'),
|
||||
'nick': conf.getTagData('nick'),
|
||||
'print_status': print_status}
|
||||
|
||||
bm_jids = [b['jid'] for b in self.bookmarks]
|
||||
if bm['jid'] not in bm_jids:
|
||||
|
|
Loading…
Reference in New Issue