mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-23 14:32:55 -06:00
[bugfix] Fix setting bot on/off (#3986)
* [bugfix] Fix setting bot on/off * read client messages in tests * test fix
This commit is contained in:
parent
eb4114bf12
commit
c8a780e12a
5 changed files with 97 additions and 23 deletions
|
|
@ -39,20 +39,32 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
||||
)
|
||||
|
||||
// AccountToAS converts a gts model account
|
||||
// into an activity streams person or service.
|
||||
func accountableForActorType(actorType gtsmodel.AccountActorType) ap.Accountable {
|
||||
switch actorType {
|
||||
case gtsmodel.AccountActorTypeApplication:
|
||||
return streams.NewActivityStreamsApplication()
|
||||
case gtsmodel.AccountActorTypeGroup:
|
||||
return streams.NewActivityStreamsGroup()
|
||||
case gtsmodel.AccountActorTypeOrganization:
|
||||
return streams.NewActivityStreamsOrganization()
|
||||
case gtsmodel.AccountActorTypePerson:
|
||||
return streams.NewActivityStreamsPerson()
|
||||
case gtsmodel.AccountActorTypeService:
|
||||
return streams.NewActivityStreamsService()
|
||||
default:
|
||||
panic("invalid actor type")
|
||||
}
|
||||
}
|
||||
|
||||
// AccountToAS converts a gts model
|
||||
// account into an accountable.
|
||||
func (c *Converter) AccountToAS(
|
||||
ctx context.Context,
|
||||
a *gtsmodel.Account,
|
||||
) (ap.Accountable, error) {
|
||||
// accountable is a service if this
|
||||
// is a bot account, otherwise a person.
|
||||
var accountable ap.Accountable
|
||||
if a.ActorType.IsBot() {
|
||||
accountable = streams.NewActivityStreamsService()
|
||||
} else {
|
||||
accountable = streams.NewActivityStreamsPerson()
|
||||
}
|
||||
// Use appropriate underlying
|
||||
// actor type of accountable.
|
||||
accountable := accountableForActorType(a.ActorType)
|
||||
|
||||
// id should be the activitypub URI of this user
|
||||
// something like https://example.org/users/example_user
|
||||
|
|
@ -389,14 +401,9 @@ func (c *Converter) AccountToASMinimal(
|
|||
ctx context.Context,
|
||||
a *gtsmodel.Account,
|
||||
) (ap.Accountable, error) {
|
||||
// accountable is a service if this
|
||||
// is a bot account, otherwise a person.
|
||||
var accountable ap.Accountable
|
||||
if a.ActorType.IsBot() {
|
||||
accountable = streams.NewActivityStreamsService()
|
||||
} else {
|
||||
accountable = streams.NewActivityStreamsPerson()
|
||||
}
|
||||
// Use appropriate underlying
|
||||
// actor type of accountable.
|
||||
accountable := accountableForActorType(a.ActorType)
|
||||
|
||||
// id should be the activitypub URI of this user
|
||||
// something like https://example.org/users/example_user
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ func (suite *InternalToASTestSuite) TestAccountToASBot() {
|
|||
*testAccount = *suite.testAccounts["local_account_1"] // take zork for this test
|
||||
|
||||
// Update zork to be a bot.
|
||||
testAccount.ActorType = gtsmodel.AccountActorTypeService
|
||||
testAccount.ActorType = gtsmodel.AccountActorTypeApplication
|
||||
if err := suite.state.DB.UpdateAccount(context.Background(), testAccount); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
|
@ -155,7 +155,7 @@ func (suite *InternalToASTestSuite) TestAccountToASBot() {
|
|||
"published": "2022-05-20T11:09:18Z",
|
||||
"summary": "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e",
|
||||
"tag": [],
|
||||
"type": "Service",
|
||||
"type": "Application",
|
||||
"url": "http://localhost:8080/@the_mighty_zork"
|
||||
}`, string(bytes))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue