forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_contact.go
48 lines (37 loc) · 1.49 KB
/
api_contact.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package bertyprotocol
import (
"context"
"berty.tech/berty/v2/go/pkg/bertytypes"
"berty.tech/berty/v2/go/pkg/errcode"
"github.com/libp2p/go-libp2p-core/crypto"
)
func (s *service) ContactAliasKeySend(ctx context.Context, req *bertytypes.ContactAliasKeySend_Request) (*bertytypes.ContactAliasKeySend_Reply, error) {
g, err := s.getContextGroupForID(req.GroupPK)
if err != nil {
return nil, errcode.ErrGroupMissing.Wrap(err)
}
if _, err := g.MetadataStore().ContactSendAliasKey(ctx); err != nil {
return nil, errcode.ErrOrbitDBAppend.Wrap(err)
}
return &bertytypes.ContactAliasKeySend_Reply{}, nil
}
func (s *service) ContactBlock(ctx context.Context, req *bertytypes.ContactBlock_Request) (*bertytypes.ContactBlock_Reply, error) {
pk, err := crypto.UnmarshalEd25519PublicKey(req.ContactPK)
if err != nil {
return nil, errcode.ErrDeserialization.Wrap(err)
}
if _, err := s.accountGroup.MetadataStore().ContactBlock(ctx, pk); err != nil {
return nil, errcode.ErrOrbitDBAppend.Wrap(err)
}
return &bertytypes.ContactBlock_Reply{}, nil
}
func (s *service) ContactUnblock(ctx context.Context, req *bertytypes.ContactUnblock_Request) (*bertytypes.ContactUnblock_Reply, error) {
pk, err := crypto.UnmarshalEd25519PublicKey(req.ContactPK)
if err != nil {
return nil, errcode.ErrDeserialization.Wrap(err)
}
if _, err := s.accountGroup.MetadataStore().ContactUnblock(ctx, pk); err != nil {
return nil, errcode.ErrOrbitDBAppend.Wrap(err)
}
return &bertytypes.ContactUnblock_Reply{}, nil
}