|
6 | 6 | "encoding/base64" |
7 | 7 | "fmt" |
8 | 8 | "io" |
| 9 | + "slices" |
9 | 10 | "strings" |
10 | 11 |
|
11 | 12 | coreiface "github.com/ipfs/kubo/core/coreiface" |
@@ -427,13 +428,7 @@ func (m *MetadataStore) ListContactsByStatus(states ...protocoltypes.ContactStat |
427 | 428 | contacts := []*protocoltypes.ShareableContact(nil) |
428 | 429 |
|
429 | 430 | for _, c := range idx.contacts { |
430 | | - hasState := false |
431 | | - for _, s := range states { |
432 | | - if c.state == s { |
433 | | - hasState = true |
434 | | - break |
435 | | - } |
436 | | - } |
| 431 | + hasState := slices.Contains(states, c.state) |
437 | 432 |
|
438 | 433 | if hasState { |
439 | 434 | contacts = append(contacts, c.contact) |
@@ -876,13 +871,7 @@ func (m *MetadataStore) getContactStatus(pk crypto.PubKey) protocoltypes.Contact |
876 | 871 | func (m *MetadataStore) checkContactStatus(pk crypto.PubKey, states ...protocoltypes.ContactState) bool { |
877 | 872 | contactStatus := m.getContactStatus(pk) |
878 | 873 |
|
879 | | - for _, s := range states { |
880 | | - if contactStatus == s { |
881 | | - return true |
882 | | - } |
883 | | - } |
884 | | - |
885 | | - return false |
| 874 | + return slices.Contains(states, contactStatus) |
886 | 875 | } |
887 | 876 |
|
888 | 877 | type EventMetadataReceived struct { |
@@ -1027,19 +1016,19 @@ func constructorFactoryGroupMetadata(s *WeshOrbitDB, logger *zap.Logger) iface.S |
1027 | 1016 |
|
1028 | 1017 | func (m *MetadataStore) initEmitter() (err error) { |
1029 | 1018 | if m.emitters.metadataReceived, err = m.eventBus.Emitter(new(EventMetadataReceived)); err != nil { |
1030 | | - return |
| 1019 | + return err |
1031 | 1020 | } |
1032 | 1021 |
|
1033 | 1022 | if m.emitters.groupMetadata, err = m.eventBus.Emitter(new(*protocoltypes.GroupMetadataEvent)); err != nil { |
1034 | | - return |
| 1023 | + return err |
1035 | 1024 | } |
1036 | 1025 |
|
1037 | | - return |
| 1026 | + return err |
1038 | 1027 | } |
1039 | 1028 |
|
1040 | 1029 | func genNewSeed() (seed []byte, err error) { |
1041 | 1030 | seed, err = io.ReadAll(io.LimitReader(crand.Reader, protocoltypes.RendezvousSeedLength)) |
1042 | | - return |
| 1031 | + return seed, err |
1043 | 1032 | } |
1044 | 1033 |
|
1045 | 1034 | func (m *MetadataStore) Close() error { |
|
0 commit comments