Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matrix -> signal join rule handling #536

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ require (
github.com/tidwall/sjson v1.2.5 // indirect
github.com/yuin/goldmark v1.7.4 // indirect
go.mau.fi/zeroconfig v0.1.3 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
maunium.net/go/mauflag v1.0.0 // indirect
)

replace maunium.net/go/mautrix => github.com/maltee1/mautrix-go v0.0.0-20240820201051-5fa9ef2ab1bf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only as long as the relevant change in mautrix-go hasn't been merged yet.

6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/maltee1/mautrix-go v0.0.0-20240820201051-5fa9ef2ab1bf h1:n18kxEPB1c7mlMP0ysiel3orOa5uoi1O60yY21UQbfM=
github.com/maltee1/mautrix-go v0.0.0-20240820201051-5fa9ef2ab1bf/go.mod h1:NhWZ4jpQ2CW+t6TmGrnydAIL0htdoXmGiNTdHb2PzL4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down Expand Up @@ -72,6 +74,8 @@ golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDT
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -90,7 +94,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/mautrix v0.20.1-0.20240817111253-2355d70426f4 h1:S4+mHwQC2CiCTl0cn21zd4V8JiqGYMYlsde2v7jC8bE=
maunium.net/go/mautrix v0.20.1-0.20240817111253-2355d70426f4/go.mod h1:V725r8w7oddsS7CxnmTAp634A4nwJCFY7J3jiTMUz2c=
nhooyr.io/websocket v1.8.17 h1:KEVeLJkUywCKVsnLIDlD/5gtayKp8VoCkksHCGGfT9Y=
nhooyr.io/websocket v1.8.17/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
1 change: 1 addition & 0 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var (
_ bridgev2.RoomNameHandlingNetworkAPI = (*SignalClient)(nil)
_ bridgev2.RoomAvatarHandlingNetworkAPI = (*SignalClient)(nil)
_ bridgev2.RoomTopicHandlingNetworkAPI = (*SignalClient)(nil)
_ bridgev2.JoinRulesHandlingNetworkAPI = (*SignalClient)(nil)
)

var pushCfg = &bridgev2.PushConfig{
Expand Down
47 changes: 47 additions & 0 deletions pkg/connector/handlematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,50 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2
msg.Portal.Metadata.(*signalid.PortalMetadata).Revision = revision
return true, nil
}

func joinRuleToAccessControl(ctx context.Context, joinRule event.JoinRule) signalmeow.AccessControl {
log := zerolog.Ctx(ctx).With().
Str("JoinRule", string(joinRule)).
Logger()
var addFromInviteLinkAccess signalmeow.AccessControl
switch joinRule {
case event.JoinRuleInvite:
addFromInviteLinkAccess = signalmeow.AccessControl_UNSATISFIABLE
case event.JoinRuleKnock, event.JoinRuleKnockRestricted:
addFromInviteLinkAccess = signalmeow.AccessControl_ADMINISTRATOR
case event.JoinRulePublic, event.JoinRuleRestricted:
addFromInviteLinkAccess = signalmeow.AccessControl_ANY
default:
log.Debug().Msg("unknown join rule")
addFromInviteLinkAccess = signalmeow.AccessControl_UNSATISFIABLE
}
return addFromInviteLinkAccess
}

func (s *SignalClient) HandleMatrixJoinRules(ctx context.Context, msg *bridgev2.MatrixJoinRule) (bool, error) {
log := zerolog.Ctx(ctx).With().
Str("From JoinRule", string(msg.PrevContent.JoinRule)).
Str("To JoinRule", string(msg.Content.JoinRule)).
Logger()
if msg.Portal.RoomType == database.RoomTypeDM {
log.Info().Msg("Ignoring Join Rule Change for DM")
return false, nil
}
newAddFromInviteLinkAccess := joinRuleToAccessControl(ctx, msg.Content.JoinRule)
oldAddFromInviteLinkAccess := joinRuleToAccessControl(ctx, msg.PrevContent.JoinRule)
if newAddFromInviteLinkAccess == oldAddFromInviteLinkAccess {
log.Debug().Msg("join rule change does not hange access control")
return false, nil
}
gc := &signalmeow.GroupChange{ModifyAddFromInviteLinkAccess: &newAddFromInviteLinkAccess}
_, groupID, err := signalid.ParsePortalID(msg.Portal.ID)
if err != nil || groupID == "" {
return false, err
}
revision, err := s.Client.UpdateGroup(ctx, gc, groupID)
if err != nil {
return false, err
}
msg.Portal.Metadata.(*signalid.PortalMetadata).Revision = revision
return true, nil
}
Loading