Skip to content

Commit

Permalink
Merge branch 'main' into tulir/extended-profiles-for-everyone
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir authored Sep 4, 2024
2 parents 7280884 + e750881 commit e4e8933
Show file tree
Hide file tree
Showing 19 changed files with 397 additions and 183 deletions.
1 change: 1 addition & 0 deletions bridgev2/bridgeconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type BridgeConfig struct {
CommandPrefix string `yaml:"command_prefix"`
PersonalFilteringSpaces bool `yaml:"personal_filtering_spaces"`
PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"`
AsyncEvents bool `yaml:"async_events"`
BridgeMatrixLeave bool `yaml:"bridge_matrix_leave"`
TagOnlyOnCreate bool `yaml:"tag_only_on_create"`
MuteOnlyOnCreate bool `yaml:"mute_only_on_create"`
Expand Down
1 change: 1 addition & 0 deletions bridgev2/bridgeconfig/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func doUpgrade(helper up.Helper) {
helper.Copy(up.Str, "bridge", "command_prefix")
helper.Copy(up.Bool, "bridge", "personal_filtering_spaces")
helper.Copy(up.Bool, "bridge", "private_chat_portal_meta")
helper.Copy(up.Bool, "bridge", "async_events")
helper.Copy(up.Bool, "bridge", "bridge_matrix_leave")
helper.Copy(up.Bool, "bridge", "tag_only_on_create")
helper.Copy(up.Bool, "bridge", "mute_only_on_create")
Expand Down
3 changes: 2 additions & 1 deletion bridgev2/matrix/intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ func (as *ASIntent) UploadMediaStream(
var res *bridgev2.FileStreamResult
res, err = cb(tempFile)
if err != nil {
err = fmt.Errorf("failed to write to temp file: %w", err)
err = fmt.Errorf("write callback failed: %w", err)
return
}
var replFile *os.File
if res.ReplacementFile != "" {
Expand Down
3 changes: 3 additions & 0 deletions bridgev2/matrix/mxmain/example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ bridge:
# Whether the bridge should set names and avatars explicitly for DM portals.
# This is only necessary when using clients that don't support MSC4171.
private_chat_portal_meta: false
# Should events be handled asynchronously within portal rooms?
# If true, events may end up being out of order, but slow events won't block other ones.
async_events: false

# Should leaving Matrix rooms be bridged as leaving groups on the remote network?
bridge_matrix_leave: false
Expand Down
16 changes: 16 additions & 0 deletions bridgev2/matrix/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ type ProvisioningAPI struct {
// GetAuthFromRequest is a custom function for getting the auth token from
// the request if the Authorization header is not present.
GetAuthFromRequest func(r *http.Request) string

// GetUserIDFromRequest is a custom function for getting the user ID to
// authenticate as instead of using the user ID provided in the query
// parameter.
GetUserIDFromRequest func(r *http.Request) id.UserID
}

type ProvLogin struct {
Expand Down Expand Up @@ -200,6 +205,9 @@ func (prov *ProvisioningAPI) AuthMiddleware(h http.Handler) http.Handler {
return
}
userID := id.UserID(r.URL.Query().Get("user_id"))
if userID == "" && prov.GetUserIDFromRequest != nil {
userID = prov.GetUserIDFromRequest(r)
}
if auth != prov.br.Config.Provisioning.SharedSecret {
var err error
if strings.HasPrefix(auth, "openid:") {
Expand Down Expand Up @@ -227,6 +235,14 @@ func (prov *ProvisioningAPI) AuthMiddleware(h http.Handler) http.Handler {
return
}
// TODO handle user being nil?
// TODO per-endpoint permissions?
if !user.Permissions.Login {
jsonResponse(w, http.StatusForbidden, &mautrix.RespError{
Err: "User does not have login permissions",
ErrCode: mautrix.MForbidden.ErrCode,
})
return
}

ctx := context.WithValue(r.Context(), provisioningUserKey, user)
if loginID, ok := mux.Vars(r)["loginProcessID"]; ok {
Expand Down
11 changes: 8 additions & 3 deletions bridgev2/networkinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,16 @@ type MaxFileSizeingNetwork interface {
SetMaxFileSize(maxSize int64)
}

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

type MatrixMessageResponse struct {
DB *database.Message

Pending networkid.TransactionID
HandleEcho func(RemoteMessage, *database.Message) (bool, error)
// 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
}

type FileRestriction struct {
Expand Down
Loading

0 comments on commit e4e8933

Please sign in to comment.