Skip to content

Commit

Permalink
function instead of boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
Malte committed Aug 9, 2024
1 parent 3dca57a commit 2a11a90
Showing 1 changed file with 30 additions and 53 deletions.
83 changes: 30 additions & 53 deletions pkg/connector/groupinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,12 @@ func (s *SignalClient) getGroupInfo(ctx context.Context, groupID types.GroupIden
}
}
for _, member := range groupInfo.PendingMembers {
var aci uuid.UUID
if member.ServiceID.Type == libsignalgo.ServiceIDTypePNI {
device, err := s.Client.Store.DeviceStore.DeviceByPNI(ctx, member.ServiceID.UUID)
if err != nil || device == nil {
continue
}
aci = device.ACI
} else {
aci = member.ServiceID.UUID
aci := maybeResolvePNItoACI(member.ServiceID)

Check failure on line 124 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

undefined: maybeResolvePNItoACI

Check failure on line 124 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

undefined: maybeResolvePNItoACI

Check failure on line 124 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

undefined: maybeResolvePNItoACI

Check failure on line 124 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

undefined: maybeResolvePNItoACI
if aci == nil {
continue
}
members.Members = append(members.Members, bridgev2.ChatMember{
EventSender: s.makeEventSender(aci),
EventSender: s.makeEventSender(*aci),
PowerLevel: roleToPL(member.Role),
Membership: event.MembershipInvite,
})
Expand All @@ -144,18 +138,12 @@ func (s *SignalClient) getGroupInfo(ctx context.Context, groupID types.GroupIden
})
}
for _, member := range groupInfo.BannedMembers {
var aci uuid.UUID
if member.ServiceID.Type == libsignalgo.ServiceIDTypePNI {
device, err := s.Client.Store.DeviceStore.DeviceByPNI(ctx, member.ServiceID.UUID)
if err != nil || device == nil {
continue
}
aci = device.ACI
} else {
aci = member.ServiceID.UUID
aci := maybeResolvePNItoACI(member.ServiceID)

Check failure on line 141 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

undefined: maybeResolvePNItoACI

Check failure on line 141 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

undefined: maybeResolvePNItoACI

Check failure on line 141 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

undefined: maybeResolvePNItoACI

Check failure on line 141 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

undefined: maybeResolvePNItoACI
if aci == nil {
continue
}
members.Members = append(members.Members, bridgev2.ChatMember{
EventSender: s.makeEventSender(aci),
EventSender: s.makeEventSender(*aci),
Membership: event.MembershipBan,
})
}
Expand Down Expand Up @@ -258,39 +246,23 @@ func (s *SignalClient) groupChangeToChatInfoChange(ctx context.Context, rev uint
})
}
for _, member := range groupChange.AddPendingMembers {
if member.ServiceID.Type != libsignalgo.ServiceIDTypeACI {
aci := maybeResolvePNItoACI(member.ServiceID)

Check failure on line 249 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

undefined: maybeResolvePNItoACI

Check failure on line 249 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

undefined: maybeResolvePNItoACI

Check failure on line 249 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

undefined: maybeResolvePNItoACI

Check failure on line 249 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

undefined: maybeResolvePNItoACI
if aci == nil {
continue
}
var aci uuid.UUID
if member.ServiceID.Type == libsignalgo.ServiceIDTypePNI {
device, err := s.Client.Store.DeviceStore.DeviceByPNI(ctx, member.ServiceID.UUID)
if err != nil || device == nil {
continue
}
aci = device.ACI
} else {
aci = member.ServiceID.UUID
}

mc = append(mc, bridgev2.ChatMember{
EventSender: s.makeEventSender(aci),
EventSender: s.makeEventSender(*aci),
PowerLevel: roleToPL(member.Role),
Membership: event.MembershipInvite,
})
}
for _, memberServiceID := range groupChange.DeletePendingMembers {

Check failure on line 259 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

memberServiceID declared and not used

Check failure on line 259 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

memberServiceID declared and not used

Check failure on line 259 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

memberServiceID declared and not used

Check failure on line 259 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

memberServiceID declared and not used
var aci uuid.UUID
if memberServiceID.Type == libsignalgo.ServiceIDTypePNI {
device, err := s.Client.Store.DeviceStore.DeviceByPNI(ctx, memberServiceID.UUID)
if err != nil || device == nil {
continue
}
aci = device.ACI
} else {
aci = memberServiceID.UUID
aci := maybeResolvePNItoACI(member.ServiceID)

Check failure on line 260 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

undefined: maybeResolvePNItoACI

Check failure on line 260 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

undefined: member

Check failure on line 260 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

undefined: maybeResolvePNItoACI

Check failure on line 260 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

undefined: member

Check failure on line 260 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

undefined: maybeResolvePNItoACI

Check failure on line 260 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

undefined: member

Check failure on line 260 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

undefined: maybeResolvePNItoACI

Check failure on line 260 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

undefined: member
if aci == nil {
continue
}
mc = append(mc, bridgev2.ChatMember{
EventSender: s.makeEventSender(aci),
EventSender: s.makeEventSender(*aci),
Membership: event.MembershipLeave,
PrevMembership: event.MembershipInvite,
})
Expand All @@ -309,18 +281,12 @@ func (s *SignalClient) groupChangeToChatInfoChange(ctx context.Context, rev uint
})
}
for _, member := range groupChange.AddBannedMembers {

Check failure on line 283 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

member declared and not used

Check failure on line 283 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

member declared and not used

Check failure on line 283 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

member declared and not used

Check failure on line 283 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

member declared and not used
var aci uuid.UUID
if member.ServiceID.Type == libsignalgo.ServiceIDTypePNI {
device, err := s.Client.Store.DeviceStore.DeviceByPNI(ctx, member.ServiceID.UUID)
if err != nil || device == nil {
continue
}
aci = device.ACI
} else {
aci = member.ServiceID.UUID
aci := maybeResolvePNItoACI(memberServiceID)

Check failure on line 284 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

undefined: maybeResolvePNItoACI

Check failure on line 284 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

undefined: memberServiceID

Check failure on line 284 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

undefined: maybeResolvePNItoACI

Check failure on line 284 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

undefined: memberServiceID

Check failure on line 284 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

undefined: maybeResolvePNItoACI

Check failure on line 284 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

undefined: memberServiceID

Check failure on line 284 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

undefined: maybeResolvePNItoACI

Check failure on line 284 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

undefined: memberServiceID
if aci == nil {
continue
}
mc = append(mc, bridgev2.ChatMember{
EventSender: s.makeEventSender(aci),
EventSender: s.makeEventSender(*aci),
Membership: event.MembershipBan,
})
}
Expand All @@ -340,6 +306,17 @@ func (s *SignalClient) groupChangeToChatInfoChange(ctx context.Context, rev uint
return ic
}

func (s *SignalClient) maybeResolvePNItoACI(serviceID libsignalgo.ServiceID) *uuid.UUID {
if serviceID.Type == libsignalgo.ServiceIDTypeACI {
return &serviceID.UUID
}
device, err := s.Client.Store.DeviceStore.DeviceByPNI(ctx, serviceID.UUID)

Check failure on line 313 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (old)

undefined: ctx

Check failure on line 313 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (old)

undefined: ctx

Check failure on line 313 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Test (latest)

undefined: ctx

Check failure on line 313 in pkg/connector/groupinfo.go

View workflow job for this annotation

GitHub Actions / Lint (latest)

undefined: ctx
if err != nil || device == nil {
return nil
}
return &device.ACI
}

func (s *SignalClient) catchUpGroup(ctx context.Context, portal *bridgev2.Portal, fromRevision, toRevision uint32, ts uint64) {
if fromRevision >= toRevision {
return
Expand Down

0 comments on commit 2a11a90

Please sign in to comment.