Follow accept works and messags are pushed as expected
Some checks failed
/ docker (push) Failing after 2m50s

This commit is contained in:
Melody Becker 2025-05-10 11:18:28 +02:00
parent 9a3a330b1d
commit ff6a730e58
Signed by: mstar
SSH key fingerprint: SHA256:vkXfS9FG2pVNVfvDrzd1VW9n8VJzqqdKQGljxxX8uK8
10 changed files with 482 additions and 19 deletions

View file

@ -4,6 +4,7 @@ import (
"database/sql"
"encoding/json"
"errors"
"io"
"net/http"
webutils "git.mstar.dev/mstar/goutils/http"
@ -11,10 +12,12 @@ import (
"github.com/rs/zerolog/hlog"
"gorm.io/gorm"
"git.mstar.dev/mstar/linstrom/activitypub"
"git.mstar.dev/mstar/linstrom/shared"
"git.mstar.dev/mstar/linstrom/storage-new"
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
"git.mstar.dev/mstar/linstrom/storage-new/models"
webap "git.mstar.dev/mstar/linstrom/web/public/api/activitypub"
webshared "git.mstar.dev/mstar/linstrom/web/shared"
)
@ -66,7 +69,8 @@ func postAs(w http.ResponseWriter, r *http.Request) {
AccessLevel: models.NOTE_TARGET_PUBLIC,
OriginId: 1,
}
err = n.Select(
tx := dbgen.Q.Begin()
err = tx.Note.Select(
n.ID,
n.CreatorId,
n.RawContent,
@ -78,6 +82,7 @@ func postAs(w http.ResponseWriter, r *http.Request) {
n.OriginId,
).Create(&note)
if err != nil {
_ = tx.Rollback()
log.Error().
Err(err).
Str("username", data.Username).
@ -92,11 +97,51 @@ func postAs(w http.ResponseWriter, r *http.Request) {
ObjectId: note.ID,
ObjectType: uint32(models.ActivitystreamsActivityTargetNote),
}
a := dbgen.Activity
err = a.Create(&activity)
err = tx.Activity.Create(&activity)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Msg("Failed to create activity for new note")
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to commit note creation")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
u2u := dbgen.UserToUserRelation
links, err := u2u.GetFollowersForId(user.ID)
if err != nil {
log.Error().Err(err).Msg("Failed to get follower inbox links for user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
log.Debug().Strs("links", links).Send()
act, err := webap.CreateFromStorage(r.Context(), activity.Id)
if err != nil {
log.Error().Err(err).Msg("Failed to fetch and format new note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
act.Context = activitypub.BaseLdContext
outData, err := json.Marshal(act)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal new note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
for _, link := range links {
log.Debug().Str("target-inbox", link).Msg("Sending message to")
go func() {
res, err := webshared.RequestSignedCavage("POST", link, outData, user)
if err != nil {
log.Warn().Err(err).Str("link", link).Msg("Failed to send create to target inbox")
}
if res.StatusCode >= 400 {
body, _ := io.ReadAll(res.Body)
log.Warn().Int("status-code", res.StatusCode).Bytes("body", body).Msg("Bad reply")
}
}()
}
}
func notesFrom(w http.ResponseWriter, r *http.Request) {