Philipp Hörist pushed to branch master at gajim / gajim

Commits:

2 changed files:

Changes:

  • gajim/common/logger.py
    ... ... @@ -526,9 +526,9 @@ class Logger:
    526 526
                 return [user['jid'] for user in family]
    
    527 527
             return [jid]
    
    528 528
     
    
    529
    -    def get_account_id(self, account):
    
    529
    +    def get_account_id(self, account, type_=JIDConstant.NORMAL_TYPE):
    
    530 530
             jid = app.get_jid_from_account(account)
    
    531
    -        return self.get_jid_id(jid, type_=JIDConstant.NORMAL_TYPE)
    
    531
    +        return self.get_jid_id(jid, type_=type_)
    
    532 532
     
    
    533 533
         @timeit
    
    534 534
         def get_jid_id(self, jid, kind=None, type_=None):
    
    ... ... @@ -755,6 +755,26 @@ class Logger:
    755 755
                 all_messages.append((result, shown))
    
    756 756
             return all_messages
    
    757 757
     
    
    758
    +    def load_groupchat_messages(self, account, jid):
    
    759
    +        account_id = self.get_account_id(account, type_=JIDConstant.ROOM_TYPE)
    
    760
    +
    
    761
    +        sql = '''
    
    762
    +            SELECT time, contact_name, message, additional_data, message_id
    
    763
    +            FROM logs NATURAL JOIN jids WHERE jid = ?
    
    764
    +            AND account_id = ? AND kind = ?
    
    765
    +            ORDER BY time DESC, log_line_id DESC LIMIT ?'''
    
    766
    +
    
    767
    +        try:
    
    768
    +            messages = self._con.execute(
    
    769
    +                sql, (jid, account_id, KindConstant.GC_MSG, 50)).fetchall()
    
    770
    +        except sqlite.DatabaseError:
    
    771
    +            self.dispatch('DB_ERROR',
    
    772
    +                          exceptions.DatabaseMalformed(self._log_db_path))
    
    773
    +            return []
    
    774
    +
    
    775
    +        messages.reverse()
    
    776
    +        return messages
    
    777
    +
    
    758 778
         @timeit
    
    759 779
         def get_last_conversation_lines(self, account, jid, pending):
    
    760 780
             """
    

  • gajim/groupchat_control.py
    ... ... @@ -242,6 +242,7 @@ class GroupchatControl(ChatControlBase):
    242 242
             # PluginSystem: adding GUI extension point for this GroupchatControl
    
    243 243
             # instance object
    
    244 244
             app.plugin_manager.gui_extension_point('groupchat_control', self)
    
    245
    +        self._restore_conversation()
    
    245 246
     
    
    246 247
         @property
    
    247 248
         def nick(self):
    
    ... ... @@ -443,6 +444,25 @@ class GroupchatControl(ChatControlBase):
    443 444
     
    
    444 445
             self._get_action('kick-').set_enabled(self.is_connected)
    
    445 446
     
    
    447
    +    def _restore_conversation(self):
    
    448
    +        rows = app.logger.load_groupchat_messages(
    
    449
    +            self.account, self.contact.jid)
    
    450
    +
    
    451
    +        for row in rows:
    
    452
    +            other_tags_for_name = ['muc_nickname_color_%s' % row.contact_name]
    
    453
    +            ChatControlBase.add_message(self,
    
    454
    +                                        row.message,
    
    455
    +                                        'incoming',
    
    456
    +                                        row.contact_name,
    
    457
    +                                        float(row.time),
    
    458
    +                                        other_tags_for_name=other_tags_for_name,
    
    459
    +                                        message_id=row.message_id,
    
    460
    +                                        restored=True,
    
    461
    +                                        additional_data=row.additional_data)
    
    462
    +
    
    463
    +        if rows:
    
    464
    +            self.conv_textview.print_empty_line()
    
    465
    +
    
    446 466
         def _is_subject_change_allowed(self):
    
    447 467
             contact = app.contacts.get_gc_contact(
    
    448 468
                 self.account, self.room_jid, self.nick)