status.go (10693B)
1 // GoToSocial 2 // Copyright (C) GoToSocial Authors admin@gotosocial.org 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package gtsmodel 19 20 import ( 21 "time" 22 ) 23 24 // Status represents a user-created 'post' or 'status' in the database, either remote or local 25 type Status struct { 26 ID string `validate:"required,ulid" bun:"type:CHAR(26),pk,nullzero,notnull,unique"` // id of this item in the database 27 CreatedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item created 28 UpdatedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item last updated 29 URI string `validate:"required,url" bun:",unique,nullzero,notnull"` // activitypub URI of this status 30 URL string `validate:"url" bun:",nullzero"` // web url for viewing this status 31 Content string `validate:"-" bun:""` // content of this status; likely html-formatted but not guaranteed 32 AttachmentIDs []string `validate:"dive,ulid" bun:"attachments,array"` // Database IDs of any media attachments associated with this status 33 Attachments []*MediaAttachment `validate:"-" bun:"attached_media,rel:has-many"` // Attachments corresponding to attachmentIDs 34 TagIDs []string `validate:"dive,ulid" bun:"tags,array"` // Database IDs of any tags used in this status 35 Tags []*Tag `validate:"-" bun:"attached_tags,m2m:status_to_tags"` // Tags corresponding to tagIDs. https://bun.uptrace.dev/guide/relations.html#many-to-many-relation 36 MentionIDs []string `validate:"dive,ulid" bun:"mentions,array"` // Database IDs of any mentions in this status 37 Mentions []*Mention `validate:"-" bun:"attached_mentions,rel:has-many"` // Mentions corresponding to mentionIDs 38 EmojiIDs []string `validate:"dive,ulid" bun:"emojis,array"` // Database IDs of any emojis used in this status 39 Emojis []*Emoji `validate:"-" bun:"attached_emojis,m2m:status_to_emojis"` // Emojis corresponding to emojiIDs. https://bun.uptrace.dev/guide/relations.html#many-to-many-relation 40 Local bool `validate:"-" bun:",notnull,default:false"` // is this status from a local account? 41 AccountID string `validate:"required,ulid" bun:"type:CHAR(26),nullzero,notnull"` // which account posted this status? 42 Account *Account `validate:"-" bun:"rel:belongs-to"` // account corresponding to accountID 43 AccountURI string `validate:"required,url" bun:",nullzero,notnull"` // activitypub uri of the owner of this status 44 InReplyToID string `validate:"required_with=InReplyToURI InReplyToAccountID,omitempty,ulid" bun:"type:CHAR(26),nullzero"` // id of the status this status replies to 45 InReplyToURI string `validate:"required_with=InReplyToID InReplyToAccountID,omitempty,url" bun:",nullzero"` // activitypub uri of the status this status is a reply to 46 InReplyToAccountID string `validate:"required_with=InReplyToID InReplyToURI,omitempty,ulid" bun:"type:CHAR(26),nullzero"` // id of the account that this status replies to 47 InReplyTo *Status `validate:"-" bun:"-"` // status corresponding to inReplyToID 48 InReplyToAccount *Account `validate:"-" bun:"rel:belongs-to"` // account corresponding to inReplyToAccountID 49 BoostOfID string `validate:"required_with=BoostOfAccountID,omitempty,ulid" bun:"type:CHAR(26),nullzero"` // id of the status this status is a boost of 50 BoostOfAccountID string `validate:"required_with=BoostOfID,omitempty,ulid" bun:"type:CHAR(26),nullzero"` // id of the account that owns the boosted status 51 BoostOf *Status `validate:"-" bun:"-"` // status that corresponds to boostOfID 52 BoostOfAccount *Account `validate:"-" bun:"rel:belongs-to"` // account that corresponds to boostOfAccountID 53 ContentWarning string `validate:"-" bun:",nullzero"` // cw string for this status 54 Visibility Visibility `validate:"oneof=public unlocked followers_only mutuals_only direct" bun:",nullzero,notnull"` // visibility entry for this status 55 Sensitive bool `validate:"-" bun:",notnull,default:false"` // mark the status as sensitive? 56 Language string `validate:"-" bun:",nullzero"` // what language is this status written in? 57 CreatedWithApplicationID string `validate:"required_if=Local true,omitempty,ulid" bun:"type:CHAR(26),nullzero"` // Which application was used to create this status? 58 CreatedWithApplication *Application `validate:"-" bun:"rel:belongs-to"` // application corresponding to createdWithApplicationID 59 ActivityStreamsType string `validate:"required" bun:",nullzero,notnull"` // What is the activitystreams type of this status? See: https://www.w3.org/TR/activitystreams-vocabulary/#object-types. Will probably almost always be Note but who knows!. 60 Text string `validate:"-" bun:""` // Original text of the status without formatting 61 Pinned bool `validate:"-" bun:",notnull,default:false"` // Has this status been pinned by its owner? 62 Federated bool `validate:"-" bun:",notnull"` // This status will be federated beyond the local timeline(s) 63 Boostable bool `validate:"-" bun:",notnull"` // This status can be boosted/reblogged 64 Replyable bool `validate:"-" bun:",notnull"` // This status can be replied to 65 Likeable bool `validate:"-" bun:",notnull"` // This status can be liked/faved 66 } 67 68 // StatusToTag is an intermediate struct to facilitate the many2many relationship between a status and one or more tags. 69 type StatusToTag struct { 70 StatusID string `validate:"ulid,required" bun:"type:CHAR(26),unique:statustag,nullzero,notnull"` 71 Status *Status `validate:"-" bun:"rel:belongs-to"` 72 TagID string `validate:"ulid,required" bun:"type:CHAR(26),unique:statustag,nullzero,notnull"` 73 Tag *Tag `validate:"-" bun:"rel:belongs-to"` 74 } 75 76 // StatusToEmoji is an intermediate struct to facilitate the many2many relationship between a status and one or more emojis. 77 type StatusToEmoji struct { 78 StatusID string `validate:"ulid,required" bun:"type:CHAR(26),unique:statusemoji,nullzero,notnull"` 79 Status *Status `validate:"-" bun:"rel:belongs-to"` 80 EmojiID string `validate:"ulid,required" bun:"type:CHAR(26),unique:statusemoji,nullzero,notnull"` 81 Emoji *Emoji `validate:"-" bun:"rel:belongs-to"` 82 } 83 84 // Visibility represents the visibility granularity of a status. 85 type Visibility string 86 87 const ( 88 // VisibilityPublic means this status will be visible to everyone on all timelines. 89 VisibilityPublic Visibility = "public" 90 // VisibilityUnlocked means this status will be visible to everyone, but will only show on home timeline to followers, and in lists. 91 VisibilityUnlocked Visibility = "unlocked" 92 // VisibilityFollowersOnly means this status is viewable to followers only. 93 VisibilityFollowersOnly Visibility = "followers_only" 94 // VisibilityMutualsOnly means this status is visible to mutual followers only. 95 VisibilityMutualsOnly Visibility = "mutuals_only" 96 // VisibilityDirect means this status is visible only to mentioned recipients. 97 VisibilityDirect Visibility = "direct" 98 // VisibilityDefault is used when no other setting can be found. 99 VisibilityDefault Visibility = VisibilityUnlocked 100 )