Merge pull request #14 from status-im/expose_fields

Expose Channel and channel.PubKey as part of the message
This commit is contained in:
Adrià Cidre 2018-05-07 13:46:18 +02:00 committed by GitHub
commit 771747fd66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -177,6 +177,11 @@ func (c *Channel) removeSubscription(sub *Subscription) {
c.subscriptions = subs
}
// PubKey return the channel's associated publike key
func (c *Channel) PubKey() string {
return c.account.PubKey
}
func (c *Channel) pollMessages() (msg *Msg) {
res, err := shhGetFilterMessagesRequest(c.account.conn, []string{c.filterID})
if err != nil {
@ -189,6 +194,7 @@ func (c *Channel) pollMessages() (msg *Msg) {
for _, u := range vv {
msg, err = messageFromEnvelope(u)
if err == nil && supportedMessage(msg.Type) {
msg.Channel = c
msg.ChannelName = c.name
return
}

9
msg.go
View File

@ -52,10 +52,11 @@ func supportedMessage(msgType string) bool {
// Msg is a structure used by Subscribers and Publish().
type Msg struct {
From string `json:"from"`
ChannelName string `json:"channel"`
Raw string `json:"-"`
Type string `json:"-"`
From string `json:"from"`
ChannelName string `json:"channel"`
Channel *Channel `json:"-"`
Raw string `json:"-"`
Type string `json:"-"`
Properties interface{}
}