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 20, 2024
1 parent 31a4522 commit 9364f1f
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions pkg/connector/groupinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,27 @@ func (s *SignalClient) groupChangeToChatInfoChange(ctx context.Context, rev uint
Membership: event.MembershipJoin,
})
}
bannedMembers := make(map[libsignalgo.ServiceID]bridgev2.ChatMember)
for _, member := range groupChange.AddBannedMembers {
aci := s.maybeResolvePNItoACI(ctx, &member.ServiceID)
if aci == nil {
continue
}
bannedMembers[member.ServiceID] = bridgev2.ChatMember{
EventSender: s.makeEventSender(*aci),
Membership: event.MembershipBan,
}
}
for _, memberACI := range groupChange.DeleteMembers {
membership := event.MembershipLeave
serviceID := libsignalgo.NewACIServiceID(*memberACI)
if _, ok := bannedMembers[serviceID]; ok {
membership = event.MembershipBan
delete(bannedMembers, serviceID)
}
mc = append(mc, bridgev2.ChatMember{
EventSender: s.makeEventSender(*memberACI),
Membership: event.MembershipLeave,
Membership: membership,
PrevMembership: event.MembershipJoin,
})
}
Expand All @@ -261,9 +278,14 @@ func (s *SignalClient) groupChangeToChatInfoChange(ctx context.Context, rev uint
if aci == nil {
continue
}
membership := event.MembershipLeave
if _, ok := bannedMembers[*memberServiceID]; ok {
membership = event.MembershipBan
delete(bannedMembers, *memberServiceID)
}
mc = append(mc, bridgev2.ChatMember{
EventSender: s.makeEventSender(*aci),
Membership: event.MembershipLeave,
Membership: membership,
PrevMembership: event.MembershipInvite,
})
}
Expand All @@ -274,21 +296,20 @@ func (s *SignalClient) groupChangeToChatInfoChange(ctx context.Context, rev uint
})
}
for _, memberACI := range groupChange.DeleteRequestingMembers {
membership := event.MembershipLeave
serviceID := libsignalgo.NewACIServiceID(*memberACI)
if _, ok := bannedMembers[serviceID]; ok {
membership = event.MembershipBan
delete(bannedMembers, serviceID)
}
mc = append(mc, bridgev2.ChatMember{
EventSender: s.makeEventSender(*memberACI),
Membership: event.MembershipLeave,
Membership: membership,
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 _, chatMember := range bannedMembers {
mc = append(mc, chatMember)
}
for _, memberServiceID := range groupChange.DeleteBannedMembers {
aci := s.maybeResolvePNItoACI(ctx, memberServiceID)
Expand Down

0 comments on commit 9364f1f

Please sign in to comment.