chat2: Query message integrated

This commit is contained in:
Oskar Thoren 2021-06-10 19:36:00 +08:00
parent e44e3414f2
commit 3d0e3d5625
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
2 changed files with 12 additions and 9 deletions

View File

@ -14,7 +14,7 @@ import (
wpb "github.com/status-im/go-waku/waku/v2/protocol/pb"
"golang.org/x/crypto/pbkdf2"
// "github.com/status-im/go-nwaku/nwaku"
"github.com/status-im/go-nwaku/nwaku"
)
// Chat represents a subscription to a single PubSub topic. Messages
@ -117,7 +117,7 @@ func (cr *Chat) Publish(ctx context.Context, message string) error {
return err
}
func (cr *Chat) decodeMessage(wakumsg *wpb.WakuMessage) {
func (cr *Chat) decodeMessage(wakumsg nwaku.WakuMessage) {
var keyInfo *node.KeyInfo = &node.KeyInfo{}
if cr.useV1Payload { // Use WakuV1 encryption
keyInfo.Kind = node.Symmetric
@ -126,13 +126,10 @@ func (cr *Chat) decodeMessage(wakumsg *wpb.WakuMessage) {
keyInfo.Kind = node.None
}
payload, err := node.DecodePayload(wakumsg, keyInfo)
if err != nil {
return
}
var payload = wakumsg.Payload
msg := &pb.Chat2Message{}
if err := proto.Unmarshal(payload.Data, msg); err != nil {
if err := proto.Unmarshal(payload, msg); err != nil {
return
}
@ -148,7 +145,7 @@ func (cr *Chat) readLoop() {
// }
}
func (cr *Chat) displayMessages(messages []*wpb.WakuMessage) {
func (cr *Chat) displayMessages(messages []nwaku.WakuMessage) {
for _, msg := range messages {
cr.decodeMessage(msg)
}

View File

@ -23,7 +23,7 @@ import (
// "github.com/status-im/go-waku/waku/v2/node"
// "github.com/status-im/go-waku/waku/v2/protocol/store"
"github.com/ethereum/go-ethereum/rpc"
//"github.com/status-im/go-nwaku/nwaku"
"github.com/status-im/go-nwaku/nwaku"
)
var DefaultContentTopic string = "/toy-chat/2/huilong/proto"
@ -158,6 +158,12 @@ func main() {
// store.WithPeer(*storeNodeId),
// store.WithPaging(true, 0))
// Query messages
// TODO Error handling, e.g. if no store peer
var contentTopic = "/toy-chat/2/huilong/proto"
var response = nwaku.GetWakuStoreMessages(client, contentTopic)
chat.displayMessages(response.Messages)
// if err != nil {
// ui.displayMessage("Could not query storenode: " + err.Error())
// } else {