diff --git a/indexedDb/implementation.go b/indexedDb/implementation.go index cf26157e385409424549b323365847cbaaf178f9..050e5926497fe5564a48003e087e492eb59b3281 100644 --- a/indexedDb/implementation.go +++ b/indexedDb/implementation.go @@ -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{ diff --git a/indexedDb/implementation_test.go b/indexedDb/implementation_test.go index 2cad70dbcce304406e00299215c1edc80faf9df1..d4f6226f956b1547e17100062db2b6f603df42d0 100644 --- a/indexedDb/implementation_test.go +++ b/indexedDb/implementation_test.go @@ -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 { diff --git a/indexedDb/model.go b/indexedDb/model.go index 3500e643abb9a6cc0a447caf0f21968fd0df9d51..c6e29184705b83cc4992b4801fce78b7a12fc4e4 100644 --- a/indexedDb/model.go +++ b/indexedDb/model.go @@ -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"`