Skip to content

Commit

Permalink
bridge permissions S->M
Browse files Browse the repository at this point in the history
  • Loading branch information
maltee1 committed Jan 31, 2024
1 parent 2d1ae2e commit 27f5ff6
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,8 @@ func (portal *Portal) handleSignalGroupChange(source *User, sender *Puppet, grou
}
}
for _, promoteRequestingMember := range groupChange.PromoteRequestingMembers {
puppet := portal.bridge.GetPuppetBySignalID(promoteRequestingMember.UserID)
if puppet != nil {
puppet, err := portal.sendMembershipForPuppetAndUser(ctx, sender, promoteRequestingMember.UserID, event.MembershipInvite, "accepted")
if err == nil {
err = puppet.IntentFor(portal).EnsureJoined(ctx, portal.MXID)
if err != nil {
log.Warn().Stringer("signal_user_id", promoteRequestingMember.UserID).Msg("failed to join puppet")
Expand Down Expand Up @@ -1030,7 +1030,51 @@ func (portal *Portal) handleSignalGroupChange(source *User, sender *Puppet, grou
log.Err(err).Msg("Changing power level failed")
}
}
// TODO: Join Rules/AccessControl
if groupChange.ModifyAttributesAccess != nil || groupChange.ModifyAnnouncementsOnly != nil || groupChange.ModifyMemberAccess != nil {
levels, err := portal.MainIntent().PowerLevels(ctx, portal.MXID)
if err != nil {
log.Err(err).Msg("Couldn't get power levels")
} else {
if groupChange.ModifyAnnouncementsOnly != nil {
levels.EventsDefault = 0
if *groupChange.ModifyAnnouncementsOnly {
levels.EventsDefault = 50
}
}
if groupChange.ModifyAttributesAccess != nil {
level := 0
if *groupChange.ModifyAttributesAccess == signalmeow.AccessControl_ADMINISTRATOR {
level = 50
}
levels.EnsureEventLevel(event.StateRoomName, level)
levels.EnsureEventLevel(event.StateTopic, level)
levels.EnsureEventLevel(event.StateRoomAvatar, level)
}
if groupChange.ModifyMemberAccess != nil {
level := 0
if *groupChange.ModifyMemberAccess == signalmeow.AccessControl_ADMINISTRATOR {
level = 50
}
levels.InvitePtr = &level
}
_, err = intent.SetPowerLevels(ctx, portal.MXID, levels)
if errors.Is(err, mautrix.MForbidden) {
_, err = portal.MainIntent().SetPowerLevels(ctx, portal.MXID, levels)
}
if err != nil {
log.Err(err).Msg("Couldn't set power levels")
}
}
}
// TODO: join rules
// if groupChange.ModifyAddFromInviteLinkAccess != nil {
// joinRule := event.JoinRuleInvite
// if *groupChange.ModifyAddFromInviteLinkAccess == signalmeow.AccessControl_ADMINISTRATOR {
// joinRule = event.JoinRuleKnock
// } else if *groupChange.ModifyAddFromInviteLinkAccess == signalmeow.AccessControl_ANY && portal.bridge.Config.Bridge.PublicPortals {
// joinRule = event.JoinRulePublic
// }
// }
}

func (portal *Portal) sendMembershipForPuppetAndUser(ctx context.Context, sender *Puppet, target uuid.UUID, membership event.Membership, action string) (puppet *Puppet, err error) {
Expand Down

0 comments on commit 27f5ff6

Please sign in to comment.