typeutils

package
v0.12.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2023 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIMarkerNameToMarkerName added in v0.11.0

func APIMarkerNameToMarkerName(m apimodel.MarkerName) gtsmodel.MarkerName

func APIVisToVis added in v0.8.0

func APIVisToVis(m apimodel.Visibility) gtsmodel.Visibility

Types

type Converter added in v0.12.0

type Converter struct {
	// contains filtered or unexported fields
}

func NewConverter

func NewConverter(state *state.State) *Converter

func (*Converter) ASAnnounceToStatus added in v0.12.0

func (c *Converter) ASAnnounceToStatus(ctx context.Context, announceable ap.Announceable) (*gtsmodel.Status, bool, error)

ASAnnounceToStatus converts an activitystreams 'announce' into a status.

The returned bool indicates whether this status is new (true) or not new (false).

In other words, if the status is already in the database with the ID set on the announceable, then that will be returned, the returned bool will be false, and no further processing is necessary. If the returned bool is true, indicating that this is a new announce, then further processing will be necessary, because the returned status will be bareboned and require further dereferencing.

This is useful when multiple users on an instance might receive the same boost, and we only want to process the boost once.

NOTE -- this is different from one status being boosted multiple times! In this case, new boosts should indeed be created.

Implementation note: this function creates and returns a boost WRAPPER status which references the boosted status in its BoostOf field. No dereferencing is done on the boosted status by this function. Callers should look at `status.BoostOf` to see the status being boosted, and do dereferencing on it as appropriate.

The returned boolean indicates whether or not the boost has already been seen before by this instance. If it was, then status.BoostOf should be a fully filled-out status. If not, then only status.BoostOf.URI will be set.

func (*Converter) ASBlockToBlock added in v0.12.0

func (c *Converter) ASBlockToBlock(ctx context.Context, blockable ap.Blockable) (*gtsmodel.Block, error)

ASBlockToBlock converts a remote activity streams 'block' representation into a gts model block.

func (*Converter) ASFlagToReport added in v0.12.0

func (c *Converter) ASFlagToReport(ctx context.Context, flaggable ap.Flaggable) (*gtsmodel.Report, error)

ASFlagToReport converts a remote activitystreams 'flag' representation into a gts model report.

func (*Converter) ASFollowToFollow added in v0.12.0

func (c *Converter) ASFollowToFollow(ctx context.Context, followable ap.Followable) (*gtsmodel.Follow, error)

ASFollowToFollowRequest converts a remote activitystreams `follow` representation into gts model follow.

func (*Converter) ASFollowToFollowRequest added in v0.12.0

func (c *Converter) ASFollowToFollowRequest(ctx context.Context, followable ap.Followable) (*gtsmodel.FollowRequest, error)

ASFollowToFollowRequest converts a remote activitystreams `follow` representation into gts model follow request.

func (*Converter) ASLikeToFave added in v0.12.0

func (c *Converter) ASLikeToFave(ctx context.Context, likeable ap.Likeable) (*gtsmodel.StatusFave, error)

ASLikeToFave converts a remote activitystreams 'like' representation into a gts model status fave.

func (*Converter) ASRepresentationToAccount added in v0.12.0

func (c *Converter) ASRepresentationToAccount(ctx context.Context, accountable ap.Accountable, accountDomain string) (*gtsmodel.Account, error)

ASRepresentationToAccount converts a remote account/person/application representation into a gts model account.

If accountDomain is provided then this value will be used as the account's Domain, else the AP ID host.

func (*Converter) ASStatusToStatus added in v0.12.0

func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusable) (*gtsmodel.Status, error)

ASStatus converts a remote activitystreams 'status' representation into a gts model status.

func (*Converter) AccountToAPIAccountBlocked added in v0.12.0

func (c *Converter) AccountToAPIAccountBlocked(ctx context.Context, a *gtsmodel.Account) (*apimodel.Account, error)

AccountToAPIAccountBlocked takes a db model account as a param, and returns a apitype account, or an error if something goes wrong. The returned account will be a bare minimum representation of the account. This function should be used when someone wants to view an account they've blocked.

func (*Converter) AccountToAPIAccountPublic added in v0.12.0

func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.Account) (*apimodel.Account, error)

AccountToAPIAccountPublic takes a db model account as a param, and returns a populated apitype account, or an error if something goes wrong. The returned account should be ready to serialize on an API level, and may NOT have sensitive fields. In other words, this is the public record that the server has of an account.

func (*Converter) AccountToAPIAccountSensitive added in v0.12.0

func (c *Converter) AccountToAPIAccountSensitive(ctx context.Context, a *gtsmodel.Account) (*apimodel.Account, error)

AppToAPIAppSensitive takes a db model application as a param, and returns a populated apitype application, or an error if something goes wrong. The returned application should be ready to serialize on an API level, and may have sensitive fields (such as client id and client secret), so serve it only to an authorized user who should have permission to see it.

func (*Converter) AccountToAS added in v0.12.0

AccountToAS converts a gts model account into an activity streams person, suitable for federation

func (*Converter) AccountToASMinimal added in v0.12.0

func (c *Converter) AccountToASMinimal(ctx context.Context, a *gtsmodel.Account) (vocab.ActivityStreamsPerson, error)

AccountToASMinimal converts a gts model account into an activity streams person, suitable for federation.

The returned account will just have the Type, Username, PublicKey, and ID properties set. This is suitable for serving to requesters to whom we want to give as little information as possible because we don't trust them (yet).

func (*Converter) AccountToAdminAPIAccount added in v0.12.0

func (c *Converter) AccountToAdminAPIAccount(ctx context.Context, a *gtsmodel.Account) (*apimodel.AdminAccountInfo, error)

func (*Converter) AppToAPIAppPublic added in v0.12.0

func (c *Converter) AppToAPIAppPublic(ctx context.Context, a *gtsmodel.Application) (*apimodel.Application, error)

AppToAPIAppPublic takes a db model application as a param, and returns a populated apitype application, or an error if something goes wrong. The returned application should be ready to serialize on an API level, and has sensitive fields sanitized so that it can be served to non-authorized accounts without revealing any private information.

func (*Converter) AppToAPIAppSensitive added in v0.12.0

func (c *Converter) AppToAPIAppSensitive(ctx context.Context, a *gtsmodel.Application) (*apimodel.Application, error)

func (*Converter) AttachmentToAPIAttachment added in v0.12.0

func (c *Converter) AttachmentToAPIAttachment(ctx context.Context, a *gtsmodel.MediaAttachment) (apimodel.Attachment, error)

AttachmentToAPIAttachment converts a gts model media attacahment into its api representation for serialization on the API.

func (*Converter) AttachmentToAS added in v0.12.0

AttachmentToAS converts a gts model media attachment into an activity streams Attachment, suitable for federation

func (*Converter) BlockToAS added in v0.12.0

BlockToAS converts a gts model block into an activityStreams BLOCK, suitable for federation. we want to end up with something like this:

{
	"@context": "https://www.w3.org/ns/activitystreams",
	"actor": "https://example.org/users/some_user",
	"id":"https://example.org/users/some_user/blocks/SOME_ULID_OF_A_BLOCK",
	"object":"https://some_other.instance/users/some_other_user",
	"type":"Block"
}

func (*Converter) BoostToAS added in v0.12.0

func (c *Converter) BoostToAS(ctx context.Context, boostWrapperStatus *gtsmodel.Status, boostingAccount *gtsmodel.Account, boostedAccount *gtsmodel.Account) (vocab.ActivityStreamsAnnounce, error)

BoostToAS converts a gts model boost into an activityStreams ANNOUNCE, suitable for federation

func (*Converter) DomainPermToAPIDomainPerm added in v0.12.0

func (c *Converter) DomainPermToAPIDomainPerm(
	ctx context.Context,
	d gtsmodel.DomainPermission,
	export bool,
) (*apimodel.DomainPermission, error)

DomainPermToAPIDomainPerm converts a gts model domin block or allow into an api domain permission.

func (*Converter) EmojiCategoryToAPIEmojiCategory added in v0.12.0

func (c *Converter) EmojiCategoryToAPIEmojiCategory(ctx context.Context, category *gtsmodel.EmojiCategory) (*apimodel.EmojiCategory, error)

EmojiCategoryToAPIEmojiCategory converts a gts model emoji category into its api (frontend) representation.

func (*Converter) EmojiToAPIEmoji added in v0.12.0

func (c *Converter) EmojiToAPIEmoji(ctx context.Context, e *gtsmodel.Emoji) (apimodel.Emoji, error)

EmojiToAPIEmoji converts a gts model emoji into its api (frontend) representation for serialization on the API.

func (*Converter) EmojiToAS added in v0.12.0

func (c *Converter) EmojiToAS(ctx context.Context, e *gtsmodel.Emoji) (vocab.TootEmoji, error)

EmojiToAS converts a gts emoji into a mastodon ns Emoji, suitable for federation. we're making something like this:

{
	"id": "https://example.com/emoji/123",
	"type": "Emoji",
	"name": ":kappa:",
	"icon": {
		"type": "Image",
		"mediaType": "image/png",
		"url": "https://example.com/files/kappa.png"
	}
}

func (*Converter) EmojiToAdminAPIEmoji added in v0.12.0

func (c *Converter) EmojiToAdminAPIEmoji(ctx context.Context, e *gtsmodel.Emoji) (*apimodel.AdminEmoji, error)

EmojiToAdminAPIEmoji converts a gts model emoji into an API representation with extra admin information.

func (*Converter) FaveToAS added in v0.12.0

FaveToAS converts a gts model status fave into an activityStreams LIKE, suitable for federation. We want to end up with something like this:

{ "@context": "https://www.w3.org/ns/activitystreams", "actor": "https://ondergrond.org/users/dumpsterqueer", "id": "https://ondergrond.org/users/dumpsterqueer#likes/44584", "object": "https://testingtesting123.xyz/users/gotosocial_test_account/statuses/771aea80-a33d-4d6d-8dfd-57d4d2bfcbd4", "type": "Like" }

func (*Converter) FollowRequestToFollow added in v0.12.0

func (c *Converter) FollowRequestToFollow(ctx context.Context, f *gtsmodel.FollowRequest) *gtsmodel.Follow

FollowRequestToFollow just converts a follow request into a follow, that's it! No bells and whistles.

func (*Converter) FollowToAS added in v0.12.0

FollowToASFollow converts a gts model Follow into an activity streams Follow, suitable for federation

func (*Converter) InstanceRuleToAPIRule added in v0.12.0

func (c *Converter) InstanceRuleToAPIRule(r gtsmodel.Rule) apimodel.InstanceRule

InstanceRuleToAdminAPIRule converts a local instance rule into its api equivalent for serving at /api/v1/admin/instance/rules/:id

func (*Converter) InstanceRuleToAdminAPIRule added in v0.12.0

func (c *Converter) InstanceRuleToAdminAPIRule(r *gtsmodel.Rule) *apimodel.AdminInstanceRule

InstanceRuleToAdminAPIRule converts a local instance rule into its api equivalent for serving at /api/v1/admin/instance/rules/:id

func (*Converter) InstanceRulesToAPIRules added in v0.12.0

func (c *Converter) InstanceRulesToAPIRules(r []gtsmodel.Rule) []apimodel.InstanceRule

InstanceRulesToAPIRules converts all local instance rules into their api equivalent for serving at /api/v1/instance/rules

func (*Converter) InstanceToAPIV1Instance added in v0.12.0

func (c *Converter) InstanceToAPIV1Instance(ctx context.Context, i *gtsmodel.Instance) (*apimodel.InstanceV1, error)

InstanceToAPIV1Instance converts a gts instance into its api equivalent for serving at /api/v1/instance

func (*Converter) InstanceToAPIV2Instance added in v0.12.0

func (c *Converter) InstanceToAPIV2Instance(ctx context.Context, i *gtsmodel.Instance) (*apimodel.InstanceV2, error)

InstanceToAPIV2Instance converts a gts instance into its api equivalent for serving at /api/v2/instance

func (*Converter) ListToAPIList added in v0.12.0

func (c *Converter) ListToAPIList(ctx context.Context, l *gtsmodel.List) (*apimodel.List, error)

ListToAPIList converts one gts model list into an api model list, for serving at /api/v1/lists/{id}

func (*Converter) MarkersToAPIMarker added in v0.12.0

func (c *Converter) MarkersToAPIMarker(ctx context.Context, markers []*gtsmodel.Marker) (*apimodel.Marker, error)

MarkersToAPIMarker converts several gts model markers into an api marker, for serving at /api/v1/markers

func (*Converter) MentionToAPIMention added in v0.12.0

func (c *Converter) MentionToAPIMention(ctx context.Context, m *gtsmodel.Mention) (apimodel.Mention, error)

MentionToAPIMention converts a gts model mention into its api (frontend) representation for serialization on the API.

func (*Converter) MentionToAS added in v0.12.0

MentionToAS converts a gts model mention into an activity streams Mention, suitable for federation

func (*Converter) NotificationToAPINotification added in v0.12.0

func (c *Converter) NotificationToAPINotification(ctx context.Context, n *gtsmodel.Notification) (*apimodel.Notification, error)

NotificationToAPINotification converts a gts notification into a api notification

func (*Converter) OutboxToASCollection added in v0.12.0

func (c *Converter) OutboxToASCollection(ctx context.Context, outboxID string) (vocab.ActivityStreamsOrderedCollection, error)

OutboxToASCollection returns an ordered collection with appropriate id, next, and last fields. The returned collection won't have any actual entries; just links to where entries can be obtained. we want something that looks like this:

{
	"@context": "https://www.w3.org/ns/activitystreams",
	"id": "https://example.org/users/whatever/outbox",
	"type": "OrderedCollection",
	"first": "https://example.org/users/whatever/outbox?page=true"
}

func (*Converter) RelationshipToAPIRelationship added in v0.12.0

func (c *Converter) RelationshipToAPIRelationship(ctx context.Context, r *gtsmodel.Relationship) (*apimodel.Relationship, error)

RelationshipToAPIRelationship converts a gts relationship into its api equivalent for serving in various places

func (*Converter) ReportToAPIReport added in v0.12.0

func (c *Converter) ReportToAPIReport(ctx context.Context, r *gtsmodel.Report) (*apimodel.Report, error)

ReportToAPIReport converts a gts model report into an api model report, for serving at /api/v1/reports

func (*Converter) ReportToASFlag added in v0.12.0

func (c *Converter) ReportToASFlag(ctx context.Context, r *gtsmodel.Report) (vocab.ActivityStreamsFlag, error)

ReportToASFlag converts a gts model report into an activitystreams FLAG, suitable for federation.

func (*Converter) ReportToAdminAPIReport added in v0.12.0

func (c *Converter) ReportToAdminAPIReport(ctx context.Context, r *gtsmodel.Report, requestingAccount *gtsmodel.Account) (*apimodel.AdminReport, error)

ReportToAdminAPIReport converts a gts model report into an admin view report, for serving at /api/v1/admin/reports

func (*Converter) StatusToAPIStatus added in v0.12.0

func (c *Converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*apimodel.Status, error)

StatusToAPIStatus converts a gts model status into its api (frontend) representation for serialization on the API.

Requesting account can be nil.

func (*Converter) StatusToAS added in v0.12.0

func (c *Converter) StatusToAS(ctx context.Context, s *gtsmodel.Status) (ap.Statusable, error)

StatusToAS converts a gts model status into an ActivityStreams Statusable implementation, suitable for federation

func (*Converter) StatusToASDelete added in v0.12.0

func (c *Converter) StatusToASDelete(ctx context.Context, s *gtsmodel.Status) (vocab.ActivityStreamsDelete, error)

StatusToASDelete converts a gts model status into a Delete of that status, using just the URI of the status as object, and addressing the Delete appropriately.

func (*Converter) StatusToASRepliesCollection added in v0.12.0

func (c *Converter) StatusToASRepliesCollection(ctx context.Context, status *gtsmodel.Status, onlyOtherAccounts bool) (vocab.ActivityStreamsCollection, error)

StatusToASRepliesCollection converts a gts model status into an activityStreams REPLIES collection. the goal is to end up with something like this:

{
	"@context": "https://www.w3.org/ns/activitystreams",
	"id": "https://example.org/users/whatever/statuses/01FCNEXAGAKPEX1J7VJRPJP490/replies",
	"type": "Collection",
	"first": {
	"id": "https://example.org/users/whatever/statuses/01FCNEXAGAKPEX1J7VJRPJP490/replies?page=true",
	"type": "CollectionPage",
	"next": "https://example.org/users/whatever/statuses/01FCNEXAGAKPEX1J7VJRPJP490/replies?only_other_accounts=true&page=true",
	"partOf": "https://example.org/users/whatever/statuses/01FCNEXAGAKPEX1J7VJRPJP490/replies",
	"items": []
	}
}

func (*Converter) StatusToBoost added in v0.12.0

func (c *Converter) StatusToBoost(ctx context.Context, s *gtsmodel.Status, boostingAccount *gtsmodel.Account) (*gtsmodel.Status, error)

StatusToBoost wraps the given status into a boosting status.

func (*Converter) StatusToRSSItem added in v0.12.0

func (c *Converter) StatusToRSSItem(ctx context.Context, s *gtsmodel.Status) (*feeds.Item, error)

func (*Converter) StatusURIsToASRepliesPage added in v0.12.0

func (c *Converter) StatusURIsToASRepliesPage(ctx context.Context, status *gtsmodel.Status, onlyOtherAccounts bool, minID string, replies map[string]*url.URL) (vocab.ActivityStreamsCollectionPage, error)

StatusURIsToASRepliesPage returns a collection page with appropriate next/part of pagination. the goal is to end up with something like this:

{
	"@context": "https://www.w3.org/ns/activitystreams",
	"id": "https://example.org/users/whatever/statuses/01FCNEXAGAKPEX1J7VJRPJP490/replies?only_other_accounts=true&page=true",
	"type": "CollectionPage",
	"next": "https://example.org/users/whatever/statuses/01FCNEXAGAKPEX1J7VJRPJP490/replies?min_id=106720870266901180&only_other_accounts=true&page=true",
	"partOf": "https://example.org/users/whatever/statuses/01FCNEXAGAKPEX1J7VJRPJP490/replies",
	"items": [
		"https://example.com/users/someone/statuses/106720752853216226",
		"https://somewhere.online/users/eeeeeeeeeep/statuses/106720870163727231"
	]
}

func (*Converter) StatusesToASFeaturedCollection added in v0.12.0

func (c *Converter) StatusesToASFeaturedCollection(ctx context.Context, featuredCollectionID string, statuses []*gtsmodel.Status) (vocab.ActivityStreamsOrderedCollection, error)

StatusesToASFeaturedCollection converts a slice of statuses into an ordered collection of URIs, suitable for serializing and serving via the activitypub API.

func (*Converter) StatusesToASOutboxPage added in v0.12.0

func (c *Converter) StatusesToASOutboxPage(ctx context.Context, outboxID string, maxID string, minID string, statuses []*gtsmodel.Status) (vocab.ActivityStreamsOrderedCollectionPage, error)

StatusesToASOutboxPage returns an ordered collection page using the given statuses and parameters as contents.

The maxID and minID should be the parameters that were passed to the database to obtain the given statuses. These will be used to create the 'id' field of the collection.

OutboxID is used to create the 'partOf' field in the collection.

Appropriate 'next' and 'prev' fields will be created based on the highest and lowest IDs present in the statuses slice. the goal is to end up with something like this:

{
	"id": "https://example.org/users/whatever/outbox?page=true",
	"type": "OrderedCollectionPage",
	"next": "https://example.org/users/whatever/outbox?max_id=01FJC1Q0E3SSQR59TD2M1KP4V8&page=true",
	"prev": "https://example.org/users/whatever/outbox?min_id=01FJC1Q0E3SSQR59TD2M1KP4V8&page=true",
	"partOf": "https://example.org/users/whatever/outbox",
	"orderedItems": [
		"id": "https://example.org/users/whatever/statuses/01FJC1MKPVX2VMWP2ST93Q90K7/activity",
		"type": "Create",
		"actor": "https://example.org/users/whatever",
		"published": "2021-10-18T20:06:18Z",
		"to": [
			"https://www.w3.org/ns/activitystreams#Public"
		],
		"cc": [
			"https://example.org/users/whatever/followers"
		],
		"object": "https://example.org/users/whatever/statuses/01FJC1MKPVX2VMWP2ST93Q90K7"
	]
}

func (*Converter) TagToAPITag added in v0.12.0

func (c *Converter) TagToAPITag(ctx context.Context, t *gtsmodel.Tag, stubHistory bool) (apimodel.Tag, error)

TagToAPITag converts a gts model tag into its api (frontend) representation for serialization on the API. If stubHistory is set to 'true', then the 'history' field of the tag will be populated with a pointer to an empty slice, for API compatibility reasons.

func (*Converter) TagToAS added in v0.12.0

func (c *Converter) TagToAS(ctx context.Context, t *gtsmodel.Tag) (vocab.TootHashtag, error)

TagToAS converts a gts model tag into a toot Hashtag, suitable for federation.

func (*Converter) VisToAPIVis added in v0.12.0

VisToAPIVis converts a gts visibility into its api equivalent

func (*Converter) WrapPersonInUpdate added in v0.12.0

func (c *Converter) WrapPersonInUpdate(person vocab.ActivityStreamsPerson, originAccount *gtsmodel.Account) (vocab.ActivityStreamsUpdate, error)

WrapPersonInUpdate ...

func (*Converter) WrapStatusableInCreate added in v0.12.0

func (c *Converter) WrapStatusableInCreate(status ap.Statusable, objectIRIOnly bool) (vocab.ActivityStreamsCreate, error)

WrapNoteInCreate wraps a Statusable with a Create activity.

If objectIRIOnly is set to true, then the function won't put the *entire* note in the Object field of the Create, but just the AP URI of the note. This is useful in cases where you want to give a remote server something to dereference, and still have control over whether or not they're allowed to actually see the contents.

func (*Converter) WrapStatusableInUpdate added in v0.12.0

func (c *Converter) WrapStatusableInUpdate(status ap.Statusable, objectIRIOnly bool) (vocab.ActivityStreamsUpdate, error)

WrapStatusableInUpdate wraps a Statusable with an Update activity.

If objectIRIOnly is set to true, then the function won't put the *entire* note in the Object field of the Create, but just the AP URI of the note. This is useful in cases where you want to give a remote server something to dereference, and still have control over whether or not they're allowed to actually see the contents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL