From 745598bba4ea70743fb284e0d6886a58777729fa Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 7 Dec 2023 13:24:01 +0100 Subject: [PATCH] Implement starring --- routers/api/v1/activitypub/repository.go | 30 +++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/routers/api/v1/activitypub/repository.go b/routers/api/v1/activitypub/repository.go index 0b077f7b91..3596f94bb4 100644 --- a/routers/api/v1/activitypub/repository.go +++ b/routers/api/v1/activitypub/repository.go @@ -297,14 +297,32 @@ func RepositoryInbox(ctx *context.APIContext) { } } - } else { - // use first user - user := users[0] - log.Info("%v", user) + remoteUser, err := user_model.GetUserByEmail(ctx, user.Email) + if err != nil { + ctx.Error(http.StatusInternalServerError, "StarRepo", err) + return } - // TODO: handle case of count > 1 - // execute star action + // check if already starred by this user + alreadyStared := repo_model.IsStaring(ctx, remoteUser.ID, ctx.Repo.Repository.ID) + switch alreadyStared { + case true: // execute unstar action + { + err = repo_model.StarRepo(ctx, remoteUser.ID, ctx.Repo.Repository.ID, false) + if err != nil { + ctx.Error(http.StatusInternalServerError, "StarRepo", err) + return + } + } + case false: // execute star action + { + err = repo_model.StarRepo(ctx, remoteUser.ID, ctx.Repo.Repository.ID, true) + if err != nil { + ctx.Error(http.StatusInternalServerError, "StarRepo", err) + return + } + } + } // wait 15 sec.