From 4b62c322473cf0a2c177e3074795166f69c9e51f Mon Sep 17 00:00:00 2001 From: mstar Date: Fri, 13 Jun 2025 16:45:28 +0200 Subject: [PATCH] Start work on likes/reactions --- activitypub/translators/like.go | 12 ++++++++ activitypub/translators/note.go | 9 +++++- samples/mkLikeDefaultEmote.json | 53 +++++++++++++++++++++++++++++++++ storage-new/models/Reaction.go | 5 +++- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 activitypub/translators/like.go create mode 100644 samples/mkLikeDefaultEmote.json diff --git a/activitypub/translators/like.go b/activitypub/translators/like.go new file mode 100644 index 0000000..227f313 --- /dev/null +++ b/activitypub/translators/like.go @@ -0,0 +1,12 @@ +package translators + +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"` +} diff --git a/activitypub/translators/note.go b/activitypub/translators/note.go index a7b3bae..0dfb297 100644 --- a/activitypub/translators/note.go +++ b/activitypub/translators/note.go @@ -13,8 +13,15 @@ import ( type Tag struct { Type string `json:"type"` - Href string `json:"href"` Name string `json:"name"` + + // ---- Section Hashtag & Mention + Href *string `json:"href,omitempty"` + + // Section Emote + Id *string `json:"id,omitempty"` + Updated *time.Time `json:"updated,omitempty"` + Icon *Media `json:"icon,omitempty"` } type ObjectNote struct { diff --git a/samples/mkLikeDefaultEmote.json b/samples/mkLikeDefaultEmote.json new file mode 100644 index 0000000..cfbf002 --- /dev/null +++ b/samples/mkLikeDefaultEmote.json @@ -0,0 +1,53 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "Key": "sec:Key", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "sensitive": "as:sensitive", + "Hashtag": "as:Hashtag", + "quoteUrl": "as:quoteUrl", + "fedibird": "http://fedibird.com/ns#", + "quoteUri": "fedibird:quoteUri", + "toot": "http://joinmastodon.org/ns#", + "Emoji": "toot:Emoji", + "featured": "toot:featured", + "discoverable": "toot:discoverable", + "indexable": "toot:indexable", + "schema": "http://schema.org#", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value", + "misskey": "https://misskey-hub.net/ns#", + "_misskey_content": "misskey:_misskey_content", + "_misskey_quote": "misskey:_misskey_quote", + "_misskey_reaction": "misskey:_misskey_reaction", + "_misskey_votes": "misskey:_misskey_votes", + "_misskey_summary": "misskey:_misskey_summary", + "_misskey_followedMessage": "misskey:_misskey_followedMessage", + "_misskey_requireSigninToViewContents": "misskey:_misskey_requireSigninToViewContents", + "_misskey_makeNotesFollowersOnlyBefore": "misskey:_misskey_makeNotesFollowersOnlyBefore", + "_misskey_makeNotesHiddenBefore": "misskey:_misskey_makeNotesHiddenBefore", + "_misskey_license": "misskey:_misskey_license", + "freeText": { + "@id": "misskey:freeText", + "@type": "schema:text" + }, + "isCat": "misskey:isCat", + "firefish": "https://joinfirefish.org/ns#", + "speakAsCat": "firefish:speakAsCat", + "sharkey": "https://joinsharkey.org/ns#", + "hideOnlineStatus": "sharkey:hideOnlineStatus", + "backgroundUrl": "sharkey:backgroundUrl", + "listenbrainz": "sharkey:listenbrainz", + "enableRss": "sharkey:enableRss", + "vcard": "http://www.w3.org/2006/vcard/ns#" + } + ], + "type": "Like", + "id": "https://mk.absturztau.be/likes/a8ydcaw713im02nm", + "actor": "https://mk.absturztau.be/users/a1xy7910yc8401z8", + "object": "https://activitypub.academy/users/fabota_kovacul/statuses/114676133656288280", + "content": "👍", + "_misskey_reaction": "👍" +} diff --git a/storage-new/models/Reaction.go b/storage-new/models/Reaction.go index 7f9bfd2..e29605b 100644 --- a/storage-new/models/Reaction.go +++ b/storage-new/models/Reaction.go @@ -6,7 +6,9 @@ import ( "gorm.io/gorm" ) -// A Reaction is a user liking a note using an emote +// A Reaction is a user liking a note (optionally using an emote) +// A reaction may contain some content text. If yes, this is the reaction. +// It also may contain a specifically linked emote (via tag). If yes, this is the reaction and takes precedence over the content type Reaction struct { gorm.Model Note Note @@ -15,4 +17,5 @@ type Reaction struct { ReactorId string Emote *Emote // Emote is optional. If not set, use the default emote of the server EmoteId sql.NullInt64 + Content sql.NullString // Content/text of the reaction. Used for example in cases where a unicode character is sent as emote reaction }