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
6d299939
Commit
6d299939
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
made byte encoding for indexedDb consistent
parent
c45ee47c
No related branches found
No related tags found
2 merge requests
!80
made byte encoding for indexedDb consistent
,
!67
fix for latest client release
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
indexedDb/impl/channels/implementation.go
+5
-10
5 additions, 10 deletions
indexedDb/impl/channels/implementation.go
indexedDb/impl/dm/implementation.go
+2
-3
2 additions, 3 deletions
indexedDb/impl/dm/implementation.go
indexedDb/impl/utils.go
+6
-0
6 additions, 0 deletions
indexedDb/impl/utils.go
with
13 additions
and
13 deletions
indexedDb/impl/channels/implementation.go
+
5
−
10
View file @
6d299939
...
...
@@ -11,7 +11,6 @@ package main
import
(
"crypto/ed25519"
"encoding/base64"
"encoding/json"
"strings"
"sync"
...
...
@@ -122,8 +121,7 @@ func (w *wasmModel) deleteMsgByChannel(channelID *id.ID) error {
}
// Perform the operation
channelIdStr
:=
base64
.
StdEncoding
.
EncodeToString
(
channelID
.
Marshal
())
keyRange
,
err
:=
idb
.
NewKeyRangeOnly
(
js
.
ValueOf
(
channelIdStr
))
keyRange
,
err
:=
idb
.
NewKeyRangeOnly
(
impl
.
EncodeBytes
(
channelID
.
Marshal
()))
cursorRequest
,
err
:=
index
.
OpenCursorRange
(
keyRange
,
idb
.
CursorNext
)
if
err
!=
nil
{
return
errors
.
WithMessagef
(
parentErr
,
"Unable to open Cursor: %+v"
,
err
)
...
...
@@ -303,9 +301,8 @@ func (w *wasmModel) UpdateFromMessageID(messageID message.ID,
w
.
updateMux
.
Lock
()
defer
w
.
updateMux
.
Unlock
()
msgIDStr
:=
base64
.
StdEncoding
.
EncodeToString
(
messageID
.
Marshal
())
currentMsgObj
,
err
:=
impl
.
GetIndex
(
w
.
db
,
messageStoreName
,
messageStoreMessageIndex
,
js
.
ValueOf
(
msgIDStr
))
messageStoreMessageIndex
,
impl
.
EncodeBytes
(
messageID
.
Marshal
()
))
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Failed to get message by index: %+v"
,
err
))
...
...
@@ -489,10 +486,8 @@ func (w *wasmModel) GetMessage(
// DeleteMessage removes a message with the given messageID from storage.
func
(
w
*
wasmModel
)
DeleteMessage
(
messageID
message
.
ID
)
error
{
msgId
:=
js
.
ValueOf
(
base64
.
StdEncoding
.
EncodeToString
(
messageID
.
Bytes
()))
err
:=
impl
.
DeleteIndex
(
w
.
db
,
messageStoreName
,
messageStoreMessageIndex
,
pkeyName
,
msgId
)
err
:=
impl
.
DeleteIndex
(
w
.
db
,
messageStoreName
,
messageStoreMessageIndex
,
pkeyName
,
impl
.
EncodeBytes
(
messageID
.
Marshal
()))
if
err
!=
nil
{
return
err
}
...
...
@@ -510,7 +505,7 @@ func (w *wasmModel) MuteUser(
// msgIDLookup gets the UUID of the Message with the given messageID.
func
(
w
*
wasmModel
)
msgIDLookup
(
messageID
message
.
ID
)
(
*
Message
,
error
)
{
msgIDStr
:=
js
.
ValueOf
(
base64
.
StdEncoding
.
EncodeToString
(
messageID
.
Bytes
()
))
msgIDStr
:=
impl
.
EncodeBytes
(
messageID
.
Marshal
(
))
resultObj
,
err
:=
impl
.
GetIndex
(
w
.
db
,
messageStoreName
,
messageStoreMessageIndex
,
msgIDStr
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
indexedDb/impl/dm/implementation.go
+
2
−
3
View file @
6d299939
...
...
@@ -223,8 +223,7 @@ func (w *wasmModel) receiveWrapper(messageID message.ID, parentID *message.ID, n
timestamp
time
.
Time
,
round
rounds
.
Round
,
mType
dm
.
MessageType
,
status
dm
.
Status
)
(
uint64
,
error
)
{
// If there is no extant Conversation, create one.
_
,
err
:=
impl
.
Get
(
w
.
db
,
conversationStoreName
,
utils
.
CopyBytesToJS
(
partnerKey
[
:
]))
_
,
err
:=
impl
.
Get
(
w
.
db
,
conversationStoreName
,
impl
.
EncodeBytes
(
partnerKey
))
if
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
impl
.
ErrDoesNotExist
)
{
err
=
w
.
joinConversation
(
nickname
,
partnerKey
,
dmToken
,
...
...
@@ -315,7 +314,7 @@ func (w *wasmModel) receiveHelper(
// msgIDLookup gets the UUID of the Message with the given messageID.
func
(
w
*
wasmModel
)
msgIDLookup
(
messageID
message
.
ID
)
(
uint64
,
error
)
{
resultObj
,
err
:=
impl
.
GetIndex
(
w
.
db
,
messageStoreName
,
messageStoreMessageIndex
,
utils
.
Copy
Bytes
ToJS
(
messageID
.
Marshal
()))
messageStoreMessageIndex
,
impl
.
Encode
Bytes
(
messageID
.
Marshal
()))
if
err
!=
nil
{
return
0
,
err
}
...
...
This diff is collapsed.
Click to expand it.
indexedDb/impl/utils.go
+
6
−
0
View file @
6d299939
...
...
@@ -14,6 +14,7 @@ package impl
import
(
"context"
"encoding/base64"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
...
...
@@ -36,6 +37,11 @@ func NewContext() (context.Context, context.CancelFunc) {
return
context
.
WithTimeout
(
context
.
Background
(),
dbTimeout
)
}
// EncodeBytes returns the proper IndexedDb encoding for a byte slice into js.Value.
func
EncodeBytes
(
input
[]
byte
)
js
.
Value
{
return
js
.
ValueOf
(
base64
.
StdEncoding
.
EncodeToString
(
input
))
}
// Get is a generic helper for getting values from the given [idb.ObjectStore].
// Only usable by primary key.
func
Get
(
db
*
idb
.
Database
,
objectStoreName
string
,
key
js
.
Value
)
(
js
.
Value
,
error
)
{
...
...
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