MCPcopy Index your code
hub / github.com/writefreely/writefreely / apAddRemoteUser

Function apAddRemoteUser

database_activitypub.go:20–49  ·  view source on GitHub ↗
(app *App, t *sql.Tx, fullActor *activitystreams.Person)

Source from the content-addressed store, hash-verified

18)
19
20func apAddRemoteUser(app *App, t *sql.Tx, fullActor *activitystreams.Person) (int64, error) {
21 // Add remote user locally, since it wasn't found before
22 res, err := t.Exec("INSERT INTO remoteusers (actor_id, inbox, shared_inbox, url) VALUES (?, ?, ?, ?)", fullActor.ID, fullActor.Inbox, fullActor.Endpoints.SharedInbox, fullActor.URL)
23 if err != nil {
24 t.Rollback()
25 return -1, fmt.Errorf("couldn't add new remoteuser in DB: %v", err)
26 }
27
28 remoteUserID, err := res.LastInsertId()
29 if err != nil {
30 t.Rollback()
31 return -1, fmt.Errorf("no lastinsertid for followers, rolling back: %v", err)
32 }
33
34 // Add in key
35 _, err = t.Exec("INSERT INTO remoteuserkeys (id, remote_user_id, public_key) VALUES (?, ?, ?)", fullActor.PublicKey.ID, remoteUserID, fullActor.PublicKey.PublicKeyPEM)
36 if err != nil {
37 if !app.db.isDuplicateKeyErr(err) {
38 t.Rollback()
39 log.Error("Couldn't add follower keys in DB: %v\n", err)
40 return -1, fmt.Errorf("couldn't add follower keys in DB: %v", err)
41 } else {
42 t.Rollback()
43 log.Error("Couldn't add follower keys in DB: %v\n", err)
44 return -1, fmt.Errorf("couldn't add follower keys in DB: %v", err)
45 }
46 }
47
48 return remoteUserID, nil
49}

Callers 1

Calls 1

isDuplicateKeyErrMethod · 0.45

Tested by

no test coverage detected