history

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: BSD-2-Clause Imports: 14 Imported by: 1

Documentation

Overview

Package history implements fetching messages from an archive.

Index

Constants

View Source
const (
	NS    = `urn:xmpp:mam:2`
	NSExt = `urn:xmpp:mam:2#extended`
)

The namespaces used by this package, provided as a convenience.

Variables

This section is empty.

Functions

func Handle

func Handle(h *Handler) mux.Option

Handle returns an option that registers a Handler for incoming history query results.

Types

type Handler

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

Handler handles incoming messages from an archive and either passes them on to the underlying handler if they are not being tracked or ensures they are passed to the correct iterator for syncronous processing if they are.

func NewHandler

func NewHandler(inner mux.MessageHandler) *Handler

NewHandler returns a handler capable of handling messages sent from an archive. Any messages that are part of untracked queries will be passed to the inner handler.

func (*Handler) Fetch

func (h *Handler) Fetch(ctx context.Context, filter Query, to jid.JID, s *xmpp.Session) *Iter

Fetch requests messages from the archive and returns an iterator over the results. Any errors encountered are deferred and returned by the iterator.

func (*Handler) FetchIQ

func (h *Handler) FetchIQ(ctx context.Context, filter Query, iq stanza.IQ, s *xmpp.Session) *Iter

FetchIQ is like Fetch but it allows modifying the underlying IQ. Changing the type of the IQ has no effect.

func (*Handler) HandleMessage

func (h *Handler) HandleMessage(msg stanza.Message, r xmlstream.TokenReadEncoder) error

HandleMessage implements mux.MessageHandler.

type Iter

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

Iter is an iterator over message history.

func (*Iter) Close

func (i *Iter) Close() error

Close stops iterating over this query. Future messages will still be received but will be handled by the fallback handler instead.

func (*Iter) Current

func (i *Iter) Current() xml.TokenReader

Current returns the current message stream read from the iterator.

func (*Iter) Err

func (i *Iter) Err() error

Err returns any error encountered by the iterator.

func (*Iter) Next

func (i *Iter) Next() bool

Next advances the iterator

func (*Iter) Result

func (i *Iter) Result() Result

Result contains the results of the query after iteration has completed if no error was encountered.

type Query

type Query struct {
	// Query parameters
	ID string

	// Filters
	With     jid.JID
	Start    time.Time
	End      time.Time
	BeforeID string
	AfterID  string
	IDs      []string

	// Limit limits the total number of messages returned.
	Limit uint64

	// Last starts fetching from the last page (or before PageID if set).
	Last bool

	// PageID is the ID of a message within the existing query that we should
	// start paging after (or before, if Last is set).
	// This lets us skip over the redundant message when querying with Start/End,
	// or skip to a later page within the query if we abandoned it and need to
	// start over (but don't want to fetch all the pages we've already processed).
	PageID string

	// Reverse flips messages returned within a page.
	Reverse bool
}

Query is a request to the archive for data. An empty query indicates all messages should be fetched without a filter and with a random ID.

func (*Query) MarshalXML

func (f *Query) MarshalXML(e *xml.Encoder, _ xml.StartElement) error

MarshalXML implements xml.Marshaler.

func (*Query) TokenReader

func (f *Query) TokenReader() xml.TokenReader

TokenReader implements xmlstream.Marshaler.

func (*Query) UnmarshalXML

func (f *Query) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler.

func (*Query) WriteXML

func (f *Query) WriteXML(w xmlstream.TokenWriter) (int, error)

WriteXML implements xmlstream.WriterTo.

type Result

type Result struct {
	XMLName  xml.Name
	Complete bool
	Unstable bool
	Set      paging.Set
}

Result is the metadata (not messages) returned from a MAM query.

func Fetch

func Fetch(ctx context.Context, filter Query, to jid.JID, s *xmpp.Session) (Result, error)

Fetch requests messages from the archive. Messages are received asyncronously and Fetch blocks until the session handler has processed them all.

func FetchIQ

func FetchIQ(ctx context.Context, filter Query, iq stanza.IQ, s *xmpp.Session) (Result, error)

FetchIQ is like Fetch but it allows modifying the underlying IQ. Changing the type of the IQ has no effect.

func (*Result) MarshalXML

func (r *Result) MarshalXML(e *xml.Encoder, _ xml.StartElement) error

MarshalXML implements xml.Marshaler.

func (*Result) TokenReader

func (r *Result) TokenReader() xml.TokenReader

TokenReader implements xmlstream.Marshaler.

func (*Result) UnmarshalXML

func (r *Result) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler.

func (*Result) WriteXML

func (r *Result) WriteXML(w xmlstream.TokenWriter) (int, error)

WriteXML implements xmlstream.WriterTo.

Jump to

Keyboard shortcuts

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