Skip to content
Snippets Groups Projects
Commit 9ec9c60c authored by Jake Taylor's avatar Jake Taylor
Browse files

make text field into bytes

parent 020a97c5
No related branches found
No related tags found
1 merge request!60Revert "Fail a test to be sure it works"
......@@ -206,20 +206,21 @@ func (w *wasmModel) ReceiveMessage(channelID *id.ID,
pubKey ed25519.PublicKey, codeset uint8,
timestamp time.Time, lease time.Duration, round rounds.Round,
mType channels.MessageType, status channels.SentStatus) uint64 {
textBytes := []byte(text)
var err error
// Handle encryption, if it is present
if w.cipher != nil {
cipherText, err := w.cipher.Encrypt([]byte(text))
textBytes, err = w.cipher.Encrypt([]byte(text))
if err != nil {
jww.ERROR.Printf("Failed to encrypt Message: %+v", err)
return 0
}
text = string(cipherText)
}
msgToInsert := buildMessage(
channelID.Marshal(), messageID.Bytes(), nil, nickname, text, pubKey,
codeset, timestamp, lease, round.ID, mType, status)
channelID.Marshal(), messageID.Bytes(), nil, nickname,
textBytes, pubKey, codeset, timestamp, lease, round.ID, mType, status)
uuid, err := w.receiveHelper(msgToInsert, false)
if err != nil {
......@@ -243,7 +244,7 @@ func (w *wasmModel) ReceiveReply(channelID *id.ID,
mType channels.MessageType, status channels.SentStatus) uint64 {
msgToInsert := buildMessage(channelID.Marshal(), messageID.Bytes(),
replyTo.Bytes(), nickname, text, pubKey, codeset, timestamp, lease,
replyTo.Bytes(), nickname, []byte(text), pubKey, codeset, timestamp, lease,
round.ID, mType, status)
uuid, err := w.receiveHelper(msgToInsert, false)
......@@ -269,7 +270,7 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID,
msgToInsert := buildMessage(
channelID.Marshal(), messageID.Bytes(), reactionTo.Bytes(), nickname,
reaction, pubKey, codeset, timestamp, lease, round.ID, mType, status)
[]byte(reaction), pubKey, codeset, timestamp, lease, round.ID, mType, status)
uuid, err := w.receiveHelper(msgToInsert, false)
if err != nil {
......@@ -339,8 +340,8 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64,
// NOTE: ID is not set inside this function because we want to use the
// autoincrement key by default. If you are trying to overwrite an existing
// message, then you need to set it manually yourself.
func buildMessage(channelID, messageID, parentID []byte, nickname, text string,
pubKey ed25519.PublicKey, codeset uint8, timestamp time.Time,
func buildMessage(channelID, messageID, parentID []byte, nickname string,
text []byte, pubKey ed25519.PublicKey, codeset uint8, timestamp time.Time,
lease time.Duration, round id.Round, mType channels.MessageType,
status channels.SentStatus) *Message {
return &Message{
......
......@@ -46,7 +46,7 @@ func Test_wasmModel_UpdateSentStatus(t *testing.T) {
// Store a test message
testMsg := buildMessage([]byte(testString), testMsgId.Bytes(), nil,
testString, testString, []byte{8, 6, 7, 5}, 0, netTime.Now(),
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, netTime.Now(),
time.Second, 0, 0, channels.Sent)
uuid, err := eventModel.receiveHelper(testMsg, false)
if err != nil {
......@@ -285,7 +285,7 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
// First message insert should succeed
testMsgId := channel.MakeMessageID([]byte(testString), &id.ID{1})
testMsg := buildMessage([]byte(testString), testMsgId.Bytes(), nil,
testString, testString, []byte{8, 6, 7, 5}, 0, netTime.Now(),
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, netTime.Now(),
time.Second, 0, 0, channels.Sent)
_, err = eventModel.receiveHelper(testMsg, false)
if err != nil {
......@@ -308,7 +308,7 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
// Now insert a message with a different message ID from the first
testMsgId2 := channel.MakeMessageID([]byte(testString), &id.ID{2})
testMsg = buildMessage([]byte(testString), testMsgId2.Bytes(), nil,
testString, testString, []byte{8, 6, 7, 5}, 0, netTime.Now(),
testString, []byte(testString), []byte{8, 6, 7, 5}, 0, netTime.Now(),
time.Second, 0, 0, channels.Sent)
primaryKey, err := eventModel.receiveHelper(testMsg, false)
if err != nil {
......
......@@ -55,7 +55,7 @@ type Message struct {
Status uint8 `json:"status"`
Hidden bool `json:"hidden"`
Pinned bool `json:"pinned"` // Index
Text string `json:"text"`
Text []byte `json:"text"`
Type uint16 `json:"type"`
Round uint64 `json:"round"`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment