mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:40:01 +00:00
[bugfix] Fix relationship not updating 'following' on accept follow request (#1658)
This commit is contained in:
parent
fe4ea964cd
commit
344c7e5cbd
3 changed files with 33 additions and 9 deletions
3
internal/cache/cache.go
vendored
3
internal/cache/cache.go
vendored
|
@ -102,6 +102,9 @@ func (c *Caches) setuphooks() {
|
||||||
// Invalidate follow request target account ID cached visibility.
|
// Invalidate follow request target account ID cached visibility.
|
||||||
c.Visibility.Invalidate("ItemID", followReq.TargetAccountID)
|
c.Visibility.Invalidate("ItemID", followReq.TargetAccountID)
|
||||||
c.Visibility.Invalidate("RequesterID", followReq.TargetAccountID)
|
c.Visibility.Invalidate("RequesterID", followReq.TargetAccountID)
|
||||||
|
|
||||||
|
// Invalidate any cached follow corresponding to this request.
|
||||||
|
c.GTS.Follow().Invalidate("AccountID.TargetAccountID", followReq.AccountID, followReq.TargetAccountID)
|
||||||
})
|
})
|
||||||
|
|
||||||
c.GTS.Status().SetInvalidateCallback(func(status *gtsmodel.Status) {
|
c.GTS.Status().SetInvalidateCallback(func(status *gtsmodel.Status) {
|
||||||
|
|
|
@ -204,7 +204,8 @@ func (r *relationshipDB) AcceptFollowRequest(ctx context.Context, sourceAccountI
|
||||||
return nil, r.conn.ProcessError(err)
|
return nil, r.conn.ProcessError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalidate follow request from cache lookups.
|
// Invalidate follow request from cache lookups; this will
|
||||||
|
// invalidate the follow as well via the invalidate hook.
|
||||||
r.state.Caches.GTS.FollowRequest().Invalidate("ID", followReq.ID)
|
r.state.Caches.GTS.FollowRequest().Invalidate("ID", followReq.ID)
|
||||||
|
|
||||||
// Delete original follow request notification
|
// Delete original follow request notification
|
||||||
|
@ -225,12 +226,8 @@ func (r *relationshipDB) RejectFollowRequest(ctx context.Context, sourceAccountI
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete original follow request.
|
// Delete original follow request.
|
||||||
if _, err := r.conn.
|
if err := r.DeleteFollowRequestByID(ctx, followReq.ID); err != nil {
|
||||||
NewDelete().
|
return err
|
||||||
Table("follow_requests").
|
|
||||||
Where("? = ?", bun.Ident("id"), followReq.ID).
|
|
||||||
Exec(ctx); err != nil {
|
|
||||||
return r.conn.ProcessError(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete original follow request notification
|
// Delete original follow request notification
|
||||||
|
|
|
@ -568,6 +568,14 @@ func (suite *RelationshipTestSuite) TestAcceptFollowRequestOK() {
|
||||||
account := suite.testAccounts["admin_account"]
|
account := suite.testAccounts["admin_account"]
|
||||||
targetAccount := suite.testAccounts["local_account_2"]
|
targetAccount := suite.testAccounts["local_account_2"]
|
||||||
|
|
||||||
|
// Fetch relationship before follow request.
|
||||||
|
relationship, err := suite.db.GetRelationship(ctx, account.ID, targetAccount.ID)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
suite.False(relationship.Following)
|
||||||
|
suite.False(relationship.Requested)
|
||||||
|
|
||||||
followRequest := >smodel.FollowRequest{
|
followRequest := >smodel.FollowRequest{
|
||||||
ID: "01GEF753FWHCHRDWR0QEHBXM8W",
|
ID: "01GEF753FWHCHRDWR0QEHBXM8W",
|
||||||
URI: "http://localhost:8080/weeeeeeeeeeeeeeeee",
|
URI: "http://localhost:8080/weeeeeeeeeeeeeeeee",
|
||||||
|
@ -575,10 +583,18 @@ func (suite *RelationshipTestSuite) TestAcceptFollowRequestOK() {
|
||||||
TargetAccountID: targetAccount.ID,
|
TargetAccountID: targetAccount.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := suite.db.Put(ctx, followRequest); err != nil {
|
if err := suite.db.PutFollowRequest(ctx, followRequest); err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch relationship while follow requested.
|
||||||
|
relationship, err = suite.db.GetRelationship(ctx, account.ID, targetAccount.ID)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
suite.False(relationship.Following)
|
||||||
|
suite.True(relationship.Requested)
|
||||||
|
|
||||||
followRequestNotification := >smodel.Notification{
|
followRequestNotification := >smodel.Notification{
|
||||||
ID: "01GV8MY1Q9KX2ZSWN4FAQ3V1PB",
|
ID: "01GV8MY1Q9KX2ZSWN4FAQ3V1PB",
|
||||||
OriginAccountID: account.ID,
|
OriginAccountID: account.ID,
|
||||||
|
@ -586,7 +602,7 @@ func (suite *RelationshipTestSuite) TestAcceptFollowRequestOK() {
|
||||||
NotificationType: gtsmodel.NotificationFollowRequest,
|
NotificationType: gtsmodel.NotificationFollowRequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := suite.db.Put(ctx, followRequestNotification); err != nil {
|
if err := suite.db.PutNotification(ctx, followRequestNotification); err != nil {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,6 +615,14 @@ func (suite *RelationshipTestSuite) TestAcceptFollowRequestOK() {
|
||||||
notification, err := suite.db.GetNotificationByID(ctx, followRequestNotification.ID)
|
notification, err := suite.db.GetNotificationByID(ctx, followRequestNotification.ID)
|
||||||
suite.ErrorIs(err, db.ErrNoEntries)
|
suite.ErrorIs(err, db.ErrNoEntries)
|
||||||
suite.Nil(notification)
|
suite.Nil(notification)
|
||||||
|
|
||||||
|
// Fetch relationship while followed.
|
||||||
|
relationship, err = suite.db.GetRelationship(ctx, account.ID, targetAccount.ID)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
suite.True(relationship.Following)
|
||||||
|
suite.False(relationship.Requested)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RelationshipTestSuite) TestAcceptFollowRequestNoNotification() {
|
func (suite *RelationshipTestSuite) TestAcceptFollowRequestNoNotification() {
|
||||||
|
|
Loading…
Reference in a new issue