client: unlink device when logging out

This commit is contained in:
Tulir Asokan 2025-01-19 20:47:07 +02:00
parent dceab3c8b3
commit 3db54fd574
2 changed files with 18 additions and 0 deletions

View file

@ -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")

View file

@ -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,