mirror of
https://github.com/vacp2p/dasy.git
synced 2026-01-09 14:58:06 -05:00
updated protobufs, added some helpers
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user