updated protobufs, added some helpers

This commit is contained in:
decanus
2019-07-09 17:21:01 -04:00
parent 859cef4fd8
commit f7faf94c40
4 changed files with 62 additions and 48 deletions

View File

@@ -2,8 +2,6 @@
package client
import (
"time"
"github.com/golang/protobuf/proto"
"github.com/status-im/dasy/protobuf"
mvds "github.com/status-im/mvds/node"
@@ -16,6 +14,8 @@ type Chat state.GroupID
// Client is the actual daisy client.
type Client struct {
node mvds.Node
lastMessage protobuf.MessageID
}
// Invite invites a peer to a chat.
@@ -44,23 +44,22 @@ func (c *Client) Ack(chat Chat, messageID []byte) {
}
// Post sends a message to a chat.
func (c *Client) Post(chat Chat, body []byte) {
c.send(chat, protobuf.Message_POST, body) // @todo
func (c *Client) Post(chat Chat, body []byte) error {
return c.send(chat, protobuf.Message_POST, body)
}
func (c *Client) send(chat Chat, t protobuf.Message_MessageType, body []byte) error {
msg := &protobuf.Message{
Clock: 0,
Timestamp: uint64(time.Now().Unix()), // @todo we may be able to take this from mvds
MessageType: protobuf.Message_MessageType(t),
Body: body,
MessageType: protobuf.Message_MessageType(t),
Body: body,
PreviousMessage: c.lastMessage[:],
}
// @todo sign
buf, err := proto.Marshal(msg)
if err != nil {
return err
return err
}
_, err = c.node.AppendMessage(state.GroupID(chat), buf)
@@ -68,5 +67,7 @@ func (c *Client) send(chat Chat, t protobuf.Message_MessageType, body []byte) er
return err
}
c.lastMessage = msg.ID()
return nil
}