Skip to content
Snippets Groups Projects
Commit 3afb721f authored by Jono Wenger's avatar Jono Wenger
Browse files

Fix formatting

parent 6557ee52
No related branches found
No related tags found
2 merge requests!67fix for latest client release,!52XX-4382 / Move indexedDb databases to web workers
......@@ -30,9 +30,8 @@ import (
"gitlab.com/elixxir/crypto/message"
)
// wasmModel implements [dm.Receiver] interface, which uses the channels
// system passed an object that adheres to in order to get events on the
// channel.
// wasmModel implements dm.EventModel interface, which uses the channels system
// passed an object that adheres to in order to get events on the channel.
type wasmModel struct {
db *idb.Database
cipher cryptoChannel.Cipher
......@@ -74,15 +73,15 @@ func (w *wasmModel) joinConversation(nickname string,
return nil
}
// buildMessage is a private helper that converts typical [dm.Receiver]
// inputs into a basic Message structure for insertion into storage.
// buildMessage is a private helper that converts typical dm.EventModel inputs
// into a basic Message structure for insertion into storage.
//
// 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(messageID, parentID []byte, text []byte,
pubKey ed25519.PublicKey, timestamp time.Time, round id.Round,
mType dm.MessageType, status dm.Status) *Message {
func buildMessage(messageID, parentID, text []byte, pubKey ed25519.PublicKey,
timestamp time.Time, round id.Round, mType dm.MessageType,
status dm.Status) *Message {
return &Message{
MessageID: messageID,
ConversationPubKey: pubKey,
......@@ -96,13 +95,13 @@ func buildMessage(messageID, parentID []byte, text []byte,
}
func (w *wasmModel) Receive(messageID message.ID, nickname string, text []byte,
pubKey ed25519.PublicKey, dmToken uint32, codeset uint8,
timestamp time.Time, round rounds.Round, mType dm.MessageType,
status dm.Status) uint64 {
pubKey ed25519.PublicKey, dmToken uint32, codeset uint8, timestamp time.Time,
round rounds.Round, mType dm.MessageType, status dm.Status) uint64 {
parentErr := errors.New("failed to Receive")
// If there is no extant Conversation, create one.
_, err := indexedDb.Get(w.db, conversationStoreName, utils.CopyBytesToJS(pubKey))
_, err := indexedDb.Get(
w.db, conversationStoreName, utils.CopyBytesToJS(pubKey))
if err != nil {
if strings.Contains(err.Error(), indexedDb.ErrDoesNotExist) {
err = w.joinConversation(nickname, pubKey, dmToken, codeset)
......@@ -127,8 +126,8 @@ func (w *wasmModel) Receive(messageID message.ID, nickname string, text []byte,
}
}
msgToInsert := buildMessage(messageID.Bytes(), nil, text,
pubKey, timestamp, round.ID, mType, status)
msgToInsert := buildMessage(messageID.Bytes(), nil, text, pubKey, timestamp,
round.ID, mType, status)
uuid, err := w.receiveHelper(msgToInsert, false)
if err != nil {
jww.ERROR.Printf("Failed to receive Message: %+v", err)
......@@ -144,7 +143,8 @@ func (w *wasmModel) ReceiveText(messageID message.ID, nickname, text string,
parentErr := errors.New("failed to ReceiveText")
// If there is no extant Conversation, create one.
_, err := indexedDb.Get(w.db, conversationStoreName, utils.CopyBytesToJS(pubKey))
_, err := indexedDb.Get(
w.db, conversationStoreName, utils.CopyBytesToJS(pubKey))
if err != nil {
if strings.Contains(err.Error(), indexedDb.ErrDoesNotExist) {
err = w.joinConversation(nickname, pubKey, dmToken, codeset)
......@@ -188,7 +188,8 @@ func (w *wasmModel) ReceiveReply(messageID, reactionTo message.ID, nickname,
parentErr := errors.New("failed to ReceiveReply")
// If there is no extant Conversation, create one.
_, err := indexedDb.Get(w.db, conversationStoreName, utils.CopyBytesToJS(pubKey))
_, err := indexedDb.Get(
w.db, conversationStoreName, utils.CopyBytesToJS(pubKey))
if err != nil {
if strings.Contains(err.Error(), indexedDb.ErrDoesNotExist) {
err = w.joinConversation(nickname, pubKey, dmToken, codeset)
......@@ -226,13 +227,14 @@ func (w *wasmModel) ReceiveReply(messageID, reactionTo message.ID, nickname,
return uuid
}
func (w *wasmModel) ReceiveReaction(messageID, reactionTo message.ID, nickname,
func (w *wasmModel) ReceiveReaction(messageID, _ message.ID, nickname,
reaction string, pubKey ed25519.PublicKey, dmToken uint32, codeset uint8,
timestamp time.Time, round rounds.Round, status dm.Status) uint64 {
parentErr := errors.New("failed to ReceiveText")
// If there is no extant Conversation, create one.
_, err := indexedDb.Get(w.db, conversationStoreName, utils.CopyBytesToJS(pubKey))
_, err := indexedDb.Get(
w.db, conversationStoreName, utils.CopyBytesToJS(pubKey))
if err != nil {
if strings.Contains(err.Error(), indexedDb.ErrDoesNotExist) {
err = w.joinConversation(nickname, pubKey, dmToken, codeset)
......
......@@ -35,7 +35,8 @@ const (
// MessageReceivedCallback is called any time a message is received or updated.
//
// update is true if the row is old and was edited.
type MessageReceivedCallback func(uuid uint64, pubKey ed25519.PublicKey, update bool)
type MessageReceivedCallback func(
uuid uint64, pubKey ed25519.PublicKey, update bool)
// NewWASMEventModel returns a [channels.EventModel] backed by a wasmModel.
// The name should be a base64 encoding of the users public key.
......
......@@ -26,6 +26,7 @@ const (
// dbTimeout is the global timeout for operations with the storage
// [context.Context].
dbTimeout = time.Second
// ErrDoesNotExist is an error string for got undefined on Get operations.
ErrDoesNotExist = "result is undefined"
)
......
......@@ -18,16 +18,17 @@ import (
const databaseEncryptionToggleKey = "xxdkWasmDatabaseEncryptionToggle/"
// StoreIndexedDbEncryptionStatus stores the encryption status if it has not
// been previously saved. If it has, it returns its value.
// been previously saved. If it has, then it returns its value.
func StoreIndexedDbEncryptionStatus(
databaseName string, encryption bool) (bool, error) {
databaseName string, encryptionStatus bool) (
loadedEncryptionStatus bool, err error) {
data, err := GetLocalStorage().GetItem(
databaseEncryptionToggleKey + databaseName)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
GetLocalStorage().SetItem(
databaseEncryptionToggleKey+databaseName, []byte{1})
return encryption, nil
return encryptionStatus, nil
} else {
return false, err
}
......
......@@ -18,23 +18,23 @@ import (
func TestStoreIndexedDbEncryptionStatus(t *testing.T) {
databaseName := "databaseA"
encrypted, err := StoreIndexedDbEncryptionStatus(databaseName, true)
encryptionStatus, err := StoreIndexedDbEncryptionStatus(databaseName, true)
if err != nil {
t.Errorf("Failed to store/get encryption status: %+v", err)
}
if encrypted != true {
if encryptionStatus != true {
t.Errorf("Incorrect encryption values.\nexpected: %t\nreceived: %t",
true, encrypted)
true, encryptionStatus)
}
encrypted, err = StoreIndexedDbEncryptionStatus(databaseName, false)
encryptionStatus, err = StoreIndexedDbEncryptionStatus(databaseName, false)
if err != nil {
t.Errorf("Failed to store/get encryption status: %+v", err)
}
if encrypted != true {
if encryptionStatus != true {
t.Errorf("Incorrect encryption values.\nexpected: %t\nreceived: %t",
true, encrypted)
true, encryptionStatus)
}
}
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