From 982db9636cd50b17b8de179b9623fe4fa70b14a0 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Thu, 27 Aug 2009 18:08:14 +0200
Subject: [PATCH] add 2 advanced option to configure how many log lines we want
 when entering a room. Fixes #5237

---
 src/common/config.py     |  2 ++
 src/common/connection.py | 10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/src/common/config.py b/src/common/config.py
index ff780715a3..bfb6405d6e 100644
--- a/src/common/config.py
+++ b/src/common/config.py
@@ -160,6 +160,8 @@ class Config:
 		'change_roster_title': [ opt_bool, True, _('Add * and [n] in roster title?')],
 		'restore_lines': [opt_int, 4, _('How many lines to remember from previous conversation when a chat tab/window is reopened.')],
 		'restore_timeout': [opt_int, 60, _('How many minutes should last lines from previous conversation last.')],
+		'muc_restore_lines': [opt_int, 20, _('How many lines to request to server when entering a groupchat.')],
+		'muc_restore_timeout': [opt_int, 60, _('How many minutes back to request logs when a entering a groupchat.')],
 		'send_on_ctrl_enter': [opt_bool, False, _('Send message on Ctrl+Enter and with Enter make new line (Mirabilis ICQ Client default behaviour).')],
 		'show_roster_on_startup': [opt_bool, True],
 		'key_up_lines': [opt_int, 25, _('How many lines to store for Ctrl+KeyUP.')],
diff --git a/src/common/connection.py b/src/common/connection.py
index 865b63cfbe..053fb44e9e 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -1746,6 +1746,16 @@ class Connection(ConnectionHandlers):
 		self.add_lang(p)
 		if not change_nick:
 			t = p.setTag(common.xmpp.NS_MUC + ' x')
+		last_date = gajim.logger.get_last_date_that_has_logs(room_jid, self.name,
+			is_room=True)
+		if last_date is None:
+			last_date = time.time() - gajim.config.get('muc_restore_timeout') * 60
+		else:
+			last_time = min(last_date, time.time() - gajim.config.get(
+				'muc_restore_timeout') * 60)
+		last_date = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(last_date))
+		t.setTag('history', {'maxstanzas': gajim.config.get('muc_restore_lines'),
+			'since': last_date})
 		if password:
 			t.setTagData('password', password)
 		self.connection.send(p)
-- 
GitLab