From 3db54fd574d5291be6fbf8609ba9122c50126067 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 19 Jan 2025 20:47:07 +0200 Subject: [PATCH] client: unlink device when logging out --- pkg/connector/client.go | 4 ++++ pkg/signalmeow/provisioning.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/pkg/connector/client.go b/pkg/connector/client.go index 44a1d2a7..7bf68841 100644 --- a/pkg/connector/client.go +++ b/pkg/connector/client.go @@ -90,6 +90,10 @@ func (s *SignalClient) LogoutRemote(ctx context.Context) { if err != nil { zerolog.Ctx(ctx).Err(err).Msg("Failed to stop receive loops for logout") } + err = s.Client.Unlink(ctx) + if err != nil { + zerolog.Ctx(ctx).Err(err).Msg("Failed to unlink device") + } err = s.Main.Store.DeleteDevice(context.TODO(), &s.Client.Store.DeviceData) if err != nil { zerolog.Ctx(ctx).Err(err).Msg("Failed to delete device from store") diff --git a/pkg/signalmeow/provisioning.go b/pkg/signalmeow/provisioning.go index d6774ae9..f0e4ff8d 100644 --- a/pkg/signalmeow/provisioning.go +++ b/pkg/signalmeow/provisioning.go @@ -385,6 +385,20 @@ func (cli *Client) RegisterCapabilities(ctx context.Context) error { return nil } +func (cli *Client) Unlink(ctx context.Context) error { + username, password := cli.Store.BasicAuthCreds() + resp, err := web.SendHTTPRequest(ctx, http.MethodDelete, fmt.Sprintf("/v1/devices/%d", cli.Store.DeviceID), &web.HTTPReqOpt{ + Username: &username, + Password: &password, + }) + if err != nil { + return err + } else if resp.StatusCode >= 400 { + return fmt.Errorf("unexpected status code %d", resp.StatusCode) + } + return nil +} + func confirmDevice( ctx context.Context, username string,