Fix additional_data in events

This commit is contained in:
Thilo Molitor 2017-11-01 23:14:47 +01:00
parent ecd5c652a2
commit 0638cdc690
6 changed files with 17 additions and 9 deletions

View File

@ -1385,7 +1385,7 @@ class ChatControl(ChatControlBase):
self.print_conversation(event.message, kind, tim=event.time,
encrypted=event.encrypted, subject=event.subject,
xhtml=event.xhtml, displaymarking=event.displaymarking,
correct_id=event.correct_id)
correct_id=event.correct_id, additional_data=event.additional_data)
if isinstance(event.msg_log_id, int):
message_ids.append(event.msg_log_id)

View File

@ -1124,7 +1124,7 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
base_network_events = ['raw-message-received']
def init(self):
self.additional_data = None
self.additional_data = {}
def generate(self):
self.conn = self.base_event.conn
@ -2696,7 +2696,7 @@ class MessageOutgoingEvent(nec.NetworkOutgoingEvent):
base_network_events = []
def init(self):
self.additional_data = None
self.additional_data = {}
self.message = None
self.keyID = None
self.type_ = 'chat'

View File

@ -83,6 +83,8 @@ class ChatEvent(Event):
self.form_node = form_node
self.displaymarking = displaymarking
self.sent_forwarded = sent_forwarded
if additional_data is None:
additional_data = {}
self.additional_data = additional_data
class NormalEvent(ChatEvent):

View File

@ -132,9 +132,8 @@ class Logger:
Row = namedtuple("Row", fields)
named_row = Row(*row)
if 'additional_data' in fields:
if named_row.additional_data is not None:
named_row = named_row._replace(
additional_data=json.loads(named_row.additional_data))
named_row = named_row._replace(
additional_data=json.loads(named_row.additional_data or '{}'))
return named_row
def dispatch(self, event, error):
@ -1113,7 +1112,13 @@ class Logger:
a field in the `logs` table
"""
jid_id = self.get_jid_id(jid, kind=kind)
if 'additional_data' in kwargs:
if not kwargs['additional_data']:
del kwargs['additional_data']
else:
kwargs['additional_data'] = json.dumps(kwargs["additional_data"])
sql = '''
INSERT INTO logs (jid_id, time, kind, {columns})
VALUES (?, ?, ?, {values})

View File

@ -2723,7 +2723,7 @@ class RosterWindow:
tim=obj.timestamp, encrypted=obj.encrypted, subject=obj.subject,
xhtml=obj.xhtml, displaymarking=obj.displaymarking,
msg_log_id=obj.msg_log_id, msg_stanza_id=obj.id_, correct_id=obj.correct_id,
xep0184_id=xep0184_id)
xep0184_id=xep0184_id, additional_data=obj.additional_data)
if obj.msg_log_id:
pw = obj.session.control.parent_win
end = obj.session.control.was_at_the_end

View File

@ -273,7 +273,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
displaymarking=obj.displaymarking,
sent_forwarded=obj.forwarded and obj.sent,
show_in_roster=obj.show_in_roster,
show_in_systray=obj.show_in_systray)
show_in_systray=obj.show_in_systray,
additional_data=obj.additional_data)
app.events.add_event(self.conn.name, fjid, event)