+ .omemo directory is now placed inside the configuration directory and is created if missing

This commit is contained in:
nicobo 2021-01-24 22:56:32 +01:00
parent 3cb25d287e
commit 314df61e4d
No known key found for this signature in database
GPG key ID: 2581E71C5FA5285F
2 changed files with 11 additions and 7 deletions

View file

@ -109,7 +109,8 @@ class ArgsHelper:
def jabber_chatter( args ):
"""
Builds a JabberChatter from Namespace argument 'args'
Builds a JabberChatter from Namespace argument 'args'.
Sets its data directory to <config_dir>/.omemo
"""
username = args.jabber_username if args.jabber_username else args.username
@ -124,7 +125,8 @@ class ArgsHelper:
return JabberChatter(
jid=username,
password=args.jabber_password,
recipient=recipients[0]
recipient=recipients[0],
data_dir=os.path.join(args.config_dir,".omemo")
)

View file

@ -30,7 +30,7 @@ class SliXmppClient(ClientXMPP):
eme_ns = 'eu.siacs.conversations.axolotl'
def __init__(self, jid, password, message_handler):
def __init__(self, jid, password, message_handler, data_dir):
"""
jid, password : valid account to send and receive messages
@ -46,16 +46,18 @@ class SliXmppClient(ClientXMPP):
self.register_plugin('xep_0199') # XMPP Ping
self.register_plugin('xep_0380') # Explicit Message Encryption
if not os.path.exists(data_dir):
os.makedirs(data_dir)
try:
self.register_plugin(
'xep_0384',
{
'data_dir': '.omemo',
'data_dir': data_dir,
},
module=slixmpp_omemo,
) # OMEMO
except (PluginCouldNotLoad,):
log.exception('And error occured when loading the omemo plugin.')
logging.exception('And error occured when loading the omemo plugin.')
sys.exit(1)
self.message_handler = message_handler
@ -265,10 +267,10 @@ class JabberChatter(Chatter):
It implements nicobot.Chatter by wrapping an internal slixmpp.ClientXMPP instance.
"""
def __init__( self, jid, password, recipient ):
def __init__( self, jid, password, recipient, data_dir ):
self.recipient = recipient
self.xmpp = SliXmppClient( jid, password, message_handler=self.on_xmpp_message )
self.xmpp = SliXmppClient( jid, password, message_handler=self.on_xmpp_message, data_dir=data_dir )
def on_xmpp_message( self, original_message, decrypted_body ):
"""