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