using mvds id

This commit is contained in:
decanus
2019-07-12 12:54:41 -04:00
parent 8bf8e755f2
commit 23e616bc9b
2 changed files with 4 additions and 26 deletions

View File

@@ -18,7 +18,7 @@ type Peer state.PeerID
type Client struct {
node mvds.Node
lastMessage protobuf.MessageID
lastMessage state.MessageID // @todo maybe make type
}
// Invite invites a peer to a chat.
@@ -43,7 +43,7 @@ func (c *Client) Kick(chat Chat, peer Peer) {
// We may not need this as we can rely on the acks of data sync
// Ack acknowledges `Join`, `Leave` and `Kick` messages.
func (c *Client) Ack(chat Chat, messageID protobuf.MessageID) {
func (c *Client) Ack(chat Chat, messageID state.MessageID) {
}
@@ -66,12 +66,12 @@ func (c *Client) send(chat Chat, t protobuf.Message_MessageType, body []byte) er
return err
}
_, err = c.node.AppendMessage(state.GroupID(chat), buf)
id, err := c.node.AppendMessage(state.GroupID(chat), buf)
if err != nil {
return err
}
c.lastMessage = msg.ID()
c.lastMessage = id
return nil
}

View File

@@ -1,22 +0,0 @@
// Package protobuf contains protocol buffers as well as helper functions for those buffers.
package protobuf
import (
"crypto/sha256"
"encoding/binary"
)
// MessageID is a hash of `message_type`, `body` & `previous_message`.
type MessageID [32]byte
// ID returns the message ID.
func (m *Message) ID() MessageID {
t := make([]byte, 8)
binary.LittleEndian.PutUint32(t, uint32(m.MessageType))
b := append([]byte("MESSAGE_ID"), t...)
b = append(b, m.Body...)
b = append(b, m.PreviousMessage...)
return sha256.Sum256(b)
}