diff --git a/gajim/application.py b/gajim/application.py index 4d8328f265c111d98297752418708914df770119..23f1ba0f1d87fa12b583790b658d863c83970625 100644 --- a/gajim/application.py +++ b/gajim/application.py @@ -593,7 +593,7 @@ def _on_feature_discovered(self, event): if event.feature == nbxmpp.NS_VCARD: action = '%s-profile' % event.account self.lookup_action(action).set_enabled(True) - elif event.feature in (nbxmpp.NS_MAM_1, nbxmpp.NS_MAM_2): + elif event.feature == nbxmpp.NS_MAM_2: action = '%s-archive' % event.account self.lookup_action(action).set_enabled(True) elif event.feature == nbxmpp.NS_PRIVACY: diff --git a/gajim/common/logger.py b/gajim/common/logger.py index 8f5e5fcd8e29f4df24cdd958ebbc2bdf2409ff72..4e348594be21b7ab3be47774c40bb16729d39762 100644 --- a/gajim/common/logger.py +++ b/gajim/common/logger.py @@ -1333,42 +1333,6 @@ def deduplicate_muc_message(self, account, jid, resource, return True return False - @timeit - def search_for_duplicate(self, account, jid, timestamp, msg): - """ - Check if a message is already in the `logs` table - - :param account: The account - - :param jid: The jid as string - - :param timestamp: The timestamp in UTC epoch - - :param msg: The message text - """ - - # Add 10 seconds around the timestamp - start_time = timestamp - 30 - end_time = timestamp + 30 - - account_id = self.get_account_id(account) - log.debug('start: %s, end: %s, jid: %s, message: %s', - start_time, end_time, jid, msg) - - sql = ''' - SELECT * FROM logs - NATURAL JOIN jids WHERE jid = ? AND message = ? AND account_id = ? - AND time BETWEEN ? AND ? - ''' - - result = self._con.execute( - sql, (jid, msg, account_id, start_time, end_time)).fetchone() - - if result is not None: - log.debug('Message already in DB') - return True - return False - @timeit def find_stanza_id(self, account, archive_jid, stanza_id, origin_id=None, groupchat=False): diff --git a/gajim/common/modules/mam.py b/gajim/common/modules/mam.py index 8cfc75e4b27d8128cc8577d1af15c00407d20560..bc629ba54153a9b950b0d72223d31cd15c4c7e19 100644 --- a/gajim/common/modules/mam.py +++ b/gajim/common/modules/mam.py @@ -59,28 +59,22 @@ def __init__(self, con): ] self.available = False - self.archiving_namespace = None self._mam_query_ids = {} # Holds archive jids where catch up was successful self._catch_up_finished = [] def pass_disco(self, info): - if nbxmpp.NS_MAM_2 in info.features: - self.archiving_namespace = nbxmpp.NS_MAM_2 - elif nbxmpp.NS_MAM_1 in info.features: - self.archiving_namespace = nbxmpp.NS_MAM_1 - else: + if nbxmpp.NS_MAM_2 not in info.features: return self.available = True - self._log.info('Discovered MAM %s: %s', - self.archiving_namespace, info.jid) + self._log.info('Discovered MAM: %s', info.jid) app.nec.push_incoming_event( NetworkEvent('feature-discovered', account=self._account, - feature=self.archiving_namespace)) + feature=nbxmpp.NS_MAM_2)) def reset_state(self): self._mam_query_ids.clear() @@ -125,27 +119,26 @@ def _set_message_archive_info(self, _con, _stanza, properties): if properties.type.is_groupchat: archive_jid = properties.jid.getBare() + timestamp = properties.timestamp + disco_info = app.logger.get_last_disco_info(archive_jid) if disco_info is None: # This is the case on MUC creation # After MUC configuration we receive a configuration change # message before we had the chance to disco the new MUC return - namespace = disco_info.mam_namespace - timestamp = properties.timestamp - if namespace is None: - # MUC History - app.logger.set_archive_infos( - archive_jid, - last_muc_timestamp=timestamp) + + if disco_info.mam_namespace != nbxmpp.NS_MAM_2: return else: + if not self.available: + return + archive_jid = self._con.get_own_jid().getBare() - namespace = self.archiving_namespace timestamp = None - if properties.stanza_id is None or namespace != nbxmpp.NS_MAM_2: + if properties.stanza_id is None: return if not archive_jid == properties.stanza_id.by: @@ -192,16 +185,15 @@ def _mam_message_received(self, _con, stanza, properties): stanza_id, message_id = self._get_unique_id(properties) - if properties.mam.is_ver_2: - # Search only with stanza-id for duplicates on mam:2 - if app.logger.find_stanza_id(self._account, - str(properties.mam.archive), - stanza_id, - message_id, - groupchat=is_groupchat): - self._log.info('Found duplicate with stanza-id: %s, ' - 'message-id: %s', stanza_id, message_id) - raise nbxmpp.NodeProcessed + # Search for duplicates + if app.logger.find_stanza_id(self._account, + str(properties.mam.archive), + stanza_id, + message_id, + groupchat=is_groupchat): + self._log.info('Found duplicate with stanza-id: %s, ' + 'message-id: %s', stanza_id, message_id) + raise nbxmpp.NodeProcessed additional_data = AdditionalDataDict() if properties.has_user_delay: @@ -236,12 +228,6 @@ def _mam_message_received(self, _con, stanza, properties): return stanza_id = message_id - if properties.mam.namespace == nbxmpp.NS_MAM_1: - if app.logger.search_for_duplicate( - self._account, with_, properties.mam.timestamp, msgtxt): - self._log.info('Found duplicate with fallback for mam:1') - return - app.logger.insert_into_logs(self._account, with_, properties.mam.timestamp, diff --git a/gajim/common/modules/message.py b/gajim/common/modules/message.py index 0ce18479341c5d192600dc844193d61f6f1bdc66..01dd1cfdb194cbee303d52031c12d786c7060fa9 100644 --- a/gajim/common/modules/message.py +++ b/gajim/common/modules/message.py @@ -266,15 +266,16 @@ def _get_unique_id(self, properties): if properties.type.is_groupchat: disco_info = app.logger.get_last_disco_info( properties.jid.getBare()) - namespace = disco_info.mam_namespace + + if disco_info.mam_namespace != nbxmpp.NS_MAM_2: + return None, None + archive = properties.jid else: - namespace = self._con.get_module('MAM').archiving_namespace - archive = self._con.get_own_jid() + if not self._con.get_module('MAM').available: + return None, None - if namespace != nbxmpp.NS_MAM_2: - # Only mam:2 ensures valid stanza-id - return None, None + archive = self._con.get_own_jid() if archive.bareMatch(properties.stanza_id.by): return properties.stanza_id.id, None diff --git a/gajim/gtk/groupchat_info.py b/gajim/gtk/groupchat_info.py index 1644b0750a23bf4319c69a5daac6efa9110773b2..560e4eff5f3abfff633f8f543bfebc6ec1d691d8 100644 --- a/gajim/gtk/groupchat_info.py +++ b/gajim/gtk/groupchat_info.py @@ -18,7 +18,6 @@ from gi.repository import GLib from gi.repository import Gtk -from nbxmpp.protocol import NS_MAM_1 from nbxmpp.protocol import NS_MAM_2 from gajim.common import app @@ -206,8 +205,7 @@ def _add_features(self, features): grid.remove_row(row) features = list(features) - has_mam = NS_MAM_2 in features or NS_MAM_1 in features - if has_mam: + if NS_MAM_2 in features: features.append('mam') row = 10 diff --git a/gajim/gtk/server_info.py b/gajim/gtk/server_info.py index 4898524efd03d5670acfbec8ca31ad50cc3de7af..cf823fd8c8c46978e4ef344f82cd19b32ce74bb8 100644 --- a/gajim/gtk/server_info.py +++ b/gajim/gtk/server_info.py @@ -288,8 +288,7 @@ def get_features(self): con.get_module('Carbons').supported, nbxmpp.NS_CARBONS), Feature('XEP-0313: Message Archive Management', - con.get_module('MAM').available, - con.get_module('MAM').archiving_namespace), + con.get_module('MAM').available), Feature('XEP-0363: HTTP File Upload', con.get_module('HTTPUpload').available, http_upload_info),