Prep for reactions, some fixes and improvements
Some checks failed
/ docker (push) Failing after 1m35s

This commit is contained in:
Melody Becker 2025-06-16 08:13:11 +02:00
parent 4b62c32247
commit 8947d97825
Signed by: mstar
SSH key fingerprint: SHA256:vkXfS9FG2pVNVfvDrzd1VW9n8VJzqqdKQGljxxX8uK8
13 changed files with 262 additions and 43 deletions

View file

@ -1,5 +1,14 @@
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"`
@ -10,3 +19,37 @@ type ActivityLikeOut struct {
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
}