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
9556df0a
Commit
9556df0a
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
fix updateMessageStatus
parent
36b27a73
No related branches found
No related tags found
2 merge requests
!60
Revert "Fail a test to be sure it works"
,
!4
Xx 4114/index db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indexedDb/implementation.go
+57
-4
57 additions, 4 deletions
indexedDb/implementation.go
with
57 additions
and
4 deletions
indexedDb/implementation.go
+
57
−
4
View file @
9556df0a
...
@@ -12,6 +12,7 @@ package indexedDb
...
@@ -12,6 +12,7 @@ package indexedDb
import
(
import
(
"context"
"context"
"encoding/base64"
"encoding/json"
"encoding/json"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
"github.com/pkg/errors"
...
@@ -193,12 +194,26 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID, messageID cryptoChannel.Me
...
@@ -193,12 +194,26 @@ func (w *wasmModel) ReceiveReaction(channelID *id.ID, messageID cryptoChannel.Me
func
(
w
*
wasmModel
)
UpdateSentStatus
(
messageID
cryptoChannel
.
MessageID
,
func
(
w
*
wasmModel
)
UpdateSentStatus
(
messageID
cryptoChannel
.
MessageID
,
status
channels
.
SentStatus
)
{
status
channels
.
SentStatus
)
{
parentErr
:=
errors
.
New
(
"failed to UpdateSentStatus"
)
parentErr
:=
errors
.
New
(
"failed to UpdateSentStatus"
)
newMessage
:=
&
Message
{
Id
:
messageID
.
Bytes
(),
// Convert messageID to the key generated by json.Marshal
Status
:
uint8
(
status
),
key
:=
js
.
ValueOf
(
base64
.
StdEncoding
.
EncodeToString
(
messageID
[
:
]))
// Use the key to get the existing Message
currentMsg
,
err
:=
w
.
get
(
messageStoreName
,
key
)
if
err
!=
nil
{
return
}
// Extract the existing Message and update the Status
newMessage
:=
&
Message
{}
err
=
json
.
Unmarshal
([]
byte
(
currentMsg
),
newMessage
)
if
err
!=
nil
{
return
}
}
newMessage
.
Status
=
uint8
(
status
)
err
:=
w
.
receiveHelper
(
newMessage
)
// Store the updated Message
err
=
w
.
receiveHelper
(
newMessage
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrap
(
parentErr
,
err
.
Error
()))
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrap
(
parentErr
,
err
.
Error
()))
}
}
...
@@ -263,6 +278,44 @@ func (w *wasmModel) receiveHelper(newMessage *Message) error {
...
@@ -263,6 +278,44 @@ func (w *wasmModel) receiveHelper(newMessage *Message) error {
return
nil
return
nil
}
}
// get is a generic private helper for getting values from the given [idb.ObjectStore].
func
(
w
*
wasmModel
)
get
(
objectStoreName
string
,
key
js
.
Value
)
(
string
,
error
)
{
parentErr
:=
errors
.
Errorf
(
"failed to get %s/%s"
,
objectStoreName
,
key
)
// Prepare the Transaction
txn
,
err
:=
w
.
db
.
Transaction
(
idb
.
TransactionReadOnly
,
objectStoreName
)
if
err
!=
nil
{
return
""
,
errors
.
WithMessagef
(
parentErr
,
"Unable to create Transaction: %+v"
,
err
)
}
store
,
err
:=
txn
.
ObjectStore
(
objectStoreName
)
if
err
!=
nil
{
return
""
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get ObjectStore: %+v"
,
err
)
}
// Perform the operation
getRequest
,
err
:=
store
.
Get
(
key
)
if
err
!=
nil
{
return
""
,
errors
.
WithMessagef
(
parentErr
,
"Unable to Get from ObjectStore: %+v"
,
err
)
}
// Wait for the operation to return
ctx
,
cancel
:=
newContext
()
resultObj
,
err
:=
getRequest
.
Await
(
ctx
)
cancel
()
if
err
!=
nil
{
return
""
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get from ObjectStore: %+v"
,
err
)
}
// Process result into string
resultStr
:=
utils
.
JsToJson
(
resultObj
)
jww
.
DEBUG
.
Printf
(
"Got from %s/%s: %s"
,
objectStoreName
,
key
,
resultStr
)
return
resultStr
,
nil
}
// dump given [idb.ObjectStore] contents to string slice for debugging purposes
// dump given [idb.ObjectStore] contents to string slice for debugging purposes
func
(
w
*
wasmModel
)
dump
(
objectStoreName
string
)
([]
string
,
error
)
{
func
(
w
*
wasmModel
)
dump
(
objectStoreName
string
)
([]
string
,
error
)
{
parentErr
:=
errors
.
Errorf
(
"failed to dump %s"
,
objectStoreName
)
parentErr
:=
errors
.
Errorf
(
"failed to dump %s"
,
objectStoreName
)
...
...
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