room

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package room handles matrix rooms.

Index

Constants

View Source
const (
	// EventTypeMessage in a event type field indicates that the event is a room message.
	EventTypeMessage = "m.room.message"
	// MessageTypeText in a message content message type field indicates that the event is a text message.
	MessageTypeText = "m.text"
)
View Source
const EventTypeReaction = "m.reaction"

EventTypeReaction in a event type field indicates that the event is a room reaction.

Variables

This section is empty.

Functions

func IsMessageEvent added in v0.0.3

func IsMessageEvent(evt event.Metadata) bool

IsMessageEvent returns true if the given event metadata indicates that the event is a room message.

func IsReactionEvent added in v0.0.3

func IsReactionEvent(evt event.Metadata) bool

IsReactionEvent returns true if the given event metadata indicates that the event is a room reaction.

func Join added in v0.0.3

func Join(ctx context.Context, cli matrix.Client, id string) error

Join the given room ID with the client.

func Joined added in v0.0.3

func Joined(ctx context.Context, cli matrix.Client) ([]string, error)

Joined returns all rooms this client is part of.

Types

type MessageContent

type MessageContent struct {
	MessageType string          `json:"msgtype"`
	Body        string          `json:"body"`
	RelatesTo   *MessageRelates `json:"m.relates_to,omitempty"`
}

MessageContent represents the content of room message.

type MessageEvent

type MessageEvent struct {
	event.Metadata
	Content MessageContent `struct:"content"`
}

MessageEvent is a message sent to a room.

func AsMessageEvent added in v0.0.3

func AsMessageEvent(evt event.Opaque) (MessageEvent, error)

AsMessageEvent converts the given opaque event to a room message. Panics is metadata indicates that the event is not a room message and returns an error if unmarshalling of the content failed.

func NewTextMessage added in v0.0.3

func NewTextMessage(room, body string) MessageEvent

NewTextMessage creates a new MessageEvent with the content of a text message with the given body and sets the room of the event.

func (MessageEvent) AsReplyTo added in v0.0.3

func (m MessageEvent) AsReplyTo(toID string) MessageEvent

AsReplyTo marks the message as a reply to the given event ID.

func (MessageEvent) Send added in v0.0.3

func (m MessageEvent) Send(ctx context.Context, cli matrix.Client) (string, error)

Send the event via the given matrix client with the given transaction ID. The room field of the even metadata must be set. Returns the event ID of the sent content.

type MessageReference added in v0.0.2

type MessageReference struct {
	ID   string `json:"event_id"`
	Key  string `json:"key,omitempty"`
	Type string `json:"rel_type,omitempty"`
}

MessageReference references another message.

type MessageRelates added in v0.0.2

type MessageRelates struct {
	RepliesTo MessageReference `json:"m.in_reply_to"`
}

MessageRelates indicates that a message relates so another one.

type ReactionContent added in v0.0.2

type ReactionContent struct {
	RelatesTo MessageReference `json:"m.relates_to"`
}

ReactionContent represents the content of room reaction.

type ReactionEvent added in v0.0.3

type ReactionEvent struct {
	event.Metadata
	Content ReactionContent `struct:"content"`
}

ReactionEvent is a reaction sent to a room.

func AsReactionEvent added in v0.0.3

func AsReactionEvent(evt event.Opaque) (ReactionEvent, error)

AsReactionEvent converts the given opaque event to a room reaction. Panics is metadata indicates that the event is not a room message and returns an error if unmarshalling of the content failed.

func NewReaction added in v0.0.3

func NewReaction(room, key, toID string) ReactionEvent

NewReaction creates a new ReactionEvent with the content of a reaction with the given key and reference to the given event ID and sets the room of the event.

func (ReactionEvent) Send added in v0.0.3

func (r ReactionEvent) Send(ctx context.Context, cli matrix.Client) (string, error)

Send the event via the given matrix client with the given transaction ID. The room field of the even metadata must be set. Returns the event ID of the sent content.

Jump to

Keyboard shortcuts

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