Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maltee1 committed Aug 8, 2024
1 parent 12b153e commit aec8c02
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ require (

//replace maunium.net/go/mautrix => ../mautrix-go
//replace go.mau.fi/util => ../../Go/go-util
replace maunium.net/go/mautrix => github.com/maltee1/mautrix-go v0.0.0-20240808193435-264b3853ebfc
replace maunium.net/go/mautrix => github.com/maltee1/mautrix-go v0.0.0-20240808204140-9598e29d1124
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +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-20240808193435-264b3853ebfc h1:Ct/HVKLCGXt3yvj+JbG8ccXJgI/kNr/ZoTsNQL6xRR8=
github.com/maltee1/mautrix-go v0.0.0-20240808193435-264b3853ebfc/go.mod h1:ZWyxoQxRTBxzWIMs0kQCVogZIY0clTu33h102veCT/Q=
github.com/maltee1/mautrix-go v0.0.0-20240808204140-9598e29d1124 h1:zgSOHfcfq6NXuHL+mo/IexMGksBmrZcVyPjipTjEILc=
github.com/maltee1/mautrix-go v0.0.0-20240808204140-9598e29d1124/go.mod h1:ZWyxoQxRTBxzWIMs0kQCVogZIY0clTu33h102veCT/Q=
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
32 changes: 21 additions & 11 deletions pkg/connector/handlematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,7 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2
}
gc := &signalmeow.GroupChange{}
role := signalmeow.GroupMember_DEFAULT
toMembership := msg.Type.GetTo()
if toMembership == event.MembershipBan {
gc.AddBannedMembers = []*signalmeow.BannedMember{{
ServiceID: libsignalgo.NewACIServiceID(targetSignalID),
Timestamp: uint64(time.Now().UnixMilli()),
}}
}
if toMembership == event.MembershipInvite || msg.Type == bridgev2.AcceptKnock {
if msg.Type.To == event.MembershipInvite || msg.Type == bridgev2.AcceptKnock {
levels, err := msg.Portal.Bridge.Matrix.GetPowerLevels(ctx, msg.Portal.MXID)
if err != nil {
log.Err(err).Msg("Couldn't get power levels")
Expand All @@ -391,10 +384,10 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2
}
switch msg.Type {
case bridgev2.AcceptInvite:
gc.PromotePendingMembers = []*signalmeow.PromotePendingMember{&signalmeow.PromotePendingMember{
gc.PromotePendingMembers = []*signalmeow.PromotePendingMember{{
ACI: targetSignalID,
}}
case bridgev2.RevokeInvite, bridgev2.RejectInvite, bridgev2.BanInvited:
case bridgev2.RevokeInvite, bridgev2.RejectInvite:
deletePendingMember := libsignalgo.NewACIServiceID(targetSignalID)
gc.DeletePendingMembers = []*libsignalgo.ServiceID{&deletePendingMember}
case bridgev2.Leave, bridgev2.Kick:
Expand Down Expand Up @@ -426,11 +419,28 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2
ACI: targetSignalID,
Role: role,
}}
case bridgev2.RetractKnock, bridgev2.RejectKnock, bridgev2.BanKnocked:
case bridgev2.RetractKnock, bridgev2.RejectKnock:
gc.DeleteRequestingMembers = []*uuid.UUID{&targetSignalID}
case bridgev2.BanKnocked, bridgev2.BanInvited, bridgev2.BanJoined, bridgev2.Ban:
gc.AddBannedMembers = []*signalmeow.BannedMember{{
ServiceID: libsignalgo.NewACIServiceID(targetSignalID),
Timestamp: uint64(time.Now().UnixMilli()),
}}
switch msg.Type {
case bridgev2.BanJoined:
gc.DeleteMembers = []*uuid.UUID{&targetSignalID}
case bridgev2.BanInvited:
deletePendingMember := libsignalgo.NewACIServiceID(targetSignalID)
gc.DeletePendingMembers = []*libsignalgo.ServiceID{&deletePendingMember}
case bridgev2.BanKnocked:
gc.DeleteRequestingMembers = []*uuid.UUID{&targetSignalID}
}
case bridgev2.Unban:
unbanUser := libsignalgo.NewACIServiceID(targetSignalID)
gc.DeleteBannedMembers = []*libsignalgo.ServiceID{&unbanUser}
default:
log.Debug().Msg("unsupported membership change")
return false, nil
}
_, groupID, err := signalid.ParsePortalID(msg.Portal.ID)
if err != nil || groupID == "" {
Expand Down
7 changes: 2 additions & 5 deletions pkg/signalid/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ func ParseUserID(userID networkid.UserID) (uuid.UUID, error) {
}

func ParseUserLoginID(userLoginID networkid.UserLoginID) (uuid.UUID, error) {
serviceID, err := ParseUserLoginIDAsServiceID(userLoginID)
userID, err := ParseUserLoginID(userLoginID)
if err != nil {
return uuid.Nil, err
} else if serviceID.Type != libsignalgo.ServiceIDTypeACI {
return uuid.Nil, fmt.Errorf("invalid user ID: expected ACI type")
} else {
return serviceID.UUID, nil
}
return userID, nil
}

func ParseUserIDAsServiceID(userID networkid.UserID) (libsignalgo.ServiceID, error) {
Expand Down

0 comments on commit aec8c02

Please sign in to comment.