Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Malte L
gajim-plugins
Commits
b56223dd
Commit
b56223dd
authored
Feb 17, 2019
by
Philipp Hörist
Browse files
[omemo] Make sure to use only enabled accounts
parent
ac8ef789
Changes
2
Hide whitespace changes
Inline
Side-by-side
omemo/modules/omemo.py
View file @
b56223dd
...
...
@@ -38,6 +38,8 @@ from gajim.common.const import EncryptionData
from
gajim.common.modules.base
import
BaseModule
from
gajim.common.modules.util
import
event_node
from
gajim.plugins.plugins_i18n
import
_
from
omemo.backend.state
import
OmemoState
from
omemo.backend.state
import
KeyExchangeMessage
from
omemo.backend.state
import
SelfMessage
...
...
omemo/plugin.py
View file @
b56223dd
...
...
@@ -98,13 +98,13 @@ class OmemoPlugin(GajimPlugin):
'hyperlink_handler'
:
(
self
.
_file_decryption
,
None
),
'encrypt'
+
self
.
encryption_name
:
(
self
.
_encrypt_message
,
None
),
'gc_encrypt'
+
self
.
encryption_name
:
(
self
.
_
g
c_encrypt_message
,
None
),
self
.
_
mu
c_encrypt_message
,
None
),
'send_message'
+
self
.
encryption_name
:
(
self
.
before_sendmessage
,
None
),
self
.
_
before_sendmessage
,
None
),
'encryption_dialog'
+
self
.
encryption_name
:
(
self
.
_on_encryption_button_clicked
,
None
),
'encryption_state'
+
self
.
encryption_name
:
(
self
.
encryption_state
,
None
),
self
.
_
encryption_state
,
None
),
'update_caps'
:
(
self
.
_update_caps
,
None
)}
self
.
disabled_accounts
=
[]
...
...
@@ -123,6 +123,17 @@ class OmemoPlugin(GajimPlugin):
self
.
_load_css
()
def
_is_enabled_account
(
self
,
account
):
if
account
in
self
.
disabled_accounts
:
return
False
if
account
==
'Local'
:
return
False
return
True
@
staticmethod
def
get_omemo
(
account
):
return
app
.
connections
[
account
].
get_module
(
'OMEMO'
)
@
staticmethod
def
_load_css
():
path
=
Path
(
__file__
).
parent
/
'gtk'
/
'style.css'
...
...
@@ -141,40 +152,39 @@ class OmemoPlugin(GajimPlugin):
except
Exception
:
log
.
exception
(
'Error loading application css'
)
def
_on_signed_in
(
self
,
event
):
if
event
.
conn
.
name
in
self
.
disabled_accounts
:
return
app
.
connections
[
event
.
conn
.
name
].
get_module
(
'OMEMO'
).
on_signed_in
()
def
_on_muc_config_changed
(
self
,
event
):
if
event
.
account
in
self
.
disabled_accounts
:
return
app
.
connections
[
event
.
account
].
get_module
(
'OMEMO'
).
on_muc_config_changed
(
event
)
def
activate
(
self
):
""" Method called when the Plugin is activated in the PluginManager
"""
Method called when the Plugin is activated in the PluginManager
"""
for
account
in
app
.
connections
:
if
account
==
'Local'
:
if
not
self
.
_is_enabled_account
(
account
)
:
continue
if
account
in
self
.
disabled_accounts
:
continue
app
.
connections
[
account
].
get_module
(
'OMEMO'
).
activate
()
self
.
get_omemo
(
account
).
activate
()
@
staticmethod
def
deactivate
():
"""
Method called when the Plugin is deactivated in the PluginManager
def
deactivate
(
self
):
"""
Method called when the Plugin is deactivated in the PluginManager
"""
for
account
in
app
.
connections
:
if
account
==
'Local'
:
if
not
self
.
_is_enabled_account
(
account
)
:
continue
app
.
connections
[
account
].
get_module
(
'OMEMO'
).
deactivate
()
self
.
get_omemo
(
account
).
deactivate
()
@
staticmethod
def
_update_caps
(
account
):
if
account
==
'Local'
:
def
_on_signed_in
(
self
,
event
):
account
=
event
.
conn
.
name
if
not
self
.
_is_enabled_account
(
account
):
return
self
.
get_omemo
(
account
).
on_signed_in
()
def
_on_muc_config_changed
(
self
,
event
):
if
not
self
.
_is_enabled_account
(
event
.
account
):
return
self
.
get_omemo
(
event
.
account
).
on_muc_config_changed
(
event
)
def
_update_caps
(
self
,
account
):
if
not
self
.
_is_enabled_account
(
account
):
return
app
.
connections
[
account
].
get_module
(
'OMEMO'
).
update_caps
(
account
)
self
.
get_omemo
(
account
).
update_caps
(
account
)
@
staticmethod
def
activate_encryption
(
chat_control
):
...
...
@@ -188,19 +198,17 @@ class OmemoPlugin(GajimPlugin):
return
False
return
True
@
staticmethod
def
_gc_encrypt_message
(
conn
,
obj
,
callback
):
if
conn
.
name
==
'Local'
:
def
_muc_encrypt_message
(
self
,
conn
,
obj
,
callback
):
account
=
conn
.
name
if
not
self
.
_is_enabled_account
(
account
)
:
return
app
.
connections
[
conn
.
name
].
get_module
(
'OMEMO'
).
encrypt_message
(
conn
,
obj
,
callback
,
True
)
self
.
get_omemo
(
account
).
encrypt_message
(
conn
,
obj
,
callback
,
True
)
@
staticmethod
def
_encrypt_message
(
conn
,
obj
,
callback
):
if
conn
.
name
==
'Local'
:
def
_encrypt_message
(
self
,
conn
,
obj
,
callback
):
account
=
conn
.
name
if
not
self
.
_is_enabled_account
(
account
)
:
return
app
.
connections
[
conn
.
name
].
get_module
(
'OMEMO'
).
encrypt_message
(
conn
,
obj
,
callback
,
False
)
self
.
get_omemo
(
account
).
encrypt_message
(
conn
,
obj
,
callback
,
False
)
def
_file_decryption
(
self
,
url
,
kind
,
instance
,
window
):
file_crypto
.
FileDecryption
(
self
).
hyperlink_handler
(
...
...
@@ -224,20 +232,16 @@ class OmemoPlugin(GajimPlugin):
GLib
.
idle_add
(
callback
,
file
)
@
staticmethod
def
encryption_state
(
_chat_control
,
state
):
def
_
encryption_state
(
_chat_control
,
state
):
state
[
'visible'
]
=
True
state
[
'authenticated'
]
=
True
def
_on_encryption_button_clicked
(
self
,
chat_control
):
self
.
show_fingerprint_window
(
chat_control
)
@
staticmethod
def
get_omemo
(
account
):
return
app
.
connections
[
account
].
get_module
(
'OMEMO'
)
self
.
_show_fingerprint_window
(
chat_control
)
def
before_sendmessage
(
self
,
chat_control
):
def
_
before_sendmessage
(
self
,
chat_control
):
account
=
chat_control
.
account
if
account
==
'Local'
:
if
not
self
.
_is_enabled_account
(
account
)
:
return
contact
=
chat_control
.
contact
omemo
=
self
.
get_omemo
(
account
)
...
...
@@ -281,16 +285,16 @@ class OmemoPlugin(GajimPlugin):
without_self
=
False
):
fingerprints
=
omemo
.
backend
.
storage
.
getNewFingerprints
(
jid_
)
if
fingerprints
:
self
.
show_fingerprint_window
(
self
.
_
show_fingerprint_window
(
chat_control
,
fingerprints
)
break
elif
not
isinstance
(
chat_control
,
GroupchatControl
):
fingerprints
=
omemo
.
backend
.
storage
.
getNewFingerprints
(
jid
)
if
fingerprints
:
self
.
show_fingerprint_window
(
self
.
_
show_fingerprint_window
(
chat_control
,
fingerprints
)
def
show_fingerprint_window
(
self
,
chat_control
,
fingerprints
=
None
):
def
_
show_fingerprint_window
(
self
,
chat_control
,
fingerprints
=
None
):
contact
=
chat_control
.
contact
account
=
chat_control
.
account
omemo
=
self
.
get_omemo
(
account
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment