2023-07-14 13:23:55 +00:00
|
|
|
package activitypub
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2023-07-17 13:39:41 +00:00
|
|
|
|
|
|
|
"github.com/xeronith/diamante/utility"
|
2023-07-14 13:23:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Follow struct {
|
2023-07-17 13:39:41 +00:00
|
|
|
Context string `json:"@context" validate:"activitystream"`
|
|
|
|
UniqueIdentifier string `json:"-"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Actor string `json:"actor"`
|
|
|
|
Object string `json:"object"`
|
2023-07-14 13:23:55 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 13:39:41 +00:00
|
|
|
func NewFollow(follower, followee string) *Follow {
|
|
|
|
uuid := utility.GenerateUUID()
|
2023-07-14 13:23:55 +00:00
|
|
|
return &Follow{
|
2023-07-17 13:39:41 +00:00
|
|
|
Context: ActivityStreams,
|
|
|
|
UniqueIdentifier: uuid,
|
|
|
|
Id: fmt.Sprintf("%s#follow/%s", follower, uuid),
|
|
|
|
Type: TypeFollow,
|
|
|
|
Actor: follower,
|
|
|
|
Object: followee,
|
2023-07-14 13:23:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func UnmarshalFollow(data []byte) (Follow, error) {
|
|
|
|
var follow Follow
|
|
|
|
err := json.Unmarshal(data, &follow)
|
|
|
|
return follow, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (follow *Follow) Marshal() ([]byte, error) {
|
|
|
|
return json.Marshal(follow)
|
|
|
|
}
|