xep0313

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package xep0313 implements XEP-0313: Message Archive Management.

Index

Constants

View Source
const (
	// ModuleName represents mam module name.
	ModuleName = "mam"

	// XEPNumber represents mam XEP number.
	XEPNumber = "0313"
)

Variables

This section is empty.

Functions

func ExtractReceivedArchiveID

func ExtractReceivedArchiveID(ctx context.Context) string

ExtractReceivedArchiveID returns message received archive ID by inspecting the passed context.

func ExtractSentArchiveID

func ExtractSentArchiveID(ctx context.Context) string

ExtractSentArchiveID returns message sent archive ID by inspecting the passed context.

func IsArchiveRequested

func IsArchiveRequested(inf c2smodel.Info) bool

IsArchiveRequested determines whether archive has been requested over a C2S stream by inspecting inf parameter.

func IsMessageArchievable

func IsMessageArchievable(msg *stravaganza.Message) bool

IsMessageArchievable returns true if the message is archievable. Respects XEP-0334 Message Processing Hints: messages with or hints are not archivable. Per XEP-0313 §4.1, delivery receipts (XEP-0184) and chat markers (XEP-0333) are archived even when they carry no body, so clients can reconstruct read state. Chat-state-only messages (XEP-0085: composing, paused, etc.) are never archived.

func QueryFilters added in v0.6.0

func QueryFilters(qChild stravaganza.Element) (*archivemodel.Filters, error)

QueryFilters parses the optional XEP-0004 data form of a MAM element into archive filters. A query without form yields empty filters. It is shared by the user archive and the MUC room archive (xep0045).

func QueryRSMRequest added in v0.6.0

func QueryRSMRequest(qChild stravaganza.Element) (*xep0059.Request, error)

QueryRSMRequest parses the optional XEP-0059 of a MAM element. Without the default page size applies; is capped at the maximum page size.

func StripChatStates

func StripChatStates(msg *stravaganza.Message) *stravaganza.Message

StripChatStates returns a new message with all XEP-0085 chat-state children removed. If the resulting message has no body and no meaningful children (only chat states were present), it returns nil.

Types

type Config

type Config struct {
	// QueueSize defines maximum number of archive messages stanzas.
	// When the limit is reached, the oldest message will be purged to make room for the new one.
	QueueSize int `fig:"queue_size" default:"1000"`

	// QueryGuard limits repeated MAM queries from one account.
	QueryGuard QueryGuardConfig `fig:"query_guard"`
}

Config contains mam module configuration options.

type Mam

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

Mam represents a mam (XEP-0313) module type.

func New

func New(
	cfg Config,
	router router.Router,
	hosts *host.Hosts,
	rep repository.Repository,
	hk *hook.Hooks,
	logger kitlog.Logger,
) *Mam

New returns a new initialized mam instance.

func (*Mam) AccountFeatures

func (m *Mam) AccountFeatures(_ context.Context) ([]string, error)

AccountFeatures returns mam account disco features.

func (*Mam) MatchesNamespace

func (m *Mam) MatchesNamespace(namespace string, serverTarget bool) bool

MatchesNamespace tells whether namespace matches mam module.

func (*Mam) Name

func (m *Mam) Name() string

Name returns mam module name.

func (*Mam) ProcessIQ

func (m *Mam) ProcessIQ(ctx context.Context, iq *stravaganza.IQ) error

ProcessIQ process a mam iq.

func (*Mam) ServerFeatures

func (m *Mam) ServerFeatures(_ context.Context) ([]string, error)

ServerFeatures returns mam server disco features.

func (*Mam) Start

func (m *Mam) Start(_ context.Context) error

Start starts mam module.

func (*Mam) Stop

func (m *Mam) Stop(_ context.Context) error

Stop stops mam module.

func (*Mam) StreamFeature

func (m *Mam) StreamFeature(_ context.Context, _ string) (stravaganza.Element, error)

StreamFeature returns mam module stream feature.

type QueryGuardConfig

type QueryGuardConfig struct {
	// MaxQueries is the maximum number of archive queries allowed within Window.
	// Set to 0 to disable the guard.
	MaxQueries int `fig:"max_queries" default:"120"`

	// Window is the sliding time window used to count MAM archive queries.
	Window time.Duration `fig:"window" default:"1m"`

	// Lockout is the duration for which a client is throttled after exceeding MaxQueries.
	Lockout time.Duration `fig:"lockout" default:"2m"`
}

QueryGuardConfig contains MAM query loop protection settings.

type Service

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

Service represents a MAM service.

func NewService

func NewService(
	router router.Router,
	hk *hook.Hooks,
	rep repository.Repository,
	maxQueueSize int,
	logger kitlog.Logger,
) *Service

NewService returns a new archive service instance.

func NewServiceWithConfig

func NewServiceWithConfig(
	router router.Router,
	hk *hook.Hooks,
	rep repository.Repository,
	maxQueueSize int,
	queryGuard QueryGuardConfig,
	logger kitlog.Logger,
) *Service

NewServiceWithConfig returns a new archive service instance with explicit query loop protection settings.

func (*Service) ArchiveMessage

func (m *Service) ArchiveMessage(ctx context.Context, message *stravaganza.Message, archiveID, id string) error

ArchiveMessage archives a message.

func (*Service) DeleteArchive

func (m *Service) DeleteArchive(ctx context.Context, archiveID string) error

DeleteArchive deletes an archive.

func (*Service) DeleteArchiveMessage

func (m *Service) DeleteArchiveMessage(ctx context.Context, archiveID, id string) error

DeleteArchiveMessage deletes a single archived message by its stanza ID.

func (*Service) ProcessIQ

func (m *Service) ProcessIQ(ctx context.Context, iq *stravaganza.IQ, onArchiveRequestedFn func(archiveID string) error) error

ProcessIQ processes a MAM IQ.

Jump to

Keyboard shortcuts

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