Commit 8b00e25a authored by Maxime Buquet's avatar Maxime Buquet
Browse files

WIP: Have decrypt API method return Optional[str] (body)



We have this method return the decrypted body instead of changing the the
referenced message's body because the poezio event system doesn't handle
ordering for async methods. The message may already be displayed when we finish
decrypting.

We now try to replace the displayed message ourselves once decrypted.

Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <pep@bouah.net>
parent b45925f4
......@@ -419,16 +419,33 @@ class E2EEPlugin(BasePlugin):
if user is not None:
jid = user.jid or None
# Call the enabled encrypt method
# Call the enabled decrypt method.
# We have this method return the decrypted body instead of changing
# the the referenced message's body because the poezio event system
# doesn't handle ordering for async methods. The message may already
# be displayed when we finish decrypting.
func = self.decrypt
if iscoroutinefunction(func):
# pylint: disable=unexpected-keyword-arg
await func(message, jid, tab, passthrough=True)
body = await func(message, jid, tab, passthrough=True)
else:
# pylint: disable=unexpected-keyword-arg
func(message, jid, tab)
body = func(message, jid, tab)
log.debug('Decrypted %s message: %r', self.encryption_name, body)
if body is not None:
message['body'] = message
# tab.modify_message(body, message['id'], message['id'], time=None, delayed=False)
_, i = tab._text_buffer._find_message(message['id'])
if i == -1:
return
found = tab._text_buffer.messages[i]
log.debug('Found message: %r', found.txt)
found.txt = body
tab.text_win.modify_message(found.identifier, found)
tab.text_win.refresh()
# self.core.doupdate()
log.debug('Decrypted %s message: %r', self.encryption_name, message['body'])
return None
async def _encrypt(self, stanza: StanzaBase, passthrough: bool = True) -> Optional[StanzaBase]:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment