Skip to content

Commit

Permalink
[bugfix] Status visibility + excludeReplies fixes (#769)
Browse files Browse the repository at this point in the history
* Fix some bugs when viewing a user's posts: include their self-replies (threads) even when excludeReplies is set, and use in_reply_to_uri instead of in_reply_to_id to filter out replies

* Assign values to InReplyToURI when creating statuses. Add index and update old statuses with a migration
  • Loading branch information
blackle committed Aug 27, 2022
1 parent 4c60a14 commit 54f6cae
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/db/bundb/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,14 @@ func (a *accountDB) GetAccountStatuses(ctx context.Context, accountID string, li
}

if excludeReplies {
q = q.WhereGroup(" AND ", whereEmptyOrNull("in_reply_to_id"))
// include self-replies (threads)
whereGroup := func(*bun.SelectQuery) *bun.SelectQuery {
return q.
WhereOr("in_reply_to_account_id = ?", accountID).
WhereGroup(" OR ", whereEmptyOrNull("in_reply_to_uri"))
}

q = q.WhereGroup(" AND ", whereGroup)
}

if excludeReblogs {
Expand Down Expand Up @@ -332,7 +339,7 @@ func (a *accountDB) GetAccountWebStatuses(ctx context.Context, accountID string,
Table("statuses").
Column("id").
Where("account_id = ?", accountID).
WhereGroup(" AND ", whereEmptyOrNull("in_reply_to_id")).
WhereGroup(" AND ", whereEmptyOrNull("in_reply_to_uri")).
WhereGroup(" AND ", whereEmptyOrNull("boost_of_id")).
Where("visibility = ?", gtsmodel.VisibilityPublic).
Where("federated = ?", true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
GoToSocial
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package migrations

import (
"context"

"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/uptrace/bun"
)

func init() {
up := func(ctx context.Context, db *bun.DB) error {
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
// set in_reply_to_uri to the uri of the status pointed to by in_reply_to_id
if _, err := tx.NewUpdate().
Table("statuses").
TableExpr("statuses AS secondary").
SetColumn("in_reply_to_uri", "secondary.uri").
Where("statuses.in_reply_to_id = secondary.id").
Where("statuses.in_reply_to_id IS NOT null").
Where("statuses.in_reply_to_uri IS null").
Exec(ctx); err != nil {
return err
}

// add index to in_reply_to_uri
if _, err := tx.
NewCreateIndex().
Model(&gtsmodel.Status{}).
Index("statuses_in_reply_to_uri_idx").
Column("in_reply_to_uri").
Exec(ctx); err != nil {
return err
}

return nil
})
}

down := func(ctx context.Context, db *bun.DB) error {
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
return nil
})
}

if err := Migrations.Register(up, down); err != nil {
panic(err)
}
}
1 change: 1 addition & 0 deletions internal/processing/status/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (p *processor) ProcessReplyToID(ctx context.Context, form *apimodel.Advance
}

status.InReplyToID = repliedStatus.ID
status.InReplyToURI = repliedStatus.URI
status.InReplyToAccountID = repliedAccount.ID

return nil
Expand Down

0 comments on commit 54f6cae

Please sign in to comment.