Skip to content

Commit

Permalink
bridgev2: allow passing extra data in ConnectBackground
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 23, 2025
1 parent 524379b commit 2d79ce4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions bridgev2/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (br *Bridge) Start() error {
return nil
}

func (br *Bridge) RunOnce(ctx context.Context, loginID networkid.UserLoginID) error {
func (br *Bridge) RunOnce(ctx context.Context, loginID networkid.UserLoginID, params *ConnectBackgroundParams) error {
br.Background = true
err := br.StartConnectors(ctx)
if err != nil {
Expand Down Expand Up @@ -159,7 +159,7 @@ func (br *Bridge) RunOnce(ctx context.Context, loginID networkid.UserLoginID) er
return nil
} else {
br.Log.Info().Str("user_login_id", string(login.ID)).Msg("Starting individual user login in background mode")
return syncClient.ConnectBackground(login.Log.WithContext(ctx))
return syncClient.ConnectBackground(login.Log.WithContext(ctx), params)
}
}

Expand Down
10 changes: 9 additions & 1 deletion bridgev2/networkinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,21 @@ type NetworkAPI interface {
HandleMatrixMessage(ctx context.Context, msg *MatrixMessage) (message *MatrixMessageResponse, err error)
}

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
}

// BackgroundSyncingNetworkAPI is an optional interface that network connectors can implement to support background resyncs.
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) error
ConnectBackground(ctx context.Context, params *ConnectBackgroundParams) error
}

// FetchMessagesParams contains the parameters for a message history pagination request.
Expand Down

0 comments on commit 2d79ce4

Please sign in to comment.