forgejo/modules/forgefed/star.go

67 lines
1.3 KiB
Go
Raw Normal View History

2023-11-07 09:30:32 +01:00
// Copyright 2023 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package forgefed
import (
2023-11-09 15:38:55 +01:00
"code.gitea.io/gitea/modules/context"
2023-11-07 09:30:32 +01:00
ap "github.com/go-ap/activitypub"
)
type (
SourceType string
)
type SourceTypes []SourceType
const (
StarType ap.ActivityVocabularyType = "Star"
)
const (
ForgejoSourceType SourceType = "frogejo"
)
var KnownSourceTypes = SourceTypes{
ForgejoSourceType,
}
2023-11-09 14:24:19 +01:00
// Star activity data type
2023-11-09 21:59:51 +01:00
// swagger:model
2023-11-07 09:30:32 +01:00
type Star struct {
2023-11-09 21:54:17 +01:00
// swagger:ignore
2023-11-07 09:30:32 +01:00
ap.Activity
2023-11-09 14:24:19 +01:00
// Source identifies the system which generated this activity. Exactly one value has to be specified.
2023-11-07 09:30:32 +01:00
Source SourceType `jsonld:"source,omitempty"`
}
2023-11-09 15:38:55 +01:00
// Infos needed to star a repo
type StarRepo struct {
StargazerID int `json:"Stargazer"`
RepoID int `json:"RepoToStar"`
}
// StarNew initializes a Star type activity
// Guess: no return value needed, we may need to add the star to the context
2023-11-07 09:30:32 +01:00
func StarNew(id ap.ID, ob ap.ID) *Star {
a := ap.ActivityNew(id, StarType, ob)
2023-11-09 15:38:55 +01:00
o := Star{Activity: *a, Source: ForgejoSourceType}
2023-11-07 09:30:32 +01:00
return &o
}
2023-11-09 15:38:55 +01:00
func AddStar(ctx *context.APIContext) {
}
func (a Star) MarshalJSON() ([]byte, error) {
b := make([]byte, 0)
ap.JSONWrite(&b, '{')
ap.JSONWriteStringProp(&b, "source", string(a.Source))
if !ap.JSONWriteActivityValue(&b, a.Activity) {
return nil, nil
}
ap.JSONWrite(&b, '}')
return b, nil
}