mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-25 11:16:11 +01:00
Merge branch 'forgejo-federated-star' of codeberg.org:meissa/forgejo into forgejo-federated-star
This commit is contained in:
parent
fc8e2b3f8a
commit
e2b11b93bc
|
@ -14,10 +14,10 @@ import (
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/forgefed"
|
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
"code.gitea.io/gitea/services/convert"
|
"code.gitea.io/gitea/services/convert"
|
||||||
|
"code.gitea.io/gitea/services/repository"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getStarredRepos returns the repos that the user with the specified userID has
|
// getStarredRepos returns the repos that the user with the specified userID has
|
||||||
|
@ -157,7 +157,7 @@ func Star(ctx *context.APIContext) {
|
||||||
// "404":
|
// "404":
|
||||||
// "$ref": "#/responses/notFound"
|
// "$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 {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||||
return
|
return
|
||||||
|
@ -188,7 +188,7 @@ func Unstar(ctx *context.APIContext) {
|
||||||
// "404":
|
// "404":
|
||||||
// "$ref": "#/responses/notFound"
|
// "$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 {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/cache"
|
"code.gitea.io/gitea/modules/cache"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/forgefed"
|
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
repo_module "code.gitea.io/gitea/modules/repository"
|
repo_module "code.gitea.io/gitea/modules/repository"
|
||||||
|
@ -34,6 +33,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
"code.gitea.io/gitea/services/convert"
|
"code.gitea.io/gitea/services/convert"
|
||||||
"code.gitea.io/gitea/services/forms"
|
"code.gitea.io/gitea/services/forms"
|
||||||
|
"code.gitea.io/gitea/services/repository"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
||||||
)
|
)
|
||||||
|
@ -318,9 +318,9 @@ func Action(ctx *context.Context) {
|
||||||
case "unwatch":
|
case "unwatch":
|
||||||
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||||
case "star":
|
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":
|
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":
|
case "accept_transfer":
|
||||||
err = acceptOrRejectRepoTransfer(ctx, true)
|
err = acceptOrRejectRepoTransfer(ctx, true)
|
||||||
case "reject_transfer":
|
case "reject_transfer":
|
||||||
|
|
|
@ -82,7 +82,7 @@ func ProcessLikeActivity(ctx context.Context, form any, repositoryID int64) (int
|
||||||
// execute the activity if the repo was not stared already
|
// execute the activity if the repo was not stared already
|
||||||
alreadyStared := repo.IsStaring(ctx, user.ID, repositoryID)
|
alreadyStared := repo.IsStaring(ctx, user.ID, repositoryID)
|
||||||
if !alreadyStared {
|
if !alreadyStared {
|
||||||
err = StarRepoAndFederate(ctx, *user, repositoryID, true)
|
err = repo.StarRepo(ctx, user.ID, repositoryID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusNotAcceptable, "Error staring", err
|
return http.StatusNotAcceptable, "Error staring", err
|
||||||
}
|
}
|
||||||
|
@ -271,17 +271,3 @@ func SendLikeActivities(ctx context.Context, doer user.User, repoID int64) error
|
||||||
|
|
||||||
return nil
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
"code.gitea.io/gitea/services/federation"
|
"code.gitea.io/gitea/services/federation"
|
||||||
)
|
)
|
||||||
|
|
||||||
func StarRepo(ctx context.Context, doer user.User, repoID int64, star bool) error {
|
func StarRepoAndFederate(ctx context.Context, doer user.User, repoID int64, star bool) error {
|
||||||
if err := repo.StarLocalRepo(ctx, doer.ID, repoID, star); err != nil {
|
if err := repo.StarRepo(ctx, doer.ID, repoID, star); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue