Commit 85d220c8 authored by Philipp Hörist's avatar Philipp Hörist

Add Synchronise History Dialog

- On first contact with the MAM Archive only request 7 days
- To sync the rest of the archive the new Dialog can be used.
parent e548a892
......@@ -12,3 +12,12 @@ popover#EmoticonPopover flowboxchild > label { font-size: 24px; }
popover#EmoticonPopover notebook label { font-size: 24px; }
popover#EmoticonPopover flowbox { padding-left: 5px; padding-right: 6px; }
popover#EmoticonPopover flowboxchild { padding-top: 5px; padding-bottom: 5px; }
/* HistorySyncAssistant */
#HistorySyncAssistant list { border: 1px solid; border-color: @borders; }
#HistorySyncAssistant progressbar text { color: #000; font-size: 18px; padding: 10px;}
#HistorySyncAssistant list > row { padding: 10px 30px 10px 30px; }
#HistorySyncAssistant list > row > label { color: @insensitive_fg_color }
#HistorySyncAssistant list > row.activatable > label { color: @theme_text_color; }
#HistorySyncAssistant list > row.activatable:selected > label { color: @theme_selected_fg_color; }
#FinishedLabel { font-size: 14px; font-weight: bold }
......@@ -31,6 +31,7 @@ import shortcuts_window
import plugins.gui
import history_window
import disco
from history_sync import HistorySyncAssistant
class AppActions():
......@@ -150,6 +151,14 @@ class AppActions():
gajim.interface.instances[account]['archiving_preferences'] = \
dialogs.ArchivingPreferencesWindow(account)
def on_history_sync(self, action, param):
account = param.get_string()
if 'history_sync' in gajim.interface.instances[account]:
gajim.interface.instances[account]['history_sync'].present()
else:
gajim.interface.instances[account]['history_sync'] = \
HistorySyncAssistant(account, gajim.interface.roster.window)
def on_privacy_lists(self, action, param):
account = param.get_string()
if 'privacy_lists' in gajim.interface.instances[account]:
......
......@@ -419,6 +419,7 @@ class Config:
'oauth2_redirect_url': [ opt_str, 'https%3A%2F%2Fgajim.org%2Fmsnauth%2Findex.cgi', _('redirect_url for OAuth 2.0 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')],
'mam_start_date': [opt_int, 0, _('The earliest date we requested MAM history for')],
}, {}),
'statusmsg': ({
'message': [ opt_str, '' ],
......
......@@ -1220,7 +1220,7 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
nbxmpp.NS_MAM_2):
forwarded = result.getTag('forwarded', namespace=nbxmpp.NS_FORWARD)
gajim.nec.push_incoming_event(MamMessageReceivedEvent(None,
conn=self.conn, stanza=forwarded))
conn=self.conn, stanza=forwarded, query_id=result.getAttr('queryid')))
return
# Mediated invitation?
......@@ -1807,8 +1807,8 @@ class ArchivingFinishedReceivedEvent(nec.NetworkIncomingEvent):
if self.type_ != 'result' or not self.fin:
return
self.queryid = self.fin.getAttr('queryid')
if not self.queryid:
self.query_id = self.fin.getAttr('queryid')
if not self.query_id:
return
return True
......@@ -1825,8 +1825,8 @@ class ArchivingFinishedLegacyReceivedEvent(nec.NetworkIncomingEvent):
if not self.fin:
return
self.queryid = self.fin.getAttr('queryid')
if not self.queryid:
self.query_id = self.fin.getAttr('queryid')
if not self.query_id:
return
return True
......
......@@ -26,6 +26,7 @@ from common.connection_handlers_events import ArchivingReceivedEvent
from calendar import timegm
from time import localtime
from datetime import datetime, timedelta
import logging
log = logging.getLogger('gajim.c.message_archiving')
......@@ -33,7 +34,6 @@ log = logging.getLogger('gajim.c.message_archiving')
ARCHIVING_COLLECTIONS_ARRIVED = 'archiving_collections_arrived'
ARCHIVING_COLLECTION_ARRIVED = 'archiving_collection_arrived'
ARCHIVING_MODIFICATIONS_ARRIVED = 'archiving_modifications_arrived'
MAM_RESULTS_ARRIVED = 'mam_results_arrived'
class ConnectionArchive:
def __init__(self):
......@@ -46,6 +46,8 @@ class ConnectionArchive313(ConnectionArchive):
self.archiving_313_supported = False
self.mam_awaiting_disco_result = {}
self.iq_answer = []
self.mam_query_date = None
self.mam_query_id = None
gajim.ged.register_event_handler('archiving-finished-legacy', ged.CORE,
self._nec_result_finished)
gajim.ged.register_event_handler('archiving-finished', ged.CORE,
......@@ -108,19 +110,24 @@ class ConnectionArchive313(ConnectionArchive):
if obj.conn.name != self.name:
return
if obj.queryid not in self.awaiting_answers:
if obj.query_id != self.mam_query_id:
return
if self.awaiting_answers[obj.queryid][0] == MAM_RESULTS_ARRIVED:
set_ = obj.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)
complete = obj.fin.getAttr('complete')
if complete != 'true':
self.request_archive(after=last)
del self.awaiting_answers[obj.queryid]
set_ = obj.fin.getTag('set', namespace=nbxmpp.NS_RSM)
if set_:
last = set_.getTagData('last')
complete = obj.fin.getAttr('complete')
if last:
gajim.config.set_per('accounts', self.name, 'last_mam_id', last)
if complete != 'true':
self.request_archive(self.get_query_id(), after=last)
if complete == 'true':
self.mam_query_id = None
if self.mam_query_date:
gajim.config.set_per(
'accounts', self.name,
'mam_start_date', self.mam_query_date.timestamp())
self.mam_query_date = None
def _nec_mam_decrypted_message_received(self, obj):
if obj.conn.name != self.name:
......@@ -128,28 +135,53 @@ class ConnectionArchive313(ConnectionArchive):
gajim.logger.save_if_not_exists(obj.with_, obj.direction, obj.tim,
msg=obj.msgtxt, nick=obj.nick, additional_data=obj.additional_data)
def request_archive(self, start=None, end=None, with_=None, after=None,
max=30):
iq_ = nbxmpp.Iq('set')
query = iq_.addChild('query', namespace=self.archiving_namespace)
x = query.addChild(node=nbxmpp.DataForm(typ='submit'))
x.addChild(node=nbxmpp.DataField(typ='hidden', name='FORM_TYPE', value=self.archiving_namespace))
def get_query_id(self):
self.mam_query_id = self.connection.getAnID()
return self.mam_query_id
def request_archive_on_signin(self):
mam_id = gajim.config.get_per('accounts', self.name, 'last_mam_id')
query_id = self.get_query_id()
if mam_id:
self.request_archive(query_id, after=mam_id)
else:
# First Start, we request the last week
self.mam_query_date = datetime.utcnow() - timedelta(days=7)
log.info('First start: query archive start: %s', self.mam_query_date)
self.request_archive(query_id, start=self.mam_query_date)
def request_archive(self, query_id, start=None, end=None, with_=None,
after=None, max_=30):
namespace = self.archiving_namespace
iq = nbxmpp.Iq('set')
query = iq.addChild('query', namespace=namespace)
form = query.addChild(node=nbxmpp.DataForm(typ='submit'))
field = nbxmpp.DataField(typ='hidden',
name='FORM_TYPE',
value=namespace)
form.addChild(node=field)
if start:
x.addChild(node=nbxmpp.DataField(typ='text-single', name='start', value=start))
field = nbxmpp.DataField(typ='text-single',
name='start',
value=start.strftime('%Y-%m-%dT%H:%M:%SZ'))
form.addChild(node=field)
if end:
x.addChild(node=nbxmpp.DataField(typ='text-single', name='end', value=end))
field = nbxmpp.DataField(typ='text-single',
name='end',
value=end.strftime('%Y-%m-%dT%H:%M:%SZ'))
form.addChild(node=field)
if with_:
x.addChild(node=nbxmpp.DataField(typ='jid-single', name='with', value=with_))
field = nbxmpp.DataField(typ='jid-single', name='with', value=with_)
form.addChild(node=field)
set_ = query.setTag('set', namespace=nbxmpp.NS_RSM)
set_.setTagData('max', max)
set_.setTagData('max', max_)
if after:
set_.setTagData('after', after)
queryid_ = self.connection.getAnID()
query.setAttr('queryid', queryid_)
query.setAttr('queryid', query_id)
id_ = self.connection.getAnID()
iq_.setID(id_)
self.awaiting_answers[queryid_] = (MAM_RESULTS_ARRIVED, )
self.connection.send(iq_)
iq.setID(id_)
self.connection.send(iq)
def request_archive_preferences(self):
if not gajim.account_is_connected(self.name):
......@@ -367,7 +399,6 @@ class ConnectionArchive136(ConnectionArchive):
return ['may']
def _ArchiveCB(self, con, iq_obj):
log.debug('_ArchiveCB %s' % iq_obj.getType())
gajim.nec.push_incoming_event(ArchivingReceivedEvent(None, conn=self,
stanza=iq_obj))
raise nbxmpp.NodeProcessed
......
......@@ -326,6 +326,7 @@ class GajimApplication(Gtk.Application):
('-profile', action.on_profile, 'feature', 's'),
('-xml-console', action.on_xml_console, 'always', 's'),
('-archive', action.on_archiving_preferences, 'feature', 's'),
('-sync-history', action.on_history_sync, 'online', 's'),
('-privacylists', action.on_privacy_lists, 'feature', 's'),
('-send-server-message',
action.on_send_server_message, 'online', 's'),
......
......@@ -1187,11 +1187,7 @@ class Interface:
time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()))
if obj.conn.archiving_313_supported and gajim.config.get_per('accounts',
account, 'sync_logs_with_server'):
mam_id = gajim.config.get_per('accounts', account, 'last_mam_id')
if mam_id:
obj.conn.request_archive(after=mam_id)
else:
obj.conn.request_archive(start='2013-02-24T03:51:42Z')
obj.conn.request_archive_on_signin()
invisible_show = gajim.SHOW_LIST.index('invisible')
# We cannot join rooms if we are invisible
......
......@@ -671,6 +671,7 @@ def get_account_menu(account):
('-start-single-chat', _('Send Single Message...')),
('Advanced', [
('-archive', _('Archiving Preferences')),
('-sync-history', _('Synchronise History')),
('-privacylists', _('Privacy Lists')),
('-xml-console', _('XML Console'))
]),
......
This diff is collapsed.
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