forked from
tangled.org/core
Monorepo for Tangled
1package pulls
2
3import (
4 "net/http"
5 "time"
6
7 comatproto "github.com/bluesky-social/indigo/api/atproto"
8 "github.com/bluesky-social/indigo/atproto/syntax"
9 lexutil "github.com/bluesky-social/indigo/lex/util"
10 "github.com/samber/lo"
11
12 "tangled.org/core/api/tangled"
13 "tangled.org/core/appview/models"
14 "tangled.org/core/tid"
15)
16
17func (s *Pulls) writePullStatusRecords(r *http.Request, actorDid string, subjects []syntax.ATURI, value models.StateValue) error {
18 if len(subjects) == 0 {
19 return nil
20 }
21
22 client, err := s.oauth.AuthorizedClient(r)
23 if err != nil {
24 return err
25 }
26
27 records, err := models.AsPullStatusRecords(subjects, value, time.Now())
28 if err != nil {
29 return err
30 }
31
32 writes := lo.Map(records, func(record tangled.RepoPullStatus, _ int) *comatproto.RepoApplyWrites_Input_Writes_Elem {
33 rkey := tid.TID()
34 return &comatproto.RepoApplyWrites_Input_Writes_Elem{
35 RepoApplyWrites_Create: &comatproto.RepoApplyWrites_Create{
36 Collection: tangled.RepoPullStatusNSID,
37 Rkey: &rkey,
38 Value: &lexutil.LexiconTypeDecoder{
39 Val: &record,
40 },
41 },
42 }
43 })
44
45 _, err = comatproto.RepoApplyWrites(r.Context(), client, &comatproto.RepoApplyWrites_Input{
46 Repo: actorDid,
47 Writes: writes,
48 })
49 return err
50}