2022-11-27 00:34:24 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-12-31 17:58:01 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-11-27 00:34:24 +00:00
|
|
|
|
|
|
|
package activitypub
|
|
|
|
|
|
|
|
import (
|
2022-12-29 23:13:48 +00:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2022-11-27 00:34:24 +00:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-12-29 23:13:48 +00:00
|
|
|
"code.gitea.io/gitea/modules/forgefed"
|
2022-11-27 00:34:24 +00:00
|
|
|
|
|
|
|
ap "github.com/go-ap/activitypub"
|
|
|
|
)
|
|
|
|
|
2022-12-26 17:43:31 +00:00
|
|
|
// Create Follow activity
|
2022-12-31 17:58:01 +00:00
|
|
|
func Follow(actorUser, followUser *user_model.User) *ap.Follow {
|
2022-11-27 00:34:24 +00:00
|
|
|
object := ap.PersonNew(ap.IRI(followUser.LoginName))
|
2022-12-31 17:58:01 +00:00
|
|
|
follow := ap.FollowNew("", object)
|
2022-11-28 19:22:23 +00:00
|
|
|
follow.Actor = ap.PersonNew(ap.IRI(actorUser.GetIRI()))
|
2022-11-27 00:34:24 +00:00
|
|
|
follow.To = ap.ItemCollection{ap.Item(ap.IRI(followUser.LoginName + "/inbox"))}
|
2022-12-31 17:58:01 +00:00
|
|
|
return follow
|
2022-11-27 00:34:24 +00:00
|
|
|
}
|
|
|
|
|
2022-12-26 17:43:31 +00:00
|
|
|
// Create Undo Follow activity
|
2022-12-31 17:58:01 +00:00
|
|
|
func Unfollow(actorUser, followUser *user_model.User) *ap.Undo {
|
|
|
|
unfollow := ap.UndoNew("", Follow(actorUser, followUser))
|
2022-12-30 00:07:00 +00:00
|
|
|
unfollow.Actor = ap.PersonNew(ap.IRI(actorUser.GetIRI()))
|
2022-11-27 00:34:24 +00:00
|
|
|
unfollow.To = ap.ItemCollection{ap.Item(ap.IRI(followUser.LoginName + "/inbox"))}
|
2022-12-31 17:58:01 +00:00
|
|
|
return unfollow
|
2022-12-29 23:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create Like activity
|
2022-12-31 17:58:01 +00:00
|
|
|
func Star(user *user_model.User, repo *repo_model.Repository) *ap.Like {
|
|
|
|
like := ap.LikeNew("", forgefed.RepositoryNew(ap.IRI(repo.GetIRI())))
|
2022-12-29 23:13:48 +00:00
|
|
|
like.Actor = ap.PersonNew(ap.IRI(user.GetIRI()))
|
|
|
|
like.To = ap.ItemCollection{ap.IRI(repo.GetIRI() + "/inbox")}
|
2022-12-31 17:58:01 +00:00
|
|
|
return like
|
2022-11-27 00:34:24 +00:00
|
|
|
}
|
2022-12-30 00:07:00 +00:00
|
|
|
|
|
|
|
// Create Undo Like activity
|
2022-12-31 17:58:01 +00:00
|
|
|
func Unstar(user *user_model.User, repo *repo_model.Repository) *ap.Undo {
|
|
|
|
unlike := ap.UndoNew("", Star(user, repo))
|
|
|
|
unlike.Actor = ap.PersonNew(ap.IRI(user.GetIRI()))
|
|
|
|
unlike.To = ap.ItemCollection{ap.IRI(repo.GetIRI() + "/inbox")}
|
|
|
|
return unlike
|
2022-12-30 00:07:00 +00:00
|
|
|
}
|