mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-01 06:50:00 +00:00
[feature] Add requested_by
to relationship model (#2672)
* [feature] Add `requested_by` to relationship model * whoops, missed some tests
This commit is contained in:
parent
65a273bc39
commit
8cafa6b74b
9 changed files with 121 additions and 2 deletions
|
@ -345,6 +345,10 @@ definitions:
|
||||||
description: You have requested to follow this account, and the request is pending.
|
description: You have requested to follow this account, and the request is pending.
|
||||||
type: boolean
|
type: boolean
|
||||||
x-go-name: Requested
|
x-go-name: Requested
|
||||||
|
requested_by:
|
||||||
|
description: This account has requested to follow you, and the request is pending.
|
||||||
|
type: boolean
|
||||||
|
x-go-name: RequestedBy
|
||||||
showing_reblogs:
|
showing_reblogs:
|
||||||
description: You are seeing reblogs/boosts from this account in your home timeline.
|
description: You are seeing reblogs/boosts from this account in your home timeline.
|
||||||
type: boolean
|
type: boolean
|
||||||
|
@ -1487,7 +1491,10 @@ definitions:
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
format: int64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
description: 'Statistics about the instance: number of posts, accounts, etc.'
|
description: |-
|
||||||
|
Statistics about the instance: number of posts, accounts, etc.
|
||||||
|
Values are pointers because we don't want to skip 0 values when
|
||||||
|
rendering stats via web templates.
|
||||||
type: object
|
type: object
|
||||||
x-go-name: Stats
|
x-go-name: Stats
|
||||||
terms:
|
terms:
|
||||||
|
@ -3648,6 +3655,7 @@ paths:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- multipart/form-data
|
- multipart/form-data
|
||||||
|
description: NOT IMPLEMENTED YET!
|
||||||
operationId: accountMove
|
operationId: accountMove
|
||||||
parameters:
|
parameters:
|
||||||
- description: Password of the account user, for confirmation.
|
- description: Password of the account user, for confirmation.
|
||||||
|
|
|
@ -92,6 +92,7 @@ func (suite *AuthorizeTestSuite) TestAuthorize() {
|
||||||
"muting": false,
|
"muting": false,
|
||||||
"muting_notifications": false,
|
"muting_notifications": false,
|
||||||
"requested": false,
|
"requested": false,
|
||||||
|
"requested_by": false,
|
||||||
"domain_blocking": false,
|
"domain_blocking": false,
|
||||||
"endorsed": false,
|
"endorsed": false,
|
||||||
"note": ""
|
"note": ""
|
||||||
|
|
|
@ -92,6 +92,7 @@ func (suite *RejectTestSuite) TestReject() {
|
||||||
"muting": false,
|
"muting": false,
|
||||||
"muting_notifications": false,
|
"muting_notifications": false,
|
||||||
"requested": false,
|
"requested": false,
|
||||||
|
"requested_by": false,
|
||||||
"domain_blocking": false,
|
"domain_blocking": false,
|
||||||
"endorsed": false,
|
"endorsed": false,
|
||||||
"note": ""
|
"note": ""
|
||||||
|
|
|
@ -42,6 +42,8 @@ type Relationship struct {
|
||||||
MutingNotifications bool `json:"muting_notifications"`
|
MutingNotifications bool `json:"muting_notifications"`
|
||||||
// You have requested to follow this account, and the request is pending.
|
// You have requested to follow this account, and the request is pending.
|
||||||
Requested bool `json:"requested"`
|
Requested bool `json:"requested"`
|
||||||
|
// This account has requested to follow you, and the request is pending.
|
||||||
|
RequestedBy bool `json:"requested_by"`
|
||||||
// You are blocking this account's domain.
|
// You are blocking this account's domain.
|
||||||
DomainBlocking bool `json:"domain_blocking"`
|
DomainBlocking bool `json:"domain_blocking"`
|
||||||
// You are featuring this account on your profile.
|
// You are featuring this account on your profile.
|
||||||
|
|
|
@ -74,6 +74,15 @@ func (r *relationshipDB) GetRelationship(ctx context.Context, requestingAccount
|
||||||
return nil, gtserror.Newf("error checking requested: %w", err)
|
return nil, gtserror.Newf("error checking requested: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if target has follow requested requesting
|
||||||
|
rel.RequestedBy, err = r.IsFollowRequested(ctx,
|
||||||
|
targetAccount,
|
||||||
|
requestingAccount,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, gtserror.Newf("error checking requestedBy: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// check if the requesting account is blocking the target account
|
// check if the requesting account is blocking the target account
|
||||||
rel.Blocking, err = r.IsBlocked(ctx, requestingAccount, targetAccount)
|
rel.Blocking, err = r.IsBlocked(ctx, requestingAccount, targetAccount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -596,6 +596,14 @@ func (suite *RelationshipTestSuite) TestAcceptFollowRequestOK() {
|
||||||
suite.False(relationship.Following)
|
suite.False(relationship.Following)
|
||||||
suite.True(relationship.Requested)
|
suite.True(relationship.Requested)
|
||||||
|
|
||||||
|
// Check the other way around too; local_account_2
|
||||||
|
// should have requested_by true for admin now.
|
||||||
|
inverse, err := suite.db.GetRelationship(ctx, targetAccount.ID, account.ID)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
suite.True(inverse.RequestedBy)
|
||||||
|
|
||||||
followRequestNotification := >smodel.Notification{
|
followRequestNotification := >smodel.Notification{
|
||||||
ID: "01GV8MY1Q9KX2ZSWN4FAQ3V1PB",
|
ID: "01GV8MY1Q9KX2ZSWN4FAQ3V1PB",
|
||||||
OriginAccountID: account.ID,
|
OriginAccountID: account.ID,
|
||||||
|
|
|
@ -200,7 +200,8 @@ type Relationship struct {
|
||||||
BlockedBy bool // Is this user blocking you?
|
BlockedBy bool // Is this user blocking you?
|
||||||
Muting bool // Are you muting this user?
|
Muting bool // Are you muting this user?
|
||||||
MutingNotifications bool // Are you muting notifications from this user?
|
MutingNotifications bool // Are you muting notifications from this user?
|
||||||
Requested bool // Do you have a pending follow request for this user?
|
Requested bool // Do you have a pending follow request targeting this user?
|
||||||
|
RequestedBy bool // Does the user have a pending follow request targeting you?
|
||||||
DomainBlocking bool // Are you blocking this user's domain?
|
DomainBlocking bool // Are you blocking this user's domain?
|
||||||
Endorsed bool // Are you featuring this user on your profile?
|
Endorsed bool // Are you featuring this user on your profile?
|
||||||
Note string // Your note on this account.
|
Note string // Your note on this account.
|
||||||
|
|
|
@ -1194,6 +1194,7 @@ func (c *Converter) RelationshipToAPIRelationship(ctx context.Context, r *gtsmod
|
||||||
Muting: r.Muting,
|
Muting: r.Muting,
|
||||||
MutingNotifications: r.MutingNotifications,
|
MutingNotifications: r.MutingNotifications,
|
||||||
Requested: r.Requested,
|
Requested: r.Requested,
|
||||||
|
RequestedBy: r.RequestedBy,
|
||||||
DomainBlocking: r.DomainBlocking,
|
DomainBlocking: r.DomainBlocking,
|
||||||
Endorsed: r.Endorsed,
|
Endorsed: r.Endorsed,
|
||||||
Note: r.Note,
|
Note: r.Note,
|
||||||
|
|
|
@ -1967,6 +1967,94 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontendSuspendedLoca
|
||||||
}`, string(b))
|
}`, string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *InternalToFrontendTestSuite) TestRelationshipFollowRequested() {
|
||||||
|
var (
|
||||||
|
ctx = context.Background()
|
||||||
|
account1 = suite.testAccounts["admin_account"]
|
||||||
|
account2 = suite.testAccounts["local_account_2"]
|
||||||
|
)
|
||||||
|
|
||||||
|
// Put a follow request in the db from
|
||||||
|
// admin account targeting local_account_2.
|
||||||
|
followRequest := >smodel.FollowRequest{
|
||||||
|
ID: "01GEF753FWHCHRDWR0QEHBXM8W",
|
||||||
|
URI: "http://localhost:8080/weeeeeeeeeeeeeeeee",
|
||||||
|
AccountID: account1.ID,
|
||||||
|
TargetAccountID: account2.ID,
|
||||||
|
}
|
||||||
|
if err := suite.db.PutFollowRequest(ctx, followRequest); err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the relationship from the database.
|
||||||
|
dbRelationship, err := suite.state.DB.GetRelationship(ctx, account1.ID, account2.ID)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check API model is set appropriately.
|
||||||
|
relationship, err := suite.typeconverter.RelationshipToAPIRelationship(ctx, dbRelationship)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := json.MarshalIndent(relationship, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
suite.Equal(`{
|
||||||
|
"id": "01F8MH5NBDF2MV7CTC4Q5128HF",
|
||||||
|
"following": false,
|
||||||
|
"showing_reblogs": false,
|
||||||
|
"notifying": false,
|
||||||
|
"followed_by": false,
|
||||||
|
"blocking": false,
|
||||||
|
"blocked_by": false,
|
||||||
|
"muting": false,
|
||||||
|
"muting_notifications": false,
|
||||||
|
"requested": true,
|
||||||
|
"requested_by": false,
|
||||||
|
"domain_blocking": false,
|
||||||
|
"endorsed": false,
|
||||||
|
"note": ""
|
||||||
|
}`, string(b))
|
||||||
|
|
||||||
|
// Check relationship from the other side too.
|
||||||
|
dbRelationship, err = suite.state.DB.GetRelationship(ctx, account2.ID, account1.ID)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check API model is set appropriately.
|
||||||
|
relationship, err = suite.typeconverter.RelationshipToAPIRelationship(ctx, dbRelationship)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err = json.MarshalIndent(relationship, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
suite.Equal(`{
|
||||||
|
"id": "01F8MH17FWEB39HZJ76B6VXSKF",
|
||||||
|
"following": false,
|
||||||
|
"showing_reblogs": false,
|
||||||
|
"notifying": false,
|
||||||
|
"followed_by": false,
|
||||||
|
"blocking": false,
|
||||||
|
"blocked_by": false,
|
||||||
|
"muting": false,
|
||||||
|
"muting_notifications": false,
|
||||||
|
"requested": false,
|
||||||
|
"requested_by": true,
|
||||||
|
"domain_blocking": false,
|
||||||
|
"endorsed": false,
|
||||||
|
"note": ""
|
||||||
|
}`, string(b))
|
||||||
|
}
|
||||||
|
|
||||||
func TestInternalToFrontendTestSuite(t *testing.T) {
|
func TestInternalToFrontendTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(InternalToFrontendTestSuite))
|
suite.Run(t, new(InternalToFrontendTestSuite))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue