-
Notifications
You must be signed in to change notification settings - Fork 246
/
request_to_join.go
59 lines (50 loc) · 1.65 KB
/
request_to_join.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 communities
import (
"fmt"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/protobuf"
)
type RequestToJoinState uint
const (
RequestToJoinStatePending RequestToJoinState = iota + 1
RequestToJoinStateDeclined
RequestToJoinStateAccepted
)
type RequestToJoin struct {
ID types.HexBytes `json:"id"`
PublicKey string `json:"publicKey"`
Clock uint64 `json:"clock"`
ENSName string `json:"ensName,omitempty"`
ChatID string `json:"chatId"`
CommunityID types.HexBytes `json:"communityId"`
State RequestToJoinState `json:"state"`
Our bool `json:"our"`
}
func (r *RequestToJoin) CalculateID() {
idString := fmt.Sprintf("%s-%s", r.PublicKey, r.CommunityID)
r.ID = crypto.Keccak256([]byte(idString))
}
func (r *RequestToJoin) ToSyncProtobuf() *protobuf.SyncCommunityRequestsToJoin {
return &protobuf.SyncCommunityRequestsToJoin{
Id: r.ID,
PublicKey: r.PublicKey,
Clock: r.Clock,
EnsName: r.ENSName,
ChatId: r.ChatID,
CommunityId: r.CommunityID,
State: uint64(r.State),
}
}
func (r *RequestToJoin) InitFromSyncProtobuf(proto *protobuf.SyncCommunityRequestsToJoin) {
r.ID = proto.Id
r.PublicKey = proto.PublicKey
r.Clock = proto.Clock
r.ENSName = proto.EnsName
r.ChatID = proto.ChatId
r.CommunityID = proto.CommunityId
r.State = RequestToJoinState(proto.State)
}
func (r *RequestToJoin) Empty() bool {
return len(r.ID)+len(r.PublicKey)+int(r.Clock)+len(r.ENSName)+len(r.ChatID)+len(r.CommunityID)+int(r.State) == 0
}