summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-03-26 16:59:39 +0100
committerLibravatar GitHub <noreply@github.com>2025-03-26 15:59:39 +0000
commitb6e481d63eec15191f2717957682c13ee8a68308 (patch)
tree03cb9fc8bcb5f9eefddee754ad64b9de10c44c39 /internal/processing
parent[chore] bumps our spf13/viper version (#3943) (diff)
downloadgotosocial-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/processing')
-rw-r--r--internal/processing/account/rss.go16
-rw-r--r--internal/processing/account/statuses.go15
-rw-r--r--internal/processing/account/update.go12
3 files changed, 40 insertions, 3 deletions
diff --git a/internal/processing/account/rss.go b/internal/processing/account/rss.go
index 22ba0fe42..b0debcc91 100644
--- a/internal/processing/account/rss.go
+++ b/internal/processing/account/rss.go
@@ -115,8 +115,20 @@ func (p *Processor) GetRSSFeedForUsername(ctx context.Context, username string)
// Reuse the lastPostAt value for feed.Updated.
feed.Updated = lastPostAt
- // Retrieve latest statuses as they'd be shown on the web view of the account profile.
- statuses, err := p.state.DB.GetAccountWebStatuses(ctx, account, rssFeedLength, "")
+ // Retrieve latest statuses as they'd be shown
+ // on the web view of the account profile.
+ //
+ // Take into account whether the user wants
+ // their web view laid out in gallery mode.
+ mediaOnly := account.Settings != nil &&
+ account.Settings.WebLayout == gtsmodel.WebLayoutGallery
+ statuses, err := p.state.DB.GetAccountWebStatuses(
+ ctx,
+ account,
+ mediaOnly,
+ rssFeedLength,
+ "", // Latest posts from the top.
+ )
if err != nil && !errors.Is(err, db.ErrNoEntries) {
err = fmt.Errorf("db error getting account web statuses: %w", err)
return "", gtserror.NewErrorInternalError(err)
diff --git a/internal/processing/account/statuses.go b/internal/processing/account/statuses.go
index 8029a460b..701fe44ae 100644
--- a/internal/processing/account/statuses.go
+++ b/internal/processing/account/statuses.go
@@ -143,6 +143,7 @@ func (p *Processor) StatusesGet(
func (p *Processor) WebStatusesGet(
ctx context.Context,
targetAccountID string,
+ mediaOnly bool,
maxID string,
) (*apimodel.PageableResponse, gtserror.WithCode) {
account, err := p.state.DB.GetAccountByID(ctx, targetAccountID)
@@ -159,7 +160,13 @@ func (p *Processor) WebStatusesGet(
return nil, gtserror.NewErrorNotFound(err)
}
- statuses, err := p.state.DB.GetAccountWebStatuses(ctx, account, 10, maxID)
+ statuses, err := p.state.DB.GetAccountWebStatuses(
+ ctx,
+ account,
+ mediaOnly,
+ 20,
+ maxID,
+ )
if err != nil && !errors.Is(err, db.ErrNoEntries) {
return nil, gtserror.NewErrorInternalError(err)
}
@@ -198,6 +205,7 @@ func (p *Processor) WebStatusesGet(
func (p *Processor) WebStatusesGetPinned(
ctx context.Context,
targetAccountID string,
+ mediaOnly bool,
) ([]*apimodel.WebStatus, gtserror.WithCode) {
statuses, err := p.state.DB.GetAccountPinnedStatuses(ctx, targetAccountID)
if err != nil && !errors.Is(err, db.ErrNoEntries) {
@@ -206,6 +214,11 @@ func (p *Processor) WebStatusesGetPinned(
webStatuses := make([]*apimodel.WebStatus, 0, len(statuses))
for _, status := range statuses {
+ if mediaOnly && len(status.Attachments) == 0 {
+ // No media, skip.
+ continue
+ }
+
// Ensure visible via the web.
visible, err := p.visFilter.StatusVisible(ctx, nil, status)
if err != nil {
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index 3a59dbdf3..a833d72c1 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -294,6 +294,18 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
settingsColumns = append(settingsColumns, "web_visibility")
}
+ if form.WebLayout != nil {
+ webLayout := gtsmodel.ParseWebLayout(*form.WebLayout)
+ if webLayout == gtsmodel.WebLayoutUnknown {
+ const text = "web_layout must be one of microblog or gallery"
+ err := errors.New(text)
+ return nil, gtserror.NewErrorBadRequest(err, text)
+ }
+
+ account.Settings.WebLayout = webLayout
+ settingsColumns = append(settingsColumns, "web_layout")
+ }
+
// We've parsed + set everything, do
// necessary database updates now.