mastodon

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package mastodon provides Mastodon API compatibility services for actor and account management.

Index

Constants

View Source
const (
	// VisibilityPublic represents public visibility for posts
	VisibilityPublic = "public"
)

Variables

View Source
var EmojiRegex = regexp.MustCompile(`:([a-zA-Z0-9_]+):`)

EmojiRegex matches emoji shortcodes in text Format: :shortcode: where shortcode contains alphanumeric characters and underscores

Functions

func ExtractHashtags

func ExtractHashtags(content string) []string

ExtractHashtags extracts hashtags from HTML or plain text content Returns a slice of unique hashtag names (without the # prefix)

func ExtractHashtagsWithCase

func ExtractHashtagsWithCase(content string) []string

ExtractHashtagsWithCase extracts hashtags preserving their original case Useful for display purposes

func ExtractShortcodes

func ExtractShortcodes(content string) []string

ExtractShortcodes extracts just the shortcodes from content without looking them up Useful for validation or when you just need the shortcode list

func GenerateNumericID

func GenerateNumericID(username string) string

GenerateNumericID generates a stable numeric ID from a username This ensures the same username always generates the same ID

func GenerateNumericIDFromActorID

func GenerateNumericIDFromActorID(actorID string) string

GenerateNumericIDFromActorID generates a stable numeric ID from an ActivityPub actor ID

func NormalizeHashtag

func NormalizeHashtag(tag string) string

NormalizeHashtag normalizes a hashtag for storage/lookup Converts to lowercase and removes the # prefix if present

Types

type ActorService

type ActorService interface {
	GetAccountByUsername(ctx context.Context, username string) (*models.Account, error)
	GetAccountWithStats(ctx context.Context, username string) (*models.Account, error)
	GetAccountsByIDs(ctx context.Context, actorIDs []string) ([]models.Account, error)
}

ActorService provides higher-level actor operations

func NewActorService

func NewActorService(store core.RepositoryStorage, converter Converter, logger *zap.Logger) ActorService

NewActorService creates a new actor service instance

type Converter

type Converter interface {
	// Actor conversions
	ActorToAccount(actor *activitypub.Actor) models.Account
	ActorToAccountWithCounts(actor *activitypub.Actor, followers, following, statuses int) models.Account
	ActorToAccountWithMetadata(actor *activitypub.Actor, metadata *storage.ActorMetadata, followers, following, statuses int) models.Account

	// Object conversions
	ObjectToStatus(obj any, actor *activitypub.Actor) models.Status
	ObjectToStatusWithContext(ctx context.Context, obj any, actor *activitypub.Actor, likeCount, reblogCount int, favorited, reblogged, bookmarked bool) models.Status

	// Conversation conversions
	ConversationToAPI(conv *storagemodels.Conversation, participants []*activitypub.Actor, lastStatus any, unread bool) models.Conversation

	// Filter conversions
	ConvertFilterToMastodon(filter *storage.Filter, keywords []*storage.FilterKeyword, statuses []*storage.FilterStatus) *Filter
	ConvertFilterKeywordToV1(keyword *storage.FilterKeyword, filter *storage.Filter) *V1Filter

	// Mute conversions
	ConvertMuteToRelationship(relationship *models.Relationship, mute *storage.Mute)

	// Notes conversions
	NotesToStatus(note any) models.Status

	// Poll conversions
	PollToAPI(poll *storage.Poll, userVotes []int) models.Poll

	// Utility methods
	ExtractUsernameFromActorID(actorID string) string
	ExtractIDFromURL(url string) string
}

Converter handles all ActivityPub to Mastodon API conversions

func NewConverter

func NewConverter(baseURL string) Converter

NewConverter creates a new converter instance with optimizations

func NewConverterWithEmojis

func NewConverterWithEmojis(baseURL string, emojiRepo *repositories.EmojiRepository) Converter

NewConverterWithEmojis creates a new converter instance with emoji repository access and optimizations

type EmojiParser

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

EmojiParser handles parsing and replacing emoji shortcodes in content

func NewEmojiParser

func NewEmojiParser(store core.RepositoryStorage) *EmojiParser

NewEmojiParser creates a new emoji parser

func (*EmojiParser) ParseEmojis

func (p *EmojiParser) ParseEmojis(ctx context.Context, content string) ([]ParsedEmoji, error)

ParseEmojis extracts emoji shortcodes from content and looks them up

func (*EmojiParser) ProcessContent

func (p *EmojiParser) ProcessContent(ctx context.Context, content string) (string, []ParsedEmoji, error)

ProcessContent parses emojis in content and returns both the processed content and used emojis

func (*EmojiParser) ReplaceEmojis

func (p *EmojiParser) ReplaceEmojis(content string, emojis []ParsedEmoji) string

ReplaceEmojis replaces emoji shortcodes in content with HTML img tags

type Filter

type Filter struct {
	ID           string          `json:"id"`
	Title        string          `json:"title"`
	Context      []string        `json:"context"`
	ExpiresAt    *string         `json:"expires_at"`
	FilterAction string          `json:"filter_action"`
	Keywords     []FilterKeyword `json:"keywords,omitempty"`
	Statuses     []FilterStatus  `json:"statuses,omitempty"`
}

Filter represents a filter group in the Mastodon API v2

type FilterKeyword

type FilterKeyword struct {
	ID        string `json:"id"`
	Keyword   string `json:"keyword"`
	WholeWord bool   `json:"whole_word"`
}

FilterKeyword represents a keyword within a filter

type FilterResult

type FilterResult struct {
	Filter         Filter   `json:"filter"`
	KeywordMatches []string `json:"keyword_matches,omitempty"`
	StatusMatches  []string `json:"status_matches,omitempty"`
}

FilterResult represents a filter match on a status

type FilterStatus

type FilterStatus struct {
	ID       string `json:"id"`
	StatusID string `json:"status_id"`
}

FilterStatus represents a status within a filter

type ParsedEmoji

type ParsedEmoji struct {
	Shortcode string
	Emoji     *storage.CustomEmoji
}

ParsedEmoji represents a parsed emoji from content

type V1Filter

type V1Filter struct {
	ID           string   `json:"id"`
	Phrase       string   `json:"phrase"`
	Context      []string `json:"context"`
	ExpiresAt    *string  `json:"expires_at"`
	Irreversible bool     `json:"irreversible"`
	WholeWord    bool     `json:"whole_word"`
}

V1Filter represents a filter in the Mastodon API v1 (deprecated)

Directories

Path Synopsis
Package transformers provides consolidated Mastodon API transformations for converting between storage models and Mastodon API response formats.
Package transformers provides consolidated Mastodon API transformations for converting between storage models and Mastodon API response formats.

Jump to

Keyboard shortcuts

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