Follow accept works and messags are pushed as expected
Some checks failed
/ docker (push) Failing after 2m50s
Some checks failed
/ docker (push) Failing after 2m50s
This commit is contained in:
parent
9a3a330b1d
commit
ff6a730e58
10 changed files with 482 additions and 19 deletions
|
@ -1,5 +1,75 @@
|
|||
package activitypub
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
func activityAccept(w http.ResponseWriter, r *http.Request) {}
|
||||
webutils "git.mstar.dev/mstar/goutils/http"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/activitypub"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||
)
|
||||
|
||||
type ActivityAcceptOut struct {
|
||||
Context any `json:"@context,omitempty"`
|
||||
Id string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Actor string `json:"actor"`
|
||||
Object any `json:"object"`
|
||||
}
|
||||
|
||||
func activityAccept(w http.ResponseWriter, r *http.Request) {
|
||||
log := hlog.FromRequest(r)
|
||||
id := r.PathValue("id")
|
||||
activity, err := CreateFromStorage(r.Context(), id)
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
case nil:
|
||||
activity.Context = activitypub.BaseLdContext
|
||||
data, err := json.Marshal(activity)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Add("Content-Type", "application/activity+json")
|
||||
fmt.Fprint(w, string(data))
|
||||
default:
|
||||
if storage.HandleReconnectError(err) {
|
||||
log.Error().Err(err).Msg("Connection failed, restart attempt started")
|
||||
} else {
|
||||
log.Error().Err(err).Msg("Failed to get create activity from db")
|
||||
}
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func AcceptFromStorage(ctx context.Context, id string) (*ActivityAcceptOut, error) {
|
||||
a := dbgen.Activity
|
||||
activity, err := a.Where(a.Id.Eq(id), a.Type.Eq(string(models.ActivityAccept))).First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// switch activity.ObjectType {
|
||||
// case models.ActivitystreamsActivityTargetFollow:
|
||||
// default:
|
||||
// return nil, errors.New("unknown activity target type")
|
||||
// }
|
||||
follow, err := FollowFromStorage(ctx, activity.ObjectId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ActivityAcceptOut{
|
||||
Id: id,
|
||||
Actor: follow.Object.(string),
|
||||
Type: "Accept",
|
||||
Object: follow,
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue