linstrom/activitypub/translators/like.go
mStar 8947d97825
Some checks failed
/ docker (push) Failing after 1m35s
Prep for reactions, some fixes and improvements
2025-06-16 08:13:11 +02:00

55 lines
1.5 KiB
Go

package translators
import (
"context"
"strings"
"git.mstar.dev/mstar/linstrom/activitypub"
"git.mstar.dev/mstar/linstrom/config"
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
)
type ActivityLikeOut struct {
Context any `json:"@context"`
Type string `json:"type"`
Id string `json:"id"`
Actor string `json:"actor"`
Object string `json:"object"`
Content *string `json:"content,omitempty"`
MkReaction *string `json:"_misskey_reaction,omitempty"`
Tags []Tag `json:"tag,omitempty"`
}
func LikeFromStorage(ctx context.Context, id string) (*ActivityLikeOut, error) {
reaction, err := dbgen.Reaction.
Where(dbgen.Reaction.ID.Eq(id)).
Preload(dbgen.Reaction.Emote).
First()
if err != nil {
return nil, err
}
like := &ActivityLikeOut{
Type: "Like",
Id: config.GlobalConfig.General.GetFullPublicUrl() + "/api/activitypub/activity/like/" + id,
Actor: activitypub.UserIdToApUrl(reaction.ReactorId),
}
if strings.HasPrefix(reaction.NoteId, "http") {
like.Object = reaction.NoteId
} else {
like.Object = config.GlobalConfig.General.GetFullPublicUrl() + "/api/activitypub/note/" + reaction.NoteId
}
if reaction.Content.Valid {
like.Content = &reaction.Content.String
like.MkReaction = &reaction.Content.String
}
if reaction.Emote != nil {
like.Content = &reaction.Emote.Name
like.MkReaction = &reaction.Emote.Name
emote, err := EmoteTagFromStorage(ctx, reaction.Emote.ID)
if err != nil {
return nil, err
}
like.Tags = append(like.Tags, *emote)
}
return like, nil
}