display historic messages on chat2

This commit is contained in:
Richard Ramos 2021-04-12 14:03:58 -04:00
parent fa79f9a864
commit 38da4144f6
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
6 changed files with 35 additions and 28 deletions

View File

@ -5,5 +5,5 @@ go 1.15
require (
github.com/ethereum/go-ethereum v1.9.5
github.com/ipfs/go-log v1.0.5
github.com/status-im/go-waku v0.0.0-20210411234359-f9e7589ffdd9
github.com/status-im/go-waku v0.0.0-20210412175941-fa79f9a864bb
)

View File

@ -436,6 +436,8 @@ github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcncea
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
@ -597,6 +599,8 @@ github.com/status-im/go-waku v0.0.0-20210404170848-47752170e9df h1:wm5+68DGiRMvZ
github.com/status-im/go-waku v0.0.0-20210404170848-47752170e9df/go.mod h1:949jqEGfl0gWv8NMWJU5xhW0hSRJicDxYWQAZkJMsqQ=
github.com/status-im/go-waku v0.0.0-20210411234359-f9e7589ffdd9 h1:smFp8UIU5OYZuWNxyNfIKcCbP74NSqi6EqVmcqh6Zlo=
github.com/status-im/go-waku v0.0.0-20210411234359-f9e7589ffdd9/go.mod h1:2fHIqaNF8M8W/DQL5J3R9dXbrTLpOefvD5tbKSvoxBg=
github.com/status-im/go-waku v0.0.0-20210412175941-fa79f9a864bb h1:Nw2aNm6JgjHbCvIneCBP0Cju66mhVXfEP5VyfAK2TQk=
github.com/status-im/go-waku v0.0.0-20210412175941-fa79f9a864bb/go.mod h1:J+Pvtku93TXlU/X3CzLwD4C7bXUFVpIiF4iPQksbUBY=
github.com/status-im/go-wakurelay-pubsub v0.4.2 h1:F4UGcP80H0PGaeJ0mRMzA1Ux3DKYiyv/qu3bOR/efTg=
github.com/status-im/go-wakurelay-pubsub v0.4.2/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

View File

@ -89,20 +89,30 @@ func (cr *Chat) Publish(message string) error {
return err
}
func (cr *Chat) decodeMessage(wakumsg *protocol.WakuMessage) {
payload, err := node.DecodePayload(wakumsg, &node.KeyInfo{Kind: node.None})
if err != nil {
return
}
msg := &pb.Chat2Message{}
if err := proto.Unmarshal(payload.Data, msg); err != nil {
return
}
// send valid messages onto the Messages channel
cr.Messages <- msg
}
// readLoop pulls messages from the pubsub topic and pushes them onto the Messages channel.
func (cr *Chat) readLoop() {
for value := range cr.sub.C {
payload, err := node.DecodePayload(value.Message(), &node.KeyInfo{Kind: node.None})
if err != nil {
continue
}
msg := &pb.Chat2Message{}
if err := proto.Unmarshal(payload.Data, msg); err != nil {
continue
}
// send valid messages onto the Messages channel
cr.Messages <- msg
cr.decodeMessage(value.Message())
}
}
func (cr *Chat) displayMessages(messages []*protocol.WakuMessage) {
for _, msg := range messages {
cr.decodeMessage(msg)
}
}

View File

@ -10,6 +10,6 @@ require (
github.com/ipfs/go-log/v2 v2.1.1
github.com/libp2p/go-libp2p-core v0.8.5
github.com/rivo/tview v0.0.0-20210312174852-ae9464cc3598
github.com/status-im/go-waku v0.0.0-20210411234359-f9e7589ffdd9
github.com/status-im/go-waku v0.0.0-20210412175941-fa79f9a864bb
google.golang.org/protobuf v1.25.0
)

View File

@ -566,6 +566,8 @@ github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=

View File

@ -13,8 +13,6 @@ import (
"net"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/ethereum/go-ethereum/crypto"
@ -113,27 +111,20 @@ func main() {
ui.displayMessage("Connected to storenode: " + storenode)
}
// TODO: query historic messages
/*time.Sleep(300 * time.Millisecond)
time.Sleep(300 * time.Millisecond)
ui.displayMessage("Querying historic messages")
response, err := wakuNode.Query(DefaultContentTopic, true, 0)
if err != nil {
fmt.Println(err)
return
}*/
ui.displayMessage("Could not query storenode: " + err.Error())
} else {
chat.displayMessages(response.Messages)
}
}()
//draw the UI
if err = ui.Run(); err != nil {
printErr("error running text UI: %s", err)
}
// Wait for a SIGINT or SIGTERM signal
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
fmt.Println("\n\n\nReceived signal, shutting down...")
}
// Generates a random hex string with a length of n