Philipp Hörist pushed to branch master at gajim / gajim
Commits:
aa6053a2 by lovetox at 2020-07-07T20:56:52+02:00
Groupchat: Display recent history from the database
- - - - -
2 changed files:
- gajim/common/logger.py
- gajim/groupchat_control.py
Changes:
=====================================
gajim/common/logger.py
=====================================
@@ -526,9 +526,9 @@ class Logger:
return [user['jid'] for user in family]
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)
- return self.get_jid_id(jid, type_=JIDConstant.NORMAL_TYPE)
+ return self.get_jid_id(jid, type_=type_)
@timeit
def get_jid_id(self, jid, kind=None, type_=None):
@@ -755,6 +755,26 @@ class Logger:
all_messages.append((result, shown))
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
def get_last_conversation_lines(self, account, jid, pending):
"""
=====================================
gajim/groupchat_control.py
=====================================
@@ -242,6 +242,7 @@ class GroupchatControl(ChatControlBase):
# PluginSystem: adding GUI extension point for this GroupchatControl
# instance object
app.plugin_manager.gui_extension_point('groupchat_control', self)
+ self._restore_conversation()
@property
def nick(self):
@@ -443,6 +444,25 @@ class GroupchatControl(ChatControlBase):
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):
contact = app.contacts.get_gc_contact(
self.account, self.room_jid, self.nick)
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/aa6053a2a0cd66b0fd9a61452e35cf3b2aa443de
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/aa6053a2a0cd66b0fd9a61452e35cf3b2aa443de
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits