Corrected last commit and added ability to set and log additional_data for outgoing messages as well (and for gc messages, too)
This commit is contained in:
parent
8bfde7d924
commit
235cadd5cc
|
@ -148,23 +148,23 @@ class ConfigPaths:
|
|||
'RNG_SEED': 'rng_seed',
|
||||
'SECRETS_FILE': 'secrets', 'MY_PEER_CERTS': 'certs'}
|
||||
for name in d:
|
||||
d[name] += u'.' + profile
|
||||
d[name] += profile
|
||||
self.add(name, TYPE_DATA, windowsify(d[name]))
|
||||
self.add('MY_DATA', TYPE_DATA, 'data' + profile)
|
||||
self.add('MY_DATA', TYPE_DATA, 'data.dir' + profile)
|
||||
|
||||
d = {'CACHE_DB': 'cache.db', 'VCARD': 'vcards',
|
||||
'AVATAR': 'avatars',
|
||||
'PID_FILE': 'gajim.pid'}
|
||||
for name in d:
|
||||
d[name] += u'.' + profile
|
||||
d[name] += profile
|
||||
self.add(name, TYPE_CACHE, windowsify(d[name]))
|
||||
self.add('MY_CACHE', TYPE_CACHE, 'cache' + profile)
|
||||
self.add('MY_CACHE', TYPE_CACHE, 'cache.dir' + profile)
|
||||
|
||||
d = {'CONFIG_FILE': 'config', 'PLUGINS_CONFIG_DIR': 'pluginsconfig', 'MY_CERT': 'localcerts'}
|
||||
for name in d:
|
||||
d[name] += u'.' + profile
|
||||
d[name] += profile
|
||||
self.add(name, TYPE_CONFIG, windowsify(d[name]))
|
||||
self.add('MY_CONFIG', TYPE_CONFIG, 'config' + profile)
|
||||
self.add('MY_CONFIG', TYPE_CONFIG, 'config.dir' + profile)
|
||||
|
||||
basedir = fse(os.environ.get('GAJIM_BASEDIR', defs.basedir))
|
||||
self.add('DATA', None, os.path.join(basedir, windowsify('data')))
|
||||
|
|
|
@ -515,7 +515,7 @@ class CommonConnection:
|
|||
subject, type_, msg_iq, xhtml)
|
||||
|
||||
def log_message(self, jid, msg, forward_from, session, original_message,
|
||||
subject, type_, xhtml=None):
|
||||
subject, type_, xhtml=None, additional_data={}):
|
||||
if not forward_from and session and session.is_loggable():
|
||||
ji = gajim.get_jid_without_resource(jid)
|
||||
if gajim.config.should_log(self.name, ji):
|
||||
|
@ -531,7 +531,7 @@ class CommonConnection:
|
|||
if xhtml and gajim.config.get('log_xhtml_messages'):
|
||||
log_msg = '<body xmlns="%s">%s</body>' % (
|
||||
nbxmpp.NS_XHTML, xhtml)
|
||||
gajim.logger.write(kind, jid, log_msg, subject=subject)
|
||||
gajim.logger.write(kind, jid, log_msg, subject=subject, additional_data=additional_data)
|
||||
except exceptions.PysqliteOperationalError as e:
|
||||
self.dispatch('DB_ERROR', (_('Disk Write Error'),
|
||||
str(e)))
|
||||
|
@ -2145,13 +2145,13 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
if isinstance(msg_iq, list):
|
||||
for iq in msg_iq:
|
||||
gajim.nec.push_incoming_event(StanzaMessageOutgoingEvent(
|
||||
None, conn=self, msg_iq=iq, now=obj.now, automatic_message=obj.automatic_message,
|
||||
None, conn=self, msg_iq=iq, now=obj.now, automatic_message=obj.automatic_message, additional_data=obj.additional_data,
|
||||
_cb_parameters={"jid":jid, "msg":msg, "keyID":keyID, "forward_from":forward_from,
|
||||
"session":session, "original_message":original_message, "subject":subject, "type_":type_,
|
||||
"msg_iq":msg_iq, "xhtml":xhtml, "obj":obj}))
|
||||
else:
|
||||
gajim.nec.push_incoming_event(StanzaMessageOutgoingEvent(None,
|
||||
conn=self, msg_iq=msg_iq, now=obj.now, automatic_message=obj.automatic_message,
|
||||
conn=self, msg_iq=msg_iq, now=obj.now, automatic_message=obj.automatic_message, additional_data=obj.additional_data,
|
||||
_cb_parameters={"jid":jid, "msg":msg, "keyID":keyID, "forward_from":forward_from,
|
||||
"session":session, "original_message":original_message, "subject":subject, "type_":type_,
|
||||
"msg_iq":msg_iq, "xhtml":xhtml, "obj":obj}))
|
||||
|
@ -2174,7 +2174,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
subject, type_, msg_iq, xhtml, msg_id):
|
||||
gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
|
||||
jid=jid, message=msg, keyID=keyID, chatstate=obj.chatstate,
|
||||
automatic_message=obj.automatic_message, msg_id=msg_id))
|
||||
automatic_message=obj.automatic_message, msg_id=msg_id, additional_data=obj.additional_data))
|
||||
if obj.callback:
|
||||
obj.callback(msg_iq, *obj.callback_args)
|
||||
|
||||
|
@ -2185,10 +2185,10 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
if session is None:
|
||||
session = self.get_or_create_session(j, '')
|
||||
self.log_message(j, msg, forward_from, session,
|
||||
original_message, subject, type_, xhtml)
|
||||
original_message, subject, type_, xhtml, obj.additional_data)
|
||||
else:
|
||||
self.log_message(jid, msg, forward_from, session,
|
||||
original_message, subject, type_, xhtml)
|
||||
original_message, subject, type_, xhtml, obj.additional_data)
|
||||
|
||||
cb(msg_id=obj.msg_id, **obj._cb_parameters)
|
||||
|
||||
|
@ -2749,7 +2749,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
gajim.nec.push_incoming_event(GcStanzaMessageOutgoingEvent(
|
||||
None, conn=self, automatic_message=obj.automatic_message,
|
||||
jid=obj.jid, message=obj.message,
|
||||
correction_msg=obj.correction_msg))
|
||||
correction_msg=obj.correction_msg, additional_data=obj.additional_data))
|
||||
if obj.callback:
|
||||
obj.callback(obj.correction_msg, obj.message)
|
||||
return
|
||||
|
@ -2763,7 +2763,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
gajim.nec.push_incoming_event(GcStanzaMessageOutgoingEvent(
|
||||
None, conn=self, msg_iq=msg_iq,
|
||||
automatic_message=obj.automatic_message,
|
||||
jid=obj.jid, message=obj.message, correction_msg=None))
|
||||
jid=obj.jid, message=obj.message, correction_msg=None, additional_data=obj.additional_data))
|
||||
if obj.callback:
|
||||
obj.callback(msg_iq, obj.message)
|
||||
|
||||
|
@ -2777,7 +2777,7 @@ class Connection(CommonConnection, ConnectionHandlers):
|
|||
gajim.nec.push_incoming_event(MessageSentEvent(
|
||||
None, conn=self, jid=obj.jid, message=obj.message, keyID=None,
|
||||
chatstate=None, automatic_message=obj.automatic_message,
|
||||
msg_id=obj.msg_id))
|
||||
msg_id=obj.msg_id, additional_data=obj.additional_data))
|
||||
|
||||
def send_gc_subject(self, jid, subject):
|
||||
if not gajim.account_is_connected(self.name):
|
||||
|
|
|
@ -1025,11 +1025,12 @@ class MamMessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
name = 'mam-message-received'
|
||||
base_network_events = []
|
||||
|
||||
def init(self):
|
||||
self.additional_data = {}
|
||||
|
||||
def generate(self):
|
||||
if not self.stanza:
|
||||
return
|
||||
if not hasattr(self, 'additional_data'):
|
||||
self.additional_data = {}
|
||||
account = self.conn.name
|
||||
self.msg_ = self.stanza.getTag('message')
|
||||
# use timestamp of archived message, if available and archive timestamp otherwise
|
||||
|
@ -1104,15 +1105,15 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
name = 'message-received'
|
||||
base_network_events = ['raw-message-received']
|
||||
|
||||
def init(self):
|
||||
self.additional_data = {}
|
||||
|
||||
def generate(self):
|
||||
self.conn = self.base_event.conn
|
||||
self.stanza = self.base_event.stanza
|
||||
self.get_id()
|
||||
self.forwarded = False
|
||||
self.sent = False
|
||||
if not hasattr(self, 'additional_data'):
|
||||
self.additional_data = {}
|
||||
|
||||
account = self.conn.name
|
||||
|
||||
# check if the message is a roster item exchange (XEP-0144)
|
||||
|
@ -1823,9 +1824,9 @@ class StanzaReceivedEvent(nec.NetworkIncomingEvent):
|
|||
name = 'stanza-received'
|
||||
base_network_events = []
|
||||
|
||||
def init(self):
|
||||
self.additional_data = {}
|
||||
def generate(self):
|
||||
if not hasattr(self, 'additional_data'):
|
||||
self.additional_data = {}
|
||||
return True
|
||||
|
||||
class StanzaSentEvent(nec.NetworkIncomingEvent):
|
||||
|
@ -2669,6 +2670,7 @@ class MessageOutgoingEvent(nec.NetworkOutgoingEvent):
|
|||
base_network_events = []
|
||||
|
||||
def init(self):
|
||||
self.additional_data = {}
|
||||
self.message = ''
|
||||
self.keyID = None
|
||||
self.type_ = 'chat'
|
||||
|
@ -2715,6 +2717,7 @@ class GcMessageOutgoingEvent(nec.NetworkOutgoingEvent):
|
|||
base_network_events = []
|
||||
|
||||
def init(self):
|
||||
self.additional_data = {}
|
||||
self.message = ''
|
||||
self.xhtml = None
|
||||
self.label = None
|
||||
|
|
|
@ -142,8 +142,6 @@ class Logger:
|
|||
# if locked, wait up to 20 sec to unlock
|
||||
# before raise (hopefully should be enough)
|
||||
|
||||
print("*****")
|
||||
print("%s/%s" % (LOG_DB_FOLDER, LOG_DB_FILE))
|
||||
self.con = sqlite.connect(LOG_DB_FILE, timeout=20.0,
|
||||
isolation_level='IMMEDIATE')
|
||||
os.chdir(back)
|
||||
|
@ -1159,7 +1157,7 @@ class Logger:
|
|||
# usually it hold description and can be send at each connection
|
||||
# so don't store it in logs
|
||||
try:
|
||||
self.write('gc_msg', obj.fjid, obj.msgtxt, tim=obj.timestamp)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue