github.com/status-im/status-go@v1.1.0/protocol/group_chat_invitation.go (about) 1 package protocol 2 3 import ( 4 "crypto/ecdsa" 5 "encoding/json" 6 "fmt" 7 8 "github.com/golang/protobuf/proto" 9 10 "github.com/status-im/status-go/eth-node/crypto" 11 "github.com/status-im/status-go/eth-node/types" 12 "github.com/status-im/status-go/protocol/protobuf" 13 ) 14 15 // Invitation represents a group chat invitation request from a user in the application layer, used for persistence, querying and 16 // signaling 17 type GroupChatInvitation struct { 18 *protobuf.GroupChatInvitation 19 20 // From is a public key of the author of the invitation request. 21 From string `json:"from,omitempty"` 22 23 // SigPubKey is the ecdsa encoded public key of the invitation author 24 SigPubKey *ecdsa.PublicKey `json:"-"` 25 } 26 27 func NewGroupChatInvitation() *GroupChatInvitation { 28 return &GroupChatInvitation{GroupChatInvitation: &protobuf.GroupChatInvitation{}} 29 } 30 31 // ID is the Keccak256() contatenation of From-ChatId 32 func (g *GroupChatInvitation) ID() string { 33 return types.EncodeHex(crypto.Keccak256([]byte(fmt.Sprintf("%s%s", g.From, g.ChatId)))) 34 } 35 36 // GetSigPubKey returns an ecdsa encoded public key 37 // this function is required to implement the ChatEntity interface 38 func (g *GroupChatInvitation) GetSigPubKey() *ecdsa.PublicKey { 39 return g.SigPubKey 40 } 41 42 // GetProtoBuf returns the struct's embedded protobuf struct 43 // this function is required to implement the ChatEntity interface 44 func (g *GroupChatInvitation) GetProtobuf() proto.Message { 45 return g.GroupChatInvitation 46 } 47 48 func (g *GroupChatInvitation) MarshalJSON() ([]byte, error) { 49 item := struct { 50 ID string `json:"id"` 51 ChatID string `json:"chatId,omitempty"` 52 From string `json:"from"` 53 IntroductionMessage string `json:"introductionMessage,omitempty"` 54 State protobuf.GroupChatInvitation_State `json:"state,omitempty"` 55 }{ 56 ID: g.ID(), 57 ChatID: g.ChatId, 58 From: g.From, 59 IntroductionMessage: g.IntroductionMessage, 60 State: g.State, 61 } 62 63 return json.Marshal(item) 64 }