Skip to content

Commit

Permalink
Add command to toggle messenger-side encryption in DMs
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Feb 9, 2024
1 parent ecf0960 commit ed82a5d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (br *MetaBridge) RegisterCommands() {
cmdLogin,
cmdSyncSpace,
cmdDeleteSession,
cmdToggleEncryption,
cmdSetRelay,
cmdUnsetRelay,
cmdDeletePortal,
Expand All @@ -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",
Expand Down

0 comments on commit ed82a5d

Please sign in to comment.