2023-09-26 11:35:08 +00:00
|
|
|
package ent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2024-08-07 20:06:16 +00:00
|
|
|
"github.com/reiver/go-erorr"
|
2024-08-01 23:04:28 +00:00
|
|
|
"github.com/reiver/go-jsonint"
|
2024-08-01 22:29:50 +00:00
|
|
|
"github.com/reiver/go-opt"
|
2024-08-01 23:59:52 +00:00
|
|
|
"github.com/reiver/go-nul"
|
2023-09-26 11:35:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Status struct {
|
|
|
|
ID opt.Optional[string] `json:"id"`
|
2024-08-06 23:11:52 +00:00
|
|
|
URI nul.Nullable[string] `json:"uri"`
|
|
|
|
URL nul.Nullable[string] `json:"url"`
|
2023-09-26 11:35:08 +00:00
|
|
|
CreatedAt opt.Optional[string] `json:"created_at"`
|
|
|
|
Account Account `json:"account"`
|
|
|
|
Content opt.Optional[string] `json:"content"`
|
|
|
|
Visibility opt.Optional[string] `json:"visibility"`
|
|
|
|
Sensitive opt.Optional[bool] `json:"sensitive"`
|
|
|
|
SpoilerText opt.Optional[string] `json:"spoiler_text"`
|
|
|
|
MediaAttachments []MediaAttachment `json:"media_attachments"`
|
|
|
|
Application nul.Nullable[Application] `json:"application"`
|
|
|
|
Mentions []Mention `json:"mentions"`
|
|
|
|
Tags []Tag `json:"tags"`
|
|
|
|
Emojis []CustomEmoji `json:"emojis"`
|
|
|
|
ReblogsCount opt.Optional[jsonint.Int] `json:"reblogs_count"`
|
|
|
|
FavouritesCount opt.Optional[jsonint.Int] `json:"favourites_count"`
|
|
|
|
RepliesCount opt.Optional[jsonint.Int] `json:"replies_count"`
|
|
|
|
InReplyToID nul.Nullable[string] `json:"in_reply_to_id"`
|
|
|
|
InReplyToAccountID nul.Nullable[string] `json:"in_reply_to_account_id"`
|
|
|
|
Reblog json.RawMessage `json:"reblog"`
|
|
|
|
Poll nul.Nullable[Poll] `json:"poll"`
|
|
|
|
Card nul.Nullable[PreviewCard] `json:"card"`
|
|
|
|
Language nul.Nullable[string] `json:"language"`
|
|
|
|
Text nul.Nullable[string] `json:"text"`
|
|
|
|
EditedAt nul.Nullable[string] `json:"edited_at"`
|
|
|
|
Favourited opt.Optional[bool] `json:"favourited"`
|
|
|
|
Reblogged opt.Optional[bool] `json:"reblogged"`
|
|
|
|
Muted opt.Optional[bool] `json:"muted"`
|
|
|
|
Bookmarked opt.Optional[bool] `json:"bookmarked"`
|
|
|
|
Pinned opt.Optional[bool] `json:"pinned"`
|
|
|
|
Filtered json.RawMessage `json:"filtered"`
|
|
|
|
}
|
2024-08-07 20:06:16 +00:00
|
|
|
|
|
|
|
func (receiver *Status) MarshalJSON() ([]byte, error) {
|
|
|
|
if nil == receiver {
|
|
|
|
return nil, errNilReceiver
|
|
|
|
}
|
|
|
|
|
|
|
|
var buffer [1024]byte
|
|
|
|
var p []byte = buffer[0:0]
|
|
|
|
|
|
|
|
p = append(p, '{')
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.ID.Get()
|
|
|
|
if !found {
|
|
|
|
return nil, errNothingID
|
|
|
|
}
|
|
|
|
|
|
|
|
const name = "id"
|
|
|
|
p = append(p, `"id":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.URI.Get()
|
|
|
|
if found {
|
|
|
|
const name = "uri"
|
|
|
|
p = append(p, `,"uri":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.URL.Get()
|
|
|
|
if found {
|
|
|
|
const name = "url"
|
|
|
|
p = append(p, `,"url":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.CreatedAt.Get()
|
|
|
|
if found {
|
|
|
|
const name = "created_at"
|
|
|
|
p = append(p, `,"created_at":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//@TODO: Account
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Content.Get()
|
|
|
|
if found {
|
|
|
|
const name = "content"
|
|
|
|
p = append(p, `,"content":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Visibility.Get()
|
|
|
|
if found {
|
|
|
|
const name = "visibility"
|
|
|
|
p = append(p, `,"visibility":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Sensitive.Get()
|
|
|
|
if found {
|
|
|
|
const name = "sensitive"
|
|
|
|
p = append(p, `,"sensitive":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.SpoilerText.Get()
|
|
|
|
if found {
|
|
|
|
const name = "spoiler_text"
|
|
|
|
p = append(p, `,"spoiler_text":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//@TODO: MediaAttachments
|
|
|
|
|
|
|
|
//@TODO: Application
|
|
|
|
|
|
|
|
//@TODO: Mentions
|
|
|
|
|
|
|
|
//@TODO: Tags
|
|
|
|
|
|
|
|
//@TODO: Emojis
|
|
|
|
|
|
|
|
//@TODO: ReblogsCount
|
|
|
|
|
|
|
|
//@TODO: FavouritesCount
|
|
|
|
|
|
|
|
//@TODO: RepliesCount
|
|
|
|
|
|
|
|
//@TODO: InReplyToID
|
|
|
|
|
|
|
|
//@TODO: InReplyToAccountID
|
|
|
|
|
|
|
|
//@TODO: Reblog
|
|
|
|
|
|
|
|
//@TODO: Poll
|
|
|
|
|
|
|
|
//@TODO: Card
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Language.Get()
|
|
|
|
if found {
|
|
|
|
const name = "language"
|
|
|
|
p = append(p, `,"language":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Text.Get()
|
|
|
|
if found {
|
|
|
|
const name = "text"
|
|
|
|
p = append(p, `,"text":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.EditedAt.Get()
|
|
|
|
if found {
|
|
|
|
const name = "edited_at"
|
|
|
|
p = append(p, `,"edited_at":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Favourited.Get()
|
|
|
|
if found {
|
|
|
|
const name = "favourited"
|
|
|
|
p = append(p, `,"favourited":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Reblogged.Get()
|
|
|
|
if found {
|
|
|
|
const name = "reblogged"
|
|
|
|
p = append(p, `,"reblogged":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Muted.Get()
|
|
|
|
if found {
|
|
|
|
const name = "muted"
|
|
|
|
p = append(p, `,"muted":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Bookmarked.Get()
|
|
|
|
if found {
|
|
|
|
const name = "bookmarked"
|
|
|
|
p = append(p, `,"bookmarked":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val, found := receiver.Pinned.Get()
|
|
|
|
if found {
|
|
|
|
const name = "pinned"
|
|
|
|
p = append(p, `,"pinned":`...)
|
|
|
|
|
|
|
|
bytes, err := json.Marshal(val)
|
|
|
|
if nil != err {
|
|
|
|
return nil, erorr.Errorf("problem marshaling %q: %w", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
bytes := []byte(receiver.Filtered)
|
|
|
|
if 0 < len(bytes) {
|
|
|
|
const name = "filtered"
|
|
|
|
p = append(p, `,"filtered":`...)
|
|
|
|
|
|
|
|
p = append(p, bytes...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = append(p, '}')
|
|
|
|
|
|
|
|
return p, nil
|
|
|
|
}
|