bridgev2

package
v0.26.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MPL-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const BackfillMinBackoffAfterRoomCreate = 1 * time.Minute
View Source
const BackfillQueueErrorBackoff = 1 * time.Minute
View Source
const BackfillQueueMaxEmptyBackoff = 10 * time.Minute
View Source
const DisappearCheckInterval = 1 * time.Hour
View Source
const TransientDisconnectNoticeDelay = 3 * time.Minute

Variables

View Source
var (
	ErrPanicInEventHandler              error = WrapErrorInStatus(errors.New("panic in event handler")).WithSendNotice(true).WithErrorAsMessage()
	ErrNoPortal                         error = WrapErrorInStatus(errors.New("room is not a portal")).WithIsCertain(true).WithSendNotice(false)
	ErrIgnoringReactionFromRelayedUser  error = WrapErrorInStatus(errors.New("ignoring reaction event from relayed user")).WithIsCertain(true).WithSendNotice(false)
	ErrIgnoringPollFromRelayedUser      error = WrapErrorInStatus(errors.New("ignoring poll event from relayed user")).WithIsCertain(true).WithSendNotice(false)
	ErrIgnoringDeleteChatRelayedUser    error = WrapErrorInStatus(errors.New("ignoring delete chat event from relayed user")).WithIsCertain(true).WithSendNotice(false)
	ErrIgnoringAcceptRequestRelayedUser error = WrapErrorInStatus(errors.New("ignoring accept message request event from relayed user")).WithIsCertain(true).WithSendNotice(false)
	ErrEditsNotSupported                error = WrapErrorInStatus(errors.New("this bridge does not support edits")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported)
	ErrEditsNotSupportedInPortal        error = WrapErrorInStatus(errors.New("edits are not allowed in this chat")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported)
	ErrCaptionsNotAllowed               error = WrapErrorInStatus(errors.New("captions are not supported here")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported)
	ErrLocationMessagesNotAllowed       error = WrapErrorInStatus(errors.New("location messages are not supported here")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported)
	ErrEditTargetTooOld                 error = WrapErrorInStatus(errors.New("the message is too old to be edited")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported)
	ErrEditTargetTooManyEdits           error = WrapErrorInStatus(errors.New("the message has been edited too many times")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported)
	ErrReactionsNotSupported            error = WrapErrorInStatus(errors.New("this bridge does not support reactions")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported)
	ErrPollsNotSupported                error = WrapErrorInStatus(errors.New("this bridge does not support polls")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported)
	ErrRoomMetadataNotSupported         error = WrapErrorInStatus(errors.New("this bridge does not support changing room metadata")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
	ErrRoomMetadataNotAllowed           error = WrapErrorInStatus(errors.New("changes are not allowed here")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
	ErrRedactionsNotSupported           error = WrapErrorInStatus(errors.New("this bridge does not support deleting messages")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported)
	ErrUnexpectedParsedContentType      error = WrapErrorInStatus(errors.New("unexpected parsed content type")).WithErrorAsMessage().WithIsCertain(true).WithSendNotice(true)
	ErrInvalidStateKey                  error = WrapErrorInStatus(errors.New("room metadata state key is unset or non-empty")).WithErrorAsMessage().WithIsCertain(true).WithSendNotice(false)
	ErrDatabaseError                    error = WrapErrorInStatus(errors.New("database error")).WithMessage("internal database error").WithIsCertain(true).WithSendNotice(true)
	ErrTargetMessageNotFound            error = WrapErrorInStatus(errors.New("target message not found")).WithErrorAsMessage().WithIsCertain(true).WithSendNotice(false)
	ErrUnsupportedMessageType           error = WrapErrorInStatus(errors.New("unsupported message type")).WithErrorAsMessage().WithIsCertain(true).WithSendNotice(true).WithErrorReason(event.MessageStatusUnsupported)
	ErrUnsupportedMediaType             error = WrapErrorInStatus(errors.New("unsupported media type")).WithErrorAsMessage().WithIsCertain(true).WithSendNotice(true).WithErrorReason(event.MessageStatusUnsupported)
	ErrMediaDurationTooLong             error = WrapErrorInStatus(errors.New("media duration too long")).WithErrorAsMessage().WithSendNotice(true).WithErrorReason(event.MessageStatusUnsupported)
	ErrVoiceMessageDurationTooLong      error = WrapErrorInStatus(errors.New("voice message too long")).WithErrorAsMessage().WithSendNotice(true).WithErrorReason(event.MessageStatusUnsupported)
	ErrMediaTooLarge                    error = WrapErrorInStatus(errors.New("media too large")).WithErrorAsMessage().WithIsCertain(true).WithSendNotice(true).WithErrorReason(event.MessageStatusUnsupported)
	ErrIgnoringMNotice                  error = WrapErrorInStatus(errors.New("ignoring m.notice message")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false)
	ErrMediaDownloadFailed              error = WrapErrorInStatus(errors.New("failed to download media")).WithMessage("failed to download media").WithIsCertain(true).WithSendNotice(true)
	ErrMediaReuploadFailed              error = WrapErrorInStatus(errors.New("failed to reupload media")).WithMessage("failed to reupload media").WithIsCertain(true).WithSendNotice(true)
	ErrMediaConvertFailed               error = WrapErrorInStatus(errors.New("failed to convert media")).WithMessage("failed to convert media").WithIsCertain(true).WithSendNotice(true)
	ErrMembershipNotSupported           error = WrapErrorInStatus(errors.New("this bridge does not support changing group membership")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
	ErrDeleteChatNotSupported           error = WrapErrorInStatus(errors.New("this bridge does not support deleting chats")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
	ErrPowerLevelsNotSupported          error = WrapErrorInStatus(errors.New("this bridge does not support changing group power levels")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
	ErrRemoteEchoTimeout                      = WrapErrorInStatus(errors.New("remote echo timed out")).WithIsCertain(false).WithSendNotice(true).WithErrorReason(event.MessageStatusTooOld)
	ErrRemoteAckTimeout                       = WrapErrorInStatus(errors.New("remote ack timed out")).WithIsCertain(false).WithSendNotice(true).WithErrorReason(event.MessageStatusTooOld)

	ErrPublicMediaDisabled         = WrapErrorInStatus(errors.New("public media is not enabled in the bridge config")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported).WithSendNotice(true)
	ErrPublicMediaDatabaseDisabled = WrapErrorInStatus(errors.New("public media database storage is disabled")).WithIsCertain(true).WithErrorAsMessage().WithErrorReason(event.MessageStatusUnsupported).WithSendNotice(true)
	ErrPublicMediaGenerateFailed   = WrapErrorInStatus(errors.New("failed to generate public media URL")).WithIsCertain(true).WithMessage("failed to generate public media URL").WithErrorReason(event.MessageStatusUnsupported).WithSendNotice(true)

	ErrDisappearingTimerUnsupported error = WrapErrorInStatus(errors.New("invalid disappearing timer")).WithIsCertain(true)
)

Common message status errors

View Source
var (
	AcceptInvite  = MembershipChangeType{From: event.MembershipInvite, To: event.MembershipJoin, IsSelf: true}
	RevokeInvite  = MembershipChangeType{From: event.MembershipInvite, To: event.MembershipLeave}
	RejectInvite  = MembershipChangeType{From: event.MembershipInvite, To: event.MembershipLeave, IsSelf: true}
	BanInvited    = MembershipChangeType{From: event.MembershipInvite, To: event.MembershipBan}
	ProfileChange = MembershipChangeType{From: event.MembershipJoin, To: event.MembershipJoin, IsSelf: true}
	Leave         = MembershipChangeType{From: event.MembershipJoin, To: event.MembershipLeave, IsSelf: true}
	Kick          = MembershipChangeType{From: event.MembershipJoin, To: event.MembershipLeave}
	BanJoined     = MembershipChangeType{From: event.MembershipJoin, To: event.MembershipBan}
	Invite        = MembershipChangeType{From: event.MembershipLeave, To: event.MembershipInvite}
	Join          = MembershipChangeType{From: event.MembershipLeave, To: event.MembershipJoin}
	BanLeft       = MembershipChangeType{From: event.MembershipLeave, To: event.MembershipBan}
	Knock         = MembershipChangeType{From: event.MembershipLeave, To: event.MembershipKnock, IsSelf: true}
	AcceptKnock   = MembershipChangeType{From: event.MembershipKnock, To: event.MembershipInvite}
	RejectKnock   = MembershipChangeType{From: event.MembershipKnock, To: event.MembershipLeave}
	RetractKnock  = MembershipChangeType{From: event.MembershipKnock, To: event.MembershipLeave, IsSelf: true}
	BanKnocked    = MembershipChangeType{From: event.MembershipKnock, To: event.MembershipBan}
	Unban         = MembershipChangeType{From: event.MembershipBan, To: event.MembershipLeave}
)
View Source
var (
	ErrEventSenderUserNotFound = WrapErrorInStatus(errors.New("sender not found for event")).WithIsCertain(true).WithErrorAsMessage()
	ErrNoPermissionToInteract  = WrapErrorInStatus(errors.New("you don't have permission to send messages")).WithIsCertain(true).WithSendNotice(false).WithErrorAsMessage()
	ErrNoPermissionForCommands = WrapErrorInStatus(WrapErrorInStatus(errors.New("you don't have permission to use commands")).WithIsCertain(true).WithSendNotice(false).WithErrorAsMessage())
	ErrCantRelayStateRequest   = WrapErrorInStatus(errors.New("relayed users can't use beeper state requests")).WithIsCertain(true).WithErrorAsMessage()
)
View Source
var (
	EventHandlingResultFailed  = EventHandlingResult{}
	EventHandlingResultQueued  = EventHandlingResult{Success: true, Queued: true}
	EventHandlingResultSuccess = EventHandlingResult{Success: true}
	EventHandlingResultIgnored = EventHandlingResult{Success: true, Ignored: true}
)
View Source
var CatchBridgeStateQueuePanics = true
View Source
var DefaultChatName = ptr.Ptr("")

DefaultChatName can be used to explicitly clear the name of a room and reset it to the default one based on members.

View Source
var ErrDirectMediaNotEnabled = errors.New("direct media is not enabled")

ErrDirectMediaNotEnabled may be returned by Matrix connectors if [MatrixConnector.GenerateContentURI] is called, but direct media is not enabled.

View Source
var ErrIgnoringRemoteEvent = errors.New("ignoring remote event")

ErrIgnoringRemoteEvent can be returned by [RemoteMessage.ConvertMessage] or [RemoteEdit.ConvertEdit] to indicate that the event should be ignored after all. Handling the event will be cancelled immediately.

View Source
var (
	ErrInvalidLoginFlowID error = RespError(mautrix.MNotFound.WithMessage("Invalid login flow ID"))
)

Common login interface errors

View Source
var ErrNoStatus = errors.New("omit message status")

ErrNoStatus can be returned by [MatrixMessageResponse.HandleEcho] to indicate that the message is still in-flight and a status should not be sent yet. The message will still be saved into the database.

View Source
var ErrNotLoggedIn = errors.New("not logged in")
View Source
var ErrPortalIsDeleted = errors.New("portal is deleted")
View Source
var ErrPortalNotFoundInEventHandler = errors.New("portal not found to handle remote event")
View Source
var ErrResolveIdentifierTryNext = errors.New("that identifier is not available via this login")

ErrResolveIdentifierTryNext can be returned by ResolveIdentifier or CreateChatWithGhost to signal that the identifier is valid, but can't be reached by the current login, and the caller should try the next login if there are more.

This should generally only be returned when resolving internal IDs (which happens when initiating chats via Matrix). For example, Google Messages would return this when trying to resolve another login's user ID, and Telegram would return this when the access hash isn't available.

View Source
var ErrRoomAlreadyExists = errors.New("this portal already has a room")
View Source
var ErrTargetRoomIsPortal = errors.New("target room is already a portal")
View Source
var PortalEventBuffer = 64
View Source
var SpecialValueDMRedirectedToBot = networkid.UserID("__fi.mau.bridgev2.dm_redirected_to_bot::" + random.String(10))
View Source
var Unmuted = time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)

Functions

func CleanNonInternationalPhoneNumber

func CleanNonInternationalPhoneNumber(phone string) (string, error)

func CleanPhoneNumber

func CleanPhoneNumber(phone string) (string, error)

func DeleteManyPortals

func DeleteManyPortals(ctx context.Context, portals []*Portal, errorCallback func(portal *Portal, delete bool, err error))

func DisappearingMessageNotice

func DisappearingMessageNotice(expiration time.Duration, implicit bool) *event.MessageEventContent

Types

type APNsPushConfig

type APNsPushConfig struct {
	BundleID string `json:"bundle_id"`
}

type Avatar

type Avatar struct {
	ID     networkid.AvatarID
	Get    func(ctx context.Context) ([]byte, error)
	Remove bool

	// For pre-uploaded avatars, the MXC URI and hash can be provided directly
	MXC  id.ContentURIString
	Hash [32]byte
}

func (*Avatar) Reupload

func (a *Avatar) Reupload(ctx context.Context, intent MatrixAPI, currentHash [32]byte, currentMXC id.ContentURIString) (id.ContentURIString, [32]byte, error)

type BackfillMessage

type BackfillMessage struct {
	*ConvertedMessage
	Sender      EventSender
	ID          networkid.MessageID
	TxnID       networkid.TransactionID
	Timestamp   time.Time
	StreamOrder int64
	Reactions   []*BackfillReaction

	ShouldBackfillThread bool
	LastThreadMessage    networkid.MessageID
}

BackfillMessage is an individual message in a history pagination request.

func (*BackfillMessage) AddLogContext

func (b *BackfillMessage) AddLogContext(c zerolog.Context) zerolog.Context

func (*BackfillMessage) ConvertMessage

func (b *BackfillMessage) ConvertMessage(ctx context.Context, portal *Portal, intent MatrixAPI) (*ConvertedMessage, error)

func (*BackfillMessage) GetID

func (b *BackfillMessage) GetID() networkid.MessageID

func (*BackfillMessage) GetPortalKey

func (b *BackfillMessage) GetPortalKey() networkid.PortalKey

func (*BackfillMessage) GetSender

func (b *BackfillMessage) GetSender() EventSender

func (*BackfillMessage) GetTimestamp

func (b *BackfillMessage) GetTimestamp() time.Time

func (*BackfillMessage) GetTransactionID

func (b *BackfillMessage) GetTransactionID() networkid.TransactionID

func (*BackfillMessage) GetType

func (b *BackfillMessage) GetType() RemoteEventType

type BackfillReaction

type BackfillReaction struct {
	// Optional part of the message that the reaction targets.
	// If nil, the reaction targets the first part of the message.
	TargetPart *networkid.PartID
	// Optional timestamp for the reaction.
	// If unset, the reaction will have a fake timestamp that is slightly after the message timestamp.
	Timestamp time.Time

	Sender       EventSender
	EmojiID      networkid.EmojiID
	Emoji        string
	ExtraContent map[string]any
	DBMetadata   any
}

BackfillReaction is an individual reaction to a message in a history pagination request.

The target message is always the BackfillMessage that contains this item. Optionally, the reaction can target a specific part by specifying TargetPart. If not specified, the first part (sorted lexicographically) is targeted.

type BackfillingNetworkAPI

type BackfillingNetworkAPI interface {
	NetworkAPI
	// FetchMessages returns a batch of messages to backfill in a portal room.
	// For details on the input and output, see the documentation of [FetchMessagesParams] and [FetchMessagesResponse].
	FetchMessages(ctx context.Context, fetchParams FetchMessagesParams) (*FetchMessagesResponse, error)
}

BackfillingNetworkAPI is an optional interface that network connectors can implement to support backfilling message history.

type BackfillingNetworkAPIWithLimits

type BackfillingNetworkAPIWithLimits interface {
	BackfillingNetworkAPI
	// GetBackfillMaxBatchCount is called before a backfill task is executed to determine the maximum number of batches
	// that should be backfilled. Return values less than 0 are treated as unlimited.
	GetBackfillMaxBatchCount(ctx context.Context, portal *Portal, task *database.BackfillTask) int
}

BackfillingNetworkAPIWithLimits is an optional interface that network connectors can implement to customize the limit for backwards backfilling tasks. It is recommended to implement this by reading the MaxBatchesOverride config field with network-specific keys for different room types.

type BackgroundSyncingNetworkAPI

type BackgroundSyncingNetworkAPI interface {
	NetworkAPI
	// ConnectBackground is called in place of Connect for background resyncs.
	// The client should connect to the remote network, handle pending messages, and then disconnect.
	// This call should block until the entire sync is complete and the client is disconnected.
	ConnectBackground(ctx context.Context, params *ConnectBackgroundParams) error
}

BackgroundSyncingNetworkAPI is an optional interface that network connectors can implement to support background resyncs.

type Bridge

type Bridge struct {
	ID  networkid.BridgeID
	DB  *database.Database
	Log zerolog.Logger

	Matrix   MatrixConnector
	Bot      MatrixAPI
	Network  NetworkConnector
	Commands CommandProcessor
	Config   *bridgeconfig.BridgeConfig

	DisappearLoop *DisappearLoop

	Background          bool
	ExternallyManagedDB bool

	BackgroundCtx context.Context
	// contains filtered or unexported fields
}

func NewBridge

func NewBridge(
	bridgeID networkid.BridgeID,
	db *dbutil.Database,
	log zerolog.Logger,
	cfg *bridgeconfig.BridgeConfig,
	matrix MatrixConnector,
	network NetworkConnector,
	newCommandProcessor func(*Bridge) CommandProcessor,
) *Bridge

func (*Bridge) DoBackfillTask

func (br *Bridge) DoBackfillTask(ctx context.Context, task *database.BackfillTask)

func (*Bridge) FindCachedPortalReceiver

func (br *Bridge) FindCachedPortalReceiver(id networkid.PortalID, maybeReceiver networkid.UserLoginID) networkid.PortalKey

func (*Bridge) FindPortalReceiver

func (br *Bridge) FindPortalReceiver(ctx context.Context, id networkid.PortalID, maybeReceiver networkid.UserLoginID) (networkid.PortalKey, error)

func (*Bridge) GetAllCachedUserLogins added in v0.26.2

func (br *Bridge) GetAllCachedUserLogins() (logins []*UserLogin)

func (*Bridge) GetAllPortals

func (br *Bridge) GetAllPortals(ctx context.Context) ([]*Portal, error)

func (*Bridge) GetAllPortalsWithMXID

func (br *Bridge) GetAllPortalsWithMXID(ctx context.Context) ([]*Portal, error)

func (*Bridge) GetCachedUserLoginByID

func (br *Bridge) GetCachedUserLoginByID(id networkid.UserLoginID) *UserLogin

func (*Bridge) GetChildPortals added in v0.26.1

func (br *Bridge) GetChildPortals(ctx context.Context, parent networkid.PortalKey) ([]*Portal, error)

func (*Bridge) GetCurrentBridgeStates

func (br *Bridge) GetCurrentBridgeStates() (states []status.BridgeState)

func (*Bridge) GetDMPortal added in v0.26.1

func (br *Bridge) GetDMPortal(ctx context.Context, receiver networkid.UserLoginID, otherUserID networkid.UserID) (*Portal, error)

func (*Bridge) GetDMPortalsWith

func (br *Bridge) GetDMPortalsWith(ctx context.Context, otherUserID networkid.UserID) ([]*Portal, error)

func (*Bridge) GetExistingGhostByID

func (br *Bridge) GetExistingGhostByID(ctx context.Context, id networkid.UserID) (*Ghost, error)

func (*Bridge) GetExistingPortalByKey

func (br *Bridge) GetExistingPortalByKey(ctx context.Context, key networkid.PortalKey) (*Portal, error)

func (*Bridge) GetExistingUserByMXID

func (br *Bridge) GetExistingUserByMXID(ctx context.Context, userID id.UserID) (*User, error)

func (*Bridge) GetExistingUserLoginByID

func (br *Bridge) GetExistingUserLoginByID(ctx context.Context, id networkid.UserLoginID) (*UserLogin, error)

func (*Bridge) GetGhostByID

func (br *Bridge) GetGhostByID(ctx context.Context, id networkid.UserID) (*Ghost, error)

func (*Bridge) GetGhostByMXID

func (br *Bridge) GetGhostByMXID(ctx context.Context, mxid id.UserID) (*Ghost, error)

func (*Bridge) GetHTTPClientSettings added in v0.26.2

func (br *Bridge) GetHTTPClientSettings() exhttp.ClientSettings

func (*Bridge) GetPortalByKey

func (br *Bridge) GetPortalByKey(ctx context.Context, key networkid.PortalKey) (*Portal, error)

func (*Bridge) GetPortalByMXID

func (br *Bridge) GetPortalByMXID(ctx context.Context, mxid id.RoomID) (*Portal, error)

func (*Bridge) GetUserByMXID

func (br *Bridge) GetUserByMXID(ctx context.Context, userID id.UserID) (*User, error)

func (*Bridge) GetUserLoginsInPortal

func (br *Bridge) GetUserLoginsInPortal(ctx context.Context, portal networkid.PortalKey) ([]*UserLogin, error)

func (*Bridge) IsGhostMXID

func (br *Bridge) IsGhostMXID(userID id.UserID) bool

func (*Bridge) IsStopping added in v0.26.1

func (br *Bridge) IsStopping() bool

func (*Bridge) MigrateToSplitPortals

func (br *Bridge) MigrateToSplitPortals(ctx context.Context) (bool, func())

func (*Bridge) NewBridgeStateQueue

func (br *Bridge) NewBridgeStateQueue(login *UserLogin) *BridgeStateQueue

func (*Bridge) PostStart

func (br *Bridge) PostStart(ctx context.Context)

func (*Bridge) QueueMatrixEvent

func (br *Bridge) QueueMatrixEvent(ctx context.Context, evt *event.Event) EventHandlingResult

func (*Bridge) QueueRemoteEvent

func (br *Bridge) QueueRemoteEvent(login *UserLogin, evt RemoteEvent) EventHandlingResult

func (*Bridge) ReIDPortal

func (br *Bridge) ReIDPortal(ctx context.Context, source, target networkid.PortalKey) (ReIDResult, *Portal, error)

func (*Bridge) ResendBridgeInfo

func (br *Bridge) ResendBridgeInfo(ctx context.Context, resendInfo, resendCaps bool)

func (*Bridge) ResetNetworkConnections added in v0.26.2

func (br *Bridge) ResetNetworkConnections()

func (*Bridge) RunBackfillQueue

func (br *Bridge) RunBackfillQueue()

func (*Bridge) RunOnce

func (br *Bridge) RunOnce(ctx context.Context, loginID networkid.UserLoginID, params *ConnectBackgroundParams) error

func (*Bridge) SendGlobalBridgeState

func (br *Bridge) SendGlobalBridgeState(state status.BridgeState)

func (*Bridge) Start

func (br *Bridge) Start(ctx context.Context) error

func (*Bridge) StartConnectors

func (br *Bridge) StartConnectors(ctx context.Context) error

func (*Bridge) StartLogins

func (br *Bridge) StartLogins(ctx context.Context) error

func (*Bridge) Stop

func (br *Bridge) Stop()

func (*Bridge) StopWithTimeout

func (br *Bridge) StopWithTimeout(timeout time.Duration)

func (*Bridge) TrackAnalytics

func (br *Bridge) TrackAnalytics(userID id.UserID, event string, props map[string]any)

func (*Bridge) UnlockedGetPortalByKey

func (br *Bridge) UnlockedGetPortalByKey(ctx context.Context, key networkid.PortalKey, onlyIfExists bool) (*Portal, error)

func (*Bridge) UpdateSetRelayFromUser added in v0.25.1

func (br *Bridge) UpdateSetRelayFromUser(
	ctx context.Context, loginID string,
) error

func (*Bridge) WakeupBackfillQueue

func (br *Bridge) WakeupBackfillQueue()

type BridgeName

type BridgeName struct {
	// The displayname of the network, e.g. `Discord`
	DisplayName string `json:"displayname"`
	// The URL to the website of the network, e.g. `https://discord.com`
	NetworkURL string `json:"network_url"`
	// The icon of the network as a mxc:// URI
	NetworkIcon id.ContentURIString `json:"network_icon"`
	// An identifier uniquely identifying the network, e.g. `discord`
	NetworkID string `json:"network_id"`
	// An identifier uniquely identifying the bridge software.
	// The Go import path is a good choice here (e.g. github.com/octocat/discordbridge)
	BeeperBridgeType string `json:"beeper_bridge_type"`
	// The default appservice port to use in the example config, defaults to 8080 if unset
	// Official mautrix bridges will use ports defined in https://mau.fi/ports
	DefaultPort uint16 `json:"default_port,omitempty"`
	// The default command prefix to use in the example config, defaults to NetworkID if unset. Must include the ! prefix.
	DefaultCommandPrefix string `json:"default_command_prefix,omitempty"`
}

BridgeName contains information about the network that a connector bridges to.

func (BridgeName) AsBridgeInfoSection

func (bn BridgeName) AsBridgeInfoSection() event.BridgeInfoSection

type BridgeStateQueue

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

func (*BridgeStateQueue) Destroy

func (bsq *BridgeStateQueue) Destroy()

func (*BridgeStateQueue) GetPrev

func (bsq *BridgeStateQueue) GetPrev() status.BridgeState

func (*BridgeStateQueue) GetPrevUnsent

func (bsq *BridgeStateQueue) GetPrevUnsent() status.BridgeState

func (*BridgeStateQueue) Send

func (bsq *BridgeStateQueue) Send(state status.BridgeState)

func (*BridgeStateQueue) SetPrev

func (bsq *BridgeStateQueue) SetPrev(prev status.BridgeState)

func (*BridgeStateQueue) StopUnknownErrorReconnect

func (bsq *BridgeStateQueue) StopUnknownErrorReconnect()

type CallbackError

type CallbackError struct {
	Type    string
	Wrapped error
}

func (CallbackError) Error

func (ce CallbackError) Error() string

func (CallbackError) Unwrap

func (ce CallbackError) Unwrap() error

type ChatInfo

type ChatInfo struct {
	Name   *string
	Topic  *string
	Avatar *Avatar

	Members  *ChatMemberList
	JoinRule *event.JoinRulesEventContent

	Type      *database.RoomType
	Disappear *database.DisappearingSetting
	ParentID  *networkid.PortalID

	UserLocal      *UserLocalPortalInfo
	MessageRequest *bool
	CanBackfill    bool

	ExcludeChangesFromTimeline bool

	ExtraUpdates ExtraUpdater[*Portal]
}

type ChatInfoChange

type ChatInfoChange struct {
	// The chat info that changed. Any fields that did not change can be left as nil.
	ChatInfo *ChatInfo
	// A list of member changes.
	// This list should only include changes, not the whole member list.
	// To resync the whole list, use the field inside ChatInfo.
	MemberChanges *ChatMemberList
}

type ChatMember

type ChatMember struct {
	EventSender
	Membership event.Membership
	// Per-room nickname for the user. Not yet used.
	Nickname *string
	// The power level to set for the user when syncing power levels.
	PowerLevel *int
	// Optional user info to sync the ghost user while updating membership.
	UserInfo *UserInfo
	// The user who sent the membership change (user who invited/kicked/banned this user).
	// Not yet used. Not applicable if Membership is join or knock.
	MemberSender EventSender
	// Extra fields to include in the member event.
	MemberEventExtra map[string]any
	// The expected previous membership. If this doesn't match, the change is ignored.
	PrevMembership event.Membership
}

type ChatMemberList

type ChatMemberList struct {
	// Whether this is the full member list.
	// If true, any extra members not listed here will be removed from the portal.
	IsFull bool
	// Should the bridge call IsThisUser for every member in the list?
	// This should be used when SenderLogin can't be filled accurately.
	CheckAllLogins bool
	// Should any changes have the `com.beeper.exclude_from_timeline` flag set by default?
	// This is recommended for syncs with non-real-time changes.
	// Real-time changes (e.g. a user joining) should not set this flag set.
	ExcludeChangesFromTimeline bool

	// The total number of members in the chat, regardless of how many of those members are included in MemberMap.
	TotalMemberCount int

	// For DM portals, the ID of the recipient user.
	// This field is optional and will be automatically filled from MemberMap if there are only 2 entries in the map.
	OtherUserID networkid.UserID

	// Deprecated: Use MemberMap instead to avoid duplicate entries
	Members     []ChatMember
	MemberMap   ChatMemberMap
	PowerLevels *PowerLevelOverrides
}

type ChatMemberMap added in v0.26.1

type ChatMemberMap map[networkid.UserID]ChatMember

func (ChatMemberMap) Add added in v0.26.1

func (cmm ChatMemberMap) Add(member ChatMember) bool

Add adds the given entry to this map, but will ignore it if an entry with the same Sender field already exists. It returns true if the entry was added, false otherwise.

func (ChatMemberMap) Set added in v0.26.1

func (cmm ChatMemberMap) Set(member ChatMember) ChatMemberMap

Set adds the given entry to this map, overwriting any existing entry with the same Sender field.

type ChatViewingNetworkAPI

type ChatViewingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixViewingChat is called when the user opens a portal room.
	// This will never be called by the standard appservice connector,
	// as Matrix doesn't have any standard way of signaling chat open status.
	// Clients are expected to call this every 5 seconds. There is no signal for closing a chat.
	HandleMatrixViewingChat(ctx context.Context, msg *MatrixViewingChat) error
}

ChatViewingNetworkAPI is an optional interface that network connectors can implement to handle viewing chat status.

type CommandProcessor

type CommandProcessor interface {
	Handle(ctx context.Context, roomID id.RoomID, eventID id.EventID, user *User, message string, replyTo id.EventID)
}

type ConfigValidatingNetwork

type ConfigValidatingNetwork interface {
	NetworkConnector
	ValidateConfig() error
}

ConfigValidatingNetwork is an optional interface that network connectors can implement to validate config fields before the bridge is started.

When the ValidateConfig method is called, the config data will already be unmarshaled into the object returned by [NetworkConnector.GetConfig].

This mechanism is usually used to refuse bridge startup if a mandatory field has an invalid value.

type ConnectBackgroundParams

type ConnectBackgroundParams struct {
	// RawData is the raw data in the push that triggered the background connection.
	RawData json.RawMessage
	// ExtraData is the data returned by [PushParsingNetwork.ParsePushNotification].
	// It's only present for native pushes. Relayed pushes will only have the raw data.
	ExtraData any
}

type ContactListingNetworkAPI

type ContactListingNetworkAPI interface {
	NetworkAPI
	GetContactList(ctx context.Context) ([]*ResolveIdentifierResponse, error)
}

ContactListingNetworkAPI is an optional interface that network connectors can implement to provide the user's contact list.

type ConvertedEdit

type ConvertedEdit struct {
	ModifiedParts []*ConvertedEditPart
	DeletedParts  []*database.Message
	// Warning: added parts will be sent at the end of the room.
	// If other messages have been sent after the message being edited,
	// these new parts will not be next to the existing parts.
	AddedParts *ConvertedMessage
}

type ConvertedEditPart

type ConvertedEditPart struct {
	Part *database.Message

	Type event.Type
	// The Content and Extra fields will be put inside `m.new_content` automatically.
	// SetEdit must NOT be called by the network connector.
	Content *event.MessageEventContent
	Extra   map[string]any
	// TopLevelExtra can be used to specify custom fields at the top level of the content rather than inside `m.new_content`.
	TopLevelExtra map[string]any
	// NewMentions can be used to specify new mentions that should ping the users again.
	// Mentions inside the edited content will not ping.
	NewMentions *event.Mentions

	DontBridge bool
}

type ConvertedMessage

type ConvertedMessage struct {
	ReplyTo *networkid.MessageOptionalPartID
	// Optional additional info about the reply. This is only used when backfilling messages
	// on Beeper, where replies may target messages that haven't been bridged yet.
	// Standard Matrix servers can't backwards backfill, so these are never used.
	ReplyToRoom  networkid.PortalKey
	ReplyToUser  networkid.UserID
	ReplyToLogin networkid.UserLoginID

	ThreadRoot *networkid.MessageID
	Parts      []*ConvertedMessagePart
	Disappear  database.DisappearingSetting
}

func (*ConvertedMessage) MergeCaption

func (cm *ConvertedMessage) MergeCaption() bool

type ConvertedMessagePart

type ConvertedMessagePart struct {
	ID         networkid.PartID
	Type       event.Type
	Content    *event.MessageEventContent
	Extra      map[string]any
	DBMetadata any
	DontBridge bool
}

func MergeCaption

func MergeCaption(textPart, mediaPart *ConvertedMessagePart) *ConvertedMessagePart

func (*ConvertedMessagePart) ToEditPart

func (cmp *ConvertedMessagePart) ToEditPart(part *database.Message) *ConvertedEditPart

type CreateChatFailedParticipant added in v0.26.1

type CreateChatFailedParticipant struct {
	Reason          string         `json:"reason"`
	InviteEventType string         `json:"invite_event_type,omitempty"`
	InviteContent   *event.Content `json:"invite_content,omitempty"`

	UserMXID   id.UserID `json:"user_mxid,omitempty"`
	DMRoomMXID id.RoomID `json:"dm_room_mxid,omitempty"`
}

type CreateChatResponse

type CreateChatResponse struct {
	PortalKey networkid.PortalKey
	// Portal and PortalInfo are not required, the caller will fetch them automatically based on PortalKey if necessary.
	Portal     *Portal
	PortalInfo *ChatInfo
	// If a start DM request (CreateChatWithGhost or ResolveIdentifier) returns the DM to a different user,
	// this field should have the user ID of said different user.
	DMRedirectedTo networkid.UserID

	FailedParticipants map[networkid.UserID]*CreateChatFailedParticipant
}

type CredentialExportingNetworkAPI

type CredentialExportingNetworkAPI interface {
	NetworkAPI
	ExportCredentials(ctx context.Context) any
}

CredentialExportingNetworkAPI is an optional interface that networks connectors can implement to support export of the credentials associated with that login. Credential type is bridge specific.

type DBUpgradeError

type DBUpgradeError struct {
	Err     error
	Section string
}

func (DBUpgradeError) Error

func (e DBUpgradeError) Error() string

func (DBUpgradeError) Unwrap

func (e DBUpgradeError) Unwrap() error

type DeleteChatHandlingNetworkAPI added in v0.25.2

type DeleteChatHandlingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixDeleteChat is called when the user explicitly deletes a chat.
	HandleMatrixDeleteChat(ctx context.Context, msg *MatrixDeleteChat) error
}

DeleteChatHandlingNetworkAPI is an optional interface that network connectors can implement to delete a chat from the remote network.

type DeleteOpts

type DeleteOpts struct {
	LogoutRemote     bool
	DontCleanupRooms bool
	BlockingCleanup  bool
	// contains filtered or unexported fields
}

type DirectMediableNetwork

type DirectMediableNetwork interface {
	NetworkConnector
	SetUseDirectMedia()
	Download(ctx context.Context, mediaID networkid.MediaID, params map[string]string) (mediaproxy.GetMediaResponse, error)
}

DirectMediableNetwork is an optional interface that network connectors can implement to support direct media access.

If the Matrix connector has direct media enabled, SetUseDirectMedia will be called before the Start method of the network connector. Download will then be called whenever someone wants to download a direct media `mxc://` URI which was generated by calling GenerateContentURI on the Matrix connector.

type DirectNotificationData

type DirectNotificationData struct {
	Portal    *Portal
	Sender    *Ghost
	MessageID networkid.MessageID
	Message   string

	FormattedNotification string
	FormattedTitle        string
}

type DisappearLoop

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

func (*DisappearLoop) Add

func (*DisappearLoop) GetNextCheck added in v0.24.3

func (dl *DisappearLoop) GetNextCheck() time.Time

func (*DisappearLoop) Start

func (dl *DisappearLoop) Start()

func (*DisappearLoop) StartAllBefore added in v0.26.1

func (dl *DisappearLoop) StartAllBefore(ctx context.Context, roomID id.RoomID, beforeTS time.Time)

func (*DisappearLoop) Stop

func (dl *DisappearLoop) Stop()

type DisappearTimerChangingNetworkAPI added in v0.25.1

type DisappearTimerChangingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixDisappearingTimer is called when the disappearing timer of a portal room is changed.
	// This method should update the Disappear field of the Portal with the new timer and return true
	// if the change was successful. If the change is not successful, then the field should not be updated.
	HandleMatrixDisappearingTimer(ctx context.Context, msg *MatrixDisappearingTimer) (bool, error)
}

type EditHandlingNetworkAPI

type EditHandlingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixEdit is called when a previously bridged message is edited in a portal room.
	// The central bridge module will save the [*database.Message] after this function returns,
	// so the network connector is allowed to mutate the provided object.
	HandleMatrixEdit(ctx context.Context, msg *MatrixEdit) error
}

EditHandlingNetworkAPI is an optional interface that network connectors can implement to handle message edits.

type EnsureJoinedParams added in v0.24.3

type EnsureJoinedParams struct {
	Via []string
}

type EventHandlingResult

type EventHandlingResult struct {
	Success bool
	Ignored bool
	Queued  bool

	SkipStateEcho bool

	// Error is an optional reason for failure. It is not required, Success may be false even without a specific error.
	Error error
	// Whether the Error should be sent as a MSS event.
	SendMSS bool

	// EventID from the network
	EventID id.EventID
	// Stream order from the network
	StreamOrder int64
}

func (EventHandlingResult) WithError

func (ehr EventHandlingResult) WithError(err error) EventHandlingResult

func (EventHandlingResult) WithEventID added in v0.26.1

func (ehr EventHandlingResult) WithEventID(id id.EventID) EventHandlingResult

func (EventHandlingResult) WithMSS

func (EventHandlingResult) WithMSSError

func (ehr EventHandlingResult) WithMSSError(err error) EventHandlingResult

func (EventHandlingResult) WithSkipStateEcho added in v0.26.1

func (ehr EventHandlingResult) WithSkipStateEcho(skip bool) EventHandlingResult

func (EventHandlingResult) WithStreamOrder added in v0.26.1

func (ehr EventHandlingResult) WithStreamOrder(order int64) EventHandlingResult

type EventSender

type EventSender struct {
	// If IsFromMe is true, the UserLogin who the event was received through is used as the sender.
	// Double puppeting will be used if available.
	IsFromMe bool
	// SenderLogin is the ID of the UserLogin who sent the event. This may be different from the
	// login the event was received through. It is used to ensure double puppeting can still be
	// used even if the event is received through another login.
	SenderLogin networkid.UserLoginID
	// Sender is the remote user ID of the user who sent the event.
	// For new events, this will not be used for double puppeting.
	//
	// However, in the member list, [ChatMemberList.CheckAllLogins] can be specified to go through every login
	// and call [NetworkAPI.IsThisUser] to check if this ID belongs to that login. This method is not recommended,
	// it is better to fill the IsFromMe and SenderLogin fields appropriately.
	Sender networkid.UserID

	// ForceDMUser can be set if the event should be sent as the DM user even if the Sender is different.
	// This only applies in DM rooms where [database.Portal.OtherUserID] is set and is ignored if IsFromMe is true.
	// A warning will be logged if the sender is overridden due to this flag.
	ForceDMUser bool
}

EventSender represents a specific user in a chat.

func (EventSender) MarshalZerologObject

func (es EventSender) MarshalZerologObject(evt *zerolog.Event)

type ExtraUpdater

type ExtraUpdater[T any] func(context.Context, T) bool

func MergeExtraUpdaters

func MergeExtraUpdaters[T any](funcs ...ExtraUpdater[T]) ExtraUpdater[T]

type FCMPushConfig

type FCMPushConfig struct {
	SenderID string `json:"sender_id"`
}

type FetchMessagesParams

type FetchMessagesParams struct {
	// The portal to fetch messages in. Always present.
	Portal *Portal
	// When fetching messages inside a thread, the ID of the thread.
	ThreadRoot networkid.MessageID
	// Whether to fetch new messages instead of old ones.
	Forward bool
	// The oldest known message in the thread or the portal. If Forward is true, this is the newest known message instead.
	// If the portal doesn't have any bridged messages, this will be nil.
	AnchorMessage *database.Message
	// The cursor returned by the previous call to FetchMessages with the same portal and thread root.
	// This will not be present in Forward calls.
	Cursor networkid.PaginationCursor
	// The preferred number of messages to return. The returned batch can be bigger or smaller
	// without any side effects, but the network connector should aim for this number.
	Count int

	// When a forward backfill is triggered by a [RemoteChatResyncBackfillBundle], this will contain
	// the bundled data returned by the event. It can be used as an optimization to avoid fetching
	// messages that were already provided by the remote network, while still supporting fetching
	// more messages if the limit is higher.
	BundledData any

	// When the messages are being fetched for a queued backfill, this is the task object.
	Task *database.BackfillTask
}

FetchMessagesParams contains the parameters for a message history pagination request.

type FetchMessagesResponse

type FetchMessagesResponse struct {
	// The messages to backfill. Messages should always be sorted in chronological order (oldest to newest).
	Messages []*BackfillMessage
	// The next cursor to use for fetching more messages.
	Cursor networkid.PaginationCursor
	// Whether there are more messages that can be backfilled.
	// This field is required. If it is false, FetchMessages will not be called again.
	HasMore bool
	// Whether the batch contains new messages rather than old ones.
	// Cursor, HasMore and the progress fields will be ignored when this is present.
	Forward bool
	// When sending forward backfill (or the first batch in a room), this field can be set
	// to mark the messages as read immediately after backfilling.
	MarkRead bool

	// Should the bridge check each message against the database to ensure it's not a duplicate before bridging?
	// By default, the bridge will only drop messages that are older than the last bridged message for forward backfills,
	// or newer than the first for backward.
	AggressiveDeduplication bool

	// Approximate backfill progress as a number between 0 and 1.
	ApproxProgress float64
	// Approximate number of messages remaining that can be backfilled.
	ApproxRemainingCount int
	// Approximate total number of messages in the chat.
	ApproxTotalCount int

	// An optional function that is called after the backfill batch has been sent.
	CompleteCallback func()
}

FetchMessagesResponse contains the response for a message history pagination request.

type FileStreamCallback

type FileStreamCallback func(file io.Writer) (*FileStreamResult, error)

FileStreamCallback is a callback function for file uploads that roundtrip via disk.

The parameter is either a file or an in-memory buffer depending on the size of the file and whether the requireFile flag was set.

The return value must be non-nil unless there's an error, and should always include FileName and MimeType.

type FileStreamResult

type FileStreamResult struct {
	// ReplacementFile is the path to a new file that replaces the original file provided to the callback.
	// Providing a replacement file is only allowed if the requireFile flag was set for the UploadMediaStream call.
	ReplacementFile string
	// FileName is the name of the file to be specified when uploading to the server.
	// This should be the same as the file name that will be included in the Matrix event (body or filename field).
	// If the file gets encrypted, this field will be ignored.
	FileName string
	// MimeType is the type of field to be specified when uploading to the server.
	// This should be the same as the mime type that will be included in the Matrix event (info -> mimetype field).
	// If the file gets encrypted, this field will be replaced with application/octet-stream.
	MimeType string
}

FileStreamResult is the result of a FileStreamCallback.

type Ghost

type Ghost struct {
	*database.Ghost
	Bridge *Bridge
	Log    zerolog.Logger
	Intent MatrixAPI
}

func (*Ghost) UpdateAvatar

func (ghost *Ghost) UpdateAvatar(ctx context.Context, avatar *Avatar) bool

func (*Ghost) UpdateContactInfo

func (ghost *Ghost) UpdateContactInfo(ctx context.Context, identifiers []string, isBot *bool) bool

func (*Ghost) UpdateInfo

func (ghost *Ghost) UpdateInfo(ctx context.Context, info *UserInfo)

func (*Ghost) UpdateInfoIfNecessary

func (ghost *Ghost) UpdateInfoIfNecessary(ctx context.Context, source *UserLogin, evtType RemoteEventType)

func (*Ghost) UpdateName

func (ghost *Ghost) UpdateName(ctx context.Context, name string) bool

type GhostDMCreatingNetworkAPI

type GhostDMCreatingNetworkAPI interface {
	IdentifierResolvingNetworkAPI
	// CreateChatWithGhost may be called instead of [IdentifierResolvingNetworkAPI.ResolveIdentifier]
	// when starting a chat with an internal user identifier that has been pre-validated using
	// [IdentifierValidatingNetwork.ValidateUserID]. If this is not implemented, ResolveIdentifier
	// will be used instead (by stringifying the ghost ID).
	CreateChatWithGhost(ctx context.Context, ghost *Ghost) (*CreateChatResponse, error)
}

GhostDMCreatingNetworkAPI is an optional extension to IdentifierResolvingNetworkAPI for starting chats with pre-validated user IDs.

type GhostOrUserLogin

type GhostOrUserLogin interface {
	// contains filtered or unexported methods
}

type GroupCreateParams added in v0.25.1

type GroupCreateParams struct {
	Type string `json:"type,omitempty"`

	Username string `json:"username,omitempty"`
	// Clients may also provide MXIDs here, but provisionutil will normalize them, so bridges only need to handle network IDs
	Participants []networkid.UserID   `json:"participants,omitempty"`
	Parent       *networkid.PortalKey `json:"parent,omitempty"`

	Name      *event.RoomNameEventContent    `json:"name,omitempty"`
	Avatar    *event.RoomAvatarEventContent  `json:"avatar,omitempty"`
	Topic     *event.TopicEventContent       `json:"topic,omitempty"`
	Disappear *event.BeeperDisappearingTimer `json:"disappear,omitempty"`

	// An existing room ID to bridge to. If unset, a new room will be created.
	RoomID id.RoomID `json:"room_id,omitempty"`
}

type GroupCreatingNetworkAPI

type GroupCreatingNetworkAPI interface {
	IdentifierResolvingNetworkAPI
	CreateGroup(ctx context.Context, params *GroupCreateParams) (*CreateChatResponse, error)
}

type GroupFieldCapability added in v0.25.1

type GroupFieldCapability struct {
	// Is setting this field allowed at all in the create request?
	// Even if false, the network connector should attempt to set the metadata after group creation,
	// as the allowed flag can't be enforced properly when creating a group for an existing Matrix room.
	Allowed bool `json:"allowed"`
	// Is setting this field mandatory for the creation to succeed?
	Required bool `json:"required,omitempty"`
	// The minimum/maximum length of the field, if applicable.
	// For members, length means the number of members excluding the creator.
	MinLength int `json:"min_length,omitempty"`
	MaxLength int `json:"max_length,omitempty"`

	// Only for the disappear field: allowed disappearing settings
	DisappearSettings *event.DisappearingTimerCapability `json:"settings,omitempty"`

	// This can be used to tell provisionutil not to call ValidateUserID on each participant.
	// It only meant to allow hacks where ResolveIdentifier returns a fake ID that isn't actually valid for MXIDs.
	SkipIdentifierValidation bool `json:"-"`
}

type GroupTypeCapabilities added in v0.25.1

type GroupTypeCapabilities struct {
	TypeDescription string `json:"type_description"`

	Name         GroupFieldCapability `json:"name"`
	Username     GroupFieldCapability `json:"username"`
	Avatar       GroupFieldCapability `json:"avatar"`
	Topic        GroupFieldCapability `json:"topic"`
	Disappear    GroupFieldCapability `json:"disappear"`
	Participants GroupFieldCapability `json:"participants"`
	Parent       GroupFieldCapability `json:"parent"`
}

type IProvisioningAPI added in v0.26.2

type IProvisioningAPI interface {
	GetRouter() *http.ServeMux
	GetUser(r *http.Request) *User
}

type IdentifierResolvingNetworkAPI

type IdentifierResolvingNetworkAPI interface {
	NetworkAPI
	// ResolveIdentifier is called when the user wants to start a new chat.
	// This can happen via the `resolve-identifier` or `start-chat` bridge bot commands,
	// or the corresponding provisioning API endpoints.
	ResolveIdentifier(ctx context.Context, identifier string, createChat bool) (*ResolveIdentifierResponse, error)
}

IdentifierResolvingNetworkAPI is an optional interface that network connectors can implement to support starting new direct chats.

type IdentifierValidatingNetwork

type IdentifierValidatingNetwork interface {
	NetworkConnector
	ValidateUserID(id networkid.UserID) bool
}

IdentifierValidatingNetwork is an optional interface that network connectors can implement to validate the shape of user IDs.

This should not perform any checks to see if the user ID actually exists on the network, just that the user ID looks valid.

type LoginCompleteParams

type LoginCompleteParams struct {
	UserLoginID networkid.UserLoginID `json:"user_login_id"`
	UserLogin   *UserLogin            `json:"-"`
}

type LoginCookieField

type LoginCookieField struct {
	// The key in the map that is submitted to the connector.
	ID       string `json:"id"`
	Required bool   `json:"required"`
	// The sources that can be used to acquire the field value. Only one of these needs to be used.
	Sources []LoginCookieFieldSource `json:"sources"`
	// A regex pattern that the client can use to validate value client-side.
	Pattern string `json:"pattern,omitempty"`
}

type LoginCookieFieldSource

type LoginCookieFieldSource struct {
	// The type of source.
	Type LoginCookieFieldSourceType `json:"type"`
	// The name of the field. The exact meaning depends on the type of source.
	// Cookie:         cookie name
	// Local storage:  key in local storage
	// Request header: header name
	// Request body:   field name inside body after it's parsed (as JSON or multipart form data)
	// Special:        a namespaced identifier that clients can implement special handling for
	Name string `json:"name"`

	// For request header & body types, a regex matching request URLs where the value can be extracted from.
	RequestURLRegex string `json:"request_url_regex,omitempty"`
	// For cookie types, the domain the cookie is present on.
	CookieDomain string `json:"cookie_domain,omitempty"`
}

type LoginCookieFieldSourceType

type LoginCookieFieldSourceType string
const (
	LoginCookieTypeCookie        LoginCookieFieldSourceType = "cookie"
	LoginCookieTypeLocalStorage  LoginCookieFieldSourceType = "local_storage"
	LoginCookieTypeRequestHeader LoginCookieFieldSourceType = "request_header"
	LoginCookieTypeRequestBody   LoginCookieFieldSourceType = "request_body"
	LoginCookieTypeSpecial       LoginCookieFieldSourceType = "special"
)

type LoginCookiesParams

type LoginCookiesParams struct {
	URL       string `json:"url"`
	UserAgent string `json:"user_agent,omitempty"`

	// The fields that are needed for this cookie login.
	Fields []LoginCookieField `json:"fields"`
	// A JavaScript snippet that can extract some or all of the fields.
	// The snippet will evaluate to a promise that resolves when the relevant fields are found.
	// Fields that are not present in the promise result must be extracted another way.
	ExtractJS string `json:"extract_js,omitempty"`
	// A regex pattern that the URL should match before the client closes the webview.
	//
	// The client may submit the login if the user closes the webview after all cookies are collected
	// even if this URL is not reached, but it should only automatically close the webview after
	// both cookies and the URL match.
	WaitForURLPattern string `json:"wait_for_url_pattern,omitempty"`
}

type LoginDisplayAndWaitParams

type LoginDisplayAndWaitParams struct {
	// The type of thing to display (QR, emoji or text code)
	Type LoginDisplayType `json:"type"`
	// The thing to display (raw data for QR, unicode emoji for emoji, plain string for code, omitted for nothing)
	Data string `json:"data,omitempty"`
	// An image containing the thing to display. If present, this is recommended over using data directly.
	// For emojis, the URL to the canonical image representation of the emoji
	ImageURL string `json:"image_url,omitempty"`
}

type LoginDisplayType

type LoginDisplayType string
const (
	LoginDisplayTypeQR      LoginDisplayType = "qr"
	LoginDisplayTypeEmoji   LoginDisplayType = "emoji"
	LoginDisplayTypeCode    LoginDisplayType = "code"
	LoginDisplayTypeNothing LoginDisplayType = "nothing"
)

type LoginFlow

type LoginFlow struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	ID          string `json:"id"`
}

type LoginInputDataField

type LoginInputDataField struct {
	// The type of input field as a hint for the client.
	Type LoginInputFieldType `json:"type"`
	// The ID of the field to be used as the key in the map that is submitted to the connector.
	ID string `json:"id"`
	// The name of the field shown to the user.
	Name string `json:"name"`
	// The description of the field shown to the user.
	Description string `json:"description"`
	// A default value that the client can pre-fill the field with.
	DefaultValue string `json:"default_value,omitempty"`
	// A regex pattern that the client can use to validate input client-side.
	Pattern string `json:"pattern,omitempty"`
	// For fields of type select, the valid options.
	// Pattern may also be filled with a regex that matches the same options.
	Options []string `json:"options,omitempty"`
	// A function that validates the input and optionally cleans it up before it's submitted to the connector.
	Validate func(string) (string, error) `json:"-"`
}

func (*LoginInputDataField) FillDefaultValidate

func (f *LoginInputDataField) FillDefaultValidate()

type LoginInputFieldType

type LoginInputFieldType string
const (
	LoginInputFieldTypeUsername    LoginInputFieldType = "username"
	LoginInputFieldTypePassword    LoginInputFieldType = "password"
	LoginInputFieldTypePhoneNumber LoginInputFieldType = "phone_number"
	LoginInputFieldTypeEmail       LoginInputFieldType = "email"
	LoginInputFieldType2FACode     LoginInputFieldType = "2fa_code"
	LoginInputFieldTypeToken       LoginInputFieldType = "token"
	LoginInputFieldTypeURL         LoginInputFieldType = "url"
	LoginInputFieldTypeDomain      LoginInputFieldType = "domain"
	LoginInputFieldTypeSelect      LoginInputFieldType = "select"
)

type LoginProcess

type LoginProcess interface {
	// Start starts the process and returns the first step.
	//
	// For example, a network using QR login may connect to the network, fetch a QR code,
	// and return a DisplayAndWait-type step.
	//
	// This will only ever be called once.
	Start(ctx context.Context) (*LoginStep, error)
	// Cancel stops the login process and cleans up any resources.
	// No other methods will be called after cancel.
	//
	// Cancel will not be called if any other method returned an error:
	// errors are always treated as fatal and the process is assumed to be automatically cancelled.
	Cancel()
}

LoginProcess represents a single occurrence of a user logging into the remote network.

type LoginProcessCookies

type LoginProcessCookies interface {
	LoginProcess
	SubmitCookies(ctx context.Context, cookies map[string]string) (*LoginStep, error)
}

type LoginProcessDisplayAndWait

type LoginProcessDisplayAndWait interface {
	LoginProcess
	Wait(ctx context.Context) (*LoginStep, error)
}

type LoginProcessUserInput

type LoginProcessUserInput interface {
	LoginProcess
	SubmitUserInput(ctx context.Context, input map[string]string) (*LoginStep, error)
}

type LoginProcessWithOverride

type LoginProcessWithOverride interface {
	LoginProcess
	// StartWithOverride starts the process with the intent of re-authenticating an existing login.
	//
	// The call to this is mutually exclusive with the call to the default Start method.
	//
	// The user login being overridden will still be logged out automatically
	// in case the complete step returns a different login.
	StartWithOverride(ctx context.Context, override *UserLogin) (*LoginStep, error)
}

type LoginStep

type LoginStep struct {
	// The type of login step
	Type LoginStepType `json:"type"`
	// A unique ID for this step. The ID should be same for every login using the same flow,
	// but it should be different for different bridges and step types.
	//
	// For example, Telegram's QR scan followed by a 2-factor password
	// might use the IDs `fi.mau.telegram.qr` and `fi.mau.telegram.2fa_password`.
	StepID string `json:"step_id"`
	// Instructions contains human-readable instructions for completing the login step.
	Instructions string `json:"instructions"`

	DisplayAndWaitParams *LoginDisplayAndWaitParams `json:"display_and_wait,omitempty"`
	CookiesParams        *LoginCookiesParams        `json:"cookies,omitempty"`
	UserInputParams      *LoginUserInputParams      `json:"user_input,omitempty"`
	CompleteParams       *LoginCompleteParams       `json:"complete,omitempty"`
}

type LoginStepType

type LoginStepType string
const (
	LoginStepTypeUserInput      LoginStepType = "user_input"
	LoginStepTypeCookies        LoginStepType = "cookies"
	LoginStepTypeDisplayAndWait LoginStepType = "display_and_wait"
	LoginStepTypeComplete       LoginStepType = "complete"
)

type LoginSubmit

type LoginSubmit struct {
}

type LoginUserInputParams

type LoginUserInputParams struct {
	// The fields that the user needs to fill in.
	Fields []LoginInputDataField `json:"fields"`
}

type MarkAsDMMatrixAPI

type MarkAsDMMatrixAPI interface {
	MatrixAPI
	MarkAsDM(ctx context.Context, roomID id.RoomID, otherUser id.UserID) error
}

type MarkedUnreadHandlingNetworkAPI

type MarkedUnreadHandlingNetworkAPI interface {
	NetworkAPI
	HandleMarkedUnread(ctx context.Context, msg *MatrixMarkedUnread) error
}

type MatrixAPI

type MatrixAPI interface {
	GetMXID() id.UserID
	IsDoublePuppet() bool

	SendMessage(ctx context.Context, roomID id.RoomID, eventType event.Type, content *event.Content, extra *MatrixSendExtra) (*mautrix.RespSendEvent, error)
	SendState(ctx context.Context, roomID id.RoomID, eventType event.Type, stateKey string, content *event.Content, ts time.Time) (*mautrix.RespSendEvent, error)
	MarkRead(ctx context.Context, roomID id.RoomID, eventID id.EventID, ts time.Time) error
	MarkUnread(ctx context.Context, roomID id.RoomID, unread bool) error
	MarkTyping(ctx context.Context, roomID id.RoomID, typingType TypingType, timeout time.Duration) error
	DownloadMedia(ctx context.Context, uri id.ContentURIString, file *event.EncryptedFileInfo) ([]byte, error)
	DownloadMediaToFile(ctx context.Context, uri id.ContentURIString, file *event.EncryptedFileInfo, writable bool, callback func(*os.File) error) error
	UploadMedia(ctx context.Context, roomID id.RoomID, data []byte, fileName, mimeType string) (url id.ContentURIString, file *event.EncryptedFileInfo, err error)
	UploadMediaStream(ctx context.Context, roomID id.RoomID, size int64, requireFile bool, cb FileStreamCallback) (url id.ContentURIString, file *event.EncryptedFileInfo, err error)

	SetDisplayName(ctx context.Context, name string) error
	SetAvatarURL(ctx context.Context, avatarURL id.ContentURIString) error
	SetExtraProfileMeta(ctx context.Context, data any) error

	CreateRoom(ctx context.Context, req *mautrix.ReqCreateRoom) (id.RoomID, error)
	DeleteRoom(ctx context.Context, roomID id.RoomID, puppetsOnly bool) error
	EnsureJoined(ctx context.Context, roomID id.RoomID, params ...EnsureJoinedParams) error
	EnsureInvited(ctx context.Context, roomID id.RoomID, userID id.UserID) error

	TagRoom(ctx context.Context, roomID id.RoomID, tag event.RoomTag, isTagged bool) error
	MuteRoom(ctx context.Context, roomID id.RoomID, until time.Time) error

	GetEvent(ctx context.Context, roomID id.RoomID, eventID id.EventID) (*event.Event, error)
}

type MatrixAcceptMessageRequest added in v0.26.1

type MatrixAcceptMessageRequest = MatrixEventBase[*event.BeeperAcceptMessageRequestEventContent]

type MatrixCapabilities

type MatrixCapabilities struct {
	AutoJoinInvites       bool
	BatchSending          bool
	ArbitraryMemberChange bool
}

type MatrixConnector

type MatrixConnector interface {
	Init(*Bridge)
	Start(ctx context.Context) error
	PreStop()
	Stop()

	GetCapabilities() *MatrixCapabilities

	ParseGhostMXID(userID id.UserID) (networkid.UserID, bool)
	GhostIntent(userID networkid.UserID) MatrixAPI
	NewUserIntent(ctx context.Context, userID id.UserID, accessToken string) (MatrixAPI, string, error)
	BotIntent() MatrixAPI

	SendBridgeStatus(ctx context.Context, state *status.BridgeState) error
	SendMessageStatus(ctx context.Context, status *MessageStatus, evt *MessageStatusEventInfo)

	GenerateContentURI(ctx context.Context, mediaID networkid.MediaID) (id.ContentURIString, error)

	GetPowerLevels(ctx context.Context, roomID id.RoomID) (*event.PowerLevelsEventContent, error)
	GetMembers(ctx context.Context, roomID id.RoomID) (map[id.UserID]*event.MemberEventContent, error)
	GetMemberInfo(ctx context.Context, roomID id.RoomID, userID id.UserID) (*event.MemberEventContent, error)
	GetDisplayname(ctx context.Context, userID id.UserID) string

	BatchSend(ctx context.Context, roomID id.RoomID, req *mautrix.ReqBeeperBatchSend, extras []*MatrixSendExtra) (*mautrix.RespBeeperBatchSend, error)
	GenerateDeterministicRoomID(portalKey networkid.PortalKey) id.RoomID
	GenerateDeterministicEventID(roomID id.RoomID, portalKey networkid.PortalKey, messageID networkid.MessageID, partID networkid.PartID) id.EventID
	GenerateReactionEventID(roomID id.RoomID, targetMessage *database.Message, sender networkid.UserID, emojiID networkid.EmojiID) id.EventID

	ServerName() string
}

type MatrixConnectorWithAnalytics

type MatrixConnectorWithAnalytics interface {
	MatrixConnector
	TrackAnalytics(userID id.UserID, event string, properties map[string]any)
}

type MatrixConnectorWithArbitraryRoomState added in v0.24.3

type MatrixConnectorWithArbitraryRoomState interface {
	MatrixConnector
	GetStateEvent(ctx context.Context, roomID id.RoomID, eventType event.Type, stateKey string) (*event.Event, error)
}

type MatrixConnectorWithBridgeIdentifier

type MatrixConnectorWithBridgeIdentifier interface {
	MatrixConnector
	GetUniqueBridgeID() string
}

type MatrixConnectorWithHTTPSettings added in v0.26.2

type MatrixConnectorWithHTTPSettings interface {
	MatrixConnector
	GetHTTPClientSettings() exhttp.ClientSettings
}

type MatrixConnectorWithNameDisambiguation

type MatrixConnectorWithNameDisambiguation interface {
	MatrixConnector
	IsConfusableName(ctx context.Context, roomID id.RoomID, userID id.UserID, name string) ([]id.UserID, error)
}

type MatrixConnectorWithNotifications

type MatrixConnectorWithNotifications interface {
	MatrixConnector
	DisplayNotification(ctx context.Context, data *DirectNotificationData)
}

type MatrixConnectorWithPostRoomBridgeHandling

type MatrixConnectorWithPostRoomBridgeHandling interface {
	MatrixConnector
	HandleNewlyBridgedRoom(ctx context.Context, roomID id.RoomID) error
}

type MatrixConnectorWithProvisioning added in v0.26.2

type MatrixConnectorWithProvisioning interface {
	MatrixConnector
	GetProvisioning() IProvisioningAPI
}

type MatrixConnectorWithPublicMedia

type MatrixConnectorWithPublicMedia interface {
	MatrixConnector
	GetPublicMediaAddress(contentURI id.ContentURIString) string
	GetPublicMediaAddressForEvent(ctx context.Context, evt *event.MessageEventContent) (string, error)
}

type MatrixConnectorWithServer

type MatrixConnectorWithServer interface {
	MatrixConnector
	GetPublicAddress() string
	GetRouter() *http.ServeMux
}

type MatrixConnectorWithURLPreviews

type MatrixConnectorWithURLPreviews interface {
	MatrixConnector
	GetURLPreview(ctx context.Context, url string) (*event.LinkPreview, error)
}

type MatrixDeleteChat added in v0.25.2

type MatrixDisappearingTimer added in v0.25.1

type MatrixDisappearingTimer = MatrixRoomMeta[*event.BeeperDisappearingTimer]

type MatrixEdit

type MatrixEdit struct {
	MatrixEventBase[*event.MessageEventContent]
	EditTarget *database.Message
}

type MatrixEventBase

type MatrixEventBase[ContentType any] struct {
	// The raw event being bridged.
	Event *event.Event
	// The parsed content struct of the event. Custom fields can be found in Event.Content.Raw.
	Content ContentType
	// The room where the event happened.
	Portal *Portal

	// The original sender user ID. Only present in case the event is being relayed (and Sender is not the same user).
	OrigSender *OrigSender

	InputTransactionID networkid.RawTransactionID
}

type MatrixMembershipChange

type MatrixMembershipChange struct {
	MatrixRoomMeta[*event.MemberEventContent]
	Target GhostOrUserLogin
	Type   MembershipChangeType
}

type MatrixMembershipResult added in v0.26.1

type MatrixMembershipResult struct {
	RedirectTo networkid.UserID
}

type MatrixMessage

type MatrixMessage struct {
	MatrixEventBase[*event.MessageEventContent]
	ThreadRoot *database.Message
	ReplyTo    *database.Message
	// contains filtered or unexported fields
}

func (*MatrixMessage) AddPendingToIgnore

func (evt *MatrixMessage) AddPendingToIgnore(txnID networkid.TransactionID)

AddPendingToIgnore adds a transaction ID that should be ignored if encountered as a new message.

This should be used when the network connector will return the real message ID from HandleMatrixMessage. The MatrixMessageResponse should include RemovePending with the transaction ID sto remove it from the lit after saving to database.

See also: MatrixMessage.AddPendingToSave

func (*MatrixMessage) AddPendingToSave

func (evt *MatrixMessage) AddPendingToSave(message *database.Message, txnID networkid.TransactionID, handleEcho RemoteEchoHandler)

AddPendingToSave adds a transaction ID that should be processed and pointed at the existing event if encountered.

This should be used when the network connector returns `Pending: true` from HandleMatrixMessage, i.e. when the network connector does not know the message ID at the end of the handler. The MatrixMessageResponse should set Pending to true to prevent saving the returned message to the database.

The provided function will be called when the message is encountered.

func (*MatrixMessage) RemovePending

func (evt *MatrixMessage) RemovePending(txnID networkid.TransactionID)

RemovePending removes a transaction ID from the list of pending messages. This should only be called if sending the message fails.

type MatrixMessageRemove

type MatrixMessageRemove struct {
	MatrixEventBase[*event.RedactionEventContent]
	TargetMessage *database.Message
}

type MatrixMessageResponse

type MatrixMessageResponse struct {
	DB          *database.Message
	StreamOrder int64
	// If Pending is set, the bridge will not save the provided message to the database.
	// This should only be used if AddPendingToSave has been called.
	Pending bool
	// If RemovePending is set, the bridge will remove the provided transaction ID from pending messages
	// after saving the provided message to the database. This should be used with AddPendingToIgnore.
	RemovePending networkid.TransactionID
	// An optional function that is called after the message is saved to the database.
	// Will not be called if the message is not saved for some reason.
	PostSave func(context.Context, *database.Message)
}

type MatrixPollStart

type MatrixPollStart struct {
	MatrixMessage
	Content *event.PollStartEventContent
}

type MatrixPollVote

type MatrixPollVote struct {
	MatrixMessage
	VoteTo  *database.Message
	Content *event.PollResponseEventContent
}

type MatrixReaction

type MatrixReaction struct {
	MatrixEventBase[*event.ReactionEventContent]
	TargetMessage *database.Message
	PreHandleResp *MatrixReactionPreResponse

	// When EmojiID is blank and there's already an existing reaction, this is the old reaction that is being overridden.
	ReactionToOverride *database.Reaction
	// When MaxReactions is >0 in the pre-response, this is the list of previous reactions that should be preserved.
	ExistingReactionsToKeep []*database.Reaction
}

type MatrixReactionPreResponse

type MatrixReactionPreResponse struct {
	SenderID     networkid.UserID
	EmojiID      networkid.EmojiID
	Emoji        string
	MaxReactions int
}

type MatrixReactionRemove

type MatrixReactionRemove struct {
	MatrixEventBase[*event.RedactionEventContent]
	TargetReaction *database.Reaction
}

type MatrixReadReceipt

type MatrixReadReceipt struct {
	Portal *Portal
	// The event ID that the receipt is targeting
	EventID id.EventID
	// The exact message that was read. This may be nil if the event ID isn't a message.
	ExactMessage *database.Message
	// The timestamp that the user has read up to. This is either the timestamp of the message
	// (if one is present) or the timestamp of the receipt.
	ReadUpTo time.Time
	// The ReadUpTo timestamp of the previous message
	LastRead time.Time
	// The receipt metadata.
	Receipt event.ReadReceipt
	// Whether the receipt is implicit, i.e. triggered by an incoming timeline event rather than an explicit receipt.
	Implicit bool
}

type MatrixRoomMeta

type MatrixRoomMeta[ContentType any] struct {
	MatrixEventBase[ContentType]
	PrevContent    ContentType
	IsStateRequest bool
}

type MatrixRoomTag

type MatrixRoomTag = MatrixRoomMeta[*event.TagEventContent]

type MatrixRoomTopic

type MatrixRoomTopic = MatrixRoomMeta[*event.TopicEventContent]

type MatrixSendExtra

type MatrixSendExtra struct {
	Timestamp    time.Time
	MessageMeta  *database.Message
	ReactionMeta *database.Reaction
	StreamOrder  int64
	PartIndex    int
}

type MatrixTyping

type MatrixTyping struct {
	Portal   *Portal
	IsTyping bool
	Type     TypingType
}

type MatrixViewingChat

type MatrixViewingChat struct {
	// The portal that the user is viewing. This will be nil when the user switches to a chat from a different bridge.
	Portal *Portal
}

type MaxFileSizeingNetwork

type MaxFileSizeingNetwork interface {
	NetworkConnector
	SetMaxFileSize(maxSize int64)
}

MaxFileSizeingNetwork is an optional interface that network connectors can implement to find out the maximum file size that can be uploaded to Matrix.

The SetMaxFileSize will be called asynchronously soon after startup. Before the function is called, the connector may assume a default limit of 50 MiB.

type MembershipChangeType

type MembershipChangeType struct {
	From   event.Membership
	To     event.Membership
	IsSelf bool
}

type MembershipHandlingNetworkAPI

type MembershipHandlingNetworkAPI interface {
	NetworkAPI
	HandleMatrixMembership(ctx context.Context, msg *MatrixMembershipChange) (*MatrixMembershipResult, error)
}

type MessageRequestAcceptingNetworkAPI added in v0.26.1

type MessageRequestAcceptingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixAcceptMessageRequest is called when the user accepts a message request.
	HandleMatrixAcceptMessageRequest(ctx context.Context, msg *MatrixAcceptMessageRequest) error
}

MessageRequestAcceptingNetworkAPI is an optional interface that network connectors can implement to accept message requests from the remote network.

type MessageStatus

type MessageStatus struct {
	Step     status.MessageCheckpointStep
	RetryNum int

	Status        event.MessageStatus
	ErrorReason   event.MessageStatusReason
	DeliveredTo   []id.UserID
	InternalError error  // Internal error to be tracked in message checkpoints
	Message       string // Human-readable message shown to users

	ErrorAsMessage bool
	IsCertain      bool
	SendNotice     bool
	DisableMSS     bool
}

MessageStatus represents the status of a message. It also implements the error interface to allow network connectors to return errors which get translated into user-friendly error messages and/or status events.

func WrapErrorInStatus

func WrapErrorInStatus(err error) MessageStatus

func (MessageStatus) Error

func (ms MessageStatus) Error() string

func (*MessageStatus) ToCheckpoint

func (*MessageStatus) ToMSSEvent

func (*MessageStatus) ToNoticeEvent

func (MessageStatus) Unwrap

func (ms MessageStatus) Unwrap() error

func (MessageStatus) WithErrorAsMessage

func (ms MessageStatus) WithErrorAsMessage() MessageStatus

func (MessageStatus) WithErrorReason

func (ms MessageStatus) WithErrorReason(reason event.MessageStatusReason) MessageStatus

func (MessageStatus) WithIsCertain

func (ms MessageStatus) WithIsCertain(certain bool) MessageStatus

func (MessageStatus) WithMessage

func (ms MessageStatus) WithMessage(msg string) MessageStatus

func (MessageStatus) WithSendNotice

func (ms MessageStatus) WithSendNotice(send bool) MessageStatus

func (MessageStatus) WithStatus

func (ms MessageStatus) WithStatus(status event.MessageStatus) MessageStatus

func (MessageStatus) WithStep

type MessageStatusEventInfo

type MessageStatusEventInfo struct {
	RoomID        id.RoomID
	TransactionID string
	SourceEventID id.EventID
	NewEventID    id.EventID
	EventType     event.Type
	MessageType   event.MessageType
	Sender        id.UserID
	ThreadRoot    id.EventID
	StreamOrder   int64

	IsSourceEventDoublePuppeted bool
}

func StatusEventInfoFromEvent

func StatusEventInfoFromEvent(evt *event.Event) *MessageStatusEventInfo

type MuteHandlingNetworkAPI

type MuteHandlingNetworkAPI interface {
	NetworkAPI
	HandleMute(ctx context.Context, msg *MatrixMute) error
}

type NetworkAPI

type NetworkAPI interface {
	// Connect is called to actually connect to the remote network.
	// If there's no persistent connection, this may just check access token validity, or even do nothing at all.
	// This method isn't allowed to return errors, because any connection errors should be sent
	// using the bridge state mechanism (UserLogin.BridgeState.Send)
	Connect(ctx context.Context)
	// Disconnect should disconnect from the remote network.
	// A clean disconnection is preferred, but it should not take too long.
	Disconnect()
	// IsLoggedIn should return whether the access tokens in this NetworkAPI are valid.
	// This should not do any IO operations, it should only return cached data which is updated elsewhere.
	IsLoggedIn() bool
	// LogoutRemote should invalidate the access tokens in this NetworkAPI if possible
	// and disconnect from the remote network.
	LogoutRemote(ctx context.Context)

	// IsThisUser should return whether the given remote network user ID is the same as this login.
	// This is used when the bridge wants to convert a user login ID to a user ID.
	IsThisUser(ctx context.Context, userID networkid.UserID) bool
	// GetChatInfo returns info for a given chat. Any fields that are nil will be ignored and not processed at all,
	// while empty strings will change the relevant value in the room to be an empty string.
	// For example, a nil name will mean the room name is not changed, while an empty string name will remove the name.
	GetChatInfo(ctx context.Context, portal *Portal) (*ChatInfo, error)
	// GetUserInfo returns info for a given user. Like chat info, fields can be nil to skip them.
	GetUserInfo(ctx context.Context, ghost *Ghost) (*UserInfo, error)
	// GetCapabilities returns the bridging capabilities in a given room.
	// This can simply return a static list if the remote network has no per-chat capability differences,
	// but all calls will include the portal, because some networks do have per-chat differences.
	GetCapabilities(ctx context.Context, portal *Portal) *event.RoomFeatures

	// HandleMatrixMessage is called when a message is sent from Matrix in an existing portal room.
	// This function should convert the message as appropriate, send it over to the remote network,
	// and return the info so the central bridge can store it in the database.
	//
	// This is only called for normal non-edit messages. For other types of events, see the optional extra interfaces (`XHandlingNetworkAPI`).
	HandleMatrixMessage(ctx context.Context, msg *MatrixMessage) (message *MatrixMessageResponse, err error)
}

NetworkAPI is an interface representing a remote network client for a single user login.

Implementations of this interface are stored in [UserLogin.Client]. The [NetworkConnector.LoadUserLogin] method is responsible for filling the Client field with a NetworkAPI.

type NetworkConnector

type NetworkConnector interface {
	// Init is called when the bridge is initialized. The connector should store the bridge instance for later use.
	// This should not do any network calls or other blocking operations.
	Init(*Bridge)
	// Start is called when the bridge is starting.
	// The connector should do any non-user-specific startup actions necessary.
	// User logins will be loaded separately, so the connector should not load them here.
	Start(context.Context) error

	// GetName returns the name of the bridge and some additional metadata,
	// which is used to fill `m.bridge` events among other things.
	//
	// The first call happens *before* the config is loaded, because the data here is also used to
	// fill parts of the example config (like the default username template and bot localpart).
	// The output can still be adjusted based on config variables, but the function must have
	// default values when called without a config.
	GetName() BridgeName
	// GetDBMetaTypes returns struct types that are used to store connector-specific metadata in various tables.
	// All fields are optional. If a field isn't provided, then the corresponding table will have no custom metadata.
	// This will be called before Init, it should have a hardcoded response.
	GetDBMetaTypes() database.MetaTypes
	// GetCapabilities returns the general capabilities of the network connector.
	// Note that most capabilities are scoped to rooms and are returned by [NetworkAPI.GetCapabilities] instead.
	GetCapabilities() *NetworkGeneralCapabilities
	// GetConfig returns all the parts of the network connector's config file. Specifically:
	// - example: a string containing an example config file
	// - data: an interface to unmarshal the actual config into
	// - upgrader: a config upgrader to ensure all fields are present and to do any migrations from old configs
	GetConfig() (example string, data any, upgrader configupgrade.Upgrader)

	// LoadUserLogin is called when a UserLogin is loaded from the database in order to fill the [UserLogin.Client] field.
	//
	// This is called within the bridge's global cache lock, so it must not do any slow operations,
	// such as connecting to the network. Instead, connecting should happen when [NetworkAPI.Connect] is called later.
	LoadUserLogin(ctx context.Context, login *UserLogin) error

	// GetLoginFlows returns a list of login flows that the network supports.
	GetLoginFlows() []LoginFlow
	// CreateLogin is called when a user wants to log in to the network.
	//
	// This should generally not do any work, it should just return a LoginProcess that remembers
	// the user and will execute the requested flow. The actual work should start when [LoginProcess.Start] is called.
	CreateLogin(ctx context.Context, user *User, flowID string) (LoginProcess, error)

	// GetBridgeInfoVersion returns version numbers for bridge info and room capabilities respectively.
	// When the versions change, the bridge will automatically resend bridge info to all rooms.
	GetBridgeInfoVersion() (info, capabilities int)
}

NetworkConnector is the main interface that a network connector must implement.

type NetworkGeneralCapabilities

type NetworkGeneralCapabilities struct {
	// Does the network connector support disappearing messages?
	// This flag enables the message disappearing loop in the bridge.
	DisappearingMessages bool
	// Should the bridge re-request user info on incoming messages even if the ghost already has info?
	// By default, info is only requested for ghosts with no name, and other updating is left to events.
	AggressiveUpdateInfo bool
	// Should the bridge call HandleMatrixReadReceipt with fake data when receiving a new message?
	// This should be enabled if the network requires each message to be marked as read independently,
	// and doesn't automatically do it when sending a message.
	ImplicitReadReceipts bool
	// If the bridge uses the pending message mechanism ([MatrixMessage.AddPendingToSave])
	// to handle asynchronous message responses, this field can be set to enable
	// automatic timeout errors in case the asynchronous response never arrives.
	OutgoingMessageTimeouts *OutgoingTimeoutConfig
	// Capabilities related to the provisioning API.
	Provisioning ProvisioningCapabilities
}

type NetworkResettingNetwork added in v0.26.2

type NetworkResettingNetwork interface {
	NetworkConnector
	// ResetHTTPTransport should recreate the HTTP client used by the bridge.
	// It should refetch settings from the Matrix connector using GetHTTPClientSettings if applicable.
	ResetHTTPTransport()
	// ResetNetworkConnections should forcefully disconnect and restart any persistent network connections.
	// ResetHTTPTransport will usually be called before this, so resetting the transport is not necessary here.
	ResetNetworkConnections()
}

type NewLoginParams

type NewLoginParams struct {
	LoadUserLogin     func(context.Context, *UserLogin) error
	DeleteOnConflict  bool
	DontReuseExisting bool
}

type OrigSender

type OrigSender struct {
	User   *User
	UserID id.UserID

	RequiresDisambiguation bool
	DisambiguatedName      string
	FormattedName          string
	PerMessageProfile      event.BeeperPerMessageProfile

	event.MemberEventContent
}

type OutgoingTimeoutConfig

type OutgoingTimeoutConfig struct {
	CheckInterval time.Duration
	NoEchoTimeout time.Duration
	NoEchoMessage string
	NoAckTimeout  time.Duration
	NoAckMessage  string
}

type PersonalFilteringCustomizingNetworkAPI added in v0.26.1

type PersonalFilteringCustomizingNetworkAPI interface {
	NetworkAPI
	CustomizePersonalFilteringSpace(req *mautrix.ReqCreateRoom)
}

type PollHandlingNetworkAPI

type PollHandlingNetworkAPI interface {
	NetworkAPI
	HandleMatrixPollStart(ctx context.Context, msg *MatrixPollStart) (*MatrixMessageResponse, error)
	HandleMatrixPollVote(ctx context.Context, msg *MatrixPollVote) (*MatrixMessageResponse, error)
}

type Portal

type Portal struct {
	*database.Portal
	Bridge *Bridge
	Log    zerolog.Logger
	Parent *Portal
	Relay  *UserLogin

	RoomCreated *exsync.Event
	// contains filtered or unexported fields
}

func (*Portal) CleanupOrphanedDM added in v0.26.1

func (portal *Portal) CleanupOrphanedDM(ctx context.Context, userMXID id.UserID)

func (*Portal) CreateMatrixRoom

func (portal *Portal) CreateMatrixRoom(ctx context.Context, source *UserLogin, info *ChatInfo) (retErr error)

func (*Portal) Delete

func (portal *Portal) Delete(ctx context.Context) error

func (*Portal) DoBackwardsBackfill

func (portal *Portal) DoBackwardsBackfill(ctx context.Context, source *UserLogin, task *database.BackfillTask) error

func (*Portal) FindPreferredLogin

func (portal *Portal) FindPreferredLogin(ctx context.Context, user *User, allowRelay bool) (*UserLogin, *database.UserPortal, error)

func (*Portal) GetIntentFor

func (portal *Portal) GetIntentFor(ctx context.Context, sender EventSender, source *UserLogin, evtType RemoteEventType) (MatrixAPI, bool)

func (*Portal) GetTopLevelParent

func (portal *Portal) GetTopLevelParent() *Portal

func (*Portal) Internal deprecated

func (portal *Portal) Internal() *PortalInternals

Deprecated: portal internals should be used carefully and only when necessary.

func (*Portal) PerMessageProfileForSender

func (portal *Portal) PerMessageProfileForSender(ctx context.Context, sender networkid.UserID) (profile event.BeeperPerMessageProfile, err error)

func (*Portal) ProcessChatInfoChange

func (portal *Portal) ProcessChatInfoChange(ctx context.Context, sender EventSender, source *UserLogin, change *ChatInfoChange, ts time.Time)

func (*Portal) RemoveMXID

func (portal *Portal) RemoveMXID(ctx context.Context) error

func (*Portal) Save

func (portal *Portal) Save(ctx context.Context) error

func (*Portal) SetRelay

func (portal *Portal) SetRelay(ctx context.Context, relay *UserLogin) error

func (*Portal) UpdateBridgeInfo

func (portal *Portal) UpdateBridgeInfo(ctx context.Context)

func (*Portal) UpdateCapabilities

func (portal *Portal) UpdateCapabilities(ctx context.Context, source *UserLogin, implicit bool) bool

func (*Portal) UpdateDisappearingSetting

func (portal *Portal) UpdateDisappearingSetting(
	ctx context.Context,
	setting database.DisappearingSetting,
	opts UpdateDisappearingSettingOpts,
) bool

func (*Portal) UpdateInfo

func (portal *Portal) UpdateInfo(ctx context.Context, info *ChatInfo, source *UserLogin, sender MatrixAPI, ts time.Time)

func (*Portal) UpdateInfoFromGhost

func (portal *Portal) UpdateInfoFromGhost(ctx context.Context, ghost *Ghost) (changed bool)

func (*Portal) UpdateMatrixRoomID added in v0.25.1

func (portal *Portal) UpdateMatrixRoomID(
	ctx context.Context,
	newRoomID id.RoomID,
	params UpdateMatrixRoomIDParams,
) error

type PortalBridgeInfoFillingNetwork

type PortalBridgeInfoFillingNetwork interface {
	NetworkConnector
	FillPortalBridgeInfo(portal *Portal, content *event.BridgeEventContent)
}

type PortalInfo deprecated

type PortalInfo = ChatInfo

Deprecated: Renamed to ChatInfo

type PortalInternals

type PortalInternals Portal

func (*PortalInternals) AddToParentSpaceAndSave

func (portal *PortalInternals) AddToParentSpaceAndSave(ctx context.Context, save bool)

func (*PortalInternals) AddToUserSpaces added in v0.25.1

func (portal *PortalInternals) AddToUserSpaces(ctx context.Context)

func (*PortalInternals) ApplyRelationMeta

func (portal *PortalInternals) ApplyRelationMeta(ctx context.Context, content *event.MessageEventContent, replyTo, threadRoot, prevThreadEvent *database.Message)

func (*PortalInternals) CallReadReceiptHandler added in v0.25.2

func (portal *PortalInternals) CallReadReceiptHandler(ctx context.Context, login *UserLogin, rrClient ReadReceiptHandlingNetworkAPI, evt *MatrixReadReceipt, userPortal *database.UserPortal)

func (*PortalInternals) CheckConfusableName

func (portal *PortalInternals) CheckConfusableName(ctx context.Context, userID id.UserID, name string) bool

func (*PortalInternals) CheckMessageContentCaps

func (portal *PortalInternals) CheckMessageContentCaps(caps *event.RoomFeatures, content *event.MessageEventContent) error

func (*PortalInternals) CheckPendingMessage

func (portal *PortalInternals) CheckPendingMessage(ctx context.Context, evt RemoteMessage) (bool, *database.Message)

func (*PortalInternals) CheckPendingMessages added in v0.24.3

func (portal *PortalInternals) CheckPendingMessages(ctx context.Context, cfg *OutgoingTimeoutConfig)

func (*PortalInternals) CompileBatchMessage

func (portal *PortalInternals) CompileBatchMessage(ctx context.Context, source *UserLogin, msg *BackfillMessage, out *compileBatchOutput, inThread bool)

func (*PortalInternals) CreateMatrixRoomInLoop

func (portal *PortalInternals) CreateMatrixRoomInLoop(ctx context.Context, source *UserLogin, info *ChatInfo, backfillBundle any) error

func (*PortalInternals) CreateParentAndAddToSpace

func (portal *PortalInternals) CreateParentAndAddToSpace(ctx context.Context, source *UserLogin)

func (*PortalInternals) CutoffMessages

func (portal *PortalInternals) CutoffMessages(ctx context.Context, messages []*BackfillMessage, aggressiveDedup, forward bool, lastMessage *database.Message) []*BackfillMessage

func (*PortalInternals) DoForwardBackfill

func (portal *PortalInternals) DoForwardBackfill(ctx context.Context, source *UserLogin, lastMessage *database.Message, bundledData any)

func (*PortalInternals) DoThreadBackfill

func (portal *PortalInternals) DoThreadBackfill(ctx context.Context, source *UserLogin, threadID networkid.MessageID)

func (*PortalInternals) EnsureFunctionalMember added in v0.25.1

func (portal *PortalInternals) EnsureFunctionalMember(ctx context.Context, ghost *Ghost)

func (*PortalInternals) EventLoop

func (portal *PortalInternals) EventLoop()

func (*PortalInternals) FetchThreadBackfill

func (portal *PortalInternals) FetchThreadBackfill(ctx context.Context, source *UserLogin, anchor *database.Message) *FetchMessagesResponse

func (*PortalInternals) FetchThreadInsideBatch

func (portal *PortalInternals) FetchThreadInsideBatch(ctx context.Context, source *UserLogin, dbMsg *database.Message, out *compileBatchOutput)

func (*PortalInternals) FindOtherLogins added in v0.25.2

func (portal *PortalInternals) FindOtherLogins(ctx context.Context, source *UserLogin) (ownUP *database.UserPortal, others []*database.UserPortal, err error)

func (*PortalInternals) GetBridgeInfo

func (portal *PortalInternals) GetBridgeInfo() (string, event.BridgeEventContent)

func (*PortalInternals) GetBridgeInfoStateKey

func (portal *PortalInternals) GetBridgeInfoStateKey() string

func (*PortalInternals) GetEventCtxWithLog

func (portal *PortalInternals) GetEventCtxWithLog(rawEvt any, idx int) context.Context

func (*PortalInternals) GetInitialMemberList

func (portal *PortalInternals) GetInitialMemberList(ctx context.Context, members *ChatMemberList, source *UserLogin, pl *event.PowerLevelsEventContent) (invite, functional []id.UserID, err error)

func (*PortalInternals) GetIntentAndUserMXIDFor

func (portal *PortalInternals) GetIntentAndUserMXIDFor(ctx context.Context, sender EventSender, source *UserLogin, otherLogins []*UserLogin, evtType RemoteEventType) (intent MatrixAPI, extraUserID id.UserID, err error)

func (*PortalInternals) GetIntentForMXID

func (portal *PortalInternals) GetIntentForMXID(ctx context.Context, userID id.UserID) (MatrixAPI, error)

func (*PortalInternals) GetRelationMeta

func (portal *PortalInternals) GetRelationMeta(ctx context.Context, currentMsgID networkid.MessageID, currentMsg *ConvertedMessage, isBatchSend bool) (replyTo, threadRoot, prevThreadEvent *database.Message)

func (*PortalInternals) GetTargetMessagePart

func (portal *PortalInternals) GetTargetMessagePart(ctx context.Context, evt RemoteEventWithTargetMessage) (*database.Message, error)

func (*PortalInternals) GetTargetReaction

func (portal *PortalInternals) GetTargetReaction(ctx context.Context, evt RemoteReactionRemove) (*database.Reaction, error)

func (*PortalInternals) GetTargetUser

func (portal *PortalInternals) GetTargetUser(ctx context.Context, userID id.UserID) (GhostOrUserLogin, error)

func (*PortalInternals) HandleMatrixDeleteChat added in v0.25.2

func (portal *PortalInternals) HandleMatrixDeleteChat(ctx context.Context, sender *UserLogin, origSender *OrigSender, evt *event.Event) EventHandlingResult

func (*PortalInternals) HandleMatrixEdit

func (portal *PortalInternals) HandleMatrixEdit(ctx context.Context, sender *UserLogin, origSender *OrigSender, evt *event.Event, content *event.MessageEventContent, caps *event.RoomFeatures) EventHandlingResult

func (*PortalInternals) HandleMatrixEvent

func (portal *PortalInternals) HandleMatrixEvent(ctx context.Context, sender *User, evt *event.Event, isStateRequest bool) EventHandlingResult

func (*PortalInternals) HandleMatrixMembership

func (portal *PortalInternals) HandleMatrixMembership(ctx context.Context, sender *UserLogin, origSender *OrigSender, evt *event.Event, isStateRequest bool) EventHandlingResult

func (*PortalInternals) HandleMatrixMessage

func (portal *PortalInternals) HandleMatrixMessage(ctx context.Context, sender *UserLogin, origSender *OrigSender, evt *event.Event) EventHandlingResult

func (*PortalInternals) HandleMatrixPowerLevels

func (portal *PortalInternals) HandleMatrixPowerLevels(ctx context.Context, sender *UserLogin, origSender *OrigSender, evt *event.Event, isStateRequest bool) EventHandlingResult

func (*PortalInternals) HandleMatrixReaction

func (portal *PortalInternals) HandleMatrixReaction(ctx context.Context, sender *UserLogin, evt *event.Event) EventHandlingResult

func (*PortalInternals) HandleMatrixReadReceipt

func (portal *PortalInternals) HandleMatrixReadReceipt(ctx context.Context, user *User, eventID id.EventID, receipt event.ReadReceipt)

func (*PortalInternals) HandleMatrixReceipts

func (portal *PortalInternals) HandleMatrixReceipts(ctx context.Context, evt *event.Event) EventHandlingResult

func (*PortalInternals) HandleMatrixRedaction

func (portal *PortalInternals) HandleMatrixRedaction(ctx context.Context, sender *UserLogin, origSender *OrigSender, evt *event.Event) EventHandlingResult

func (*PortalInternals) HandleMatrixTombstone added in v0.25.1

func (portal *PortalInternals) HandleMatrixTombstone(ctx context.Context, evt *event.Event) EventHandlingResult

func (*PortalInternals) HandleMatrixTyping

func (portal *PortalInternals) HandleMatrixTyping(ctx context.Context, evt *event.Event) EventHandlingResult

func (*PortalInternals) HandleRemoteBackfill

func (portal *PortalInternals) HandleRemoteBackfill(ctx context.Context, source *UserLogin, backfill RemoteBackfill) (res EventHandlingResult)

func (*PortalInternals) HandleRemoteChatDelete

func (portal *PortalInternals) HandleRemoteChatDelete(ctx context.Context, source *UserLogin, evt RemoteChatDelete) EventHandlingResult

func (*PortalInternals) HandleRemoteChatInfoChange

func (portal *PortalInternals) HandleRemoteChatInfoChange(ctx context.Context, source *UserLogin, evt RemoteChatInfoChange) EventHandlingResult

func (*PortalInternals) HandleRemoteChatResync

func (portal *PortalInternals) HandleRemoteChatResync(ctx context.Context, source *UserLogin, evt RemoteChatResync) EventHandlingResult

func (*PortalInternals) HandleRemoteDeliveryReceipt

func (portal *PortalInternals) HandleRemoteDeliveryReceipt(ctx context.Context, source *UserLogin, evt RemoteDeliveryReceipt) EventHandlingResult

func (*PortalInternals) HandleRemoteEdit

func (portal *PortalInternals) HandleRemoteEdit(ctx context.Context, source *UserLogin, evt RemoteEdit) EventHandlingResult

func (*PortalInternals) HandleRemoteEvent

func (portal *PortalInternals) HandleRemoteEvent(ctx context.Context, source *UserLogin, evtType RemoteEventType, evt RemoteEvent) (res EventHandlingResult)

func (*PortalInternals) HandleRemoteMarkUnread

func (portal *PortalInternals) HandleRemoteMarkUnread(ctx context.Context, source *UserLogin, evt RemoteMarkUnread) EventHandlingResult

func (*PortalInternals) HandleRemoteMessage

func (portal *PortalInternals) HandleRemoteMessage(ctx context.Context, source *UserLogin, evt RemoteMessage) (res EventHandlingResult)

func (*PortalInternals) HandleRemoteMessageRemove

func (portal *PortalInternals) HandleRemoteMessageRemove(ctx context.Context, source *UserLogin, evt RemoteMessageRemove) EventHandlingResult

func (*PortalInternals) HandleRemoteReaction

func (portal *PortalInternals) HandleRemoteReaction(ctx context.Context, source *UserLogin, evt RemoteReaction) EventHandlingResult

func (*PortalInternals) HandleRemoteReactionRemove

func (portal *PortalInternals) HandleRemoteReactionRemove(ctx context.Context, source *UserLogin, evt RemoteReactionRemove) EventHandlingResult

func (*PortalInternals) HandleRemoteReactionSync

func (portal *PortalInternals) HandleRemoteReactionSync(ctx context.Context, source *UserLogin, evt RemoteReactionSync) EventHandlingResult

func (*PortalInternals) HandleRemoteReadReceipt

func (portal *PortalInternals) HandleRemoteReadReceipt(ctx context.Context, source *UserLogin, evt RemoteReadReceipt) EventHandlingResult

func (*PortalInternals) HandleRemoteTyping

func (portal *PortalInternals) HandleRemoteTyping(ctx context.Context, source *UserLogin, evt RemoteTyping) EventHandlingResult

func (*PortalInternals) HandleRemoteUpsert

func (portal *PortalInternals) HandleRemoteUpsert(ctx context.Context, source *UserLogin, evt RemoteMessageUpsert, existing []*database.Message) (handleRes EventHandlingResult, continueHandling bool)

func (*PortalInternals) HandleSingleEvent

func (portal *PortalInternals) HandleSingleEvent(ctx context.Context, rawEvt any, doneCallback func(EventHandlingResult))

func (*PortalInternals) HandleSingleEventWithDelayLogging added in v0.25.2

func (portal *PortalInternals) HandleSingleEventWithDelayLogging(idx int, rawEvt any) (outerRes EventHandlingResult)

func (*PortalInternals) LockedUpdateInfoFromGhost

func (portal *PortalInternals) LockedUpdateInfoFromGhost(ctx context.Context, ghost *Ghost)

func (*PortalInternals) ParseInputTransactionID added in v0.24.3

func (portal *PortalInternals) ParseInputTransactionID(origSender *OrigSender, evt *event.Event) networkid.RawTransactionID

func (*PortalInternals) PendingMessageTimeoutLoop added in v0.24.3

func (portal *PortalInternals) PendingMessageTimeoutLoop(ctx context.Context, cfg *OutgoingTimeoutConfig)

func (*PortalInternals) PeriodicTypingUpdater

func (portal *PortalInternals) PeriodicTypingUpdater()

func (*PortalInternals) QueueEvent

func (portal *PortalInternals) QueueEvent(ctx context.Context, evt portalEvent) EventHandlingResult

func (*PortalInternals) RedactMessageParts

func (portal *PortalInternals) RedactMessageParts(ctx context.Context, parts []*database.Message, intent MatrixAPI, ts time.Time) EventHandlingResult

func (*PortalInternals) RemoveInPortalCache

func (portal *PortalInternals) RemoveInPortalCache(ctx context.Context)

func (*PortalInternals) RevertRoomMeta added in v0.26.1

func (portal *PortalInternals) RevertRoomMeta(ctx context.Context, evt *event.Event)

func (*PortalInternals) RoomIsPublic added in v0.26.1

func (portal *PortalInternals) RoomIsPublic(ctx context.Context) bool

func (*PortalInternals) SendBackfill

func (portal *PortalInternals) SendBackfill(ctx context.Context, source *UserLogin, messages []*BackfillMessage, forceForward, markRead, inThread bool, done func())

func (*PortalInternals) SendBatch

func (portal *PortalInternals) SendBatch(ctx context.Context, source *UserLogin, messages []*BackfillMessage, forceForward, markRead, inThread bool)

func (*PortalInternals) SendConvertedEdit

func (portal *PortalInternals) SendConvertedEdit(ctx context.Context, targetID networkid.MessageID, senderID networkid.UserID, converted *ConvertedEdit, intent MatrixAPI, ts time.Time, streamOrder int64) EventHandlingResult

func (*PortalInternals) SendConvertedMessage

func (portal *PortalInternals) SendConvertedMessage(ctx context.Context, id networkid.MessageID, intent MatrixAPI, senderID networkid.UserID, converted *ConvertedMessage, ts time.Time, streamOrder int64, logContext func(*zerolog.Event) *zerolog.Event) ([]*database.Message, EventHandlingResult)

func (*PortalInternals) SendConvertedReaction

func (portal *PortalInternals) SendConvertedReaction(ctx context.Context, senderID networkid.UserID, intent MatrixAPI, targetMessage *database.Message, emojiID networkid.EmojiID, emoji string, ts time.Time, dbMetadata any, extraContent map[string]any, logContext func(*zerolog.Event) *zerolog.Event) EventHandlingResult

func (*PortalInternals) SendErrorStatus

func (portal *PortalInternals) SendErrorStatus(ctx context.Context, evt *event.Event, err error)

func (*PortalInternals) SendLegacyBackfill

func (portal *PortalInternals) SendLegacyBackfill(ctx context.Context, source *UserLogin, messages []*BackfillMessage, markRead bool)

func (*PortalInternals) SendRemoteErrorNotice

func (portal *PortalInternals) SendRemoteErrorNotice(ctx context.Context, intent MatrixAPI, err error, ts time.Time, evtTypeName string)

func (*PortalInternals) SendRoomMeta

func (portal *PortalInternals) SendRoomMeta(ctx context.Context, sender MatrixAPI, ts time.Time, eventType event.Type, stateKey string, content any, excludeFromTimeline bool, extra map[string]any) bool

func (*PortalInternals) SendStateWithIntentOrBot

func (portal *PortalInternals) SendStateWithIntentOrBot(ctx context.Context, sender MatrixAPI, eventType event.Type, stateKey string, content *event.Content, ts time.Time) (resp *mautrix.RespSendEvent, err error)

func (*PortalInternals) SendSuccessStatus

func (portal *PortalInternals) SendSuccessStatus(ctx context.Context, evt *event.Event, streamOrder int64, newEventID id.EventID)

func (*PortalInternals) SendTypings

func (portal *PortalInternals) SendTypings(ctx context.Context, userIDs []id.UserID, typing bool)

func (*PortalInternals) SyncParticipants

func (portal *PortalInternals) SyncParticipants(ctx context.Context, members *ChatMemberList, source *UserLogin, sender MatrixAPI, ts time.Time) error

func (*PortalInternals) ToggleSpace

func (portal *PortalInternals) ToggleSpace(ctx context.Context, spaceID id.RoomID, canonical, remove bool) error

func (*PortalInternals) UnlockedDelete

func (portal *PortalInternals) UnlockedDelete(ctx context.Context) error

func (*PortalInternals) UnlockedDeleteCache

func (portal *PortalInternals) UnlockedDeleteCache()

func (*PortalInternals) UnlockedReID

func (portal *PortalInternals) UnlockedReID(ctx context.Context, target networkid.PortalKey) error

func (*PortalInternals) UnwrapBeeperSendState added in v0.26.1

func (portal *PortalInternals) UnwrapBeeperSendState(ctx context.Context, evt *event.Event) error

func (*PortalInternals) UpdateAvatar

func (portal *PortalInternals) UpdateAvatar(ctx context.Context, avatar *Avatar, sender MatrixAPI, ts time.Time, excludeFromTimeline bool) bool

func (*PortalInternals) UpdateInfoAfterTombstone added in v0.25.1

func (portal *PortalInternals) UpdateInfoAfterTombstone(ctx context.Context, senderUser *User)

func (*PortalInternals) UpdateLogger

func (portal *PortalInternals) UpdateLogger()

func (*PortalInternals) UpdateName

func (portal *PortalInternals) UpdateName(ctx context.Context, name string, sender MatrixAPI, ts time.Time, excludeFromTimeline bool) bool

func (*PortalInternals) UpdateOtherUser

func (portal *PortalInternals) UpdateOtherUser(ctx context.Context, members *ChatMemberList) (changed bool)

func (*PortalInternals) UpdateParent

func (portal *PortalInternals) UpdateParent(ctx context.Context, newParentID networkid.PortalID, source *UserLogin) bool

func (*PortalInternals) UpdateTopic

func (portal *PortalInternals) UpdateTopic(ctx context.Context, topic string, sender MatrixAPI, ts time.Time, excludeFromTimeline bool) bool

func (*PortalInternals) UpdateUserLocalInfo

func (portal *PortalInternals) UpdateUserLocalInfo(ctx context.Context, info *UserLocalPortalInfo, source *UserLogin, didJustCreate bool)

type PowerLevelChanges deprecated

type PowerLevelChanges = PowerLevelOverrides

Deprecated: renamed to PowerLevelOverrides

type PowerLevelHandlingNetworkAPI

type PowerLevelHandlingNetworkAPI interface {
	NetworkAPI
	HandleMatrixPowerLevels(ctx context.Context, msg *MatrixPowerLevelChange) (bool, error)
}

type PowerLevelOverrides

type PowerLevelOverrides struct {
	Events        map[event.Type]int
	UsersDefault  *int
	EventsDefault *int
	StateDefault  *int
	Invite        *int
	Kick          *int
	Ban           *int
	Redact        *int

	Custom func(*event.PowerLevelsEventContent) bool
}

func (*PowerLevelOverrides) Apply

func (plc *PowerLevelOverrides) Apply(actor id.UserID, content *event.PowerLevelsEventContent) (changed bool)

type ProvisioningCapabilities added in v0.25.1

type ProvisioningCapabilities struct {
	ResolveIdentifier ResolveIdentifierCapabilities    `json:"resolve_identifier"`
	GroupCreation     map[string]GroupTypeCapabilities `json:"group_creation"`
}

type PushConfig

type PushConfig struct {
	Web  *WebPushConfig  `json:"web,omitempty"`
	FCM  *FCMPushConfig  `json:"fcm,omitempty"`
	APNs *APNsPushConfig `json:"apns,omitempty"`
	// If Native is true, it means the network supports registering for pushes
	// that are delivered directly to the app without the use of a push relay.
	Native bool `json:"native,omitempty"`
}

type PushParsingNetwork

type PushParsingNetwork interface {
	NetworkConnector

	// ParsePushNotification is called when a native push is received.
	// It must return the corresponding user login ID to wake up, plus optionally data to pass to the wakeup call.
	ParsePushNotification(ctx context.Context, data json.RawMessage) (networkid.UserLoginID, any, error)
}

PushParsingNetwork is an optional interface that network connectors can implement to support parsing native push notifications from networks.

type PushType

type PushType int
const (
	PushTypeUnknown PushType = iota
	PushTypeWeb
	PushTypeAPNs
	PushTypeFCM
)

func PushTypeFromString

func PushTypeFromString(str string) PushType

func (PushType) GoString

func (pt PushType) GoString() string

func (PushType) String

func (pt PushType) String() string

type PushableNetworkAPI

type PushableNetworkAPI interface {
	NetworkAPI

	// RegisterPushNotifications is called when the wrapper app wants to register a push token with the remote network.
	RegisterPushNotifications(ctx context.Context, pushType PushType, token string) error
	// GetPushConfigs is used to find which types of push notifications the remote network can provide.
	GetPushConfigs() *PushConfig
}

PushableNetworkAPI is an optional interface that network connectors can implement to support waking up the wrapper app using push notifications.

type ReIDResult

type ReIDResult int
const (
	ReIDResultError ReIDResult = iota
	ReIDResultNoOp
	ReIDResultSourceDeleted
	ReIDResultSourceReIDd
	ReIDResultTargetDeletedAndSourceReIDd
	ReIDResultSourceTombstonedIntoTarget
)

type ReactionHandlingNetworkAPI

type ReactionHandlingNetworkAPI interface {
	NetworkAPI
	// PreHandleMatrixReaction is called as the first step of handling a reaction. It returns the emoji ID,
	// sender user ID and max reaction count to allow the central bridge module to de-duplicate the reaction
	// if appropriate.
	PreHandleMatrixReaction(ctx context.Context, msg *MatrixReaction) (MatrixReactionPreResponse, error)
	// HandleMatrixReaction is called after confirming that the reaction is not a duplicate.
	// This is the method that should actually send the reaction to the remote network.
	// The returned [database.Reaction] object may be empty: the central bridge module already has
	// all the required fields and will fill them automatically if they're empty. However, network
	// connectors are allowed to set fields themselves if any extra fields are necessary.
	HandleMatrixReaction(ctx context.Context, msg *MatrixReaction) (reaction *database.Reaction, err error)
	// HandleMatrixReactionRemove is called when a redaction event is received pointing at a previously
	// bridged reaction. The network connector should remove the reaction from the remote network.
	HandleMatrixReactionRemove(ctx context.Context, msg *MatrixReactionRemove) error
}

ReactionHandlingNetworkAPI is an optional interface that network connectors can implement to handle message reactions.

type ReactionSyncData

type ReactionSyncData struct {
	Users map[networkid.UserID]*ReactionSyncUser
	// Whether the map contains all users who have reacted to the message
	HasAllUsers bool
}

func (*ReactionSyncData) ToBackfill

func (rsd *ReactionSyncData) ToBackfill() []*BackfillReaction

type ReactionSyncUser

type ReactionSyncUser struct {
	Reactions []*BackfillReaction
	// Whether the list contains all reactions the user has sent
	HasAllReactions bool
	// If the list doesn't contain all reactions from the user,
	// then this field can be set to remove old reactions if there are more than a certain number.
	MaxCount int
}

type ReadReceiptHandlingNetworkAPI

type ReadReceiptHandlingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixReadReceipt is called when a read receipt is sent in a portal room.
	// This will be called even if the target message is not a bridged message.
	// Network connectors must gracefully handle [MatrixReadReceipt.ExactMessage] being nil.
	// The exact handling is up to the network connector.
	HandleMatrixReadReceipt(ctx context.Context, msg *MatrixReadReceipt) error
}

ReadReceiptHandlingNetworkAPI is an optional interface that network connectors can implement to handle read receipts.

type RedactionHandlingNetworkAPI

type RedactionHandlingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixMessageRemove is called when a previously bridged message is deleted in a portal room.
	HandleMatrixMessageRemove(ctx context.Context, msg *MatrixMessageRemove) error
}

RedactionHandlingNetworkAPI is an optional interface that network connectors can implement to handle message deletions.

type RemoteBackfill

type RemoteBackfill interface {
	RemoteEvent
	GetBackfillData(ctx context.Context, portal *Portal) (*FetchMessagesResponse, error)
}

type RemoteChatDelete

type RemoteChatDelete interface {
	RemoteDeleteOnlyForMe
}

type RemoteChatDeleteWithChildren added in v0.26.1

type RemoteChatDeleteWithChildren interface {
	RemoteChatDelete
	DeleteChildren() bool
}

type RemoteChatInfoChange

type RemoteChatInfoChange interface {
	RemoteEvent
	GetChatInfoChange(ctx context.Context) (*ChatInfoChange, error)
}

type RemoteChatResync

type RemoteChatResync interface {
	RemoteEvent
}

type RemoteChatResyncBackfill

type RemoteChatResyncBackfill interface {
	RemoteChatResync
	CheckNeedsBackfill(ctx context.Context, latestMessage *database.Message) (bool, error)
}

type RemoteChatResyncBackfillBundle

type RemoteChatResyncBackfillBundle interface {
	RemoteChatResyncBackfill
	GetBundledBackfillData() any
}

type RemoteChatResyncWithInfo

type RemoteChatResyncWithInfo interface {
	RemoteChatResync
	GetChatInfo(ctx context.Context, portal *Portal) (*ChatInfo, error)
}

type RemoteDeleteOnlyForMe

type RemoteDeleteOnlyForMe interface {
	RemoteEvent
	DeleteOnlyForMe() bool
}

type RemoteDeliveryReceipt

type RemoteDeliveryReceipt interface {
	RemoteEvent
	GetReceiptTargets() []networkid.MessageID
}

type RemoteEchoHandler

type RemoteEchoHandler func(RemoteMessage, *database.Message) (bool, error)

type RemoteEdit

type RemoteEdit interface {
	RemoteEventWithTargetMessage
	ConvertEdit(ctx context.Context, portal *Portal, intent MatrixAPI, existing []*database.Message) (*ConvertedEdit, error)
}

type RemoteEvent

type RemoteEvent interface {
	GetType() RemoteEventType
	GetPortalKey() networkid.PortalKey
	AddLogContext(c zerolog.Context) zerolog.Context
	GetSender() EventSender
}

RemoteEvent represents a single event from the remote network, such as a message or a reaction.

When a NetworkAPI receives an event from the remote network, it should convert it into a RemoteEvent and pass it to the bridge for processing using Bridge.QueueRemoteEvent.

type RemoteEventThatMayCreatePortal

type RemoteEventThatMayCreatePortal interface {
	RemoteEvent
	ShouldCreatePortal() bool
}

type RemoteEventType

type RemoteEventType int
const (
	RemoteEventUnknown RemoteEventType = iota
	RemoteEventMessage
	RemoteEventMessageUpsert
	RemoteEventEdit
	RemoteEventReaction
	RemoteEventReactionRemove
	RemoteEventReactionSync
	RemoteEventMessageRemove
	RemoteEventReadReceipt
	RemoteEventDeliveryReceipt
	RemoteEventMarkUnread
	RemoteEventTyping
	RemoteEventChatInfoChange
	RemoteEventChatResync
	RemoteEventChatDelete
	RemoteEventBackfill
)

func (RemoteEventType) String

func (ret RemoteEventType) String() string

type RemoteEventWithBundledParts

type RemoteEventWithBundledParts interface {
	RemoteEventWithTargetMessage
	GetTargetDBMessage() []*database.Message
}

type RemoteEventWithStreamOrder

type RemoteEventWithStreamOrder interface {
	RemoteEvent
	GetStreamOrder() int64
}

type RemoteEventWithTargetMessage

type RemoteEventWithTargetMessage interface {
	RemoteEvent
	GetTargetMessage() networkid.MessageID
}

type RemoteEventWithTargetPart

type RemoteEventWithTargetPart interface {
	RemoteEventWithTargetMessage
	GetTargetMessagePart() networkid.PartID
}

type RemoteEventWithTimestamp

type RemoteEventWithTimestamp interface {
	RemoteEvent
	GetTimestamp() time.Time
}

type RemoteEventWithUncertainPortalReceiver

type RemoteEventWithUncertainPortalReceiver interface {
	RemoteEvent
	PortalReceiverIsUncertain() bool
}

type RemoteMarkUnread

type RemoteMarkUnread interface {
	RemoteEvent
	GetUnread() bool
}

type RemoteMessage

type RemoteMessage interface {
	RemoteEvent
	GetID() networkid.MessageID
	ConvertMessage(ctx context.Context, portal *Portal, intent MatrixAPI) (*ConvertedMessage, error)
}

type RemoteMessageRemove

type RemoteMessageRemove interface {
	RemoteEventWithTargetMessage
}

type RemoteMessageUpsert

type RemoteMessageUpsert interface {
	RemoteMessage
	HandleExisting(ctx context.Context, portal *Portal, intent MatrixAPI, existing []*database.Message) (UpsertResult, error)
}

type RemoteMessageWithTransactionID

type RemoteMessageWithTransactionID interface {
	RemoteMessage
	GetTransactionID() networkid.TransactionID
}

type RemotePostHandler

type RemotePostHandler interface {
	RemoteEvent
	PostHandle(ctx context.Context, portal *Portal)
}

type RemotePreHandler

type RemotePreHandler interface {
	RemoteEvent
	PreHandle(ctx context.Context, portal *Portal)
}

type RemoteReaction

type RemoteReaction interface {
	RemoteEventWithTargetMessage
	GetReactionEmoji() (string, networkid.EmojiID)
}

type RemoteReactionRemove

type RemoteReactionRemove interface {
	RemoteEventWithTargetMessage
	GetRemovedEmojiID() networkid.EmojiID
}

type RemoteReactionSync

type RemoteReactionSync interface {
	RemoteEventWithTargetMessage
	GetReactions() *ReactionSyncData
}

type RemoteReactionWithExtraContent

type RemoteReactionWithExtraContent interface {
	RemoteReaction
	GetReactionExtraContent() map[string]any
}

type RemoteReactionWithMeta

type RemoteReactionWithMeta interface {
	RemoteReaction
	GetReactionDBMetadata() any
}

type RemoteReadReceipt

type RemoteReadReceipt interface {
	RemoteEvent
	GetLastReceiptTarget() networkid.MessageID
	GetReceiptTargets() []networkid.MessageID
	GetReadUpTo() time.Time
}

type RemoteReadReceiptWithStreamOrder

type RemoteReadReceiptWithStreamOrder interface {
	RemoteReadReceipt
	GetReadUpToStreamOrder() int64
}

type RemoteReceipt deprecated

type RemoteReceipt = RemoteReadReceipt

Deprecated: Renamed to RemoteReadReceipt.

type RemoteTyping

type RemoteTyping interface {
	RemoteEvent
	GetTimeout() time.Duration
}

type RemoteTypingWithType

type RemoteTypingWithType interface {
	RemoteTyping
	GetTypingType() TypingType
}

type ResolveIdentifierCapabilities added in v0.25.1

type ResolveIdentifierCapabilities struct {
	// Can DMs be created after resolving an identifier?
	CreateDM bool `json:"create_dm"`
	// Can users be looked up by phone number?
	LookupPhone bool `json:"lookup_phone"`
	// Can users be looked up by email address?
	LookupEmail bool `json:"lookup_email"`
	// Can users be looked up by network-specific username?
	LookupUsername bool `json:"lookup_username"`
	// Can any phone number be contacted without having to validate it via lookup first?
	AnyPhone bool `json:"any_phone"`
	// Can a contact list be retrieved from the bridge?
	ContactList bool `json:"contact_list"`
	// Can users be searched by name on the remote network?
	Search bool `json:"search"`
}

type ResolveIdentifierResponse

type ResolveIdentifierResponse struct {
	// Ghost is the ghost of the user that the identifier resolves to.
	// This field should be set whenever possible. However, it is not required,
	// and the central bridge module will not try to create a ghost if it is not set.
	Ghost *Ghost

	// UserID is the user ID of the user that the identifier resolves to.
	UserID networkid.UserID
	// UserInfo contains the info of the user that the identifier resolves to.
	// If both this and the Ghost field are set, the central bridge module will
	// automatically update the ghost's info with the data here.
	UserInfo *UserInfo

	// Chat contains info about the direct chat with the resolved user.
	// This field is required when createChat is true in the ResolveIdentifier call,
	// and optional otherwise.
	Chat *CreateChatResponse
}

type RespError

type RespError mautrix.RespError

RespError is a class of error that certain network interface methods can return to ensure that the error is properly translated into an HTTP error when the method is called via the provisioning API.

However, unlike mautrix.RespError, this does not include the error code in the message shown to users when used outside HTTP contexts.

func WrapRespErr

func WrapRespErr(err error, target mautrix.RespError) RespError

func WrapRespErrManual

func WrapRespErrManual(err error, code string, status int) RespError

func (RespError) AppendMessage

func (re RespError) AppendMessage(append string, args ...any) RespError

func (RespError) Error

func (re RespError) Error() string

func (RespError) Is

func (re RespError) Is(err error) bool

func (RespError) WithMessage

func (re RespError) WithMessage(msg string, args ...any) RespError

func (RespError) Write

func (re RespError) Write(w http.ResponseWriter)

type RoomAvatarHandlingNetworkAPI

type RoomAvatarHandlingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixRoomAvatar is called when the avatar of a portal room is changed.
	// This method should update the AvatarID, AvatarHash and AvatarMXC fields
	// with the new avatar details and return true if the change was successful.
	// If the change is not successful, then the fields should not be updated.
	HandleMatrixRoomAvatar(ctx context.Context, msg *MatrixRoomAvatar) (bool, error)
}

RoomAvatarHandlingNetworkAPI is an optional interface that network connectors can implement to handle room avatar changes.

type RoomNameHandlingNetworkAPI

type RoomNameHandlingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixRoomName is called when the name of a portal room is changed.
	// This method should update the Name and NameSet fields of the Portal with
	// the new name and return true if the change was successful.
	// If the change is not successful, then the fields should not be updated.
	HandleMatrixRoomName(ctx context.Context, msg *MatrixRoomName) (bool, error)
}

RoomNameHandlingNetworkAPI is an optional interface that network connectors can implement to handle room name changes.

type RoomTopicHandlingNetworkAPI

type RoomTopicHandlingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixRoomTopic is called when the topic of a portal room is changed.
	// This method should update the Topic and TopicSet fields of the Portal with
	// the new topic and return true if the change was successful.
	// If the change is not successful, then the fields should not be updated.
	HandleMatrixRoomTopic(ctx context.Context, msg *MatrixRoomTopic) (bool, error)
}

RoomTopicHandlingNetworkAPI is an optional interface that network connectors can implement to handle room topic changes.

type SimpleRemoteEvent deprecated

type SimpleRemoteEvent[T any] struct {
	Type         RemoteEventType
	LogContext   func(c zerolog.Context) zerolog.Context
	PortalKey    networkid.PortalKey
	Data         T
	CreatePortal bool

	ID             networkid.MessageID
	Sender         EventSender
	TargetMessage  networkid.MessageID
	EmojiID        networkid.EmojiID
	Emoji          string
	ReactionDBMeta any
	Timestamp      time.Time
	ChatInfoChange *ChatInfoChange

	ResyncChatInfo       *ChatInfo
	ResyncBackfillNeeded bool

	BackfillData *FetchMessagesResponse

	ConvertMessageFunc func(ctx context.Context, portal *Portal, intent MatrixAPI, data T) (*ConvertedMessage, error)
	ConvertEditFunc    func(ctx context.Context, portal *Portal, intent MatrixAPI, existing []*database.Message, data T) (*ConvertedEdit, error)
}

SimpleRemoteEvent is a simple implementation of RemoteEvent that can be used with struct fields and some callbacks.

Using this type is only recommended for simple bridges. More advanced ones should implement the remote event interfaces themselves by wrapping the remote network library event types.

Deprecated: use the types in the simplevent package instead.

func (*SimpleRemoteEvent[T]) AddLogContext

func (sre *SimpleRemoteEvent[T]) AddLogContext(c zerolog.Context) zerolog.Context

func (*SimpleRemoteEvent[T]) CheckNeedsBackfill

func (sre *SimpleRemoteEvent[T]) CheckNeedsBackfill(ctx context.Context, latestMessage *database.Message) (bool, error)

func (*SimpleRemoteEvent[T]) ConvertEdit

func (sre *SimpleRemoteEvent[T]) ConvertEdit(ctx context.Context, portal *Portal, intent MatrixAPI, existing []*database.Message) (*ConvertedEdit, error)

func (*SimpleRemoteEvent[T]) ConvertMessage

func (sre *SimpleRemoteEvent[T]) ConvertMessage(ctx context.Context, portal *Portal, intent MatrixAPI) (*ConvertedMessage, error)

func (*SimpleRemoteEvent[T]) GetBackfillData

func (sre *SimpleRemoteEvent[T]) GetBackfillData(ctx context.Context, portal *Portal) (*FetchMessagesResponse, error)

func (*SimpleRemoteEvent[T]) GetChatInfo

func (sre *SimpleRemoteEvent[T]) GetChatInfo(ctx context.Context, portal *Portal) (*ChatInfo, error)

func (*SimpleRemoteEvent[T]) GetChatInfoChange

func (sre *SimpleRemoteEvent[T]) GetChatInfoChange(ctx context.Context) (*ChatInfoChange, error)

func (*SimpleRemoteEvent[T]) GetID

func (sre *SimpleRemoteEvent[T]) GetID() networkid.MessageID

func (*SimpleRemoteEvent[T]) GetPortalKey

func (sre *SimpleRemoteEvent[T]) GetPortalKey() networkid.PortalKey

func (*SimpleRemoteEvent[T]) GetReactionDBMetadata

func (sre *SimpleRemoteEvent[T]) GetReactionDBMetadata() any

func (*SimpleRemoteEvent[T]) GetReactionEmoji

func (sre *SimpleRemoteEvent[T]) GetReactionEmoji() (string, networkid.EmojiID)

func (*SimpleRemoteEvent[T]) GetRemovedEmojiID

func (sre *SimpleRemoteEvent[T]) GetRemovedEmojiID() networkid.EmojiID

func (*SimpleRemoteEvent[T]) GetSender

func (sre *SimpleRemoteEvent[T]) GetSender() EventSender

func (*SimpleRemoteEvent[T]) GetTargetMessage

func (sre *SimpleRemoteEvent[T]) GetTargetMessage() networkid.MessageID

func (*SimpleRemoteEvent[T]) GetTimestamp

func (sre *SimpleRemoteEvent[T]) GetTimestamp() time.Time

func (*SimpleRemoteEvent[T]) GetType

func (sre *SimpleRemoteEvent[T]) GetType() RemoteEventType

func (*SimpleRemoteEvent[T]) ShouldCreatePortal

func (sre *SimpleRemoteEvent[T]) ShouldCreatePortal() bool

type SinglePowerLevelChange

type SinglePowerLevelChange struct {
	OrigLevel int
	NewLevel  int
	NewIsSet  bool
}

type StoppableNetwork

type StoppableNetwork interface {
	NetworkConnector
	// Stop is called when the bridge is stopping, after all network clients have been disconnected.
	Stop()
}

type StreamOrderReadingMatrixAPI

type StreamOrderReadingMatrixAPI interface {
	MatrixAPI
	MarkStreamOrderRead(ctx context.Context, roomID id.RoomID, streamOrder int64, ts time.Time) error
}

type TagHandlingNetworkAPI

type TagHandlingNetworkAPI interface {
	NetworkAPI
	HandleRoomTag(ctx context.Context, msg *MatrixRoomTag) error
}

type TransactionIDGeneratingNetwork

type TransactionIDGeneratingNetwork interface {
	NetworkConnector
	GenerateTransactionID(userID id.UserID, roomID id.RoomID, eventType event.Type) networkid.RawTransactionID
}

type TypingHandlingNetworkAPI

type TypingHandlingNetworkAPI interface {
	NetworkAPI
	// HandleMatrixTyping is called when a user starts typing in a portal room.
	// In the future, the central bridge module will likely get a loop to automatically repeat
	// calls to this function until the user stops typing.
	HandleMatrixTyping(ctx context.Context, msg *MatrixTyping) error
}

TypingHandlingNetworkAPI is an optional interface that network connectors can implement to handle typing events.

type TypingType

type TypingType int
const (
	TypingTypeText TypingType = iota
	TypingTypeUploadingMedia
	TypingTypeRecordingMedia
)

type UpdateDisappearingSettingOpts added in v0.25.1

type UpdateDisappearingSettingOpts struct {
	Sender     MatrixAPI
	Timestamp  time.Time
	Implicit   bool
	Save       bool
	SendNotice bool

	ExcludeFromTimeline bool
}

type UpdateMatrixRoomIDParams added in v0.25.1

type UpdateMatrixRoomIDParams struct {
	SyncDBMetadata     func()
	FailIfMXIDSet      bool
	OverwriteOldPortal bool
	TombstoneOldRoom   bool
	DeleteOldRoom      bool

	RoomCreateAlreadyLocked bool

	FetchInfoVia   *User
	ChatInfo       *ChatInfo
	ChatInfoSource *UserLogin
}

type UpsertResult

type UpsertResult struct {
	SubEvents               []RemoteEvent
	SaveParts               bool
	ContinueMessageHandling bool
}

type User

type User struct {
	*database.User
	Bridge *Bridge
	Log    zerolog.Logger

	CommandState unsafe.Pointer
	Permissions  bridgeconfig.Permissions
	// contains filtered or unexported fields
}

func (*User) DoublePuppet

func (user *User) DoublePuppet(ctx context.Context) MatrixAPI

func (*User) GetCachedUserLogins deprecated

func (user *User) GetCachedUserLogins() []*UserLogin

Deprecated: renamed to GetUserLogins

func (*User) GetDefaultLogin

func (user *User) GetDefaultLogin() *UserLogin

func (*User) GetFormattedUserLogins

func (user *User) GetFormattedUserLogins() string

func (*User) GetManagementRoom

func (user *User) GetManagementRoom(ctx context.Context) (id.RoomID, error)

func (*User) GetUserLoginIDs

func (user *User) GetUserLoginIDs() []networkid.UserLoginID

func (*User) GetUserLogins

func (user *User) GetUserLogins() []*UserLogin

func (*User) HasTooManyLogins added in v0.26.1

func (user *User) HasTooManyLogins() bool

func (*User) LoginDoublePuppet

func (user *User) LoginDoublePuppet(ctx context.Context, token string) error

func (*User) LogoutDoublePuppet

func (user *User) LogoutDoublePuppet(ctx context.Context)

func (*User) NewLogin

func (user *User) NewLogin(ctx context.Context, data *database.UserLogin, params *NewLoginParams) (*UserLogin, error)

NewLogin creates a UserLogin object for this user with the given parameters.

If a login already exists with the same ID, it is reused after updating the remote name and metadata from the provided data, unless DontReuseExisting is set in params.

If the existing login belongs to another user, this returns an error, unless DeleteOnConflict is set in the params, in which case the existing login is deleted.

This will automatically call LoadUserLogin after creating the UserLogin object. The load method defaults to the network connector's LoadUserLogin method, but it can be overridden in params.

func (*User) Save

func (user *User) Save(ctx context.Context) error

func (*User) TrackAnalytics

func (user *User) TrackAnalytics(event string, props map[string]any)

type UserInfo

type UserInfo struct {
	Identifiers []string
	Name        *string
	Avatar      *Avatar
	IsBot       *bool

	ExtraUpdates ExtraUpdater[*Ghost]
}

type UserLocalPortalInfo

type UserLocalPortalInfo struct {
	// To signal an indefinite mute, use [event.MutedForever] as the value here.
	// To unmute, set any time before now, e.g. [bridgev2.Unmuted].
	MutedUntil *time.Time
	Tag        *event.RoomTag
}

type UserLogin

type UserLogin struct {
	*database.UserLogin
	Bridge *Bridge
	User   *User
	Log    zerolog.Logger

	Client      NetworkAPI
	BridgeState *BridgeStateQueue
	// contains filtered or unexported fields
}

func (*UserLogin) AddPortalToSpace

func (ul *UserLogin) AddPortalToSpace(ctx context.Context, portal *Portal, userPortal *database.UserPortal) error

func (*UserLogin) Delete

func (ul *UserLogin) Delete(ctx context.Context, state status.BridgeState, opts DeleteOpts)

func (*UserLogin) Disconnect

func (ul *UserLogin) Disconnect()

func (*UserLogin) DisconnectWithTimeout

func (ul *UserLogin) DisconnectWithTimeout(timeout time.Duration)

func (*UserLogin) FillBridgeState

func (ul *UserLogin) FillBridgeState(state status.BridgeState) status.BridgeState

func (*UserLogin) GetSpaceRoom

func (ul *UserLogin) GetSpaceRoom(ctx context.Context) (id.RoomID, error)

func (*UserLogin) KickUserFromPortalsForBadCredentials

func (ul *UserLogin) KickUserFromPortalsForBadCredentials(ctx context.Context)

KickUserFromPortalsForBadCredentials can be called to kick the user from portals without deleting the entire UserLogin object.

func (*UserLogin) Logout

func (ul *UserLogin) Logout(ctx context.Context)

func (*UserLogin) MarkAsPreferredIn

func (ul *UserLogin) MarkAsPreferredIn(ctx context.Context, portal *Portal) error

func (*UserLogin) MarkInPortal

func (ul *UserLogin) MarkInPortal(ctx context.Context, portal *Portal)

func (*UserLogin) QueueRemoteEvent

func (ul *UserLogin) QueueRemoteEvent(evt RemoteEvent) EventHandlingResult

func (*UserLogin) Save

func (ul *UserLogin) Save(ctx context.Context) error

func (*UserLogin) TrackAnalytics

func (ul *UserLogin) TrackAnalytics(event string, props map[string]any)

type UserPowerLevelChange

type UserPowerLevelChange struct {
	Target GhostOrUserLogin
	SinglePowerLevelChange
}

type UserSearchingNetworkAPI

type UserSearchingNetworkAPI interface {
	IdentifierResolvingNetworkAPI
	SearchUsers(ctx context.Context, query string) ([]*ResolveIdentifierResponse, error)
}

type WebPushConfig

type WebPushConfig struct {
	VapidKey string `json:"vapid_key"`
}

Directories

Path Synopsis
mxmain
Package mxmain contains initialization code for a single-network Matrix bridge using the bridgev2 package.
Package mxmain contains initialization code for a single-network Matrix bridge using the bridgev2 package.
Package networkid contains string types used to represent different kinds of identifiers on remote networks.
Package networkid contains string types used to represent different kinds of identifiers on remote networks.

Jump to

Keyboard shortcuts

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