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
b1f40d24
Commit
b1f40d24
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
first simple implementaions of leaveChannel and joinChannel
parent
a638a8ed
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
+94
-2
94 additions, 2 deletions
indexedDb/implementation.go
with
94 additions
and
2 deletions
indexedDb/implementation.go
+
94
−
2
View file @
b1f40d24
...
...
@@ -10,8 +10,13 @@
package
indexedDb
import
(
"context"
"encoding/json"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/channels"
"syscall/js"
"time"
"gitlab.com/elixxir/client/cmix/rounds"
...
...
@@ -20,6 +25,9 @@ import (
"gitlab.com/xx_network/primitives/id"
)
// jsObject is the Golang type translation for a JavaScript object
type
jsObject
map
[
string
]
interface
{}
// wasmModel implements [channels.EventModel] interface which uses the channels
// system passed an object which adheres to in order to get events on the channel.
type
wasmModel
struct
{
...
...
@@ -28,12 +36,96 @@ type wasmModel struct {
// JoinChannel is called whenever a channel is joined locally.
func
(
w
*
wasmModel
)
JoinChannel
(
channel
*
cryptoBroadcast
.
Channel
)
{
parentErr
:=
errors
.
New
(
"failed to JoinChannel"
)
// Build Channel object
newChannel
:=
Channel
{
Id
:
channel
.
ReceptionID
.
Marshal
(),
Name
:
channel
.
Name
,
Description
:
channel
.
Description
,
}
// Convert Channel to jsObject
newChannelJson
,
err
:=
json
.
Marshal
(
&
newChannel
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Unable to marshal Channel: %+v"
,
err
))
return
}
var
channelObj
*
jsObject
err
=
json
.
Unmarshal
(
newChannelJson
,
channelObj
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Unable to unmarshal Channel: %+v"
,
err
))
return
}
// Prepare the Transaction
ctx
:=
context
.
Background
()
txn
,
err
:=
w
.
db
.
Transaction
(
idb
.
TransactionReadWrite
,
messageStoreName
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Unable to create Transaction: %+v"
,
err
))
return
}
store
,
err
:=
txn
.
ObjectStore
(
messageStoreName
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Unable to get ObjectStore: %+v"
,
err
))
return
}
// Perform the operation
_
,
err
=
store
.
Add
(
js
.
ValueOf
(
*
channelObj
))
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Unable to Add Channel: %+v"
,
err
))
return
}
// Wait for the operation to return
err
=
txn
.
Await
(
ctx
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Adding Channel failed: %+v"
,
err
))
return
}
}
// LeaveChannel is called whenever a channel is left locally.
func
(
w
*
wasmModel
)
LeaveChannel
(
channelID
*
id
.
ID
)
{
parentErr
:=
errors
.
New
(
"failed to LeaveChannel"
)
// Prepare the Transaction
ctx
:=
context
.
Background
()
txn
,
err
:=
w
.
db
.
Transaction
(
idb
.
TransactionReadWrite
,
messageStoreName
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Unable to create Transaction: %+v"
,
err
))
return
}
store
,
err
:=
txn
.
ObjectStore
(
messageStoreName
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Unable to get ObjectStore: %+v"
,
err
))
return
}
// Perform the operation
_
,
err
=
store
.
Delete
(
js
.
ValueOf
(
channelID
.
String
()))
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Unable to Delete Channel: %+v"
,
err
))
return
}
// Wait for the operation to return
err
=
txn
.
Await
(
ctx
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
Wrapf
(
parentErr
,
"Deleting Channel failed: %+v"
,
err
))
return
}
}
// ReceiveMessage is called whenever a message is received on a given channel
...
...
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