comparison sat_frontends/quick_frontend/quick_chat.py @ 3170:39d7327583e1

core: use serialised dict for `extra` in messageNew and historyGet
author Goffi <goffi@goffi.org>
date Tue, 18 Feb 2020 18:13:17 +0100
parents 559a625a236b
children 4b5c77673015
comparison
equal deleted inserted replaced
3169:560642ab1c10 3170:39d7327583e1
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 3 # helper class for making a SàT frontend
4 # helper class for making a SAT frontend
5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) 4 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
6 5
7 # This program is free software: you can redistribute it and/or modify 6 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by 7 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or 8 # the Free Software Foundation, either version 3 of the License, or
24 from sat_frontends.quick_frontend import quick_widgets 23 from sat_frontends.quick_frontend import quick_widgets
25 from sat_frontends.quick_frontend.constants import Const as C 24 from sat_frontends.quick_frontend.constants import Const as C
26 from collections import OrderedDict 25 from collections import OrderedDict
27 from sat_frontends.tools import jid 26 from sat_frontends.tools import jid
28 import time 27 import time
28
29
29 log = getLogger(__name__) 30 log = getLogger(__name__)
30 31
31 try: 32 try:
32 from locale import getlocale 33 from locale import getlocale
33 except ImportError: 34 except ImportError:
42 # from datetime import datetime 43 # from datetime import datetime
43 44
44 # FIXME: day_format need to be settable (i18n) 45 # FIXME: day_format need to be settable (i18n)
45 46
46 47
47 class Message(object): 48 class Message:
48 """Message metadata""" 49 """Message metadata"""
49 50
50 def __init__(self, parent, uid, timestamp, from_jid, to_jid, msg, subject, type_, 51 def __init__(
51 extra, profile): 52 self, parent, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra,
53 profile):
52 self.parent = parent 54 self.parent = parent
53 self.profile = profile 55 self.profile = profile
54 self.uid = uid 56 self.uid = uid
55 self.timestamp = timestamp 57 self.timestamp = timestamp
56 self.from_jid = from_jid 58 self.from_jid = from_jid
626 # message_day = datetime.fromtimestamp(timestamp).strftime(self.day_format) 628 # message_day = datetime.fromtimestamp(timestamp).strftime(self.day_format)
627 # if previous_day != message_day: 629 # if previous_day != message_day:
628 # self.printDayChange(message_day) 630 # self.printDayChange(message_day)
629 # previous_day = message_day 631 # previous_day = message_day
630 for data in history: 632 for data in history:
631 uid, timestamp, from_jid, to_jid, message, subject, type_, extra = data 633 uid, timestamp, from_jid, to_jid, message, subject, type_, extra_s = data
632 from_jid = jid.JID(from_jid) 634 from_jid = jid.JID(from_jid)
633 to_jid = jid.JID(to_jid) 635 to_jid = jid.JID(to_jid)
636 extra = data_format.deserialise(extra_s)
634 # if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or 637 # if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or
635 # (self.type == C.CHAT_ONE2ONE and type_ == C.MESS_TYPE_GROUPCHAT)): 638 # (self.type == C.CHAT_ONE2ONE and type_ == C.MESS_TYPE_GROUPCHAT)):
636 # continue 639 # continue
637 extra["history"] = True 640 extra["history"] = True
638 self.messages[uid] = Message( 641 self.messages[uid] = Message(