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

Groupchat: Display recent history from the database

parent 8801e04a
...@@ -526,9 +526,9 @@ class Logger: ...@@ -526,9 +526,9 @@ class Logger:
return [user['jid'] for user in family] return [user['jid'] for user in family]
return [jid] return [jid]
def get_account_id(self, account): def get_account_id(self, account, type_=JIDConstant.NORMAL_TYPE):
jid = app.get_jid_from_account(account) jid = app.get_jid_from_account(account)
return self.get_jid_id(jid, type_=JIDConstant.NORMAL_TYPE) return self.get_jid_id(jid, type_=type_)
@timeit @timeit
def get_jid_id(self, jid, kind=None, type_=None): def get_jid_id(self, jid, kind=None, type_=None):
...@@ -755,6 +755,26 @@ class Logger: ...@@ -755,6 +755,26 @@ class Logger:
all_messages.append((result, shown)) all_messages.append((result, shown))
return all_messages return all_messages
def load_groupchat_messages(self, account, jid):
account_id = self.get_account_id(account, type_=JIDConstant.ROOM_TYPE)
sql = '''
SELECT time, contact_name, message, additional_data, message_id
FROM logs NATURAL JOIN jids WHERE jid = ?
AND account_id = ? AND kind = ?
ORDER BY time DESC, log_line_id DESC LIMIT ?'''
try:
messages = self._con.execute(
sql, (jid, account_id, KindConstant.GC_MSG, 50)).fetchall()
except sqlite.DatabaseError:
self.dispatch('DB_ERROR',
exceptions.DatabaseMalformed(self._log_db_path))
return []
messages.reverse()
return messages
@timeit @timeit
def get_last_conversation_lines(self, account, jid, pending): def get_last_conversation_lines(self, account, jid, pending):
""" """
......
...@@ -242,6 +242,7 @@ class GroupchatControl(ChatControlBase): ...@@ -242,6 +242,7 @@ class GroupchatControl(ChatControlBase):
# PluginSystem: adding GUI extension point for this GroupchatControl # PluginSystem: adding GUI extension point for this GroupchatControl
# instance object # instance object
app.plugin_manager.gui_extension_point('groupchat_control', self) app.plugin_manager.gui_extension_point('groupchat_control', self)
self._restore_conversation()
@property @property
def nick(self): def nick(self):
...@@ -443,6 +444,25 @@ class GroupchatControl(ChatControlBase): ...@@ -443,6 +444,25 @@ class GroupchatControl(ChatControlBase):
self._get_action('kick-').set_enabled(self.is_connected) self._get_action('kick-').set_enabled(self.is_connected)
def _restore_conversation(self):
rows = app.logger.load_groupchat_messages(
self.account, self.contact.jid)
for row in rows:
other_tags_for_name = ['muc_nickname_color_%s' % row.contact_name]
ChatControlBase.add_message(self,
row.message,
'incoming',
row.contact_name,
float(row.time),
other_tags_for_name=other_tags_for_name,
message_id=row.message_id,
restored=True,
additional_data=row.additional_data)
if rows:
self.conv_textview.print_empty_line()
def _is_subject_change_allowed(self): def _is_subject_change_allowed(self):
contact = app.contacts.get_gc_contact( contact = app.contacts.get_gc_contact(
self.account, self.room_jid, self.nick) self.account, self.room_jid, self.nick)
......
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