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