mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-23 00:33:50 +01:00
[bugfix] Ensure local statuses always get a threadID so they can be muted (#2665)
* [chore/bugfix] Ensure threadID always set on local statuses * test
This commit is contained in:
parent
e2ebcbb516
commit
0554550acb
@ -190,18 +190,28 @@ func (p *Processor) processReplyToID(ctx context.Context, form *apimodel.Advance
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Processor) processThreadID(ctx context.Context, status *gtsmodel.Status) gtserror.WithCode {
|
func (p *Processor) processThreadID(ctx context.Context, status *gtsmodel.Status) gtserror.WithCode {
|
||||||
// Status takes the thread ID
|
// Status takes the thread ID of
|
||||||
// of whatever it replies to.
|
// whatever it replies to, if set.
|
||||||
if status.InReplyTo != nil {
|
//
|
||||||
|
// Might not be set if status is local
|
||||||
|
// and replies to a remote status that
|
||||||
|
// doesn't have a thread ID yet.
|
||||||
|
//
|
||||||
|
// If so, we can just thread from this
|
||||||
|
// status onwards instead, since this
|
||||||
|
// is where the relevant part of the
|
||||||
|
// thread starts, from the perspective
|
||||||
|
// of our instance at least.
|
||||||
|
if status.InReplyTo != nil &&
|
||||||
|
status.InReplyTo.ThreadID != "" {
|
||||||
|
// Just inherit threadID from parent.
|
||||||
status.ThreadID = status.InReplyTo.ThreadID
|
status.ThreadID = status.InReplyTo.ThreadID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status doesn't reply to anything,
|
// Mark new thread (or threaded
|
||||||
// so it's a new local top-level status
|
// subsection) starting from here.
|
||||||
// and therefore needs a thread ID.
|
|
||||||
threadID := id.NewULID()
|
threadID := id.NewULID()
|
||||||
|
|
||||||
if err := p.state.DB.PutThread(
|
if err := p.state.DB.PutThread(
|
||||||
ctx,
|
ctx,
|
||||||
>smodel.Thread{
|
>smodel.Thread{
|
||||||
|
@ -242,6 +242,50 @@ func (suite *StatusCreateTestSuite) TestProcessLanguageWithScriptPart() {
|
|||||||
suite.Equal("zh-Hans", *apiStatus.Language)
|
suite.Equal("zh-Hans", *apiStatus.Language)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *StatusCreateTestSuite) TestProcessReplyToUnthreadedRemoteStatus() {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
creatingAccount := suite.testAccounts["local_account_1"]
|
||||||
|
creatingApplication := suite.testApplications["application_1"]
|
||||||
|
inReplyTo := suite.testStatuses["remote_account_1_status_1"]
|
||||||
|
|
||||||
|
// Reply to a remote status that
|
||||||
|
// doesn't have a threadID set on it.
|
||||||
|
statusCreateForm := &apimodel.AdvancedStatusCreateForm{
|
||||||
|
StatusCreateRequest: apimodel.StatusCreateRequest{
|
||||||
|
Status: "boobies",
|
||||||
|
MediaIDs: []string{},
|
||||||
|
Poll: nil,
|
||||||
|
InReplyToID: inReplyTo.ID,
|
||||||
|
Sensitive: false,
|
||||||
|
SpoilerText: "this is a reply",
|
||||||
|
Visibility: apimodel.VisibilityPublic,
|
||||||
|
ScheduledAt: "",
|
||||||
|
Language: "en",
|
||||||
|
ContentType: apimodel.StatusContentTypePlain,
|
||||||
|
},
|
||||||
|
AdvancedVisibilityFlagsForm: apimodel.AdvancedVisibilityFlagsForm{
|
||||||
|
Federated: nil,
|
||||||
|
Boostable: nil,
|
||||||
|
Replyable: nil,
|
||||||
|
Likeable: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
apiStatus, err := suite.status.Create(ctx, creatingAccount, creatingApplication, statusCreateForm)
|
||||||
|
suite.NoError(err)
|
||||||
|
suite.NotNil(apiStatus)
|
||||||
|
|
||||||
|
// ThreadID should be set on the status,
|
||||||
|
// even though the replied-to status does
|
||||||
|
// not have a threadID.
|
||||||
|
dbStatus, dbErr := suite.state.DB.GetStatusByID(ctx, apiStatus.ID)
|
||||||
|
if dbErr != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
suite.NotEmpty(dbStatus.ThreadID)
|
||||||
|
}
|
||||||
|
|
||||||
func TestStatusCreateTestSuite(t *testing.T) {
|
func TestStatusCreateTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(StatusCreateTestSuite))
|
suite.Run(t, new(StatusCreateTestSuite))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user