-
Notifications
You must be signed in to change notification settings - Fork 381
/
api_contact.go
59 lines (44 loc) · 1.91 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
49
50
51
52
53
54
55
56
57
58
59
package bertyprotocol
import (
"context"
"github.com/libp2p/go-libp2p-core/crypto"
"berty.tech/berty/v2/go/pkg/errcode"
"berty.tech/berty/v2/go/pkg/protocoltypes"
"berty.tech/berty/v2/go/pkg/tyber"
)
func (s *service) ContactAliasKeySend(ctx context.Context, req *protocoltypes.ContactAliasKeySend_Request) (_ *protocoltypes.ContactAliasKeySend_Reply, err error) {
ctx, _, endSection := tyber.Section(ctx, s.logger, "Sending contact alias key")
defer func() { endSection(err, "") }()
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 &protocoltypes.ContactAliasKeySend_Reply{}, nil
}
func (s *service) ContactBlock(ctx context.Context, req *protocoltypes.ContactBlock_Request) (_ *protocoltypes.ContactBlock_Reply, err error) {
ctx, _, endSection := tyber.Section(ctx, s.logger, "Blocking contact")
defer func() { endSection(err, "") }()
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 &protocoltypes.ContactBlock_Reply{}, nil
}
func (s *service) ContactUnblock(ctx context.Context, req *protocoltypes.ContactUnblock_Request) (_ *protocoltypes.ContactUnblock_Reply, err error) {
ctx, _, endSection := tyber.Section(ctx, s.logger, "Unblocking contact")
defer func() { endSection(err, "") }()
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 &protocoltypes.ContactUnblock_Reply{}, nil
}