Skip to content

Commit 428b16e

Browse files
committedJul 9, 2023
various fixes
1 parent d48dd0f commit 428b16e

File tree

17 files changed

+213
-153
lines changed

17 files changed

+213
-153
lines changed
 

‎activitypub/activities/activities.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ func Follow(actor, object *models.Actor) map[string]any {
1414
return map[string]any{
1515
"@context": "https://www.w3.org/ns/activitystreams",
1616
"type": FOLLOW,
17-
"actor": actor.URI,
18-
"object": object.URI,
17+
"actor": actor.URI(),
18+
"object": object.URI(),
1919
}
2020
}
2121

2222
func Like(actor *models.Actor, object string) map[string]any {
2323
return map[string]any{
2424
"@context": "https://www.w3.org/ns/activitystreams",
2525
"type": LIKE,
26-
"actor": actor.URI,
26+
"actor": actor.URI(),
2727
"object": object,
2828
}
2929
}
@@ -32,7 +32,7 @@ func Unfollow(actor, object *models.Actor) map[string]any {
3232
return map[string]any{
3333
"@context": "https://www.w3.org/ns/activitystreams",
3434
"type": UNDO,
35-
"actor": actor.URI,
35+
"actor": actor.URI(),
3636
"object": Follow(actor, object),
3737
}
3838
}
@@ -41,7 +41,7 @@ func Unlike(actor *models.Actor, object string) map[string]any {
4141
return map[string]any{
4242
"@context": "https://www.w3.org/ns/activitystreams",
4343
"type": UNDO,
44-
"actor": actor.URI,
44+
"actor": actor.URI(),
4545
"object": Like(actor, object),
4646
}
4747
}

‎activitypub/activitypub.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Env struct {
2424
*gorm.DB
2525
*streaming.Mux
2626
Logger *slog.Logger
27+
Client *activitypub.Client
2728
Instance *models.Instance
2829
}
2930

‎activitypub/inbox.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/davecheney/pub/internal/activitypub"
1314
"github.com/davecheney/pub/internal/httpx"
1415
"github.com/davecheney/pub/models"
1516
"github.com/go-fed/httpsig"
@@ -42,7 +43,7 @@ func (i *InboxController) Create(env *Env, w http.ResponseWriter, r *http.Reques
4243
logger: env.Logger.With("instance", env.Instance.Domain),
4344
req: r,
4445
db: env.DB,
45-
signAs: env.Instance.Admin,
46+
client: env.Client,
4647
}
4748

4849
if err := processor.processActivity(act); err != nil {
@@ -56,7 +57,7 @@ type inboxProcessor struct {
5657
logger *slog.Logger
5758
req *http.Request
5859
db *gorm.DB
59-
signAs *models.Account
60+
client *activitypub.Client
6061
}
6162

6263
// processActivity processes an activity. If the activity can be handled without

‎activitypub/outbox.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func statusCC(s *models.Status) []string {
120120

121121
func statusToObject(s *models.Status) any {
122122
if s.ReblogID != nil {
123-
return s.Reblog.URI
123+
return s.Reblog.URI()
124124
}
125125
return nil
126126
}

‎activitypub/users.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func UsersShow(env *Env, w http.ResponseWriter, r *http.Request) error {
1919
}
2020
return err
2121
}
22+
2223
return to.JSON(w, map[string]any{
2324
"@context": []any{
2425
"https://www.w3.org/ns/activitystreams",
@@ -89,7 +90,7 @@ func UsersShow(env *Env, w http.ResponseWriter, r *http.Request) error {
8990
"featuredTags": actor.URI() + "/collections/tags",
9091
"preferredUsername": name,
9192
"name": name,
92-
"summary": actor.Note(),
93+
"summary": "toot!", // actor.Note(),
9394
"url": actor.URL(),
9495
"manuallyApprovesFollowers": actor.Locked(),
9596
"discoverable": false, // mastodon sets this to false
@@ -110,5 +111,10 @@ func UsersShow(env *Env, w http.ResponseWriter, r *http.Request) error {
110111
"mediaType": "image/jpeg",
111112
"url": "https://media.hachyderm.io/accounts/headers/109/364/117/028/564/263/original/c6b5edf498087717.jpeg",
112113
},
114+
"image": map[string]any{
115+
"type": "Image",
116+
"mediaType": "image/jpeg",
117+
"url": "https://media.hachyderm.io/accounts/headers/109/364/117/028/564/263/original/c6b5edf498087717.jpeg",
118+
},
113119
})
114120
}

‎follow.go

+27-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
package main
22

3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/davecheney/pub/models"
8+
"github.com/go-json-experiment/json"
9+
"gorm.io/gorm"
10+
)
11+
312
type FollowCmd struct {
413
Object string `help:"object to follow" required:"true"`
514
Actor string `help:"actor to follow with" required:"true"`
615
}
716

817
func (f *FollowCmd) Run(ctx *Context) error {
9-
// db, err := gorm.Open(ctx.Dialector, &ctx.Config)
10-
// if err != nil {
11-
// return err
12-
// }
13-
return nil
18+
db, err := gorm.Open(ctx.Dialector, &ctx.Config)
19+
if err != nil {
20+
return err
21+
}
1422

15-
// var account models.Account
16-
// if err := db.Joins("Actor", &models.Actor{URI: f.Actor}).Take(&account).Error; err != nil {
17-
// return err
18-
// }
23+
actor, err := models.NewActors(db).FindByURI(f.Actor)
24+
if err != nil {
25+
return fmt.Errorf("failed to find actor: %w", err)
26+
}
1927

20-
// return activitypub.Follow(context.Background(), &account, &models.Actor{URI: f.Object})
28+
object, err := models.NewActors(db).FindOrCreateByURI(f.Object)
29+
if err != nil {
30+
return err
31+
}
32+
rel, err := models.NewRelationships(db).Follow(actor, object)
33+
if err != nil {
34+
return err
35+
}
36+
json.MarshalFull(os.Stdout, rel)
37+
return nil
2138
}

‎internal/activitypub/client.go

+46-34
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,50 @@ import (
44
"context"
55
"crypto"
66
"crypto/rsa"
7-
"crypto/x509"
8-
"encoding/pem"
9-
"errors"
107
"fmt"
118
"net/http"
9+
"os"
1210

1311
"github.com/carlmjohnson/requests"
1412
"github.com/davecheney/pub/internal/httpsig"
15-
"github.com/davecheney/pub/models"
13+
"github.com/go-json-experiment/json"
1614
)
1715

16+
// ClientKey is the key used to store the ActivityPub client in the context.
17+
var ClientKey = struct{}{}
18+
19+
// FromContext returns the ActivityPub client from the given context.
20+
func FromContext(ctx context.Context) (*Client, bool) {
21+
c, ok := ctx.Value(ClientKey).(*Client)
22+
return c, ok
23+
}
24+
25+
// WithClient returns a new context with the given ActivityPub client.
26+
func WithClient(ctx context.Context, c *Client) context.Context {
27+
return context.WithValue(ctx, ClientKey, c)
28+
}
29+
1830
// Client is an ActivityPub client which can be used to fetch remote
1931
// ActivityPub resources.
2032
type Client struct {
2133
keyID string
2234
privateKey crypto.PrivateKey
2335
}
2436

25-
// NewClient returns a new ActivityPub client.
26-
func NewClient(signAs *models.Account) (*Client, error) {
27-
privPem, _ := pem.Decode(signAs.PrivateKey)
28-
if privPem == nil || privPem.Type != "RSA PRIVATE KEY" {
29-
return nil, errors.New("expected RSA PRIVATE KEY")
30-
}
31-
32-
var parsedKey interface{}
33-
var err error
34-
if parsedKey, err = x509.ParsePKCS1PrivateKey(privPem.Bytes); err != nil {
35-
if parsedKey, err = x509.ParsePKCS8PrivateKey(privPem.Bytes); err != nil { // note this returns type `interface{}`
36-
return nil, err
37-
}
38-
}
37+
// Signer represents an object that can sign HTTP requests.
38+
type Signer interface {
39+
PublicKeyID() string
40+
PrivKey() (*rsa.PrivateKey, error)
41+
}
3942

40-
privateKey, ok := parsedKey.(*rsa.PrivateKey)
41-
if !ok {
42-
return nil, errors.New("expected *rsa.PrivateKey")
43+
// NewClient returns a new ActivityPub client.
44+
func NewClient(signAs Signer) (*Client, error) {
45+
privateKey, err := signAs.PrivKey()
46+
if err != nil {
47+
return nil, err
4348
}
44-
4549
return &Client{
46-
keyID: signAs.Actor.PublicKeyID(),
50+
keyID: signAs.PublicKeyID(),
4751
privateKey: privateKey,
4852
}, nil
4953
}
@@ -52,7 +56,12 @@ func NewClient(signAs *models.Account) (*Client, error) {
5256
func (c *Client) Fetch(ctx context.Context, uri string, obj interface{}) error {
5357
return requests.URL(uri).
5458
Accept(`application/ld+json; profile="https://www.w3.org/ns/activitystreams"`).
55-
Transport(c).
59+
Transport(requests.RoundTripFunc(func(req *http.Request) (*http.Response, error) {
60+
if err := httpsig.Sign(req, c.keyID, c.privateKey, nil); err != nil {
61+
return nil, fmt.Errorf("failed to sign request: %w", err)
62+
}
63+
return http.DefaultTransport.RoundTrip(req)
64+
})).
5665
CheckContentType(
5766
"application/ld+json",
5867
"application/activity+json",
@@ -64,19 +73,22 @@ func (c *Client) Fetch(ctx context.Context, uri string, obj interface{}) error {
6473
Fetch(ctx)
6574
}
6675

67-
func (c *Client) RoundTrip(req *http.Request) (*http.Response, error) {
68-
if err := httpsig.Sign(req, c.keyID, c.privateKey, nil); err != nil {
69-
return nil, fmt.Errorf("failed to sign request: %w", err)
70-
}
71-
return http.DefaultTransport.RoundTrip(req)
72-
}
73-
7476
// Post posts the given ActivityPub object to the given URL.
7577
func (c *Client) Post(ctx context.Context, url string, obj map[string]any) error {
78+
body, err := json.Marshal(obj)
79+
if err != nil {
80+
return err
81+
}
7682
return requests.URL(url).
83+
BodyBytes(body).
7784
Header("Content-Type", `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`).
78-
BodyJSON(obj).
79-
Transport(c).
80-
CheckStatus(http.StatusOK, http.StatusCreated).
85+
Transport(requests.RoundTripFunc(func(req *http.Request) (*http.Response, error) {
86+
if err := httpsig.Sign(req, c.keyID, c.privateKey, body); err != nil {
87+
return nil, fmt.Errorf("failed to sign request: %w", err)
88+
}
89+
return http.DefaultTransport.RoundTrip(req)
90+
})).
91+
ToWriter(os.Stderr).
92+
CheckStatus(http.StatusOK, http.StatusCreated, http.StatusAccepted).
8193
Fetch(ctx)
8294
}

‎internal/crypto/crypto.go

+26
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"crypto/rsa"
77
"crypto/x509"
88
"encoding/pem"
9+
"errors"
910
)
1011

12+
// KeyPair represents a public/private keypair in PEM format.
1113
type Keypair struct {
1214
PublicKey []byte
1315
PrivateKey []byte
@@ -39,3 +41,27 @@ func GenerateRSAKeypair() (*Keypair, error) {
3941
PrivateKey: privateKeyPem,
4042
}, nil
4143
}
44+
45+
// ParseRSAPrivateKey parses a PEM encoded private key, and returns
46+
// the public key and private key.
47+
func ParseRSAPrivateKey(pemBytes []byte) (*rsa.PublicKey, *rsa.PrivateKey, error) {
48+
privPem, _ := pem.Decode(pemBytes)
49+
if privPem == nil || privPem.Type != "RSA PRIVATE KEY" {
50+
return nil, nil, errors.New("expected RSA PRIVATE KEY")
51+
}
52+
53+
var parsedKey interface{}
54+
var err error
55+
if parsedKey, err = x509.ParsePKCS1PrivateKey(privPem.Bytes); err != nil {
56+
if parsedKey, err = x509.ParsePKCS8PrivateKey(privPem.Bytes); err != nil { // note this returns type `interface{}`
57+
return nil, nil, err
58+
}
59+
}
60+
61+
switch privateKey := parsedKey.(type) {
62+
case *rsa.PrivateKey:
63+
return &privateKey.PublicKey, privateKey, nil
64+
default:
65+
return nil, nil, errors.New("expected *rsa.PrivateKey")
66+
}
67+
}

‎main.go

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var cli struct {
2424
DSN string `help:"data source name" default:"pub:pub@tcp(localhost:3306)/pub"`
2525

2626
AutoMigrate AutoMigrateCmd `cmd:"" help:"Automigrate the database."`
27-
BackfillActors BackfillActorsCmd `cmd:"" help:"Backfill actors."`
2827
CreateAccount CreateAccountCmd `cmd:"" help:"Create a new account."`
2928
CreateInstance CreateInstanceCmd `cmd:"" help:"Create a new instance."`
3029
DeleteAccount DeleteAccountCmd `cmd:"" help:"Delete an account."`

‎mastodon/mastodon.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"sort"
99
"strings"
1010

11+
"github.com/davecheney/pub/internal/activitypub"
1112
"github.com/davecheney/pub/internal/httpx"
1213
"github.com/davecheney/pub/internal/snowflake"
1314
"github.com/davecheney/pub/internal/streaming"
@@ -20,6 +21,7 @@ type Env struct {
2021
*gorm.DB
2122
*streaming.Mux
2223
Logger *slog.Logger
24+
Client *activitypub.Client
2325
}
2426

2527
func (e *Env) Log() *slog.Logger {

‎models/account.go

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package models
22

33
import (
4+
"crypto/rsa"
45
"time"
56

67
"github.com/davecheney/pub/internal/crypto"
@@ -36,6 +37,26 @@ func (a *Account) Domain() string {
3637
return a.Actor.Domain
3738
}
3839

40+
func (a *Account) PublicKeyID() string {
41+
return a.Actor.PublicKeyID()
42+
}
43+
44+
func (a *Account) PrivKey() (*rsa.PrivateKey, error) {
45+
_, privateKey, err := crypto.ParseRSAPrivateKey(a.PrivateKey)
46+
if err != nil {
47+
return nil, err
48+
}
49+
return privateKey, nil
50+
}
51+
52+
func (a *Account) PublicKey() (*rsa.PublicKey, error) {
53+
publicKey, _, err := crypto.ParseRSAPrivateKey(a.PrivateKey)
54+
if err != nil {
55+
return nil, err
56+
}
57+
return publicKey, nil
58+
}
59+
3960
type AccountRole struct {
4061
ID uint32 `gorm:"primaryKey"`
4162
CreatedAt time.Time
@@ -150,3 +171,8 @@ type AccountPreferences struct {
150171
ReadingExpandMedia string `gorm:"enum('default','show_all','hide_all');not null;default:'default'"`
151172
ReadingExpandSpoilers bool `gorm:"not null;default:false"`
152173
}
174+
175+
// PreloadAccount preloads all of an Account's relations and associations.
176+
func PreloadAccount(query *gorm.DB) *gorm.DB {
177+
return query.Preload("Actor").Preload("Actor.Object")
178+
}

‎models/object.go

+4-69
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ package models
22

33
import (
44
"context"
5-
"crypto"
6-
"crypto/rsa"
7-
"crypto/x509"
8-
"encoding/pem"
95
"errors"
106
"fmt"
117
"net/http"
128
"net/url"
139
"time"
1410

1511
"github.com/carlmjohnson/requests"
16-
"github.com/davecheney/pub/internal/httpsig"
12+
"github.com/davecheney/pub/internal/activitypub"
1713
"github.com/davecheney/pub/internal/snowflake"
1814
"gorm.io/gorm"
1915
)
@@ -244,77 +240,16 @@ func anyToSlice(v any) []any {
244240
}
245241

246242
func fetchObject(ctx context.Context, uri string) (map[string]any, error) {
247-
instance, ok := ctx.Value("instance").(*Instance)
243+
client, ok := activitypub.FromContext(ctx)
248244
if !ok {
249-
return nil, fmt.Errorf("no instance in context, got %T", ctx.Value("instance"))
250-
}
251-
252-
fmt.Println("fetching object:", "id", uri)
253-
client, err := NewClient(instance.Admin)
254-
if err != nil {
255-
return nil, err
245+
return nil, errors.New("no activitypub client in context")
256246
}
257247
var obj map[string]any
258-
err = client.Fetch(ctx, uri, &obj)
248+
err := client.Fetch(ctx, uri, &obj)
259249
// fmt.Println("fetched object:", "id", uri, "type", obj["type"], "error", err)
260250
return obj, err
261251
}
262252

263-
// Client is an ActivityPub client which can be used to fetch remote
264-
// ActivityPub resources.
265-
type Client struct {
266-
keyID string
267-
privateKey crypto.PrivateKey
268-
}
269-
270-
// NewClient returns a new ActivityPub client.
271-
func NewClient(signAs *Account) (*Client, error) {
272-
privPem, _ := pem.Decode(signAs.PrivateKey)
273-
if privPem == nil || privPem.Type != "RSA PRIVATE KEY" {
274-
return nil, errors.New("expected RSA PRIVATE KEY")
275-
}
276-
277-
var parsedKey interface{}
278-
var err error
279-
if parsedKey, err = x509.ParsePKCS1PrivateKey(privPem.Bytes); err != nil {
280-
if parsedKey, err = x509.ParsePKCS8PrivateKey(privPem.Bytes); err != nil { // note this returns type `interface{}`
281-
return nil, err
282-
}
283-
}
284-
285-
privateKey, ok := parsedKey.(*rsa.PrivateKey)
286-
if !ok {
287-
return nil, errors.New("expected *rsa.PrivateKey")
288-
}
289-
290-
return &Client{
291-
keyID: signAs.Actor.PublicKeyID(),
292-
privateKey: privateKey,
293-
}, nil
294-
}
295-
296-
// Fetch fetches the ActivityPub resource at the given URL and decodes it into the given object.
297-
func (c *Client) Fetch(ctx context.Context, uri string, obj interface{}) error {
298-
return requests.URL(uri).
299-
Accept(`application/ld+json; profile="https://www.w3.org/ns/activitystreams"`).
300-
Transport(c).
301-
CheckStatus(http.StatusOK). // check status first, so we don't get confused by the content type of an error page
302-
CheckContentType(
303-
"application/ld+json",
304-
"application/activity+json",
305-
"application/json",
306-
).
307-
ToJSON(obj).
308-
Fetch(ctx)
309-
}
310-
311-
func (c *Client) RoundTrip(req *http.Request) (*http.Response, error) {
312-
if err := httpsig.Sign(req, c.keyID, c.privateKey, nil); err != nil {
313-
return nil, fmt.Errorf("failed to sign request: %w", err)
314-
}
315-
return http.DefaultTransport.RoundTrip(req)
316-
}
317-
318253
func stringFromAny(v any) string {
319254
s, _ := v.(string)
320255
return s

‎models/status.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,20 @@ func (st *Status) Attachments() []*Attachment {
109109
Width: a.Width,
110110
Height: a.Height,
111111
Blurhash: a.Blurhash,
112-
// FocalPoint: FocalPoint{
113-
// X: func() float64 {
114-
// if len(a.FocalPoint) == 0 {
115-
// return 0
116-
// }
117-
// return a.FocalPoint[0]
118-
// }(),
119-
// Y: func() float64 {
120-
// if len(a.FocalPoint) < 2 {
121-
// return 0
122-
// }
123-
// return a.FocalPoint[1]
124-
// }(),
125-
// },
112+
FocalPoint: FocalPoint{
113+
X: func() float64 {
114+
if len(a.FocalPoint) == 0 {
115+
return 0
116+
}
117+
return a.FocalPoint[0]
118+
}(),
119+
Y: func() float64 {
120+
if len(a.FocalPoint) < 2 {
121+
return 0
122+
}
123+
return a.FocalPoint[1]
124+
}(),
125+
},
126126
}
127127
})
128128

‎oauth/oauth.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ func AuthorizeNew(env *activitypub.Env, w http.ResponseWriter, r *http.Request)
2222
ClientID string `json:"-" schema:"client_id,required"`
2323
RedirectURI string `json:"-" schema:"redirect_uri,required"`
2424
Scope string `json:"-" schema:"scope"`
25-
ForceLogin bool `json:"-" schema:"force_login"` // elk.zone, ignored
26-
Lang string `json:"-" schema:"lang"` // elk.zone, ignored
25+
ForceLogin bool `json:"-" schema:"force_login"` // elk.zone, ignored
26+
Lang string `json:"-" schema:"lang"` // elk.zone, ignored
27+
ClientSecret string `json:"-" schema:"client_secret"` // trunks, ignored
2728
}
2829
if err := httpx.Params(r, &params); err != nil {
2930
return err

‎oauth/oauth_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package oauth
2+
3+
import (
4+
"testing"
5+
6+
"github.com/davecheney/pub/models"
7+
"github.com/stretchr/testify/require"
8+
"gorm.io/driver/sqlite"
9+
"gorm.io/gorm"
10+
"gorm.io/gorm/logger"
11+
)
12+
13+
func setupTestDB(t *testing.T) *gorm.DB {
14+
t.Helper()
15+
require := require.New(t)
16+
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{
17+
TranslateError: true,
18+
Logger: logger.Default.LogMode(func() logger.LogLevel {
19+
return logger.Warn
20+
}()),
21+
})
22+
require.NoError(err)
23+
24+
err = db.AutoMigrate(models.AllTables()...)
25+
require.NoError(err)
26+
27+
// enable foreign key constraints
28+
err = db.Exec("PRAGMA foreign_keys = ON").Error
29+
require.NoError(err)
30+
31+
return db
32+
}

‎serve.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/davecheney/pub/activitypub"
15+
ap "github.com/davecheney/pub/internal/activitypub"
1516
"github.com/davecheney/pub/internal/httpx"
1617
"github.com/davecheney/pub/internal/streaming"
1718
"github.com/davecheney/pub/mastodon"
@@ -43,6 +44,16 @@ func (s *ServeCmd) Run(ctx *Context) error {
4344
return err
4445
}
4546

47+
var admin models.Account
48+
if err := db.Scopes(models.PreloadAccount).Joins("Actor", "name = ? and type = ?", "admin", "LocalService").Take(&admin).Error; err != nil {
49+
return err
50+
}
51+
52+
client, err := ap.NewClient(&admin)
53+
if err != nil {
54+
return err
55+
}
56+
4657
r := chi.NewRouter()
4758
r.Use(middleware.RequestID)
4859
r.Use(middleware.RealIP)
@@ -62,9 +73,10 @@ func (s *ServeCmd) Run(ctx *Context) error {
6273
r.Route("/api", func(r chi.Router) {
6374
envFn := func(r *http.Request) *mastodon.Env {
6475
return &mastodon.Env{
65-
DB: db.WithContext(r.Context()),
76+
DB: db.WithContext(ap.WithClient(r.Context(), client)),
6677
Mux: &mux,
6778
Logger: ctx.Logger,
79+
Client: client,
6880
}
6981
}
7082
r.Route("/v1", func(r chi.Router) {
@@ -161,9 +173,10 @@ func (s *ServeCmd) Run(ctx *Context) error {
161173
}
162174

163175
return &activitypub.Env{
164-
DB: db.WithContext(context.WithValue(r.Context(), "instance", instance)),
176+
DB: db.WithContext(ap.WithClient(r.Context(), client)),
165177
Mux: &mux,
166178
Logger: ctx.Logger,
179+
Client: client,
167180
Instance: instance,
168181
}
169182
}
@@ -243,10 +256,7 @@ func (s *ServeCmd) Run(ctx *Context) error {
243256

244257
// ActorRefreshProcessor needs an admin account to sign the activitypub requests.
245258
// Pick _an_ admin account, it doesn't matter which one.
246-
// var admin models.Account
247-
// if err := db.Joins("Actor", "name = ? and type = ?", "admin", "LocalService").Take(&admin).Error; err != nil {
248-
// return err
249-
// }
259+
250260
// g.Add(workers.NewActorRefreshProcessor(db, &admin, ctx.Logger.With("worker", "ActorRefreshProcessor")))
251261

252262
return g.Wait()

‎workers/reactions.go

-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ func processReactionRequest(db *gorm.DB, request *models.ReactionRequest) error
4545
return err
4646
}
4747

48-
inbox := request.Target.Actor.Inbox()
49-
if inbox == "" {
50-
if err := models.NewActors(db).Refresh(request.Target.Actor); err != nil {
51-
return err
52-
}
53-
return fmt.Errorf("no inbox for actor %q", request.Target.Actor.URI())
54-
}
55-
5648
switch request.Action {
5749
case "like":
5850
return activitypub.Like(db.Statement.Context, account, request.Target)

0 commit comments

Comments
 (0)
Please sign in to comment.