Skip to content
Snippets Groups Projects
Commit ee482b0f authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

merged indexedDb migrations for beta into single version; added blockedTimestamp to DM

parent 4da16211
No related branches found
No related tags found
2 merge requests!109Project/haven beta,!106merged indexedDb migrations for beta into single version; added blockedTimestamp to DM
......@@ -6,8 +6,9 @@ require (
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
github.com/hack-pad/go-indexeddb v0.2.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.7.0
github.com/spf13/jwalterweatherman v1.1.0
gitlab.com/elixxir/client/v4 v4.6.3
gitlab.com/elixxir/client/v4 v4.6.4-0.20230505231815-170bcab606e5
gitlab.com/elixxir/crypto v0.0.7-0.20230413162806-a99ec4bfea32
gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c
gitlab.com/xx_network/crypto v0.0.5-0.20230214003943-8a09396e95dd
......@@ -24,12 +25,10 @@ require (
github.com/cloudflare/circl v1.2.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/elliotchance/orderedmap v1.4.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gobwas/ws v1.1.0 // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
......@@ -37,34 +36,24 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20221003100820-41fad3beba17 // indirect
github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pkg/profile v1.6.0 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/sethvargo/go-diceware v0.3.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.2.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
gitlab.com/elixxir/bloomfilter v0.0.0-20230315224936-a4459418f300 // indirect
gitlab.com/elixxir/comms v0.0.4-0.20230310205528-f06faa0d2f0b // indirect
gitlab.com/elixxir/ekv v0.2.1 // indirect
gitlab.com/elixxir/ekv v0.2.2 // indirect
gitlab.com/xx_network/comms v0.0.4-0.20230214180029-5387fb85736d // indirect
gitlab.com/xx_network/ring v0.0.3-0.20220902183151-a7d3b15bc981 // indirect
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec // indirect
......@@ -78,9 +67,6 @@ require (
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/sqlite v1.4.4 // indirect
gorm.io/gorm v1.24.3 // indirect
nhooyr.io/websocket v1.8.7 // indirect
......
This diff is collapsed.
......@@ -23,7 +23,7 @@ import (
// currentVersion is the current version of the IndexedDb runtime. Used for
// migration purposes.
const currentVersion uint = 2
const currentVersion uint = 1
// NewWASMEventModel returns a [channels.EventModel] backed by a wasmModel.
// The name should be a base64 encoding of the users public key. Returns the
......@@ -62,14 +62,6 @@ func newWASMModel(databaseName string, encryption cryptoChannel.Cipher,
oldVersion = 1
}
if oldVersion == 1 && newVersion >= 2 {
err := v2Upgrade(db)
if err != nil {
return err
}
oldVersion = 2
}
// if oldVersion == 1 && newVersion >= 2 { v2Upgrade(), oldVersion = 2 }
return nil
})
......@@ -149,15 +141,8 @@ func v1Upgrade(db *idb.Database) error {
return err
}
return nil
}
// v1Upgrade performs the v1 -> v2 database upgrade.
//
// This can never be changed without permanently breaking backwards
// compatibility.
func v2Upgrade(db *idb.Database) error {
_, err := db.CreateObjectStore(fileStoreName, idb.ObjectStoreOptions{
// Build File ObjectStore
_, err = db.CreateObjectStore(fileStoreName, idb.ObjectStoreOptions{
KeyPath: js.ValueOf(pkeyName),
AutoIncrement: false,
})
......
......@@ -13,6 +13,7 @@ import (
"bytes"
"crypto/ed25519"
"encoding/json"
"gitlab.com/xx_network/primitives/netTime"
"strings"
"syscall/js"
"time"
......@@ -42,16 +43,16 @@ type wasmModel struct {
// upsertConversation is used for joining or updating a Conversation.
func (w *wasmModel) upsertConversation(nickname string,
pubKey ed25519.PublicKey, partnerToken uint32, codeset uint8,
blocked bool) error {
blockedTimestamp *time.Time) error {
parentErr := errors.New("[DM indexedDB] failed to upsertConversation")
// Build object
newConvo := Conversation{
Pubkey: pubKey,
Nickname: nickname,
Token: partnerToken,
CodesetVersion: codeset,
Blocked: blocked,
Pubkey: pubKey,
Nickname: nickname,
Token: partnerToken,
CodesetVersion: codeset,
BlockedTimestamp: blockedTimestamp,
}
// Convert to jsObject
......@@ -231,11 +232,11 @@ func (w *wasmModel) receiveWrapper(messageID message.ID, parentID *message.ID, n
"[DM indexedDB] Joining conversation with %s", nickname)
convoToUpdate = &Conversation{
Pubkey: partnerKey,
Nickname: nickname,
Token: partnerToken,
CodesetVersion: codeset,
Blocked: false,
Pubkey: partnerKey,
Nickname: nickname,
Token: partnerToken,
CodesetVersion: codeset,
BlockedTimestamp: nil,
}
}
} else {
......@@ -268,7 +269,7 @@ func (w *wasmModel) receiveWrapper(messageID message.ID, parentID *message.ID, n
conversationUpdated := convoToUpdate != nil
if conversationUpdated {
err = w.upsertConversation(convoToUpdate.Nickname, convoToUpdate.Pubkey,
convoToUpdate.Token, convoToUpdate.CodesetVersion, convoToUpdate.Blocked)
convoToUpdate.Token, convoToUpdate.CodesetVersion, convoToUpdate.BlockedTimestamp)
if err != nil {
return 0, err
}
......@@ -348,14 +349,20 @@ func (w *wasmModel) UnblockSender(senderPubKey ed25519.PublicKey) {
// setBlocked is a helper for blocking/unblocking a given Conversation.
func (w *wasmModel) setBlocked(senderPubKey ed25519.PublicKey, isBlocked bool) error {
// Get current Conversation and set blocked
// Get current Conversation and set blocked accordingly
resultConvo, err := w.getConversation(senderPubKey)
if err != nil {
return err
}
var timeBlocked *time.Time
if isBlocked {
blockUser := netTime.Now()
timeBlocked = &blockUser
}
return w.upsertConversation(resultConvo.Nickname, resultConvo.Pubkey,
resultConvo.Token, resultConvo.CodesetVersion, isBlocked)
resultConvo.Token, resultConvo.CodesetVersion, timeBlocked)
}
// GetConversation returns the conversation held by the model (receiver).
......@@ -368,11 +375,11 @@ func (w *wasmModel) GetConversation(senderPubKey ed25519.PublicKey) *dm.ModelCon
}
return &dm.ModelConversation{
Pubkey: resultConvo.Pubkey,
Nickname: resultConvo.Nickname,
Token: resultConvo.Token,
CodesetVersion: resultConvo.CodesetVersion,
Blocked: resultConvo.Blocked,
Pubkey: resultConvo.Pubkey,
Nickname: resultConvo.Nickname,
Token: resultConvo.Token,
CodesetVersion: resultConvo.CodesetVersion,
BlockedTimestamp: resultConvo.BlockedTimestamp,
}
}
......@@ -410,11 +417,11 @@ func (w *wasmModel) GetConversations() []dm.ModelConversation {
return nil
}
conversations[i] = dm.ModelConversation{
Pubkey: resultConvo.Pubkey,
Nickname: resultConvo.Nickname,
Token: resultConvo.Token,
CodesetVersion: resultConvo.CodesetVersion,
Blocked: resultConvo.Blocked,
Pubkey: resultConvo.Pubkey,
Nickname: resultConvo.Nickname,
Token: resultConvo.Token,
CodesetVersion: resultConvo.CodesetVersion,
BlockedTimestamp: resultConvo.BlockedTimestamp,
}
}
return conversations
......
......@@ -102,7 +102,7 @@ func TestImpl_GetConversations(t *testing.T) {
testBytes := []byte(fmt.Sprintf("%d", i))
testPubKey := ed25519.PublicKey(testBytes)
err = m.upsertConversation("test", testPubKey,
uint32(i), uint8(i), false)
uint32(i), uint8(i), nil)
if err != nil {
t.Fatal(err.Error())
}
......@@ -133,28 +133,28 @@ func TestWasmModel_BlockSender(t *testing.T) {
// Insert a test convo
testPubKey := ed25519.PublicKey{}
err = m.upsertConversation("test", testPubKey, 0, 0, false)
err = m.upsertConversation("test", testPubKey, 0, 0, nil)
if err != nil {
t.Fatal(err.Error())
}
// Default to unblocked
result := m.GetConversation(testPubKey)
if result.Blocked {
if result.BlockedTimestamp != nil {
t.Fatal("Expected blocked to be false")
}
// Now toggle blocked
m.BlockSender(testPubKey)
result = m.GetConversation(testPubKey)
if !result.Blocked {
if result.BlockedTimestamp == nil {
t.Fatal("Expected blocked to be true")
}
// Now toggle blocked again
m.UnblockSender(testPubKey)
result = m.GetConversation(testPubKey)
if result.Blocked {
if result.BlockedTimestamp != nil {
t.Fatal("Expected blocked to be false")
}
}
......@@ -55,9 +55,9 @@ type Message struct {
// message exchange between two recipients.
// A Conversation has many Message.
type Conversation struct {
Pubkey []byte `json:"pub_key"` // Matches convoPkeyName
Nickname string `json:"nickname"`
Token uint32 `json:"token"`
CodesetVersion uint8 `json:"codeset_version"`
Blocked bool `json:"blocked"`
Pubkey []byte `json:"pub_key"` // Matches convoPkeyName
Nickname string `json:"nickname"`
Token uint32 `json:"token"`
CodesetVersion uint8 `json:"codeset_version"`
BlockedTimestamp *time.Time `json:"blocked_timestamp"`
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment