/omemo_reset command behind config flag
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
86423b59a7
commit
7854f57c9f
1 changed files with 45 additions and 0 deletions
|
@ -73,6 +73,8 @@ class Plugin(E2EEPlugin):
|
|||
# Some MUC services may not reflect the message ids properly, in which
|
||||
# case it is better to set this option to false.
|
||||
'enable_muc': True,
|
||||
# For debugging purposes.
|
||||
'enable_reset_command': False,
|
||||
}
|
||||
|
||||
def init(self) -> None:
|
||||
|
@ -106,6 +108,17 @@ class Plugin(E2EEPlugin):
|
|||
self.core.xmpp['xep_0384'].session_start(self.core.xmpp.boundjid)
|
||||
)
|
||||
|
||||
if self.config.get('enable_reset_command', False):
|
||||
for tab_t in self.supported_tab_types:
|
||||
self.api.add_tab_command(
|
||||
tab_t,
|
||||
self.encryption_name + '_reset',
|
||||
self.reset_session,
|
||||
usage='<device-id>',
|
||||
short='Caution: Resets session for the specified device-id.',
|
||||
help='Caution: Resets session for the specified device-id.',
|
||||
)
|
||||
|
||||
def display_error(self, txt) -> None:
|
||||
"""Poezio logger Helper"""
|
||||
self.api.information(txt, 'Error')
|
||||
|
@ -150,6 +163,38 @@ class Plugin(E2EEPlugin):
|
|||
colored_fp += f'\x19{fg_color}}}{part}{separator}'
|
||||
return colored_fp
|
||||
|
||||
def reset_session(self, args: List[str]) -> None:
|
||||
"""
|
||||
Command wrapper for _reset_session.
|
||||
"""
|
||||
error = None
|
||||
try:
|
||||
did = int(args)
|
||||
except IndexError:
|
||||
error = 'Invalid argument for reset command.'
|
||||
except ValueError:
|
||||
error = 'Invalid device_id for reset command.'
|
||||
if error is not None:
|
||||
self.core.information(error, 'Error')
|
||||
return None
|
||||
|
||||
jid = self.api.current_tab().jid
|
||||
asyncio.create_task(self._reset_session(jid, did))
|
||||
return None
|
||||
|
||||
async def _reset_session(self, jid: JID, device_id: int) -> None:
|
||||
"""
|
||||
Resets a session for the specified jid/device-id pair.
|
||||
Sends a heartbeat right after to ensure the recipient is aware
|
||||
we've resetted it.
|
||||
"""
|
||||
log.debug('_reset_session: JID: %r, device_id: %r', jid, device_id)
|
||||
# Remove session material
|
||||
await self.core.xmpp['xep_0384'].delete_session(jid, device_id)
|
||||
# Send a heartbeat to ensure recipient is aware that the old session
|
||||
# isn't usable anymore.
|
||||
await self.core.xmpp['xep_0384'].send_heartbeat(jid, device_id)
|
||||
|
||||
async def decrypt(self, message: Message, jid: Optional[JID], tab: Optional[ChatTab]) -> None:
|
||||
if jid is None:
|
||||
self.display_error('Unable to decrypt the message.')
|
||||
|
|
Loading…
Reference in a new issue