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

Commits:

4 changed files:

Changes:

  • gajim/common/connection_handlers.py
    ... ... @@ -1095,7 +1095,7 @@ class ConnectionHandlersBase:
    1095 1095
                     DecryptedMessageReceivedEvent(None, conn=self, msg_obj=obj))
    
    1096 1096
             else:
    
    1097 1097
                 gajim.nec.push_incoming_event(
    
    1098
    -                MamDecryptedMessageReceivedEvent(None, conn=self, msg_obj=obj))
    
    1098
    +                MamDecryptedMessageReceivedEvent(None, **vars(obj)))
    
    1099 1099
     
    
    1100 1100
         def _nec_decrypted_message_received(self, obj):
    
    1101 1101
             if obj.conn.name != self.name:
    

  • gajim/common/connection_handlers_events.py
    ... ... @@ -1082,18 +1082,16 @@ class MamMessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
    1082 1082
                 else:
    
    1083 1083
                     self.stanza_id = self.msg_.getID()
    
    1084 1084
     
    
    1085
    -            self.with_ = str(to)
    
    1085
    +            self.with_ = to
    
    1086 1086
                 self.direction = 'to'
    
    1087
    -            self.resource = to.getResource()
    
    1088 1087
             else:
    
    1089 1088
                 if self.result.getNamespace() == nbxmpp.NS_MAM_2:
    
    1090 1089
                     self.stanza_id = self.result.getID()
    
    1091 1090
                 else:
    
    1092 1091
                     self.stanza_id = self.msg_.getID()
    
    1093 1092
     
    
    1094
    -            self.with_ = str(frm)
    
    1093
    +            self.with_ = frm
    
    1095 1094
                 self.direction = 'from'
    
    1096
    -            self.resource = frm.getResource()
    
    1097 1095
     
    
    1098 1096
             if not self.stanza_id:
    
    1099 1097
                 log.debug('Could not retrieve stanza-id')
    
    ... ... @@ -1118,38 +1116,18 @@ class MamDecryptedMessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
    1118 1116
         base_network_events = []
    
    1119 1117
     
    
    1120 1118
         def generate(self):
    
    1121
    -        self.nick = None
    
    1122
    -        msg_ = self.msg_obj.msg_
    
    1123
    -        if not hasattr(self, 'additional_data'):
    
    1124
    -            self.additional_data = self.msg_obj.additional_data
    
    1125
    -        self.with_ = self.msg_obj.with_
    
    1126
    -        self.direction = self.msg_obj.direction
    
    1127
    -        self.timestamp = self.msg_obj.timestamp
    
    1128
    -        res = self.msg_obj.resource
    
    1129
    -        self.msgtxt = self.msg_obj.msgtxt
    
    1130
    -        is_pm = gajim.logger.jid_is_room_jid(self.with_)
    
    1131
    -        if msg_.getAttr('type') == 'groupchat':
    
    1132
    -            if is_pm == False:
    
    1133
    -                log.warn('JID %s is marked as normal contact in database '
    
    1134
    -                         'but we got a groupchat message from it.', self.with_)
    
    1135
    -                return
    
    1136
    -            if is_pm == None:
    
    1137
    -                gajim.logger.get_jid_id(self.with_, 'ROOM')
    
    1138
    -            self.nick = res
    
    1139
    -        else:
    
    1140
    -            if is_pm == None:
    
    1141
    -                # we don't know this JID, we need to disco it.
    
    1142
    -                server = gajim.get_server_from_jid(self.with_)
    
    1143
    -                if server not in self.conn.mam_awaiting_disco_result:
    
    1144
    -                    self.conn.mam_awaiting_disco_result[server] = [
    
    1145
    -                        [self.with_, self.direction, self.timestamp, self.msgtxt,
    
    1146
    -                        res]]
    
    1147
    -                    self.conn.discoverInfo(server)
    
    1148
    -                else:
    
    1149
    -                    self.conn.mam_awaiting_disco_result[server].append(
    
    1150
    -                        [self.with_, self.direction, self.timestamp, self.msgtxt,
    
    1151
    -                        res])
    
    1152
    -                return
    
    1119
    +        is_pm = gajim.logger.jid_is_room_jid(self.with_.getStripped())
    
    1120
    +        if is_pm is None:
    
    1121
    +            # we don't know this JID, we need to disco it.
    
    1122
    +            server = self.with_.getDomain()
    
    1123
    +            if server not in self.conn.mam_awaiting_disco_result:
    
    1124
    +                self.conn.mam_awaiting_disco_result[server] = [
    
    1125
    +                    [self.with_, self.direction, self.timestamp, self.msgtxt]]
    
    1126
    +                self.conn.discoverInfo(server)
    
    1127
    +            else:
    
    1128
    +                self.conn.mam_awaiting_disco_result[server].append(
    
    1129
    +                    [self.with_, self.direction, self.timestamp, self.msgtxt])
    
    1130
    +            return
    
    1153 1131
             return True
    
    1154 1132
     
    
    1155 1133
     class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
    

  • gajim/common/logger.py
    ... ... @@ -1139,53 +1139,36 @@ class Logger:
    1139 1139
                     (account_jid_id,))
    
    1140 1140
             self._timeout_commit()
    
    1141 1141
     
    
    1142
    -    def save_if_not_exists(self, with_, direction, tim, msg='', nick=None, additional_data=None):
    
    1142
    +    def save_if_not_exists(self, with_, direction, tim, msg='', is_pm=False, additional_data=None):
    
    1143 1143
             if additional_data is None:
    
    1144 1144
                 additional_data = {}
    
    1145
    -        if tim:
    
    1146
    -            time_col = float(tim)
    
    1147
    -        else:
    
    1148
    -            time_col = float(time.time())
    
    1145
    +
    
    1149 1146
             if not msg:
    
    1150 1147
                 return
    
    1151
    -        if self.jid_is_from_pm(with_) or nick:
    
    1152
    -            # It's a groupchat message
    
    1153
    -            if nick:
    
    1154
    -                # It's a message from a groupchat occupent
    
    1155
    -                type_ = 'gc_msg'
    
    1156
    -                with_ = with_ + '/' + nick
    
    1157
    -            else:
    
    1158
    -                # It's a server message message, we don't log them
    
    1159
    -                return
    
    1148
    +        if is_pm:
    
    1149
    +            type_ = 'gc_msg'
    
    1160 1150
             else:
    
    1161 1151
                 if direction == 'from':
    
    1162 1152
                     type_ = 'chat_msg_recv'
    
    1163 1153
                 elif direction == 'to':
    
    1164 1154
                     type_ = 'chat_msg_sent'
    
    1165
    -        jid_id = self.get_jid_id(with_)
    
    1166
    -        where_sql = 'jid_id = %s AND message=?' % jid_id
    
    1167
    -        if type_ == 'gc_msg':
    
    1168
    -            # We cannot differentiate gc message and pm messages, so look in
    
    1169
    -            # both logs
    
    1170
    -            with_2 = gajim.get_jid_without_resource(with_)
    
    1171
    -            if with_ != with_2:
    
    1172
    -                jid_id2 = self.get_jid_id(with_2)
    
    1173
    -                where_sql = 'jid_id in (%s, %s) AND message=?' % (jid_id,
    
    1174
    -                    jid_id2)
    
    1175
    -        start_time = time_col - 300 # 5 minutes arrount given time
    
    1176
    -        end_time = time_col + 300 # 5 minutes arrount given time
    
    1177
    -        self.cur.execute('''
    
    1178
    -            SELECT log_line_id FROM logs
    
    1179
    -            WHERE (%s)
    
    1180
    -            AND time BETWEEN %d AND %d
    
    1181
    -            ORDER BY time
    
    1182
    -            ''' % (where_sql, start_time, end_time), (msg,))
    
    1183
    -        results = self.cur.fetchall()
    
    1184
    -        if results:
    
    1155
    +
    
    1156
    +        start_time = tim - 300 # 5 minutes arrount given time
    
    1157
    +        end_time = tim + 300 # 5 minutes arrount given time
    
    1158
    +
    
    1159
    +        sql = '''
    
    1160
    +            SELECT * FROM logs
    
    1161
    +            NATURAL JOIN jids WHERE jid = ? AND message = ?
    
    1162
    +            AND time BETWEEN ? AND ?
    
    1163
    +            '''
    
    1164
    +
    
    1165
    +        result = self.con.execute(sql, (str(with_), msg, start_time, end_time)).fetchone()
    
    1166
    +
    
    1167
    +        if result:
    
    1185 1168
                 log.debug('Log already in DB, ignoring it')
    
    1186 1169
                 return
    
    1187 1170
             log.debug('New log received from server archives, storing it')
    
    1188
    -        self.write(type_, with_, message=msg, tim=tim,
    
    1171
    +        self.write(type_, str(with_), message=msg, tim=tim,
    
    1189 1172
                        additional_data=additional_data, mam_query=True)
    
    1190 1173
     
    
    1191 1174
         def _nec_gc_message_received(self, obj):
    

  • gajim/common/message_archiving.py
    ... ... @@ -92,15 +92,15 @@ class ConnectionArchive313(ConnectionArchive):
    92 92
                 for identity in obj.identities:
    
    93 93
                     if identity['category'] == 'conference':
    
    94 94
                         # it's a groupchat
    
    95
    -                    for with_, direction, tim, msg_txt, res in \
    
    95
    +                    for with_, direction, tim, msg_txt in \
    
    96 96
                         self.mam_awaiting_disco_result[obj.jid]:
    
    97 97
                             gajim.logger.get_jid_id(with_, 'ROOM')
    
    98 98
                             gajim.logger.save_if_not_exists(with_, direction, tim,
    
    99
    -                            msg=msg_txt, nick=res)
    
    99
    +                            msg=msg_txt, is_pm=True)
    
    100 100
                         del self.mam_awaiting_disco_result[obj.jid]
    
    101 101
                         return
    
    102 102
                 # it's not a groupchat
    
    103
    -            for with_, direction, tim, msg_txt, res in \
    
    103
    +            for with_, direction, tim, msg_txt in \
    
    104 104
                 self.mam_awaiting_disco_result[obj.jid]:
    
    105 105
                     gajim.logger.get_jid_id(with_)
    
    106 106
                     gajim.logger.save_if_not_exists(with_, direction, tim,
    
    ... ... @@ -134,7 +134,7 @@ class ConnectionArchive313(ConnectionArchive):
    134 134
             if obj.conn.name != self.name:
    
    135 135
                 return
    
    136 136
             gajim.logger.save_if_not_exists(obj.with_, obj.direction, obj.timestamp,
    
    137
    -            msg=obj.msgtxt, nick=obj.nick, additional_data=obj.additional_data)
    
    137
    +            msg=obj.msgtxt, additional_data=obj.additional_data)
    
    138 138
     
    
    139 139
         def get_query_id(self):
    
    140 140
             self.mam_query_id = self.connection.getAnID()