Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
95beebc6
Commit
95beebc6
authored
Dec 20, 2022
by
Richard T. Carback III
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/project/DM' into XX-4324/finale
parents
b0d4a57b
28fb06b3
Branches
Branches containing commit
Tags
Tags containing commit
4 merge requests
!60
Revert "Fail a test to be sure it works"
,
!48
Finalize DM
,
!36
project/DM
,
!32
Admin Commands
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
indexedDb/channels/implementation_test.go
+344
-254
344 additions, 254 deletions
indexedDb/channels/implementation_test.go
indexedDb/dm/implementation.go
+50
-35
50 additions, 35 deletions
indexedDb/dm/implementation.go
indexedDb/utils.go
+11
-7
11 additions, 7 deletions
indexedDb/utils.go
with
405 additions
and
296 deletions
indexedDb/channels/implementation_test.go
+
344
−
254
View file @
95beebc6
...
@@ -20,12 +20,14 @@ import (
...
@@ -20,12 +20,14 @@ import (
"github.com/hack-pad/go-indexeddb/idb"
"github.com/hack-pad/go-indexeddb/idb"
"gitlab.com/elixxir/xxdk-wasm/indexedDb"
"gitlab.com/elixxir/xxdk-wasm/indexedDb"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/primitives/netTime"
"gitlab.com/xx_network/primitives/netTime"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/channels"
"gitlab.com/elixxir/client/v4/channels"
"gitlab.com/elixxir/client/v4/cmix/rounds"
"gitlab.com/elixxir/client/v4/cmix/rounds"
cryptoBroadcast
"gitlab.com/elixxir/crypto/broadcast"
cryptoBroadcast
"gitlab.com/elixxir/crypto/broadcast"
cryptoChannel
"gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/message"
"gitlab.com/elixxir/crypto/message"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
)
)
...
@@ -39,11 +41,22 @@ func dummyCallback(uint64, *id.ID, bool) {}
...
@@ -39,11 +41,22 @@ func dummyCallback(uint64, *id.ID, bool) {}
// Happy path, insert message and look it up
// Happy path, insert message and look it up
func
TestWasmModel_msgIDLookup
(
t
*
testing
.
T
)
{
func
TestWasmModel_msgIDLookup
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
for
_
,
c
:=
range
[]
cryptoChannel
.
Cipher
{
nil
,
cipher
}
{
cs
:=
""
if
cipher
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"TestWasmModel_msgIDLookup%s"
,
cs
),
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
"test"
testString
:=
"test"
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
0
,
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
[]
byte
(
testString
))
0
,
[]
byte
(
testString
))
eventModel
,
err
:=
newWASMModel
(
testString
,
nil
,
dummyCallback
)
eventModel
,
err
:=
newWASMModel
(
testString
,
c
,
dummyCallback
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
t
.
Fatalf
(
"%+v"
,
err
)
}
}
...
@@ -63,15 +76,27 @@ func TestWasmModel_msgIDLookup(t *testing.T) {
...
@@ -63,15 +76,27 @@ func TestWasmModel_msgIDLookup(t *testing.T) {
if
uuid
==
0
{
if
uuid
==
0
{
t
.
Fatalf
(
"Expected to get a UUID!"
)
t
.
Fatalf
(
"Expected to get a UUID!"
)
}
}
})
}
}
}
// Test wasmModel.UpdateSentStatus happy path and ensure fields don't change.
// Test wasmModel.UpdateSentStatus happy path and ensure fields don't change.
func
Test_wasmModel_UpdateSentStatus
(
t
*
testing
.
T
)
{
func
Test_wasmModel_UpdateSentStatus
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
for
_
,
c
:=
range
[]
cryptoChannel
.
Cipher
{
nil
,
cipher
}
{
cs
:=
""
if
cipher
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"Test_wasmModel_UpdateSentStatus%s"
,
cs
),
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
"test"
testString
:=
"test"
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
0
,
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
[]
byte
(
testString
))
0
,
[]
byte
(
testString
))
eventModel
,
err
:=
newWASMModel
(
testString
,
nil
,
dummyCallback
)
eventModel
,
err
:=
newWASMModel
(
testString
,
c
,
dummyCallback
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
t
.
Fatalf
(
"%+v"
,
err
)
}
}
...
@@ -120,12 +145,24 @@ func Test_wasmModel_UpdateSentStatus(t *testing.T) {
...
@@ -120,12 +145,24 @@ func Test_wasmModel_UpdateSentStatus(t *testing.T) {
if
resultMsg
.
Nickname
!=
testString
{
if
resultMsg
.
Nickname
!=
testString
{
t
.
Fatalf
(
"Unexpected Nickname: %v"
,
resultMsg
.
Nickname
)
t
.
Fatalf
(
"Unexpected Nickname: %v"
,
resultMsg
.
Nickname
)
}
}
})
}
}
}
// Smoke test wasmModel.JoinChannel/wasmModel.LeaveChannel happy paths.
// Smoke test wasmModel.JoinChannel/wasmModel.LeaveChannel happy paths.
func
Test_wasmModel_JoinChannel_LeaveChannel
(
t
*
testing
.
T
)
{
func
Test_wasmModel_JoinChannel_LeaveChannel
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
for
_
,
c
:=
range
[]
cryptoChannel
.
Cipher
{
nil
,
cipher
}
{
cs
:=
""
if
cipher
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"Test_wasmModel_JoinChannel_LeaveChannel%s"
,
cs
),
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
storage
.
GetLocalStorage
()
.
Clear
()
eventModel
,
err
:=
newWASMModel
(
"test"
,
nil
,
dummyCallback
)
eventModel
,
err
:=
newWASMModel
(
"test"
,
c
,
dummyCallback
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
t
.
Fatalf
(
"%+v"
,
err
)
}
}
...
@@ -159,13 +196,25 @@ func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) {
...
@@ -159,13 +196,25 @@ func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) {
if
len
(
results
)
!=
1
{
if
len
(
results
)
!=
1
{
t
.
Fatalf
(
"Expected 1 channels to exist"
)
t
.
Fatalf
(
"Expected 1 channels to exist"
)
}
}
})
}
}
}
// Test UUID gets returned when different messages are added.
// Test UUID gets returned when different messages are added.
func
Test_wasmModel_UUIDTest
(
t
*
testing
.
T
)
{
func
Test_wasmModel_UUIDTest
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
for
_
,
c
:=
range
[]
cryptoChannel
.
Cipher
{
nil
,
cipher
}
{
cs
:=
""
if
cipher
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"Test_wasmModel_UUIDTest%s"
,
cs
),
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
"testHello"
testString
:=
"testHello"
eventModel
,
err
:=
newWASMModel
(
testString
,
nil
,
dummyCallback
)
eventModel
,
err
:=
newWASMModel
(
testString
,
c
,
dummyCallback
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
t
.
Fatalf
(
"%+v"
,
err
)
}
}
...
@@ -192,13 +241,25 @@ func Test_wasmModel_UUIDTest(t *testing.T) {
...
@@ -192,13 +241,25 @@ func Test_wasmModel_UUIDTest(t *testing.T) {
}
}
}
}
}
}
})
}
}
}
// Tests if the same message ID being sent always returns the same UUID.
// Tests if the same message ID being sent always returns the same UUID.
func
Test_wasmModel_DuplicateReceives
(
t
*
testing
.
T
)
{
func
Test_wasmModel_DuplicateReceives
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
for
_
,
c
:=
range
[]
cryptoChannel
.
Cipher
{
nil
,
cipher
}
{
cs
:=
""
if
cipher
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"Test_wasmModel_DuplicateReceives%s"
,
cs
),
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
"testHello"
testString
:=
"testHello"
eventModel
,
err
:=
newWASMModel
(
testString
,
nil
,
dummyCallback
)
eventModel
,
err
:=
newWASMModel
(
testString
,
c
,
dummyCallback
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
t
.
Fatalf
(
"%+v"
,
err
)
}
}
...
@@ -225,16 +286,29 @@ func Test_wasmModel_DuplicateReceives(t *testing.T) {
...
@@ -225,16 +286,29 @@ func Test_wasmModel_DuplicateReceives(t *testing.T) {
}
}
}
}
}
}
})
}
}
}
// Happy path: Inserts many messages, deletes some, and checks that the final
// Happy path: Inserts many messages, deletes some, and checks that the final
// result is as expected.
// result is as expected.
func
Test_wasmModel_deleteMsgByChannel
(
t
*
testing
.
T
)
{
func
Test_wasmModel_deleteMsgByChannel
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
for
_
,
c
:=
range
[]
cryptoChannel
.
Cipher
{
nil
,
cipher
}
{
cs
:=
""
if
cipher
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"Test_wasmModel_deleteMsgByChannel%s"
,
cs
),
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
"test_deleteMsgByChannel"
testString
:=
"test_deleteMsgByChannel"
totalMessages
:=
10
totalMessages
:=
10
expectedMessages
:=
5
expectedMessages
:=
5
eventModel
,
err
:=
newWASMModel
(
testString
,
nil
,
dummyCallback
)
eventModel
,
err
:=
newWASMModel
(
testString
,
c
,
dummyCallback
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
t
.
Fatalf
(
"%+v"
,
err
)
}
}
...
@@ -253,7 +327,8 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
...
@@ -253,7 +327,8 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
thisChannel
=
keepChannel
thisChannel
=
keepChannel
}
}
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
0
,
[]
byte
(
testStr
))
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
0
,
[]
byte
(
testStr
))
eventModel
.
ReceiveMessage
(
thisChannel
,
testMsgId
,
testStr
,
testStr
,
eventModel
.
ReceiveMessage
(
thisChannel
,
testMsgId
,
testStr
,
testStr
,
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
time
.
Second
,
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
time
.
Second
,
rounds
.
Round
{
ID
:
id
.
Round
(
0
)},
0
,
channels
.
Sent
)
rounds
.
Round
{
ID
:
id
.
Round
(
0
)},
0
,
channels
.
Sent
)
...
@@ -282,14 +357,26 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
...
@@ -282,14 +357,26 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
if
len
(
result
)
!=
expectedMessages
{
if
len
(
result
)
!=
expectedMessages
{
t
.
Errorf
(
"Expected %d messages, got %d"
,
expectedMessages
,
len
(
result
))
t
.
Errorf
(
"Expected %d messages, got %d"
,
expectedMessages
,
len
(
result
))
}
}
})
}
}
}
// This test is designed to prove the behavior of unique indexes.
// This test is designed to prove the behavior of unique indexes.
// Inserts will not fail, they simply will not happen.
// Inserts will not fail, they simply will not happen.
func
TestWasmModel_receiveHelper_UniqueIndex
(
t
*
testing
.
T
)
{
func
TestWasmModel_receiveHelper_UniqueIndex
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
for
i
,
c
:=
range
[]
cryptoChannel
.
Cipher
{
nil
,
cipher
}
{
cs
:=
""
if
cipher
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"TestWasmModel_receiveHelper_UniqueIndex%s"
,
cs
),
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
"test_receiveHelper_UniqueIndex
"
testString
:=
fmt
.
Sprintf
(
"test_receiveHelper_UniqueIndex
_%d"
,
i
)
eventModel
,
err
:=
newWASMModel
(
testString
,
nil
,
dummyCallback
)
eventModel
,
err
:=
newWASMModel
(
testString
,
c
,
dummyCallback
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -315,8 +402,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
...
@@ -315,8 +402,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
}
}
// First message insert should succeed
// First message insert should succeed
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
0
,
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
[]
byte
(
testString
))
0
,
[]
byte
(
testString
))
testMsg
:=
buildMessage
([]
byte
(
testString
),
testMsgId
.
Bytes
(),
nil
,
testMsg
:=
buildMessage
([]
byte
(
testString
),
testMsgId
.
Bytes
(),
nil
,
testString
,
[]
byte
(
testString
),
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
testString
,
[]
byte
(
testString
),
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
time
.
Second
,
0
,
0
,
channels
.
Sent
)
time
.
Second
,
0
,
0
,
channels
.
Sent
)
...
@@ -339,8 +426,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
...
@@ -339,8 +426,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
}
}
// Now insert a message with a different message ID from the first
// Now insert a message with a different message ID from the first
testMsgId2
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
2
},
0
,
testMsgId2
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
[]
byte
(
testString
))
0
,
[]
byte
(
testString
))
testMsg
=
buildMessage
([]
byte
(
testString
),
testMsgId2
.
Bytes
(),
nil
,
testMsg
=
buildMessage
([]
byte
(
testString
),
testMsgId2
.
Bytes
(),
nil
,
testString
,
[]
byte
(
testString
),
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
testString
,
[]
byte
(
testString
),
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
time
.
Second
,
0
,
0
,
channels
.
Sent
)
time
.
Second
,
0
,
0
,
channels
.
Sent
)
...
@@ -365,4 +452,7 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
...
@@ -365,4 +452,7 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
t
.
Fatalf
(
"%+v"
,
err
)
t
.
Fatalf
(
"%+v"
,
err
)
}
}
// TODO: Convert JSON to Message, ensure Message ID fields differ
// TODO: Convert JSON to Message, ensure Message ID fields differ
})
}
}
}
This diff is collapsed.
Click to expand it.
indexedDb/dm/implementation.go
+
50
−
35
View file @
95beebc6
...
@@ -12,6 +12,7 @@ package channelEventModel
...
@@ -12,6 +12,7 @@ package channelEventModel
import
(
import
(
"crypto/ed25519"
"crypto/ed25519"
"encoding/json"
"encoding/json"
"strings"
"sync"
"sync"
"syscall/js"
"syscall/js"
"time"
"time"
...
@@ -101,14 +102,16 @@ func (w *wasmModel) Receive(messageID message.ID, nickname string, text []byte,
...
@@ -101,14 +102,16 @@ func (w *wasmModel) Receive(messageID message.ID, nickname string, text []byte,
var
err
error
var
err
error
// If there is no extant Conversation, create one.
// If there is no extant Conversation, create one.
if
result
,
err
:=
indexedDb
.
Get
(
w
.
db
,
conversationStoreName
,
if
_
,
err
:=
indexedDb
.
Get
(
w
.
db
,
conversationStoreName
,
utils
.
CopyBytesToJS
(
pubKey
));
err
!=
nil
{
utils
.
CopyBytesToJS
(
pubKey
));
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
indexedDb
.
ErrDoesNotExist
)
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
return
0
}
else
if
len
(
result
.
String
())
==
0
{
err
=
w
.
joinConversation
(
nickname
,
pubKey
,
dmToken
,
codeset
)
err
=
w
.
joinConversation
(
nickname
,
pubKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
err
)
jww
.
ERROR
.
Printf
(
"%+v"
,
err
)
}
}
else
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
}
return
0
return
0
}
else
{
}
else
{
jww
.
DEBUG
.
Printf
(
"Conversation with %s already joined"
,
nickname
)
jww
.
DEBUG
.
Printf
(
"Conversation with %s already joined"
,
nickname
)
...
@@ -141,14 +144,16 @@ func (w *wasmModel) ReceiveText(messageID message.ID, nickname, text string,
...
@@ -141,14 +144,16 @@ func (w *wasmModel) ReceiveText(messageID message.ID, nickname, text string,
var
err
error
var
err
error
// If there is no extant Conversation, create one.
// If there is no extant Conversation, create one.
if
result
,
err
:=
indexedDb
.
Get
(
w
.
db
,
conversationStoreName
,
if
_
,
err
:=
indexedDb
.
Get
(
w
.
db
,
conversationStoreName
,
utils
.
CopyBytesToJS
(
pubKey
));
err
!=
nil
{
utils
.
CopyBytesToJS
(
pubKey
));
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
indexedDb
.
ErrDoesNotExist
)
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
return
0
}
else
if
len
(
result
.
String
())
==
0
{
err
=
w
.
joinConversation
(
nickname
,
pubKey
,
dmToken
,
codeset
)
err
=
w
.
joinConversation
(
nickname
,
pubKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
err
)
jww
.
ERROR
.
Printf
(
"%+v"
,
err
)
}
}
else
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
}
return
0
return
0
}
else
{
}
else
{
jww
.
DEBUG
.
Printf
(
"Conversation with %s already joined"
,
nickname
)
jww
.
DEBUG
.
Printf
(
"Conversation with %s already joined"
,
nickname
)
...
@@ -183,14 +188,16 @@ func (w *wasmModel) ReceiveReply(messageID message.ID, reactionTo message.ID,
...
@@ -183,14 +188,16 @@ func (w *wasmModel) ReceiveReply(messageID message.ID, reactionTo message.ID,
var
err
error
var
err
error
// If there is no extant Conversation, create one.
// If there is no extant Conversation, create one.
if
result
,
err
:=
indexedDb
.
Get
(
w
.
db
,
conversationStoreName
,
if
_
,
err
:=
indexedDb
.
Get
(
w
.
db
,
conversationStoreName
,
utils
.
CopyBytesToJS
(
pubKey
));
err
!=
nil
{
utils
.
CopyBytesToJS
(
pubKey
));
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
indexedDb
.
ErrDoesNotExist
)
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
return
0
}
else
if
len
(
result
.
String
())
==
0
{
err
=
w
.
joinConversation
(
nickname
,
pubKey
,
dmToken
,
codeset
)
err
=
w
.
joinConversation
(
nickname
,
pubKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
err
)
jww
.
ERROR
.
Printf
(
"%+v"
,
err
)
}
}
else
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
}
return
0
return
0
}
else
{
}
else
{
jww
.
DEBUG
.
Printf
(
"Conversation with %s already joined"
,
nickname
)
jww
.
DEBUG
.
Printf
(
"Conversation with %s already joined"
,
nickname
)
...
@@ -225,14 +232,16 @@ func (w *wasmModel) ReceiveReaction(messageID message.ID, reactionTo message.ID,
...
@@ -225,14 +232,16 @@ func (w *wasmModel) ReceiveReaction(messageID message.ID, reactionTo message.ID,
var
err
error
var
err
error
// If there is no extant Conversation, create one.
// If there is no extant Conversation, create one.
if
result
,
err
:=
indexedDb
.
Get
(
w
.
db
,
conversationStoreName
,
if
_
,
err
:=
indexedDb
.
Get
(
w
.
db
,
conversationStoreName
,
utils
.
CopyBytesToJS
(
pubKey
));
err
!=
nil
{
utils
.
CopyBytesToJS
(
pubKey
));
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
indexedDb
.
ErrDoesNotExist
)
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
return
0
}
else
if
len
(
result
.
String
())
==
0
{
err
=
w
.
joinConversation
(
nickname
,
pubKey
,
dmToken
,
codeset
)
err
=
w
.
joinConversation
(
nickname
,
pubKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
err
)
jww
.
ERROR
.
Printf
(
"%+v"
,
err
)
}
}
else
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
}
return
0
return
0
}
else
{
}
else
{
jww
.
DEBUG
.
Printf
(
"Conversation with %s already joined"
,
nickname
)
jww
.
DEBUG
.
Printf
(
"Conversation with %s already joined"
,
nickname
)
...
@@ -260,8 +269,9 @@ func (w *wasmModel) ReceiveReaction(messageID message.ID, reactionTo message.ID,
...
@@ -260,8 +269,9 @@ func (w *wasmModel) ReceiveReaction(messageID message.ID, reactionTo message.ID,
return
uuid
return
uuid
}
}
func
(
w
*
wasmModel
)
UpdateSentStatus
(
uuid
uint64
,
messageID
message
.
ID
,
func
(
w
*
wasmModel
)
UpdateSentStatus
(
uuid
uint64
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
{
messageID
message
.
ID
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
{
parentErr
:=
errors
.
New
(
"failed to UpdateSentStatus"
)
parentErr
:=
errors
.
New
(
"failed to UpdateSentStatus"
)
// FIXME: this is a bit of race condition without the mux.
// FIXME: this is a bit of race condition without the mux.
...
@@ -276,15 +286,20 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID message.ID,
...
@@ -276,15 +286,20 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID message.ID,
// Use the key to get the existing Message
// Use the key to get the existing Message
currentMsg
,
err
:=
indexedDb
.
Get
(
w
.
db
,
messageStoreName
,
key
)
currentMsg
,
err
:=
indexedDb
.
Get
(
w
.
db
,
messageStoreName
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get message: %+v"
,
err
))
return
return
}
}
// Extract the existing Message and update the Status
// Extract the existing Message and update the Status
newMessage
:=
&
Message
{}
newMessage
:=
&
Message
{}
err
=
json
.
Unmarshal
([]
byte
(
currentMsg
.
String
(
)),
newMessage
)
err
=
json
.
Unmarshal
([]
byte
(
utils
.
JsToJson
(
currentMsg
)),
newMessage
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Could not JSON unmarshal message: %+v"
,
err
))
return
return
}
}
newMessage
.
Status
=
uint8
(
status
)
newMessage
.
Status
=
uint8
(
status
)
if
!
messageID
.
Equals
(
message
.
ID
{})
{
if
!
messageID
.
Equals
(
message
.
ID
{})
{
newMessage
.
MessageID
=
messageID
.
Bytes
()
newMessage
.
MessageID
=
messageID
.
Bytes
()
...
...
This diff is collapsed.
Click to expand it.
indexedDb/utils.go
+
11
−
7
View file @
95beebc6
...
@@ -22,9 +22,13 @@ import (
...
@@ -22,9 +22,13 @@ import (
"time"
"time"
)
)
const
(
// dbTimeout is the global timeout for operations with the storage
// dbTimeout is the global timeout for operations with the storage
// [context.Context].
// [context.Context].
const
dbTimeout
=
time
.
Second
dbTimeout
=
time
.
Second
// ErrDoesNotExist is an error string for got undefined on Get operations.
ErrDoesNotExist
=
"result is undefined"
)
// NewContext builds a context for indexedDb operations.
// NewContext builds a context for indexedDb operations.
func
NewContext
()
(
context
.
Context
,
context
.
CancelFunc
)
{
func
NewContext
()
(
context
.
Context
,
context
.
CancelFunc
)
{
...
@@ -62,8 +66,8 @@ func Get(db *idb.Database, objectStoreName string, key js.Value) (js.Value, erro
...
@@ -62,8 +66,8 @@ func Get(db *idb.Database, objectStoreName string, key js.Value) (js.Value, erro
return
js
.
Undefined
(),
errors
.
WithMessagef
(
parentErr
,
return
js
.
Undefined
(),
errors
.
WithMessagef
(
parentErr
,
"Unable to get from ObjectStore: %+v"
,
err
)
"Unable to get from ObjectStore: %+v"
,
err
)
}
else
if
resultObj
.
IsUndefined
()
{
}
else
if
resultObj
.
IsUndefined
()
{
return
js
.
Undefined
(),
errors
.
WithMessage
(
parentErr
,
return
js
.
Undefined
(),
errors
.
WithMessage
f
(
parentErr
,
"Unable to get from ObjectStore:
result is undefined"
)
"Unable to get from ObjectStore:
%s"
,
ErrDoesNotExist
)
}
}
// Process result into string
// Process result into string
...
@@ -111,8 +115,8 @@ func GetIndex(db *idb.Database, objectStoreName string,
...
@@ -111,8 +115,8 @@ func GetIndex(db *idb.Database, objectStoreName string,
return
js
.
Undefined
(),
errors
.
WithMessagef
(
parentErr
,
return
js
.
Undefined
(),
errors
.
WithMessagef
(
parentErr
,
"Unable to get from ObjectStore: %+v"
,
err
)
"Unable to get from ObjectStore: %+v"
,
err
)
}
else
if
resultObj
.
IsUndefined
()
{
}
else
if
resultObj
.
IsUndefined
()
{
return
js
.
Undefined
(),
errors
.
WithMessage
(
parentErr
,
return
js
.
Undefined
(),
errors
.
WithMessage
f
(
parentErr
,
"Unable to get from ObjectStore:
result is undefined"
)
"Unable to get from ObjectStore:
%s"
,
ErrDoesNotExist
)
}
}
// Process result into string
// Process result into string
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment