Move logging GC messages into connection_handlers
- It should be where all other message received handlers are - Port to new DB API
This commit is contained in:
parent
608655deed
commit
8c920b35ff
|
@ -897,6 +897,8 @@ class ConnectionHandlersBase:
|
|||
self._nec_message_received)
|
||||
gajim.ged.register_event_handler('decrypted-message-received', ged.CORE,
|
||||
self._nec_decrypted_message_received)
|
||||
gajim.ged.register_event_handler('gc-message-received', ged.CORE,
|
||||
self._nec_gc_message_received)
|
||||
|
||||
def cleanup(self):
|
||||
gajim.ged.remove_event_handler('iq-error-received', ged.CORE,
|
||||
|
@ -911,6 +913,8 @@ class ConnectionHandlersBase:
|
|||
self._nec_message_received)
|
||||
gajim.ged.remove_event_handler('decrypted-message-received', ged.CORE,
|
||||
self._nec_decrypted_message_received)
|
||||
gajim.ged.remove_event_handler('gc-message-received', ged.CORE,
|
||||
self._nec_gc_message_received)
|
||||
|
||||
def _nec_iq_error_received(self, obj):
|
||||
if obj.conn.name != self.name:
|
||||
|
@ -1157,6 +1161,24 @@ class ConnectionHandlersBase:
|
|||
conn=self, msg_obj=obj))
|
||||
return True
|
||||
|
||||
def _nec_gc_message_received(self, obj):
|
||||
if gajim.config.should_log(obj.conn.name, obj.jid) and not \
|
||||
obj.timestamp < obj.conn.last_history_time[obj.jid] and obj.msgtxt and \
|
||||
obj.nick:
|
||||
# if not obj.nick, it means message comes from room itself
|
||||
# usually it hold description and can be send at each connection
|
||||
# so don't store it in logs
|
||||
gajim.logger.insert_into_logs(obj.jid,
|
||||
obj.timestamp,
|
||||
KindConstant.GC_MSG,
|
||||
message=obj.msgtxt,
|
||||
contact_name=obj.nick,
|
||||
additional_data=obj.additional_data)
|
||||
# store in memory time of last message logged.
|
||||
# this will also be saved in rooms_last_message_time table
|
||||
# when we quit this muc
|
||||
obj.conn.last_history_time[obj.jid] = obj.timestamp
|
||||
|
||||
# process and dispatch an error message
|
||||
def dispatch_error_message(self, msg, msgtxt, session, frm, tim):
|
||||
error_msg = msg.getErrorMsg()
|
||||
|
|
|
@ -1145,7 +1145,7 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
base_network_events = ['raw-message-received']
|
||||
|
||||
def init(self):
|
||||
self.additional_data = {}
|
||||
self.additional_data = None
|
||||
|
||||
def generate(self):
|
||||
self.conn = self.base_event.conn
|
||||
|
|
|
@ -122,8 +122,6 @@ class Logger:
|
|||
# db will be created in src/common/checks_paths.py
|
||||
return
|
||||
self.attach_cache_database()
|
||||
gajim.ged.register_event_handler('gc-message-received',
|
||||
ged.POSTCORE, self._nec_gc_message_received)
|
||||
|
||||
@staticmethod
|
||||
def namedtuple_factory(cursor, row):
|
||||
|
@ -592,25 +590,11 @@ class Logger:
|
|||
|
||||
write_unread = False
|
||||
try:
|
||||
if kind == 'gc_msg':
|
||||
if jid.find('/') != -1: # if it has a /
|
||||
jid, nick = jid.split('/', 1)
|
||||
else:
|
||||
# it's server message f.e. error message
|
||||
# when user tries to ban someone but he's not allowed to
|
||||
nick = None
|
||||
|
||||
# re-get jid_id for the new jid
|
||||
jid_id = self.get_jid_id(jid, 'ROOM')
|
||||
|
||||
contact_name_col = nick
|
||||
else:
|
||||
jid_id = self.get_jid_id(jid)
|
||||
if kind == 'chat_msg_recv':
|
||||
if not self.jid_is_from_pm(jid) and not mam_query:
|
||||
# Save in unread table only if it's not a pm
|
||||
write_unread = True
|
||||
|
||||
jid_id = self.get_jid_id(jid)
|
||||
if kind == 'chat_msg_recv':
|
||||
if not self.jid_is_from_pm(jid) and not mam_query:
|
||||
# Save in unread table only if it's not a pm
|
||||
write_unread = True
|
||||
|
||||
values = (jid_id, contact_name_col, time_col, kind_col, None,
|
||||
message_col, subject_col, additional_data_col)
|
||||
|
@ -1206,18 +1190,3 @@ class Logger:
|
|||
self._timeout_commit()
|
||||
|
||||
return lastrowid
|
||||
|
||||
def _nec_gc_message_received(self, obj):
|
||||
tim_f = float(obj.timestamp)
|
||||
tim_int = int(tim_f)
|
||||
if gajim.config.should_log(obj.conn.name, obj.jid) and not \
|
||||
tim_int < obj.conn.last_history_time[obj.jid] and obj.msgtxt and \
|
||||
obj.nick:
|
||||
# if not obj.nick, it means message comes from room itself
|
||||
# usually it hold description and can be send at each connection
|
||||
# so don't store it in logs
|
||||
self.write('gc_msg', obj.fjid, obj.msgtxt, tim=obj.timestamp, additional_data=obj.additional_data)
|
||||
# store in memory time of last message logged.
|
||||
# this will also be saved in rooms_last_message_time table
|
||||
# when we quit this muc
|
||||
obj.conn.last_history_time[obj.jid] = tim_f
|
||||
|
|
Loading…
Reference in New Issue