connector

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: AGPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GMListenError               status.BridgeStateErrorCode = "gm-listen-error"
	GMFatalError                status.BridgeStateErrorCode = "gm-listen-fatal-error"
	GMUnpaired                  status.BridgeStateErrorCode = "gm-unpaired"
	GMUnpaired404               status.BridgeStateErrorCode = "gm-unpaired-entity-not-found"
	GMLoggedOut401              status.BridgeStateErrorCode = "gm-logged-out-401-polling"
	GMLoggedOutInvalidCreds     status.BridgeStateErrorCode = "gm-logged-out-invalid-credentials"
	GMLoggedOutNoEmailInConfig  status.BridgeStateErrorCode = "gm-logged-out-no-email-in-config"
	GMNotLoggedIn               status.BridgeStateErrorCode = "gm-not-logged-in"
	GMNotLoggedInCanReauth      status.BridgeStateErrorCode = "gm-not-logged-in-can-reauth"
	GMConnecting                status.BridgeStateErrorCode = "gm-connecting"
	GMConnectionFailed          status.BridgeStateErrorCode = "gm-connection-failed"
	GMConfigFetchFailed         status.BridgeStateErrorCode = "gm-config-fetch-failed"
	GMPingFailed                status.BridgeStateErrorCode = "gm-ping-failed"
	GMNotDefaultSMSApp          status.BridgeStateErrorCode = "gm-not-default-sms-app"
	GMBrowserInactive           status.BridgeStateErrorCode = "gm-browser-inactive"
	GMBrowserInactiveTimeout    status.BridgeStateErrorCode = "gm-browser-inactive-timeout"
	GMBrowserInactiveInactivity status.BridgeStateErrorCode = "gm-browser-inactive-inactivity"
	GMPhoneNotResponding        status.BridgeStateErrorCode = "gm-phone-not-responding"
	GMSwitchedToGoogleLogin     status.BridgeStateErrorCode = "gm-switched-to-google-login"
)
View Source
const (
	LoginFlowIDGoogle = "google"
	LoginFlowIDQR     = "qr"
)
View Source
const (
	LoginStepIDQR       = "fi.mau.gmessages.qr"
	LoginStepIDGoogle   = "fi.mau.gmessages.google_account"
	LoginStepIDEmoji    = "fi.mau.gmessages.emoji"
	LoginStepIDComplete = "fi.mau.gmessages.complete"
)
View Source
const DeleteAndResendThreshold = 7 * 24 * time.Hour
View Source
const GeminiPhoneNumber = "+18339913448"
View Source
const MaxDelayForNewMessagePart = 24 * time.Hour
View Source
const MinAvatarUpdateInterval = 24 * time.Hour
View Source
const QRExpiryTime = 30 * time.Second

Variables

View Source
var (
	ErrPairNoDevices          = bridgev2.RespError{Err: pairingErrMsgNoDevices, ErrCode: "FI.MAU.GMESSAGES.PAIR_NO_DEVICES", StatusCode: http.StatusBadRequest}
	ErrPairPhoneNotResponding = bridgev2.RespError{Err: pairingErrPhoneNotResponding, ErrCode: "FI.MAU.GMESSAGES.PAIR_INIT_TIMEOUT", StatusCode: http.StatusBadRequest}
	ErrPairIncorrectEmoji     = bridgev2.RespError{Err: pairingErrMsgIncorrectEmoji, ErrCode: "FI.MAU.GMESSAGES.PAIR_INCORRECT_EMOJI", StatusCode: http.StatusBadRequest}
	ErrPairCancelled          = bridgev2.RespError{Err: pairingErrMsgCancelled, ErrCode: "FI.MAU.GMESSAGES.PAIR_CANCELLED", StatusCode: http.StatusBadRequest}
	ErrPairTimeout            = bridgev2.RespError{Err: pairingErrMsgTimeout, ErrCode: "FI.MAU.GMESSAGES.PAIR_TIMEOUT", StatusCode: http.StatusBadRequest}
	ErrPairQRTimeout          = bridgev2.RespError{Err: pairingErrMsgQRTimeout, ErrCode: "FI.MAU.GMESSAGES.PAIR_QR_TIMEOUT", StatusCode: http.StatusBadRequest}
	ErrPairStartUnknown       = bridgev2.RespError{Err: pairingErrMsgStartUnknown, ErrCode: "M_UNKNOWN", StatusCode: http.StatusInternalServerError}
	ErrPairWaitUnknown        = bridgev2.RespError{Err: pairingErrMsgWaitUnknown, ErrCode: "M_UNKNOWN", StatusCode: http.StatusInternalServerError}
	ErrPairQRRefreshUnknown   = bridgev2.RespError{Err: pairingErrMsgQRRefreshUnknown, ErrCode: "M_UNKNOWN", StatusCode: http.StatusInternalServerError}
)
View Source
var (
	ErrRCSGroupRequiresName = bridgev2.WrapRespErrManual(errors.New("RCS group creation requires a name"), "FI.MAU.GMESSAGES.RCS_REQUIRES_NAME", http.StatusBadRequest)
	ErrMinimumTwoUsers      = bridgev2.WrapRespErr(errors.New("need at least 2 users to create a group"), mautrix.MInvalidParam)
)
View Source
var ErrNonSuccessResponse = bridgev2.WrapErrorInStatus(errors.New("got non-success response")).WithErrorAsMessage().WithSendNotice(true)
View Source
var ErrPrefixMismatch = bridgev2.WrapErrorInStatus(errors.New("internal error: account mismatch")).
	WithErrorAsMessage().WithIsCertain(true).WithSendNotice(true)
View Source
var ExampleConfig string

Functions

This section is empty.

Types

type Config

type Config struct {
	DisplaynameTemplate  string           `yaml:"displayname_template"`
	DeviceMeta           DeviceMetaConfig `yaml:"device_meta"`
	AggressiveReconnect  bool             `yaml:"aggressive_reconnect"`
	InitialChatSyncCount int              `yaml:"initial_chat_sync_count"`
	// contains filtered or unexported fields
}

func (*Config) FormatDisplayname

func (bc *Config) FormatDisplayname(phone, fullName, firstName string) string

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(node *yaml.Node) error

type DBMessages

type DBMessages []*database.Message

func (DBMessages) GetMainMeta

func (dbm DBMessages) GetMainMeta() *MessageMetadata

func (DBMessages) HasPendingMedia

func (dbm DBMessages) HasPendingMedia() bool

func (DBMessages) MessageWasEdited

func (dbm DBMessages) MessageWasEdited(new *gmproto.Message) (edited bool, changes *zerolog.Event)

type DeviceMetaConfig

type DeviceMetaConfig struct {
	OS      string `yaml:"os"`
	Browser string `yaml:"browser"`
	Type    string `yaml:"type"`
}

type DisplaynameTemplateArgs

type DisplaynameTemplateArgs struct {
	PhoneNumber string
	FullName    string
	FirstName   string
}

type GMChatResync

type GMChatResync struct {
	Conv *gmproto.Conversation

	AllowBackfill bool
	OnlyBackfill  bool
	// contains filtered or unexported fields
}

func (*GMChatResync) AddLogContext

func (evt *GMChatResync) AddLogContext(c zerolog.Context) zerolog.Context

func (*GMChatResync) CheckNeedsBackfill

func (evt *GMChatResync) CheckNeedsBackfill(ctx context.Context, latestMessage *database.Message) (bool, error)

func (*GMChatResync) DeleteOnlyForMe

func (evt *GMChatResync) DeleteOnlyForMe() bool

func (*GMChatResync) GetChatInfo

func (evt *GMChatResync) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) (*bridgev2.ChatInfo, error)

func (*GMChatResync) GetPortalKey

func (evt *GMChatResync) GetPortalKey() networkid.PortalKey

func (*GMChatResync) GetSender

func (evt *GMChatResync) GetSender() bridgev2.EventSender

func (*GMChatResync) GetType

func (evt *GMChatResync) GetType() bridgev2.RemoteEventType

func (*GMChatResync) ShouldCreatePortal

func (evt *GMChatResync) ShouldCreatePortal() bool

type GMClient

type GMClient struct {
	Main      *GMConnector
	UserLogin *bridgev2.UserLogin
	Client    *libgm.Client
	Meta      *UserLoginMetadata

	SwitchedToGoogleLogin bool

	PhoneResponding bool
	// contains filtered or unexported fields
}

func (*GMClient) Connect

func (gc *GMClient) Connect(ctx context.Context)

func (*GMClient) ConvertGoogleMessage

func (gc *GMClient) ConvertGoogleMessage(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI, m *libgm.WrappedMessage, allowMergeCaption bool) *bridgev2.ConvertedMessage

func (*GMClient) ConvertMatrixMessage

func (gc *GMClient) ConvertMatrixMessage(ctx context.Context, msg *bridgev2.MatrixMessage, txnID networkid.TransactionID) (*gmproto.SendMessageRequest, error)

func (*GMClient) CreateGroup

func (gc *GMClient) CreateGroup(ctx context.Context, name string, users ...networkid.UserID) (*bridgev2.CreateChatResponse, error)

func (*GMClient) Disconnect

func (gc *GMClient) Disconnect()

func (*GMClient) FetchMessages

func (*GMClient) FillBridgeState

func (gc *GMClient) FillBridgeState(state status.BridgeState) status.BridgeState

func (*GMClient) GetCapabilities

func (gc *GMClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *bridgev2.NetworkRoomCapabilities

func (*GMClient) GetChatInfo

func (gc *GMClient) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) (*bridgev2.ChatInfo, error)

func (*GMClient) GetContactList

func (gc *GMClient) GetContactList(ctx context.Context) ([]*bridgev2.ResolveIdentifierResponse, error)

func (*GMClient) GetSIM

func (gc *GMClient) GetSIM(portal *bridgev2.Portal) *gmproto.SIMCard

func (*GMClient) GetUserInfo

func (gc *GMClient) GetUserInfo(ctx context.Context, ghost *bridgev2.Ghost) (*bridgev2.UserInfo, error)

func (*GMClient) HandleMatrixMessage

func (gc *GMClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.MatrixMessage) (message *bridgev2.MatrixMessageResponse, err error)

func (*GMClient) HandleMatrixMessageRemove

func (gc *GMClient) HandleMatrixMessageRemove(ctx context.Context, msg *bridgev2.MatrixMessageRemove) error

func (*GMClient) HandleMatrixReaction

func (gc *GMClient) HandleMatrixReaction(ctx context.Context, msg *bridgev2.MatrixReaction) (reaction *database.Reaction, err error)

func (*GMClient) HandleMatrixReactionRemove

func (gc *GMClient) HandleMatrixReactionRemove(ctx context.Context, msg *bridgev2.MatrixReactionRemove) error

func (*GMClient) HandleMatrixReadReceipt

func (gc *GMClient) HandleMatrixReadReceipt(ctx context.Context, msg *bridgev2.MatrixReadReceipt) error

func (*GMClient) IsLoggedIn

func (gc *GMClient) IsLoggedIn() bool

func (*GMClient) IsThisUser

func (gc *GMClient) IsThisUser(ctx context.Context, userID networkid.UserID) bool

func (*GMClient) LogoutRemote

func (gc *GMClient) LogoutRemote(ctx context.Context)

func (*GMClient) MakeMessageID

func (gc *GMClient) MakeMessageID(messageID string) networkid.MessageID

func (*GMClient) MakePortalID

func (gc *GMClient) MakePortalID(conversationID string) networkid.PortalID

func (*GMClient) MakePortalKey

func (gc *GMClient) MakePortalKey(conversationID string) networkid.PortalKey

func (*GMClient) MakeUserID

func (gc *GMClient) MakeUserID(participantID string) networkid.UserID

func (*GMClient) NewClient

func (gc *GMClient) NewClient()

func (*GMClient) ParseMessageID

func (gc *GMClient) ParseMessageID(id networkid.MessageID) (messageID string, err error)

func (*GMClient) ParsePortalID

func (gc *GMClient) ParsePortalID(id networkid.PortalID) (participantID string, err error)

func (*GMClient) ParseUserID

func (gc *GMClient) ParseUserID(id networkid.UserID) (participantID string, err error)

func (*GMClient) PreHandleMatrixReaction

func (gc *GMClient) PreHandleMatrixReaction(ctx context.Context, msg *bridgev2.MatrixReaction) (bridgev2.MatrixReactionPreResponse, error)

func (*GMClient) ResetClient

func (gc *GMClient) ResetClient()

func (*GMClient) ResolveIdentifier

func (gc *GMClient) ResolveIdentifier(ctx context.Context, identifier string, createChat bool) (*bridgev2.ResolveIdentifierResponse, error)

func (*GMClient) SyncConversations

func (gc *GMClient) SyncConversations(ctx context.Context, lastDataReceived time.Time, minimalSync bool)

type GMConnector

type GMConnector struct {
	DB     *gmdb.GMDB
	Config Config
	// contains filtered or unexported fields
}

func (*GMConnector) CreateLogin

func (gc *GMConnector) CreateLogin(ctx context.Context, user *bridgev2.User, flowID string) (bridgev2.LoginProcess, error)

func (*GMConnector) FillPortalBridgeInfo

func (gc *GMConnector) FillPortalBridgeInfo(portal *bridgev2.Portal, content *event.BridgeEventContent)

func (*GMConnector) GetCapabilities

func (gc *GMConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilities

func (*GMConnector) GetConfig

func (gc *GMConnector) GetConfig() (example string, data any, upgrader up.Upgrader)

func (*GMConnector) GetDBMetaTypes

func (gc *GMConnector) GetDBMetaTypes() database.MetaTypes

func (*GMConnector) GetLoginFlows

func (gc *GMConnector) GetLoginFlows() []bridgev2.LoginFlow

func (*GMConnector) GetName

func (gc *GMConnector) GetName() bridgev2.BridgeName

func (*GMConnector) Init

func (gc *GMConnector) Init(bridge *bridgev2.Bridge)

func (*GMConnector) LoadUserLogin

func (gc *GMConnector) LoadUserLogin(ctx context.Context, login *bridgev2.UserLogin) error

func (*GMConnector) Start

func (gc *GMConnector) Start(ctx context.Context) error

func (*GMConnector) ValidateUserID

func (gc *GMConnector) ValidateUserID(id networkid.UserID) bool

type GhostMetadata

type GhostMetadata struct {
	Phone          string             `json:"phone"`
	ContactID      string             `json:"contact_id"`
	AvatarUpdateTS jsontime.UnixMilli `json:"avatar_update_ts"`
}

type GoogleLoginProcess

type GoogleLoginProcess struct {
	Main     *GMConnector
	User     *bridgev2.User
	Client   *libgm.Client
	Sess     *libgm.PairingSession
	Override *bridgev2.UserLogin
}

func (*GoogleLoginProcess) Cancel

func (gl *GoogleLoginProcess) Cancel()

func (*GoogleLoginProcess) Start

func (*GoogleLoginProcess) StartWithOverride added in v0.6.0

func (gl *GoogleLoginProcess) StartWithOverride(ctx context.Context, override *bridgev2.UserLogin) (*bridgev2.LoginStep, error)

func (*GoogleLoginProcess) SubmitCookies

func (gl *GoogleLoginProcess) SubmitCookies(ctx context.Context, cookies map[string]string) (*bridgev2.LoginStep, error)

func (*GoogleLoginProcess) Wait

type MessageEvent

type MessageEvent struct {
	*libgm.WrappedMessage
	// contains filtered or unexported fields
}

func (*MessageEvent) AddLogContext

func (m *MessageEvent) AddLogContext(c zerolog.Context) zerolog.Context

func (*MessageEvent) ConvertMessage

func (m *MessageEvent) ConvertMessage(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI) (*bridgev2.ConvertedMessage, error)

func (*MessageEvent) GetID

func (m *MessageEvent) GetID() networkid.MessageID

func (*MessageEvent) GetPortalKey

func (m *MessageEvent) GetPortalKey() networkid.PortalKey

func (*MessageEvent) GetSender

func (m *MessageEvent) GetSender() bridgev2.EventSender

func (*MessageEvent) GetTargetMessage

func (m *MessageEvent) GetTargetMessage() networkid.MessageID

func (*MessageEvent) GetTimestamp

func (m *MessageEvent) GetTimestamp() time.Time

func (*MessageEvent) GetTransactionID

func (m *MessageEvent) GetTransactionID() networkid.TransactionID

func (*MessageEvent) GetType

func (m *MessageEvent) GetType() bridgev2.RemoteEventType

func (*MessageEvent) HandleExisting

func (m *MessageEvent) HandleExisting(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI, existing []*database.Message) (bridgev2.UpsertResult, error)

func (*MessageEvent) ShouldCreatePortal

func (m *MessageEvent) ShouldCreatePortal() bool

type MessageMetadata

type MessageMetadata struct {
	Type gmproto.MessageStatusType `json:"type,omitempty"`

	GlobalMediaStatus string `json:"media_status,omitempty"`
	GlobalPartCount   int    `json:"part_count,omitempty"`

	TextHash     string `json:"text_hash,omitempty"`
	MediaPartID  string `json:"media_part_id,omitempty"`
	MediaID      string `json:"media_id,omitempty"`
	MediaPending bool   `json:"media_pending,omitempty"`

	IsOutgoing      bool `json:"is_outgoing,omitempty"`
	MSSSent         bool `json:"mss_sent,omitempty"`
	MSSFailSent     bool `json:"mss_fail_sent,omitempty"`
	MSSDeliverySent bool `json:"mss_delivery_sent,omitempty"`
	ReadReceiptSent bool `json:"read_receipt_sent,omitempty"`

	OrigMXID id.EventID `json:"orig_mxid,omitempty"`
}

func (*MessageMetadata) GetOrigMXID added in v0.5.1

func (m *MessageMetadata) GetOrigMXID(mxid id.EventID) id.EventID

type MessageUpdateEvent

type MessageUpdateEvent struct {
	*libgm.WrappedMessage
	// contains filtered or unexported fields
}

func (*MessageUpdateEvent) AddLogContext

func (m *MessageUpdateEvent) AddLogContext(c zerolog.Context) zerolog.Context

func (*MessageUpdateEvent) ConvertEdit

func (m *MessageUpdateEvent) ConvertEdit(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI, existing []*database.Message) (*bridgev2.ConvertedEdit, error)

func (*MessageUpdateEvent) GetPortalKey

func (m *MessageUpdateEvent) GetPortalKey() networkid.PortalKey

func (*MessageUpdateEvent) GetSender

func (m *MessageUpdateEvent) GetSender() bridgev2.EventSender

func (*MessageUpdateEvent) GetTargetDBMessage

func (m *MessageUpdateEvent) GetTargetDBMessage() []*database.Message

func (*MessageUpdateEvent) GetTargetMessage

func (m *MessageUpdateEvent) GetTargetMessage() networkid.MessageID

func (*MessageUpdateEvent) GetTimestamp

func (m *MessageUpdateEvent) GetTimestamp() time.Time

func (*MessageUpdateEvent) GetType

type PortalMetadata

type PortalMetadata struct {
	Type     gmproto.ConversationType     `json:"type"`
	SendMode gmproto.ConversationSendMode `json:"send_mode"`
	ForceRCS bool                         `json:"force_rcs"`

	OutgoingID string `json:"outgoing_id"`
}

type QRLoginProcess

type QRLoginProcess struct {
	Main        *GMConnector
	User        *bridgev2.User
	Client      *libgm.Client
	PairSuccess chan *gmproto.PairedData
	PrevStart   time.Time
	MaxAttempts int
}

func (*QRLoginProcess) Cancel

func (ql *QRLoginProcess) Cancel()

func (*QRLoginProcess) Start

func (*QRLoginProcess) Wait

type ReactionSyncEvent

type ReactionSyncEvent struct {
	*gmproto.Message
	// contains filtered or unexported fields
}

func (*ReactionSyncEvent) AddLogContext

func (r *ReactionSyncEvent) AddLogContext(c zerolog.Context) zerolog.Context

func (*ReactionSyncEvent) GetPortalKey

func (r *ReactionSyncEvent) GetPortalKey() networkid.PortalKey

func (*ReactionSyncEvent) GetReactions

func (r *ReactionSyncEvent) GetReactions() *bridgev2.ReactionSyncData

func (*ReactionSyncEvent) GetSender

func (r *ReactionSyncEvent) GetSender() bridgev2.EventSender

func (*ReactionSyncEvent) GetTargetMessage

func (r *ReactionSyncEvent) GetTargetMessage() networkid.MessageID

func (*ReactionSyncEvent) GetType

type UserLoginMetadata

type UserLoginMetadata struct {
	Session *libgm.AuthData

	Settings UserSettings
	IDPrefix string
	// contains filtered or unexported fields
}

func (*UserLoginMetadata) AddSelfParticipantID

func (ulm *UserLoginMetadata) AddSelfParticipantID(id string) bool

func (*UserLoginMetadata) CopyFrom

func (ulm *UserLoginMetadata) CopyFrom(other any)

func (*UserLoginMetadata) GetSIM

func (ulm *UserLoginMetadata) GetSIM(participantID string) *gmproto.SIMCard

func (*UserLoginMetadata) GetSIMs added in v0.5.1

func (ulm *UserLoginMetadata) GetSIMs() []*gmproto.SIMCard

func (*UserLoginMetadata) GetSIMsForBridgeState

func (ulm *UserLoginMetadata) GetSIMsForBridgeState() []bridgeStateSIMMeta

func (*UserLoginMetadata) IsSelfParticipantID

func (ulm *UserLoginMetadata) IsSelfParticipantID(id string) bool

func (*UserLoginMetadata) MarshalJSON

func (ulm *UserLoginMetadata) MarshalJSON() ([]byte, error)

func (*UserLoginMetadata) SIMCount

func (ulm *UserLoginMetadata) SIMCount() int

func (*UserLoginMetadata) SetSIMs

func (ulm *UserLoginMetadata) SetSIMs(sims []*gmproto.SIMCard) bool

func (*UserLoginMetadata) UnmarshalJSON

func (ulm *UserLoginMetadata) UnmarshalJSON(data []byte) error

type UserSettings

type UserSettings struct {
	SettingsReceived    bool `json:"settings_received"`
	RCSEnabled          bool `json:"rcs_enabled"`
	ReadReceipts        bool `json:"read_receipts"`
	TypingNotifications bool `json:"typing_notifications"`
	IsDefaultSMSApp     bool `json:"is_default_sms_app"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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