Merge branch 'forgejo-federated-star' of codeberg.org:meissa/forgejo into forgejo-federated-star

This commit is contained in:
Michael Jerger 2024-03-28 15:21:40 +01:00
parent fc8e2b3f8a
commit e2b11b93bc
4 changed files with 9 additions and 23 deletions

View file

@ -14,10 +14,10 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/forgefed"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/convert"
"code.gitea.io/gitea/services/repository"
)
// getStarredRepos returns the repos that the user with the specified userID has
@ -157,7 +157,7 @@ func Star(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
err := forgefed.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, true)
err := repository.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, true)
if err != nil {
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
return
@ -188,7 +188,7 @@ func Unstar(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
err := forgefed.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, false)
err := repository.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, false)
if err != nil {
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
return

View file

@ -23,7 +23,6 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/forgefed"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
@ -34,6 +33,7 @@ import (
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/convert"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/repository"
repo_service "code.gitea.io/gitea/services/repository"
archiver_service "code.gitea.io/gitea/services/repository/archiver"
)
@ -318,9 +318,9 @@ func Action(ctx *context.Context) {
case "unwatch":
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
case "star":
err = forgefed.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, true)
err = repository.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, true)
case "unstar":
err = forgefed.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, false)
err = repository.StarRepoAndFederate(ctx, *ctx.Doer, ctx.Repo.Repository.ID, false)
case "accept_transfer":
err = acceptOrRejectRepoTransfer(ctx, true)
case "reject_transfer":

View file

@ -82,7 +82,7 @@ func ProcessLikeActivity(ctx context.Context, form any, repositoryID int64) (int
// execute the activity if the repo was not stared already
alreadyStared := repo.IsStaring(ctx, user.ID, repositoryID)
if !alreadyStared {
err = StarRepoAndFederate(ctx, *user, repositoryID, true)
err = repo.StarRepo(ctx, user.ID, repositoryID, true)
if err != nil {
return http.StatusNotAcceptable, "Error staring", err
}
@ -271,17 +271,3 @@ func SendLikeActivities(ctx context.Context, doer user.User, repoID int64) error
return nil
}
func StarRepoAndFederate(ctx context.Context, doer user.User, repoID int64, star bool) error {
if err := repo.StarRepo(ctx, doer.ID, repoID, star); err != nil {
return err
}
if star && setting.Federation.Enabled {
if err := SendLikeActivities(ctx, doer, repoID); err != nil {
return err
}
}
return nil
}

View file

@ -12,8 +12,8 @@ import (
"code.gitea.io/gitea/services/federation"
)
func StarRepo(ctx context.Context, doer user.User, repoID int64, star bool) error {
if err := repo.StarLocalRepo(ctx, doer.ID, repoID, star); err != nil {
func StarRepoAndFederate(ctx context.Context, doer user.User, repoID int64, star bool) error {
if err := repo.StarRepo(ctx, doer.ID, repoID, star); err != nil {
return err
}