account.go (6662B)
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 db 19 20 import ( 21 "context" 22 "time" 23 24 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 25 ) 26 27 // Account contains functions related to account getting/setting/creation. 28 type Account interface { 29 // GetAccountByID returns one account with the given ID, or an error if something goes wrong. 30 GetAccountByID(ctx context.Context, id string) (*gtsmodel.Account, Error) 31 32 // GetAccountByURI returns one account with the given URI, or an error if something goes wrong. 33 GetAccountByURI(ctx context.Context, uri string) (*gtsmodel.Account, Error) 34 35 // GetAccountByURL returns one account with the given URL, or an error if something goes wrong. 36 GetAccountByURL(ctx context.Context, uri string) (*gtsmodel.Account, Error) 37 38 // GetAccountByUsernameDomain returns one account with the given username and domain, or an error if something goes wrong. 39 GetAccountByUsernameDomain(ctx context.Context, username string, domain string) (*gtsmodel.Account, Error) 40 41 // GetAccountByPubkeyID returns one account with the given public key URI (ID), or an error if something goes wrong. 42 GetAccountByPubkeyID(ctx context.Context, id string) (*gtsmodel.Account, Error) 43 44 // GetAccountByInboxURI returns one account with the given inbox_uri, or an error if something goes wrong. 45 GetAccountByInboxURI(ctx context.Context, uri string) (*gtsmodel.Account, Error) 46 47 // GetAccountByOutboxURI returns one account with the given outbox_uri, or an error if something goes wrong. 48 GetAccountByOutboxURI(ctx context.Context, uri string) (*gtsmodel.Account, Error) 49 50 // GetAccountByFollowingURI returns one account with the given following_uri, or an error if something goes wrong. 51 GetAccountByFollowingURI(ctx context.Context, uri string) (*gtsmodel.Account, Error) 52 53 // GetAccountByFollowersURI returns one account with the given followers_uri, or an error if something goes wrong. 54 GetAccountByFollowersURI(ctx context.Context, uri string) (*gtsmodel.Account, Error) 55 56 // PopulateAccount ensures that all sub-models of an account are populated (e.g. avatar, header etc). 57 PopulateAccount(ctx context.Context, account *gtsmodel.Account) error 58 59 // PutAccount puts one account in the database. 60 PutAccount(ctx context.Context, account *gtsmodel.Account) Error 61 62 // UpdateAccount updates one account by ID. 63 UpdateAccount(ctx context.Context, account *gtsmodel.Account, columns ...string) Error 64 65 // DeleteAccount deletes one account from the database by its ID. 66 // DO NOT USE THIS WHEN SUSPENDING ACCOUNTS! In that case you should mark the 67 // account as suspended instead, rather than deleting from the db entirely. 68 DeleteAccount(ctx context.Context, id string) Error 69 70 // GetAccountCustomCSSByUsername returns the custom css of an account on this instance with the given username. 71 GetAccountCustomCSSByUsername(ctx context.Context, username string) (string, Error) 72 73 // GetAccountFaves fetches faves/likes created by the target accountID. 74 GetAccountFaves(ctx context.Context, accountID string) ([]*gtsmodel.StatusFave, Error) 75 76 // GetAccountStatusesCount is a shortcut for the common action of counting statuses produced by accountID. 77 CountAccountStatuses(ctx context.Context, accountID string) (int, Error) 78 79 // CountAccountPinned returns the total number of pinned statuses owned by account with the given id. 80 CountAccountPinned(ctx context.Context, accountID string) (int, Error) 81 82 // GetAccountStatuses is a shortcut for getting the most recent statuses. accountID is optional, if not provided 83 // then all statuses will be returned. If limit is set to 0, the size of the returned slice will not be limited. This can 84 // be very memory intensive so you probably shouldn't do this! 85 // 86 // In the case of no statuses, this function will return db.ErrNoEntries. 87 GetAccountStatuses(ctx context.Context, accountID string, limit int, excludeReplies bool, excludeReblogs bool, maxID string, minID string, mediaOnly bool, publicOnly bool) ([]*gtsmodel.Status, Error) 88 89 // GetAccountPinnedStatuses returns ONLY statuses owned by the give accountID for which a corresponding StatusPin 90 // exists in the database. Statuses which are not pinned will not be returned by this function. 91 // 92 // Statuses will be returned in the order in which they were pinned, from latest pinned to oldest pinned (descending). 93 // 94 // In the case of no statuses, this function will return db.ErrNoEntries. 95 GetAccountPinnedStatuses(ctx context.Context, accountID string) ([]*gtsmodel.Status, Error) 96 97 // GetAccountWebStatuses is similar to GetAccountStatuses, but it's specifically for returning statuses that 98 // should be visible via the web view of an account. So, only public, federated statuses that aren't boosts 99 // or replies. 100 // 101 // In the case of no statuses, this function will return db.ErrNoEntries. 102 GetAccountWebStatuses(ctx context.Context, accountID string, limit int, maxID string) ([]*gtsmodel.Status, Error) 103 104 GetAccountBlocks(ctx context.Context, accountID string, maxID string, sinceID string, limit int) ([]*gtsmodel.Account, string, string, Error) 105 106 // GetAccountLastPosted simply gets the timestamp of the most recent post by the account. 107 // 108 // If webOnly is true, then the time of the last non-reply, non-boost, public status of the account will be returned. 109 // 110 // The returned time will be zero if account has never posted anything. 111 GetAccountLastPosted(ctx context.Context, accountID string, webOnly bool) (time.Time, Error) 112 113 // SetAccountHeaderOrAvatar sets the header or avatar for the given accountID to the given media attachment. 114 SetAccountHeaderOrAvatar(ctx context.Context, mediaAttachment *gtsmodel.MediaAttachment, accountID string) Error 115 116 // GetInstanceAccount returns the instance account for the given domain. 117 // If domain is empty, this instance account will be returned. 118 GetInstanceAccount(ctx context.Context, domain string) (*gtsmodel.Account, Error) 119 }