From e5ed24932a9c68db00255b89f9441697fb7f386f Mon Sep 17 00:00:00 2001 From: Oskar Thoren Date: Wed, 10 Apr 2019 15:16:25 +0800 Subject: [PATCH] Post to feed when posting message --- hello-pss/hello_pss.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/hello-pss/hello_pss.go b/hello-pss/hello_pss.go index bef9c9a..928b25c 100644 --- a/hello-pss/hello_pss.go +++ b/hello-pss/hello_pss.go @@ -114,11 +114,8 @@ func listenForMessages(msgC chan pss.APIMsg) { } } -// XXX: Lame signature, should be may more compact -func runREPL(client *rpc.Client, signer *feed.GenericSigner, receiver string, topic string) { - fmt.Println("I am Alice, and I am ready to send messages.") - - // TODO: Move this to separate function +// TODO: Error handling if fail +func postToFeed(client *rpc.Client, signer *feed.GenericSigner, receiver string, topic string) { // For creating manifest, then posting, then finally getting // Create a new feed with user and topic. @@ -156,10 +153,12 @@ func runREPL(client *rpc.Client, signer *feed.GenericSigner, receiver string, to err = httpClient.UpdateFeed(request) if err != nil { fmt.Printf("Error updating feed: %s", err.Error()) - } - + } +} - // REPL resume +// XXX: Lame signature, should be may more compact +func runREPL(client *rpc.Client, signer *feed.GenericSigner, receiver string, topic string) { + fmt.Println("I am Alice, and I am ready to send messages.") fmt.Printf("> ") // Basic REPL functionality @@ -167,7 +166,7 @@ func runREPL(client *rpc.Client, signer *feed.GenericSigner, receiver string, to for scanner.Scan() { input := scanner.Text() //sendMessage(input) - sendMessage(client, receiver, topic, input) + sendMessage(client, signer, receiver, topic, input) fmt.Printf("> ") } if err := scanner.Err(); err != nil { @@ -352,13 +351,18 @@ func init() { } // XXX: Ensure signature, also probably better with client as context but meh -func sendMessage(client *rpc.Client, receiver string, topic string, input string) { +func sendMessage(client *rpc.Client, signer *feed.GenericSigner, receiver string, topic string, input string) { //fmt.Println("Input:", input) err := client.Call(nil, "pss_sendAsym", receiver, topic, common.ToHex([]byte(input))) if err != nil { fmt.Println("Error sending message through RPC client", err) os.Exit(1) } + + // Also post to feed + // XXX: Currently hardcoded to plaintext name, could be hash of two pubkeys e.g. + // TODO: If any errors with this, show this + postToFeed(client, signer, receiver, topic) } func main() {