From ed82a5d6eede5c39012915cce5276c964bbe0c64 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 9 Feb 2024 21:30:56 +0200 Subject: [PATCH] Add command to toggle messenger-side encryption in DMs --- commands.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/commands.go b/commands.go index 8ffd5e7..3b323a3 100644 --- a/commands.go +++ b/commands.go @@ -57,6 +57,7 @@ func (br *MetaBridge) RegisterCommands() { cmdLogin, cmdSyncSpace, cmdDeleteSession, + cmdToggleEncryption, cmdSetRelay, cmdUnsetRelay, cmdDeletePortal, @@ -77,6 +78,38 @@ func wrapCommand(handler func(*WrappedCommandEvent)) func(*commands.Event) { } } +var cmdToggleEncryption = &commands.FullHandler{ + Func: wrapCommand(fnToggleEncryption), + Name: "toggle-encryption", + Help: commands.HelpMeta{ + Section: HelpSectionPortalManagement, + Description: "Toggle Messenger-side encryption for the current room", + }, + RequiresPortal: true, + RequiresLogin: true, +} + +func fnToggleEncryption(ce *WrappedCommandEvent) { + if !ce.Bridge.Config.Meta.Mode.IsMessenger() { + ce.Reply("Encryption support is not yet enabled in Instagram mode") + return + } else if !ce.Portal.IsPrivateChat() { + ce.Reply("Only private chats can be toggled between encrypted and unencrypted") + return + } + if ce.Portal.ThreadType.IsWhatsApp() { + ce.Portal.ThreadType = table.ONE_TO_ONE + ce.Reply("Messages in this room will now be sent unencrypted over Messenger") + } else { + ce.Portal.ThreadType = table.ENCRYPTED_OVER_WA_ONE_TO_ONE + ce.Reply("Messages in this room will now be sent encrypted over WhatsApp") + } + err := ce.Portal.Update(ce.Ctx) + if err != nil { + ce.ZLog.Err(err).Msg("Failed to update portal in database") + } +} + var cmdSetRelay = &commands.FullHandler{ Func: wrapCommand(fnSetRelay), Name: "set-relay",