versia-go/pkg/versia/note.go

101 lines
3.2 KiB
Go
Raw Permalink Normal View History

2024-08-22 23:03:38 +02:00
package versia
2024-08-11 03:51:22 +02:00
2024-08-22 23:03:38 +02:00
import (
"encoding/json"
2024-08-28 00:25:25 +02:00
versiautils "github.com/versia-pub/versia-go/pkg/versia/utils"
2024-08-11 03:51:22 +02:00
)
2024-08-22 23:03:38 +02:00
// Note is a published message, similar to a tweet (from Twitter) or a toot (from Mastodon).
// For more information, see the [Spec].
2024-08-11 03:51:22 +02:00
//
2024-08-22 23:03:38 +02:00
// [Spec]: https://versia.pub/entities/note
type Note struct {
2024-08-11 03:51:22 +02:00
Entity
2024-08-28 00:25:25 +02:00
// Attachments is a list of attachment objects, keyed by their MIME type
Attachments []versiautils.NoteAttachmentContentMap `json:"attachments,omitempty"`
2024-08-11 03:51:22 +02:00
// Author is the URL to the user
2024-08-22 23:03:38 +02:00
Author *versiautils.URL `json:"author"`
2024-08-11 03:51:22 +02:00
2024-08-28 00:25:25 +02:00
// Category is the category of the note
2024-08-11 03:51:22 +02:00
Category *CategoryType `json:"category,omitempty"`
2024-08-28 00:25:25 +02:00
// Content is the content of the note
Content versiautils.TextContentTypeMap `json:"content,omitempty"`
2024-08-11 03:51:22 +02:00
2024-08-28 00:25:25 +02:00
// Device that created the note
Device *Device `json:"device,omitempty"`
2024-08-11 03:51:22 +02:00
// Group is the URL to a group
2024-08-28 00:25:25 +02:00
// TODO: Properly parse these, can be "public" | "followers" as well
2024-08-22 23:03:38 +02:00
Group *versiautils.URL `json:"group,omitempty"`
2024-08-11 03:51:22 +02:00
2024-08-28 00:25:25 +02:00
// IsSensitive is a boolean indicating whether the note contains sensitive content
IsSensitive *bool `json:"is_sensitive,omitempty"`
2024-08-11 03:51:22 +02:00
// Mentions is a list of URLs to users
2024-08-22 23:03:38 +02:00
Mentions []versiautils.URL `json:"mentions,omitempty"`
2024-08-11 03:51:22 +02:00
2024-08-28 00:25:25 +02:00
// Previews is a list of URLs to preview images
Previews []LinkPreview `json:"previews,omitempty"`
2024-08-11 03:51:22 +02:00
2024-08-28 00:25:25 +02:00
// Quotes is the URL to the note being quoted
Quotes *versiautils.URL `json:"quotes,omitempty"`
2024-08-11 03:51:22 +02:00
2024-08-28 00:25:25 +02:00
// RepliesTo is the URL to the note being replied to
RepliesTo *versiautils.URL `json:"replies_to,omitempty"`
// Subject is the subject of the note
Subject *string `json:"subject,omitempty"`
2024-08-22 23:03:38 +02:00
}
func (p Note) MarshalJSON() ([]byte, error) {
type a Note
n2 := a(p)
n2.Type = "Note"
return json.Marshal(n2)
2024-08-11 03:51:22 +02:00
}
// LinkPreview is a preview of a link. For more information, see the [Spec].
//
2024-08-28 00:25:25 +02:00
// [Spec]: https://versia.pub/entities/note#entity-definition
2024-08-11 03:51:22 +02:00
type LinkPreview struct {
2024-08-22 23:03:38 +02:00
Link *versiautils.URL `json:"link"`
Title string `json:"title"`
2024-08-28 00:25:25 +02:00
Description *string `json:"description,omitempty"`
Image *versiautils.URL `json:"image,omitempty"`
Icon *versiautils.URL `json:"icon,omitempty"`
2024-08-11 03:51:22 +02:00
}
2024-08-28 00:25:25 +02:00
// Device is the device that creates note. For more information, see the [Spec].
2024-08-11 03:51:22 +02:00
//
2024-08-28 00:25:25 +02:00
// [Spec]: https://versia.pub/entities/note#entity-definition
2024-08-11 03:51:22 +02:00
type Device struct {
2024-08-22 23:03:38 +02:00
Name string `json:"name"`
Version string `json:"version,omitempty"`
URL *versiautils.URL `json:"url,omitempty"`
2024-08-11 03:51:22 +02:00
}
2024-08-28 00:25:25 +02:00
// CategoryType is the type of note. For more information, see the [Spec].
2024-08-11 03:51:22 +02:00
//
2024-08-28 00:25:25 +02:00
// [Spec]: https://versia.pub/entities/note#entity-definition
2024-08-11 03:51:22 +02:00
type CategoryType string
const (
// CategoryMicroblog is similar to Twitter, Mastodon
CategoryMicroblog CategoryType = "microblog"
// CategoryForum is similar to Reddit
CategoryForum CategoryType = "forum"
// CategoryBlog is similar to Wordpress, WriteFreely
CategoryBlog CategoryType = "blog"
// CategoryImage is similar to Instagram
CategoryImage CategoryType = "image"
// CategoryVideo is similar to YouTube
CategoryVideo CategoryType = "video"
// CategoryAudio is similar to SoundCloud, Spotify
CategoryAudio CategoryType = "audio"
// CategoryMessaging is similar to Discord, Matrix, Signal
CategoryMessaging CategoryType = "messaging"
)