summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltoas.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-04-11 16:36:40 +0200
committerLibravatar GitHub <noreply@github.com>2025-04-11 15:36:40 +0100
commitc8a780e12a8112a4d4cbe8ed72d241a382f73903 (patch)
treeb385a1d5e11a0de4a84bba01d44e2b2b75abff16 /internal/typeutils/internaltoas.go
parent[chore] Fix header insets (#3987) (diff)
downloadgotosocial-c8a780e12a8112a4d4cbe8ed72d241a382f73903.tar.xz
[bugfix] Fix setting bot on/off (#3986)
* [bugfix] Fix setting bot on/off * read client messages in tests * test fix
Diffstat (limited to 'internal/typeutils/internaltoas.go')
-rw-r--r--internal/typeutils/internaltoas.go43
1 files changed, 25 insertions, 18 deletions
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index 4e6c6da77..9d9a7e289 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -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