From 693e8c3464a2017199228f9f9818000fbb8d0193 Mon Sep 17 00:00:00 2001 From: Malte E Date: Wed, 21 Aug 2024 20:24:58 +0200 Subject: [PATCH] Skip unnecessary membership changes when banning --- pkg/connector/groupinfo.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/pkg/connector/groupinfo.go b/pkg/connector/groupinfo.go index d0ecdd49..843a18ec 100644 --- a/pkg/connector/groupinfo.go +++ b/pkg/connector/groupinfo.go @@ -238,7 +238,22 @@ func (s *SignalClient) groupChangeToChatInfoChange(ctx context.Context, rev uint Membership: event.MembershipJoin, }) } + bannedMembers := make(map[libsignalgo.ServiceID]bool) + for _, member := range groupChange.AddBannedMembers { + aci := s.maybeResolvePNItoACI(ctx, &member.ServiceID) + if aci == nil { + continue + } + bannedMembers[member.ServiceID] = true + mc = append(mc, bridgev2.ChatMember{ + EventSender: s.makeEventSender(*aci), + Membership: event.MembershipBan, + }) + } for _, memberACI := range groupChange.DeleteMembers { + if bannedMembers[libsignalgo.NewACIServiceID(*memberACI)] { + continue + } mc = append(mc, bridgev2.ChatMember{ EventSender: s.makeEventSender(*memberACI), Membership: event.MembershipLeave, @@ -257,6 +272,9 @@ func (s *SignalClient) groupChangeToChatInfoChange(ctx context.Context, rev uint }) } for _, memberServiceID := range groupChange.DeletePendingMembers { + if bannedMembers[*memberServiceID] { + continue + } aci := s.maybeResolvePNItoACI(ctx, memberServiceID) if aci == nil { continue @@ -274,22 +292,15 @@ func (s *SignalClient) groupChangeToChatInfoChange(ctx context.Context, rev uint }) } for _, memberACI := range groupChange.DeleteRequestingMembers { + if bannedMembers[libsignalgo.NewACIServiceID(*memberACI)] { + continue + } mc = append(mc, bridgev2.ChatMember{ EventSender: s.makeEventSender(*memberACI), Membership: event.MembershipLeave, PrevMembership: event.MembershipKnock, }) } - for _, member := range groupChange.AddBannedMembers { - aci := s.maybeResolvePNItoACI(ctx, &member.ServiceID) - if aci == nil { - continue - } - mc = append(mc, bridgev2.ChatMember{ - EventSender: s.makeEventSender(*aci), - Membership: event.MembershipBan, - }) - } for _, memberServiceID := range groupChange.DeleteBannedMembers { aci := s.maybeResolvePNItoACI(ctx, memberServiceID) if aci == nil {