diff options
| author | 2025-03-26 16:59:39 +0100 | |
|---|---|---|
| committer | 2025-03-26 15:59:39 +0000 | |
| commit | b6e481d63eec15191f2717957682c13ee8a68308 (patch) | |
| tree | 03cb9fc8bcb5f9eefddee754ad64b9de10c44c39 /internal/db/bundb/account.go | |
| parent | [chore] bumps our spf13/viper version (#3943) (diff) | |
| download | gotosocial-b6e481d63eec15191f2717957682c13ee8a68308.tar.xz | |
[feature] Allow user to choose "gallery" style layout for web view of profile (#3917)
* [feature] Allow user to choose "gallery" style web layout
* find a bug and squish it up and all day long you'll have good luck
* just a sec
* [performance] reindex public timeline + tinker with query a bit
* fiddling
* should be good now
* last bit of finagling, i'm done now i prommy
* panic normally
Diffstat (limited to 'internal/db/bundb/account.go')
| -rw-r--r-- | internal/db/bundb/account.go | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index f905101e4..aacfcd247 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -878,6 +878,29 @@ func (a *accountDB) GetAccountFaves(ctx context.Context, accountID string) ([]*g return *faves, nil } +func qMediaOnly(q *bun.SelectQuery) *bun.SelectQuery { + // Attachments are stored as a json object; this + // implementation differs between SQLite and Postgres, + // so we have to be thorough to cover all eventualities + return q.WhereGroup(" AND ", func(q *bun.SelectQuery) *bun.SelectQuery { + switch d := q.Dialect().Name(); d { + case dialect.PG: + return q. + Where("? IS NOT NULL", bun.Ident("status.attachments")). + Where("? != '{}'", bun.Ident("status.attachments")) + + case dialect.SQLite: + return q. + Where("? IS NOT NULL", bun.Ident("status.attachments")). + Where("? != 'null'", bun.Ident("status.attachments")). + Where("? != '[]'", bun.Ident("status.attachments")) + + default: + panic("dialect " + d.String() + " was neither pg nor sqlite") + } + }) +} + func (a *accountDB) GetAccountStatuses(ctx context.Context, accountID string, limit int, excludeReplies bool, excludeReblogs bool, maxID string, minID string, mediaOnly bool, publicOnly bool) ([]*gtsmodel.Status, error) { // Ensure reasonable if limit < 0 { @@ -918,28 +941,9 @@ func (a *accountDB) GetAccountStatuses(ctx context.Context, accountID string, li q = q.Where("? IS NULL", bun.Ident("status.boost_of_id")) } + // Respect media-only preference. if mediaOnly { - // Attachments are stored as a json object; this - // implementation differs between SQLite and Postgres, - // so we have to be thorough to cover all eventualities - q = q.WhereGroup(" AND ", func(q *bun.SelectQuery) *bun.SelectQuery { - switch a.db.Dialect().Name() { - case dialect.PG: - return q. - Where("? IS NOT NULL", bun.Ident("status.attachments")). - Where("? != '{}'", bun.Ident("status.attachments")) - case dialect.SQLite: - return q. - Where("? IS NOT NULL", bun.Ident("status.attachments")). - Where("? != ''", bun.Ident("status.attachments")). - Where("? != 'null'", bun.Ident("status.attachments")). - Where("? != '{}'", bun.Ident("status.attachments")). - Where("? != '[]'", bun.Ident("status.attachments")) - default: - log.Panic(ctx, "db dialect was neither pg nor sqlite") - return q - } - }) + q = qMediaOnly(q) } if publicOnly { @@ -1018,6 +1022,7 @@ func (a *accountDB) GetAccountPinnedStatuses(ctx context.Context, accountID stri func (a *accountDB) GetAccountWebStatuses( ctx context.Context, account *gtsmodel.Account, + mediaOnly bool, limit int, maxID string, ) ([]*gtsmodel.Status, error) { @@ -1046,10 +1051,7 @@ func (a *accountDB) GetAccountWebStatuses( TableExpr("? AS ?", bun.Ident("statuses"), bun.Ident("status")). // Select only IDs from table Column("status.id"). - Where("? = ?", bun.Ident("status.account_id"), account.ID). - // Don't show replies or boosts. - Where("? IS NULL", bun.Ident("status.in_reply_to_uri")). - Where("? IS NULL", bun.Ident("status.boost_of_id")) + Where("? = ?", bun.Ident("status.account_id"), account.ID) // Select statuses for this account according // to their web visibility preference. @@ -1074,10 +1076,19 @@ func (a *accountDB) GetAccountWebStatuses( ) } - // Don't show local-only statuses on the web view. - q = q.Where("? = ?", bun.Ident("status.federated"), true) + // Don't show replies, boosts, or + // local-only statuses on the web view. + q = q. + Where("? IS NULL", bun.Ident("status.in_reply_to_uri")). + Where("? IS NULL", bun.Ident("status.boost_of_id")). + Where("? = ?", bun.Ident("status.federated"), true) + + // Respect media-only preference. + if mediaOnly { + q = qMediaOnly(q) + } - // return only statuses LOWER (ie., older) than maxID + // Return only statuses LOWER (ie., older) than maxID if maxID == "" { maxID = id.Highest } |
