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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
ba904f8e
Commit
ba904f8e
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added update flag for message inserts to prevent weird PK logic
parent
f4975939
No related branches found
No related tags found
1 merge request
!60
Revert "Fail a test to be sure it works"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
indexedDb/implementation.go
+7
-8
7 additions, 8 deletions
indexedDb/implementation.go
indexedDb/implementation_test.go
+3
-3
3 additions, 3 deletions
indexedDb/implementation_test.go
with
10 additions
and
11 deletions
indexedDb/implementation.go
+
7
−
8
View file @
ba904f8e
...
...
@@ -221,7 +221,7 @@ func (w *wasmModel) ReceiveMessage(channelID *id.ID,
channelID
.
Marshal
(),
messageID
.
Bytes
(),
nil
,
nickname
,
text
,
pubKey
,
codeset
,
timestamp
,
lease
,
round
.
ID
,
mType
,
status
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
,
false
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to receive Message: %+v"
,
err
)
}
...
...
@@ -246,7 +246,7 @@ func (w *wasmModel) ReceiveReply(channelID *id.ID,
replyTo
.
Bytes
(),
nickname
,
text
,
pubKey
,
codeset
,
timestamp
,
lease
,
round
.
ID
,
mType
,
status
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
,
false
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to receive reply: %+v"
,
err
)
...
...
@@ -271,7 +271,7 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID,
channelID
.
Marshal
(),
messageID
.
Bytes
(),
reactionTo
.
Bytes
(),
nickname
,
reaction
,
pubKey
,
codeset
,
timestamp
,
lease
,
round
.
ID
,
mType
,
status
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
,
false
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to receive reaction: %+v"
,
err
)
}
...
...
@@ -324,7 +324,7 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64,
}
// Store the updated Message
_
,
err
=
w
.
receiveHelper
(
newMessage
)
_
,
err
=
w
.
receiveHelper
(
newMessage
,
true
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrap
(
parentErr
,
err
.
Error
()))
}
...
...
@@ -363,7 +363,7 @@ func buildMessage(channelID, messageID, parentID []byte, nickname, text string,
}
// receiveHelper is a private helper for receiving any sort of message.
func
(
w
*
wasmModel
)
receiveHelper
(
newMessage
*
Message
)
(
uint64
,
func
(
w
*
wasmModel
)
receiveHelper
(
newMessage
*
Message
,
isUpdate
bool
)
(
uint64
,
error
)
{
// Convert to jsObject
newMessageJson
,
err
:=
json
.
Marshal
(
newMessage
)
...
...
@@ -375,9 +375,8 @@ func (w *wasmModel) receiveHelper(newMessage *Message) (uint64,
return
0
,
errors
.
Errorf
(
"Unable to marshal Message: %+v"
,
err
)
}
// NOTE: This is weird, but correct. When the "ID" field is 0, we unset it
// from the JSValue so that it is auto-populated and incremented.
if
newMessage
.
ID
==
0
{
// Unset the primaryKey for inserts so it can be auto-populated and incremented.
if
!
isUpdate
{
messageObj
.
JSValue
()
.
Delete
(
"id"
)
}
...
...
This diff is collapsed.
Click to expand it.
indexedDb/implementation_test.go
+
3
−
3
View file @
ba904f8e
...
...
@@ -48,7 +48,7 @@ func Test_wasmModel_UpdateSentStatus(t *testing.T) {
testMsg
:=
buildMessage
([]
byte
(
testString
),
testMsgId
.
Bytes
(),
nil
,
testString
,
testString
,
[]
byte
{
8
,
6
,
7
,
5
},
0
,
netTime
.
Now
(),
time
.
Second
,
0
,
0
,
channels
.
Sent
)
uuid
,
err
:=
eventModel
.
receiveHelper
(
testMsg
)
uuid
,
err
:=
eventModel
.
receiveHelper
(
testMsg
,
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
}
...
...
@@ -287,13 +287,13 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
testMsg
:=
buildMessage
([]
byte
(
testString
),
testMsgId
.
Bytes
(),
nil
,
testString
,
testString
,
[]
byte
{
8
,
6
,
7
,
5
},
0
,
netTime
.
Now
(),
time
.
Second
,
0
,
0
,
channels
.
Sent
)
_
,
err
=
eventModel
.
receiveHelper
(
testMsg
)
_
,
err
=
eventModel
.
receiveHelper
(
testMsg
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// The duplicate entry won't fail, it just silently shouldn't happen
_
,
err
=
eventModel
.
receiveHelper
(
testMsg
)
_
,
err
=
eventModel
.
receiveHelper
(
testMsg
,
true
)
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
}
...
...
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