This commit is contained in:
parent
e7632c6ad4
commit
2c0a4c88d5
1 changed files with 33 additions and 6 deletions
|
@ -30,7 +30,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
|
||||||
log := hlog.FromRequest(r)
|
log := hlog.FromRequest(r)
|
||||||
userId := r.PathValue("id")
|
userId := r.PathValue("id")
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
log.Info().
|
log.Trace().
|
||||||
Err(err).
|
Err(err).
|
||||||
Str("userId", userId).
|
Str("userId", userId).
|
||||||
Bytes("body", body).
|
Bytes("body", body).
|
||||||
|
@ -268,6 +268,11 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
follower, err := activitypub.ImportRemoteAccountByAPUrl(actorApId)
|
follower, err := activitypub.ImportRemoteAccountByAPUrl(actorApId)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("Failed to import following account")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
u2u := dbgen.UserToUserRelation
|
u2u := dbgen.UserToUserRelation
|
||||||
followRelations, err := u2u.Where(
|
followRelations, err := u2u.Where(
|
||||||
u2u.UserId.Eq(follower.ID),
|
u2u.UserId.Eq(follower.ID),
|
||||||
|
@ -297,7 +302,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
}
|
}
|
||||||
err = tx.UserToUserRelation.Create(&req)
|
err = tx.UserToUserRelation.Create(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
_ = tx.Rollback()
|
||||||
log.Error().Err(err).Any("follow-request", req).Msg("Failed to store follow request")
|
log.Error().Err(err).Any("follow-request", req).Msg("Failed to store follow request")
|
||||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
@ -310,7 +315,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
}
|
}
|
||||||
err = tx.Activity.Create(&activity)
|
err = tx.Activity.Create(&activity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
_ = tx.Rollback()
|
||||||
log.Error().Err(err).Any("activity", activity).Msg("Failed to store follow activity")
|
log.Error().Err(err).Any("activity", activity).Msg("Failed to store follow activity")
|
||||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
@ -318,11 +323,18 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Failed to commit follow activity transaction")
|
log.Error().Err(err).Msg("Failed to commit follow activity transaction")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !followed.RestrictedFollow {
|
if !followed.RestrictedFollow {
|
||||||
// FIXME: Handle errors
|
|
||||||
tx = dbgen.Q.Begin()
|
tx = dbgen.Q.Begin()
|
||||||
_, err = u2u.Where(u2u.ID.Eq(req.ID)).UpdateColumn(u2u.Relation, models.RelationFollow)
|
_, err = u2u.Where(u2u.ID.Eq(req.ID)).UpdateColumn(u2u.Relation, models.RelationFollow)
|
||||||
|
if err != nil {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
log.Error().Err(err).Msg("Failed to update follow to confirmed")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
acceptActivity := models.Activity{
|
acceptActivity := models.Activity{
|
||||||
Id: shared.NewId(),
|
Id: shared.NewId(),
|
||||||
Type: string(models.ActivityAccept),
|
Type: string(models.ActivityAccept),
|
||||||
|
@ -330,9 +342,20 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
ObjectType: uint32(models.ActivitystreamsActivityTargetActivity),
|
ObjectType: uint32(models.ActivitystreamsActivityTargetActivity),
|
||||||
}
|
}
|
||||||
err = tx.Activity.Create(&acceptActivity)
|
err = tx.Activity.Create(&acceptActivity)
|
||||||
tx.Commit()
|
if err != nil {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
log.Error().Err(err).Msg("Failed to store accept activity in db")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = tx.Commit()
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("Failed to commit follow accept to db")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
// FIXME: Clean this entire mess up
|
// TODO: Maybe move this part to a separate function
|
||||||
time.Sleep(time.Millisecond * 20)
|
time.Sleep(time.Millisecond * 20)
|
||||||
webAccept, err := AcceptFromStorage(r.Context(), acceptActivity.Id)
|
webAccept, err := AcceptFromStorage(r.Context(), acceptActivity.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -345,6 +368,10 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
log.Error().Err(err).Msg("Failed to marshal accept")
|
log.Error().Err(err).Msg("Failed to marshal accept")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Debug().
|
||||||
|
Bytes("body", body).
|
||||||
|
Str("target", follower.RemoteInfo.InboxLink).
|
||||||
|
Msg("Sending follow accept out")
|
||||||
res, err := webshared.RequestSignedCavage(
|
res, err := webshared.RequestSignedCavage(
|
||||||
"POST",
|
"POST",
|
||||||
follower.RemoteInfo.InboxLink,
|
follower.RemoteInfo.InboxLink,
|
||||||
|
|
Loading…
Reference in a new issue