blocklist

package
v0.21.4 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package blocklist implements blocking and unblocking of contacts.

Index

Constants

View Source
const (
	NS          = `urn:xmpp:blocking`
	NSReporting = `urn:xmpp:reporting:1`
)

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

Variables

This section is empty.

Functions

func Add

func Add(ctx context.Context, s *xmpp.Session, j ...jid.JID) error

Add adds JIDs to the blocklist.

func AddIQ

func AddIQ(ctx context.Context, iq stanza.IQ, s *xmpp.Session, j ...jid.JID) error

AddIQ is like Add except that it lets you customize the IQ. Changing the type of the provided IQ has no effect.

func Handle

func Handle(h Handler) mux.Option

Handle returns an option that registers the given handler on the mux for the various blocking command payloads.

func Match

func Match(j1, j2 jid.JID) bool

Match checks j1 aginst a JID in the blocklist (j2) and returns true if they are a match.

The JID matches the blocklist JID if any of the following compare to the blocklist JID (falling back in this order):

  • Full JID (user@domain/resource)
  • Bare JID (user@domain)
  • Full domain (domain/resource)
  • Bare domain

func Remove

func Remove(ctx context.Context, s *xmpp.Session, j ...jid.JID) error

Remove removes JIDs from the blocklist. If no JIDs are provided the entire blocklist is cleared.

func RemoveIQ

func RemoveIQ(ctx context.Context, iq stanza.IQ, s *xmpp.Session, j ...jid.JID) error

RemoveIQ is like Remove except that it lets you customize the IQ. Changing the type of the provided IQ has no effect.

func Report added in v0.21.4

func Report(ctx context.Context, s *xmpp.Session, i ...Item) error

Report adds JIDs to the blocklist. You can optionally specify a report for each individual JID.

func ReportIQ added in v0.21.4

func ReportIQ(ctx context.Context, iq stanza.IQ, s *xmpp.Session, i ...Item) error

ReportIQ is like Report except that it lets you customize the IQ. Changing the type of the provided IQ has no effect.

Types

type Handler

type Handler struct {
	Block      func(Item)
	Unblock    func(jid.JID)
	UnblockAll func()
	List       func(chan<- jid.JID)
}

Handler can be used to respond to incoming blocking command requests.

func (Handler) HandleIQ

func (h Handler) HandleIQ(iq stanza.IQ, r xmlstream.TokenReadEncoder, start *xml.StartElement) error

HandleIQ implements mux.IQHandler.

type Item added in v0.21.4

type Item struct {
	JID       jid.JID
	Reason    ReportReason
	StanzaIDs []stanza.ID
	Text      string
}

Item is a block payload. It consists of a JID you want to block and optional report fields.

func (*Item) MarshalXML added in v0.21.4

func (i *Item) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML satisfies the xml.Marshaler interface.

func (*Item) TokenReader added in v0.21.4

func (i *Item) TokenReader() xml.TokenReader

TokenReader satisfies the xmlstream.Marshaler interface.

func (*Item) UnmarshalXML added in v0.21.4

func (i *Item) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML satisfies the xml.Unmarshaler interface.

func (*Item) WriteXML added in v0.21.4

func (i *Item) WriteXML(w xmlstream.TokenWriter) (int, error)

WriteXML satisfies the xmlstream.WriterTo interface. It is like MarshalXML except it writes tokens to w.

type Iter

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

Iter is an iterator over blocklist JIDs.

func Fetch

func Fetch(ctx context.Context, s *xmpp.Session) *Iter

Fetch sends a request to the JID asking for the blocklist.

func FetchIQ

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

FetchIQ is like Fetch except that it lets you customize the IQ. Changing the type of the provided IQ has no effect.

func (*Iter) Close

func (i *Iter) Close() error

Close indicates that we are finished with the given iterator and processing the stream may continue. Calling it multiple times has no effect.

func (*Iter) Err

func (i *Iter) Err() error

Err returns the last error encountered by the iterator (if any).

func (*Iter) JID

func (i *Iter) JID() jid.JID

JID returns the last blocked JID parsed by the iterator.

func (*Iter) Next

func (i *Iter) Next() bool

Next returns true if there are more items to decode.

type ReportReason added in v0.21.4

type ReportReason string

ReportReason is a reason of a report.

const (
	// ReasonSpam is used for reporting a JID that is sending unwanted messages.
	ReasonSpam ReportReason = "urn:xmpp:reporting:spam"

	// ReasonAbuse is used for reporting general abuse.
	ReasonAbuse ReportReason = "urn:xmpp:reporting:abuse"
)

The available report reasons are listed below.

Jump to

Keyboard shortcuts

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