Skip to content

Commit

Permalink
Skip unnecessary membership changes when banning
Browse files Browse the repository at this point in the history
  • Loading branch information
maltee1 committed Aug 21, 2024
1 parent 31a4522 commit 693e8c3
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions pkg/connector/groupinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 693e8c3

Please sign in to comment.