moved functionality

import of forgefed causes circular dependencies. This has to be solved!
This commit is contained in:
Clemens 2024-03-26 10:23:14 +01:00
parent d251fc2611
commit 7f0371056e
2 changed files with 42 additions and 31 deletions

View file

@ -7,7 +7,9 @@ import (
"context"
"code.gitea.io/gitea/models/db"
//"code.gitea.io/gitea/models/forgefed"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
)
@ -23,6 +25,7 @@ func init() {
db.RegisterModel(new(Star))
}
// TODO: why is this ctx not type *context.APIContext, as in routers/api/v1/user/star.go?
// StarRepo or unstar repository.
func StarRepo(ctx context.Context, userID, repoID int64, star bool) error {
ctx, committer, err := db.TxContext(ctx)
@ -46,6 +49,9 @@ func StarRepo(ctx context.Context, userID, repoID int64, star bool) error {
if _, err := db.Exec(ctx, "UPDATE `user` SET num_stars = num_stars + 1 WHERE id = ?", userID); err != nil {
return err
}
if err := SendLikeActivities(ctx, userID); err != nil {
return err
}
} else {
if !staring {
return nil
@ -65,6 +71,42 @@ func StarRepo(ctx context.Context, userID, repoID int64, star bool) error {
return committer.Commit()
}
// TODO: solve circular dependencies caused by import of forgefed!
func SendLikeActivities(ctx context.Context, userID int64) error {
if setting.Federation.Enabled {
/*likeActivity, err := forgefed.NewForgeLike(ctx)
if err != nil {
return err
}
json, err := likeActivity.MarshalJSON()
if err != nil {
return err
}
// TODO: is user loading necessary here?
user, err := user_model.GetUserByID(ctx, userID)
if err != nil {
return err
}
apclient, err := activitypub.NewClient(ctx, user, user.APAPIURL())
if err != nil {
return err
}
// TODO: set timeouts for outgoing request in oder to mitigate DOS by slow lories
// ToDo: Change this to the standalone table of FederatedRepos
for _, target := range strings.Split(ctx.Repo.Repository.FederationRepos, ";") {
apclient.Post([]byte(json), target)
}
*/
// Send to list of federated repos
}
return nil
}
// IsStaring checks if user has starred given repository.
func IsStaring(ctx context.Context, userID, repoID int64) bool {
has, _ := db.GetEngine(ctx).Get(&Star{UID: userID, RepoID: repoID})