mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2: remove hardcoded room version
This commit is contained in:
parent
9e3fa96fb4
commit
de52a753be
5 changed files with 54 additions and 6 deletions
|
|
@ -81,6 +81,8 @@ type Connector struct {
|
|||
|
||||
MediaConfig mautrix.RespMediaConfig
|
||||
SpecVersions *mautrix.RespVersions
|
||||
SpecCaps *mautrix.RespCapabilities
|
||||
specCapsLock sync.Mutex
|
||||
Capabilities *bridgev2.MatrixCapabilities
|
||||
IgnoreUnsupportedServer bool
|
||||
|
||||
|
|
@ -409,6 +411,21 @@ func (br *Connector) ensureConnection(ctx context.Context) {
|
|||
br.Bot.EnsureAppserviceConnection(ctx)
|
||||
}
|
||||
|
||||
func (br *Connector) fetchCapabilities(ctx context.Context) *mautrix.RespCapabilities {
|
||||
br.specCapsLock.Lock()
|
||||
defer br.specCapsLock.Unlock()
|
||||
if br.SpecCaps != nil {
|
||||
return br.SpecCaps
|
||||
}
|
||||
caps, err := br.Bot.Capabilities(ctx)
|
||||
if err != nil {
|
||||
br.Log.Err(err).Msg("Failed to fetch capabilities from homeserver")
|
||||
return nil
|
||||
}
|
||||
br.SpecCaps = caps
|
||||
return caps
|
||||
}
|
||||
|
||||
func (br *Connector) fetchMediaConfig(ctx context.Context) {
|
||||
cfg, err := br.Bot.GetMediaConfig(ctx)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -512,6 +512,39 @@ func (br *Connector) getDefaultEncryptionEvent() *event.EncryptionEventContent {
|
|||
return content
|
||||
}
|
||||
|
||||
func (as *ASIntent) filterCreateRequestForV12(ctx context.Context, req *mautrix.ReqCreateRoom) {
|
||||
if as.Connector.Config.Homeserver.Software == bridgeconfig.SoftwareHungry {
|
||||
// Hungryserv doesn't override the capabilities endpoint nor do room versions
|
||||
return
|
||||
}
|
||||
caps := as.Connector.fetchCapabilities(ctx)
|
||||
roomVer := req.RoomVersion
|
||||
if roomVer == "" && caps != nil && caps.RoomVersions != nil {
|
||||
roomVer = id.RoomVersion(caps.RoomVersions.Default)
|
||||
}
|
||||
if roomVer != "" && !roomVer.PrivilegedRoomCreators() {
|
||||
return
|
||||
}
|
||||
creators, _ := req.CreationContent["additional_creators"].([]id.UserID)
|
||||
creators = append(slices.Clone(creators), as.GetMXID())
|
||||
if req.PowerLevelOverride != nil {
|
||||
for _, creator := range creators {
|
||||
delete(req.PowerLevelOverride.Users, creator)
|
||||
}
|
||||
}
|
||||
for _, evt := range req.InitialState {
|
||||
if evt.Type != event.StatePowerLevels {
|
||||
continue
|
||||
}
|
||||
content, ok := evt.Content.Parsed.(*event.PowerLevelsEventContent)
|
||||
if ok {
|
||||
for _, creator := range creators {
|
||||
delete(content.Users, creator)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (as *ASIntent) CreateRoom(ctx context.Context, req *mautrix.ReqCreateRoom) (id.RoomID, error) {
|
||||
if as.Connector.Config.Encryption.Default {
|
||||
req.InitialState = append(req.InitialState, &event.Event{
|
||||
|
|
@ -527,6 +560,7 @@ func (as *ASIntent) CreateRoom(ctx context.Context, req *mautrix.ReqCreateRoom)
|
|||
}
|
||||
req.CreationContent["m.federate"] = false
|
||||
}
|
||||
as.filterCreateRequestForV12(ctx, req)
|
||||
resp, err := as.Matrix.CreateRoom(ctx, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
|||
|
|
@ -4999,7 +4999,6 @@ func (portal *Portal) createMatrixRoomInLoop(ctx context.Context, source *UserLo
|
|||
IsDirect: portal.RoomType == database.RoomTypeDM,
|
||||
PowerLevelOverride: powerLevels,
|
||||
BeeperLocalRoomID: portal.Bridge.Matrix.GenerateDeterministicRoomID(portal.PortalKey),
|
||||
RoomVersion: id.RoomV11,
|
||||
}
|
||||
autoJoinInvites := portal.Bridge.Matrix.GetCapabilities().AutoJoinInvites
|
||||
if autoJoinInvites {
|
||||
|
|
|
|||
|
|
@ -164,8 +164,7 @@ func (ul *UserLogin) GetSpaceRoom(ctx context.Context) (id.RoomID, error) {
|
|||
ul.UserMXID: 50,
|
||||
},
|
||||
},
|
||||
RoomVersion: id.RoomV11,
|
||||
Invite: []id.UserID{ul.UserMXID},
|
||||
Invite: []id.UserID{ul.UserMXID},
|
||||
}
|
||||
if autoJoin {
|
||||
req.BeeperInitialMembers = []id.UserID{ul.UserMXID}
|
||||
|
|
|
|||
|
|
@ -229,9 +229,8 @@ func (user *User) GetManagementRoom(ctx context.Context) (id.RoomID, error) {
|
|||
user.MXID: 50,
|
||||
},
|
||||
},
|
||||
RoomVersion: id.RoomV11,
|
||||
Invite: []id.UserID{user.MXID},
|
||||
IsDirect: true,
|
||||
Invite: []id.UserID{user.MXID},
|
||||
IsDirect: true,
|
||||
}
|
||||
if autoJoin {
|
||||
req.BeeperInitialMembers = []id.UserID{user.MXID}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue