summaryrefslogtreecommitdiff
path: root/internal/gtsmodel
diff options
context:
space:
mode:
Diffstat (limited to 'internal/gtsmodel')
-rw-r--r--internal/gtsmodel/account.go36
-rw-r--r--internal/gtsmodel/status.go105
2 files changed, 129 insertions, 12 deletions
diff --git a/internal/gtsmodel/account.go b/internal/gtsmodel/account.go
index 54d8c3d71..42e4f5ea6 100644
--- a/internal/gtsmodel/account.go
+++ b/internal/gtsmodel/account.go
@@ -27,6 +27,7 @@ import (
"time"
"github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
)
// Account represents either a local or a remote fediverse account, gotosocial or otherwise (mastodon, pleroma, etc).
@@ -35,8 +36,8 @@ type Account struct {
CreatedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item created.
UpdatedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item was last updated.
FetchedAt time.Time `validate:"required_with=Domain" bun:"type:timestamptz,nullzero"` // when was item (remote) last fetched.
- Username string `validate:"required" bun:",nullzero,notnull,unique:userdomain"` // Username of the account, should just be a string of [a-zA-Z0-9_]. Can be added to domain to create the full username in the form ``[username]@[domain]`` eg., ``user_96@example.org``. Username and domain should be unique *with* each other
- Domain string `validate:"omitempty,fqdn" bun:",nullzero,unique:userdomain"` // Domain of the account, will be null if this is a local account, otherwise something like ``example.org``. Should be unique with username.
+ Username string `validate:"required" bun:",nullzero,notnull,unique:usernamedomain"` // Username of the account, should just be a string of [a-zA-Z0-9_]. Can be added to domain to create the full username in the form ``[username]@[domain]`` eg., ``user_96@example.org``. Username and domain should be unique *with* each other
+ Domain string `validate:"omitempty,fqdn" bun:",nullzero,unique:usernamedomain"` // Domain of the account, will be null if this is a local account, otherwise something like ``example.org``. Should be unique with username.
AvatarMediaAttachmentID string `validate:"omitempty,ulid" bun:"type:CHAR(26),nullzero"` // Database ID of the media attachment, if present
AvatarMediaAttachment *MediaAttachment `validate:"-" bun:"rel:belongs-to"` // MediaAttachment corresponding to avatarMediaAttachmentID
AvatarRemoteURL string `validate:"omitempty,url" bun:",nullzero"` // For a non-local account, where can the header be fetched?
@@ -70,8 +71,8 @@ type Account struct {
FollowersURI string `validate:"required_without=Domain,omitempty,url" bun:",nullzero,unique"` // URI for getting the followers list of this account
FeaturedCollectionURI string `validate:"required_without=Domain,omitempty,url" bun:",nullzero,unique"` // URL for getting the featured collection list of this account
ActorType string `validate:"oneof=Application Group Organization Person Service" bun:",nullzero,notnull"` // What type of activitypub actor is this account?
- PrivateKey *rsa.PrivateKey `validate:"required_without=Domain"` // Privatekey for validating activitypub requests, will only be defined for local accounts
- PublicKey *rsa.PublicKey `validate:"required"` // Publickey for encoding activitypub requests, will be defined for both local and remote accounts
+ PrivateKey *rsa.PrivateKey `validate:"required_without=Domain" bun:""` // Privatekey for validating activitypub requests, will only be defined for local accounts
+ PublicKey *rsa.PublicKey `validate:"required" bun:",notnull,unique"` // Publickey for encoding activitypub requests, will be defined for both local and remote accounts
PublicKeyURI string `validate:"required,url" bun:",nullzero,notnull,unique"` // Web-reachable location of this account's public key
SensitizedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero"` // When was this account set to have all its media shown as sensitive?
SilencedAt time.Time `validate:"-" bun:"type:timestamptz,nullzero"` // When was this account silenced (eg., statuses only visible to followers, not public)?
@@ -82,23 +83,44 @@ type Account struct {
}
// IsLocal returns whether account is a local user account.
-func (a Account) IsLocal() bool {
+func (a *Account) IsLocal() bool {
return a.Domain == "" || a.Domain == config.GetHost() || a.Domain == config.GetAccountDomain()
}
// IsRemote returns whether account is a remote user account.
-func (a Account) IsRemote() bool {
+func (a *Account) IsRemote() bool {
return !a.IsLocal()
}
// IsInstance returns whether account is an instance internal actor account.
-func (a Account) IsInstance() bool {
+func (a *Account) IsInstance() bool {
return a.Username == a.Domain ||
a.FollowersURI == "" ||
a.FollowingURI == "" ||
(a.Username == "internal.fetch" && strings.Contains(a.Note, "internal service actor"))
}
+// EmojisPopulated returns whether emojis are populated according to current EmojiIDs.
+func (a *Account) EmojisPopulated() bool {
+ if len(a.EmojiIDs) != len(a.Emojis) {
+ // this is the quickest indicator.
+ return false
+ }
+
+ // Emojis must be in same order.
+ for i, id := range a.EmojiIDs {
+ if a.Emojis[i] == nil {
+ log.Warnf(nil, "nil emoji in slice for account %s", a.URI)
+ continue
+ }
+ if a.Emojis[i].ID != id {
+ return false
+ }
+ }
+
+ return true
+}
+
// AccountToEmoji is an intermediate struct to facilitate the many2many relationship between an account and one or more emojis.
type AccountToEmoji struct {
AccountID string `validate:"ulid,required" bun:"type:CHAR(26),unique:accountemoji,nullzero,notnull"`
diff --git a/internal/gtsmodel/status.go b/internal/gtsmodel/status.go
index eda24e316..d04deecef 100644
--- a/internal/gtsmodel/status.go
+++ b/internal/gtsmodel/status.go
@@ -19,6 +19,8 @@ package gtsmodel
import (
"time"
+
+ "github.com/superseriousbusiness/gotosocial/internal/log"
)
// Status represents a user-created 'post' or 'status' in the database, either remote or local
@@ -65,27 +67,120 @@ type Status struct {
Likeable *bool `validate:"-" bun:",notnull"` // This status can be liked/faved
}
-/*
- The below functions are added onto the gtsmodel status so that it satisfies
- the Timelineable interface in internal/timeline.
-*/
-
+// GetID implements timeline.Timelineable{}.
func (s *Status) GetID() string {
return s.ID
}
+// GetAccountID implements timeline.Timelineable{}.
func (s *Status) GetAccountID() string {
return s.AccountID
}
+// GetBoostID implements timeline.Timelineable{}.
func (s *Status) GetBoostOfID() string {
return s.BoostOfID
}
+// GetBoostOfAccountID implements timeline.Timelineable{}.
func (s *Status) GetBoostOfAccountID() string {
return s.BoostOfAccountID
}
+// AttachmentsPopulated returns whether media attachments are populated according to current AttachmentIDs.
+func (s *Status) AttachmentsPopulated() bool {
+ if len(s.AttachmentIDs) != len(s.Attachments) {
+ // this is the quickest indicator.
+ return false
+ }
+
+ // Attachments must be in same order.
+ for i, id := range s.AttachmentIDs {
+ if s.Attachments[i] == nil {
+ log.Warnf(nil, "nil attachment in slice for status %s", s.URI)
+ continue
+ }
+ if s.Attachments[i].ID != id {
+ return false
+ }
+ }
+
+ return true
+}
+
+// TagsPopulated returns whether tags are populated according to current TagIDs.
+func (s *Status) TagsPopulated() bool {
+ if len(s.TagIDs) != len(s.Tags) {
+ // this is the quickest indicator.
+ return false
+ }
+
+ // Tags must be in same order.
+ for i, id := range s.TagIDs {
+ if s.Tags[i] == nil {
+ log.Warnf(nil, "nil tag in slice for status %s", s.URI)
+ continue
+ }
+ if s.Tags[i].ID != id {
+ return false
+ }
+ }
+
+ return true
+}
+
+// MentionsPopulated returns whether mentions are populated according to current MentionIDs.
+func (s *Status) MentionsPopulated() bool {
+ if len(s.MentionIDs) != len(s.Mentions) {
+ // this is the quickest indicator.
+ return false
+ }
+
+ // Mentions must be in same order.
+ for i, id := range s.MentionIDs {
+ if s.Mentions[i] == nil {
+ log.Warnf(nil, "nil mention in slice for status %s", s.URI)
+ continue
+ }
+ if s.Mentions[i].ID != id {
+ return false
+ }
+ }
+
+ return true
+}
+
+// EmojisPopulated returns whether emojis are populated according to current EmojiIDs.
+func (s *Status) EmojisPopulated() bool {
+ if len(s.EmojiIDs) != len(s.Emojis) {
+ // this is the quickest indicator.
+ return false
+ }
+
+ // Emojis must be in same order.
+ for i, id := range s.EmojiIDs {
+ if s.Emojis[i] == nil {
+ log.Warnf(nil, "nil emoji in slice for status %s", s.URI)
+ continue
+ }
+ if s.Emojis[i].ID != id {
+ return false
+ }
+ }
+
+ return true
+}
+
+// MentionsAccount returns whether status mentions the given account ID.
+func (s *Status) MentionsAccount(id string) bool {
+ for _, mention := range s.Mentions {
+ if mention.TargetAccountID == id {
+ return true
+ }
+ }
+ return false
+}
+
// StatusToTag is an intermediate struct to facilitate the many2many relationship between a status and one or more tags.
type StatusToTag struct {
StatusID string `validate:"ulid,required" bun:"type:CHAR(26),unique:statustag,nullzero,notnull"`