[bugfix] Status visibility + excludeReplies fixes (#769)

* 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
This commit is contained in:
Blackle Morisanchetto 2022-08-27 05:35:31 -04:00 committed by GitHub
parent 4c60a142f8
commit 54f6caed65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 2 deletions

View File

@ -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 {
@ -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)

View File

@ -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)
}
}

View File

@ -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