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

@ -0,0 +1,30 @@
package translators
import (
"context"
"git.mstar.dev/mstar/linstrom/config"
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
)
func EmoteTagFromStorage(ctx context.Context, id string) (*Tag, error) {
emote, err := dbgen.Emote.Where(dbgen.Emote.ID.Eq(id)).First()
if err != nil {
return nil, err
}
emoteId := config.GlobalConfig.General.GetFullPublicUrl() + "/api/activitypub/emote/" + id
emoteMedia, err := MediaFromStorage(ctx, emote.MetadataId)
if err != nil {
return nil, err
}
out := Tag{
Type: "Emoji",
Name: emote.Name,
Href: nil,
Id: &emoteId,
Updated: &emote.UpdatedAt,
Icon: emoteMedia,
}
return &out, nil
}

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
}

View file

@ -0,0 +1,26 @@
package translators
import (
"context"
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
)
type Media struct {
Type string `json:"type"`
Url string `json:"url"`
MediaType string `json:"mediaType"`
}
func MediaFromStorage(ctx context.Context, id string) (*Media, error) {
metadata, err := dbgen.MediaMetadata.Where(dbgen.MediaMetadata.ID.Eq(id)).First()
if err != nil {
return nil, err
}
data := Media{
Type: "Image", // FIXME: Change this to a sort of dynamic detection based on mimetype
MediaType: metadata.Type,
Url: metadata.Location,
}
return &data, nil
}

View file

@ -103,16 +103,17 @@ func NoteFromStorage(ctx context.Context, id string) (*ObjectNote, error) {
if err != nil {
return nil, err
}
pubUrl := webshared.UserPublicUrl(target.ID)
data.Tags = append(data.Tags, Tag{
Type: "Mention",
Href: webshared.UserPublicUrl(target.ID),
Href: &pubUrl,
Name: target.Username,
})
}
for _, tag := range note.Tags {
data.Tags = append(data.Tags, Tag{
Type: "Hashtag",
Href: tag.TagUrl,
Href: &tag.TagUrl,
Name: tag.Tag,
})
}

View file

@ -21,11 +21,7 @@ type UserKey struct {
Owner string `json:"owner"`
Pem string `json:"publicKeyPem"`
}
type Media struct {
Type string `json:"type"`
Url string `json:"url"`
MediaType string `json:"mediaType"`
}
type User struct {
Context []any `json:"@context"`
Id string `json:"id"`