Documentation
¶
Overview ¶
Package xep0313 implements XEP-0313: Message Archive Management.
Index ¶
- Constants
- func ExtractReceivedArchiveID(ctx context.Context) string
- func ExtractSentArchiveID(ctx context.Context) string
- func IsArchiveRequested(inf c2smodel.Info) bool
- func IsMessageArchievable(msg *stravaganza.Message) bool
- func QueryFilters(qChild stravaganza.Element) (*archivemodel.Filters, error)
- func QueryRSMRequest(qChild stravaganza.Element) (*xep0059.Request, error)
- func StripChatStates(msg *stravaganza.Message) *stravaganza.Message
- type Config
- type Mam
- func (m *Mam) AccountFeatures(_ context.Context) ([]string, error)
- func (m *Mam) MatchesNamespace(namespace string, serverTarget bool) bool
- func (m *Mam) Name() string
- func (m *Mam) ProcessIQ(ctx context.Context, iq *stravaganza.IQ) error
- func (m *Mam) ServerFeatures(_ context.Context) ([]string, error)
- func (m *Mam) Start(_ context.Context) error
- func (m *Mam) Stop(_ context.Context) error
- func (m *Mam) StreamFeature(_ context.Context, _ string) (stravaganza.Element, error)
- type QueryGuardConfig
- type Service
- func (m *Service) ArchiveMessage(ctx context.Context, message *stravaganza.Message, archiveID, id string) error
- func (m *Service) DeleteArchive(ctx context.Context, archiveID string) error
- func (m *Service) DeleteArchiveMessage(ctx context.Context, archiveID, id string) error
- func (m *Service) ProcessIQ(ctx context.Context, iq *stravaganza.IQ, ...) error
Constants ¶
const ( // ModuleName represents mam module name. ModuleName = "mam" // XEPNumber represents mam XEP number. XEPNumber = "0313" )
Variables ¶
This section is empty.
Functions ¶
func ExtractReceivedArchiveID ¶
ExtractReceivedArchiveID returns message received archive ID by inspecting the passed context.
func ExtractSentArchiveID ¶
ExtractSentArchiveID returns message sent archive ID by inspecting the passed context.
func IsArchiveRequested ¶
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
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
func QueryRSMRequest ¶ added in v0.6.0
func QueryRSMRequest(qChild stravaganza.Element) (*xep0059.Request, error)
QueryRSMRequest parses the optional XEP-0059
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 ¶
AccountFeatures returns mam account disco features.
func (*Mam) MatchesNamespace ¶
MatchesNamespace tells whether namespace matches mam module.
func (*Mam) ServerFeatures ¶
ServerFeatures returns mam server disco features.
func (*Mam) StreamFeature ¶
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 ¶
DeleteArchive deletes an archive.
func (*Service) DeleteArchiveMessage ¶
DeleteArchiveMessage deletes a single archived message by its stanza ID.