Commit f92842d7 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

MAM: Remove mam:1 support

parent 9bb4c42a
......@@ -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:
......
......@@ -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):
......
......@@ -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,
......
......@@ -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
......
......@@ -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
......
......@@ -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),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment