1package server
2
3import (
4 "context"
5 "time"
6
7 "github.com/Azure/go-autorest/autorest/to"
8 "github.com/bluesky-social/indigo/api/atproto"
9 "github.com/bluesky-social/indigo/events"
10 "github.com/bluesky-social/indigo/util"
11 "github.com/haileyok/cocoon/internal/helpers"
12 "github.com/haileyok/cocoon/models"
13 "github.com/labstack/echo/v4"
14)
15
16type ComAtprotoServerDeactivateAccountRequest struct {
17 // NOTE: this implementation will not pay attention to this value
18 DeleteAfter time.Time `json:"deleteAfter"`
19}
20
21func (s *Server) handleServerDeactivateAccount(e echo.Context) error {
22 var req ComAtprotoServerDeactivateAccountRequest
23 if err := e.Bind(&req); err != nil {
24 s.logger.Error("error binding", "error", err)
25 return helpers.ServerError(e, nil)
26 }
27
28 urepo := e.Get("repo").(*models.RepoActor)
29
30 if err := s.db.Exec("UPDATE repos SET deactivated = ? WHERE did = ?", nil, true, urepo.Repo.Did).Error; err != nil {
31 s.logger.Error("error updating account status to deactivated", "error", err)
32 return helpers.ServerError(e, nil)
33 }
34
35 s.evtman.AddEvent(context.TODO(), &events.XRPCStreamEvent{
36 RepoAccount: &atproto.SyncSubscribeRepos_Account{
37 Active: false,
38 Did: urepo.Repo.Did,
39 Status: to.StringPtr("deactivated"),
40 Seq: time.Now().UnixMicro(), // TODO: bad puppy
41 Time: time.Now().Format(util.ISO8601),
42 },
43 })
44
45 return e.NoContent(200)
46}