[misterX] update MAM implementation to V0.3
This commit is contained in:
		
							parent
							
								
									09bf2fbd64
								
							
						
					
					
						commit
						44dc946d82
					
				
					 6 changed files with 44 additions and 27 deletions
				
			
		|  | @ -316,7 +316,6 @@ class Config: | |||
|             'ignore_incoming_attention': [opt_bool, False, _('If True, Gajim will ignore incoming attention requestd ("wizz").')], | ||||
|             'remember_opened_chat_controls': [ opt_bool, True, _('If enabled, Gajim will reopen chat windows that were opened last time Gajim was closed.')], | ||||
|             'positive_184_ack': [ opt_bool, False, _('If enabled, Gajim will show an icon to show that sent message has been received by your contact')], | ||||
|             'last_mam_id': [opt_str, '', _('Last MAM id we are syncronized with')], | ||||
|     }, {}) | ||||
| 
 | ||||
|     __options_per_key = { | ||||
|  | @ -418,6 +417,7 @@ class Config: | |||
|                     'oauth2_client_id': [ opt_str, '0000000044077801', _('client_id for Oauth2 authentication.')], | ||||
|                     'oauth2_redirect_url': [ opt_str, 'https%3A%2F%2Fgajim.org%2Fmsnauth%2Findex.cgi', _('redirect_url for Oauth2 authentication.')], | ||||
|                     'opened_chat_controls': [opt_str, '', _('Space separated list of JIDs for which we want to re-open a chat window on next startup.')], | ||||
|                     'last_mam_id': [opt_str, '', _('Last MAM id we are syncronized with')], | ||||
|             }, {}), | ||||
|             'statusmsg': ({ | ||||
|                     'message': [ opt_str, '' ], | ||||
|  |  | |||
|  | @ -27,7 +27,7 @@ docdir = '../' | |||
| basedir   = '../' | ||||
| localedir = '../po' | ||||
| 
 | ||||
| version = '0.16' | ||||
| version = '0.16.0.1' | ||||
| import subprocess | ||||
| try: | ||||
|     node = subprocess.Popen('hg tip --template "{node|short}"', shell=True, | ||||
|  |  | |||
|  | @ -41,16 +41,16 @@ class ConnectionArchive313(ConnectionArchive): | |||
|         ConnectionArchive.__init__(self) | ||||
|         self.archiving_313_supported = False | ||||
|         self.mam_awaiting_disco_result = {} | ||||
|         gajim.ged.register_event_handler('raw-iq-received', ged.CORE, | ||||
|             self._nec_raw_iq_313_received) | ||||
|         gajim.ged.register_event_handler('raw-message-received', ged.CORE, | ||||
|             self._nec_raw_message_313_received) | ||||
|         gajim.ged.register_event_handler('agent-info-error-received', ged.CORE, | ||||
|             self._nec_agent_info_error) | ||||
|         gajim.ged.register_event_handler('agent-info-received', ged.CORE, | ||||
|             self._nec_agent_info) | ||||
| 
 | ||||
|     def cleanup(self): | ||||
|         gajim.ged.remove_event_handler('raw-iq-received', ged.CORE, | ||||
|             self._nec_raw_iq_313_received) | ||||
|         gajim.ged.remove_event_handler('raw-message-received', ged.CORE, | ||||
|             self._nec_raw_message_313_received) | ||||
| 
 | ||||
|     def _nec_agent_info_error(self, obj): | ||||
|         if obj.jid in self.mam_awaiting_disco_result: | ||||
|  | @ -77,42 +77,49 @@ class ConnectionArchive313(ConnectionArchive): | |||
|                     msg=msg_txt) | ||||
|             del self.mam_awaiting_disco_result[obj.jid] | ||||
| 
 | ||||
|     def _nec_raw_iq_313_received(self, obj): | ||||
|     def _nec_raw_message_313_received(self, obj): | ||||
|         if obj.conn.name != self.name: | ||||
|             return | ||||
| 
 | ||||
|         id_ = obj.stanza.getID() | ||||
|         if id_ not in self.awaiting_answers: | ||||
|         fin_ = obj.stanza.getTag('fin', namespace=nbxmpp.NS_MAM)  | ||||
|         if fin_: | ||||
|             queryid_ = fin_.getAttr('queryid') | ||||
|             if queryid_ not in self.awaiting_answers: | ||||
|                 return | ||||
|         else: | ||||
|             return | ||||
| 
 | ||||
|         if self.awaiting_answers[id_][0] == MAM_RESULTS_ARRIVED: | ||||
|             query = obj.stanza.getTag('query', namespace=nbxmpp.NS_MAM) | ||||
|             if query: | ||||
|                 set_ = query.getTag('set', namespace=nbxmpp.NS_RSM) | ||||
|                 if set_: | ||||
|                     last = set_.getTagData('last') | ||||
|                     if last: | ||||
|                         gajim.config.set('last_mam_id', last) | ||||
|                         self.request_archive(after=last) | ||||
|             del self.awaiting_answers[id_] | ||||
|         if self.awaiting_answers[queryid_][0] == MAM_RESULTS_ARRIVED: | ||||
|             set_ = fin_.getTag('set', namespace=nbxmpp.NS_RSM) | ||||
|             if set_: | ||||
|                 last = set_.getTagData('last') | ||||
|                 if last: | ||||
|                     gajim.config.set_per('accounts', self.name, 'last_mam_id', last) | ||||
|                     self.request_archive(after=last) | ||||
| 
 | ||||
|             del self.awaiting_answers[queryid_] | ||||
| 
 | ||||
|     def request_archive(self, start=None, end=None, with_=None, after=None, | ||||
|     max=30): | ||||
|         iq_ = nbxmpp.Iq('get') | ||||
|         query = iq_.setTag('query', namespace=nbxmpp.NS_MAM) | ||||
|         iq_ = nbxmpp.Iq('set') | ||||
|         query = iq_.addChild('query', namespace=nbxmpp.NS_MAM) | ||||
|         x = query.addChild('x', namespace=nbxmpp.NS_DATA) | ||||
|         x.addChild(node=nbxmpp.DataField(typ='hidden', name='FORM_TYPE', value=nbxmpp.NS_MAM)) | ||||
|         if start: | ||||
|             query.addChild('start', payload=start) | ||||
|             x.addChild(node=nbxmpp.DataField(typ='text-single', name='start', value=start)) | ||||
|         if end: | ||||
|             query.addChild('end', payload=end) | ||||
|             x.addChild(node=nbxmpp.DataField(typ='text-single', name='end', value=end)) | ||||
|         if with_: | ||||
|             query.addChild('with', payload=with_) | ||||
|             x.addChild(node=nbxmpp.DataField(typ='jid-single', name='with', value=with_)) | ||||
|         set_ = query.setTag('set', namespace=nbxmpp.NS_RSM) | ||||
|         set_.setTagData('max', max) | ||||
|         if after: | ||||
|             set_.setTagData('after', after) | ||||
|         queryid_ = self.connection.getAnID() | ||||
|         query.setAttr('queryid', queryid_) | ||||
|         id_ = self.connection.getAnID() | ||||
|         iq_.setID(id_) | ||||
|         self.awaiting_answers[id_] = (MAM_RESULTS_ARRIVED, ) | ||||
|         self.awaiting_answers[queryid_] = (MAM_RESULTS_ARRIVED, ) | ||||
|         self.connection.send(iq_) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -215,6 +215,8 @@ class OptionsParser: | |||
|             self.update_config_to_01401() | ||||
|         if old < [0, 14, 90, 0] and new >= [0, 14, 90, 0]: | ||||
|             self.update_config_to_014900() | ||||
|         if old < [0, 16, 0, 1] and new >= [0, 16, 0, 1]: | ||||
|             self.update_config_to_01601() | ||||
| 
 | ||||
|         gajim.logger.init_vars() | ||||
|         gajim.logger.attach_cache_database() | ||||
|  | @ -902,3 +904,11 @@ class OptionsParser: | |||
|             gajim.config.set('use_stun_server', False) | ||||
|         if os.name == 'nt': | ||||
|             gajim.config.set('autodetect_browser_mailer', True) | ||||
| 
 | ||||
|     def update_config_to_01601(self): | ||||
|         if 'last_mam_id' in self.old_values: | ||||
|             last_mam_id = self.old_values['last_mam_id'] | ||||
|             for account in gajim.config.get_per('accounts'): | ||||
|                 gajim.config.set_per('accounts', account, 'last_mam_id', | ||||
|                     last_mam_id) | ||||
|         gajim.config.set('version', '0.16.0.1') | ||||
|  |  | |||
|  | @ -69,7 +69,7 @@ if os.name == 'nt': | |||
|         pass | ||||
| 
 | ||||
| HAS_NBXMPP=True | ||||
| MIN_NBXMPP_VER = "0.5.1" | ||||
| MIN_NBXMPP_VER = "0.5.2" | ||||
| try: | ||||
|     import nbxmpp | ||||
| except ImportError: | ||||
|  |  | |||
|  | @ -1141,7 +1141,7 @@ class Interface: | |||
|             gajim.config.set_per('accounts', account, 'last_archiving_time', | ||||
|                 time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())) | ||||
|         if obj.conn.archiving_313_supported: | ||||
|             mam_id = gajim.config.get('last_mam_id') | ||||
|             mam_id = gajim.config.get_per('accounts', account, 'last_mam_id') | ||||
|             if mam_id: | ||||
|                 obj.conn.request_archive(after=mam_id) | ||||
|             else: | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue