diff --git a/go.mod b/go.mod index 921917f976f647eca450308af7f08c4d00410b53..d1d0a873db4d6e7da68bfebbac1d19d455505f4c 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( 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/elixxir/wasm-utils v0.0.0-20230518173031-b91665c79b0a @@ -54,7 +54,7 @@ require ( 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 diff --git a/go.sum b/go.sum index dcc1a4da59377baf54789c83771ff5ad3f12eee2..2f1616ec0d84896d201d80d3473a33230bff3a8b 100644 --- a/go.sum +++ b/go.sum @@ -398,18 +398,16 @@ github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo= github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= gitlab.com/elixxir/bloomfilter v0.0.0-20230315224936-a4459418f300 h1:oF3Pkf5NBb48KB89Q4sQXKQCIsWp1IVsqKWHWFsfBRc= gitlab.com/elixxir/bloomfilter v0.0.0-20230315224936-a4459418f300/go.mod h1:1X8gRIAPDisS3W6Vtr/ymiUmZMJUIwDV1o5DEOo/pzw= -gitlab.com/elixxir/client/v4 v4.6.3 h1:oUsm5cn2Vnfqz+xwGYKrqFkPNN3sDAyp00EPGhUIA5E= -gitlab.com/elixxir/client/v4 v4.6.3/go.mod h1:G+lN+LvQPGcm5BQnrhnqT1xiRIAzH3OffAM+5oI9SUg= +gitlab.com/elixxir/client/v4 v4.6.4-0.20230505231815-170bcab606e5 h1:XwO9zspfX8CoeR5PydIDypJLxTL1WTwbdEyNDKIjvFs= +gitlab.com/elixxir/client/v4 v4.6.4-0.20230505231815-170bcab606e5/go.mod h1:L8wxnDC8Gqo9uVzfQg/KiAIQ3xO8vK3YIGANzfKHcHA= gitlab.com/elixxir/comms v0.0.4-0.20230310205528-f06faa0d2f0b h1:8AVK93UEs/aufoqtFgyMVt9gf0oJ8F4pA60ZvEVvG+s= gitlab.com/elixxir/comms v0.0.4-0.20230310205528-f06faa0d2f0b/go.mod h1:z+qW0D9VpY5QKTd7wRlb5SK4kBNqLYsa4DXBcUXue9Q= gitlab.com/elixxir/crypto v0.0.7-0.20230413162806-a99ec4bfea32 h1:Had0F7rMPgJJ2BUZoFNgeJq33md9RpV15nvd08Uxdzc= gitlab.com/elixxir/crypto v0.0.7-0.20230413162806-a99ec4bfea32/go.mod h1:/SLOlvkYVVJf6IU+vEjMLnS7cjjcoTlPV45g6tv6INc= -gitlab.com/elixxir/ekv v0.2.1 h1:dtwbt6KmAXG2Tik5d60iDz2fLhoFBgWwST03p7T+9Is= -gitlab.com/elixxir/ekv v0.2.1/go.mod h1:USLD7xeDnuZEavygdrgzNEwZXeLQJK/w1a+htpN+JEU= +gitlab.com/elixxir/ekv v0.2.2 h1:hzb3JLTFJXETaSvWoK1xJ89K6W00uFprcoAdogPZCEM= +gitlab.com/elixxir/ekv v0.2.2/go.mod h1:USLD7xeDnuZEavygdrgzNEwZXeLQJK/w1a+htpN+JEU= gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c h1:muG8ff95woeVVwQoJHCEclxBFB22lc7EixPylEkYDRU= gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c/go.mod h1:phun4PLkHJA6wcL4JIhhxZztrmCyJHWPNppBP3DUD2Y= -gitlab.com/elixxir/wasm-utils v0.0.0-20230518173031-b91665c79b0a h1:OU1YZwVbrkaGBD4bH+V/vgLM2o9QMi8Gct//OckA6kc= -gitlab.com/elixxir/wasm-utils v0.0.0-20230518173031-b91665c79b0a/go.mod h1:wB7Vh/7LWUm8wYRBSd+6lxfpk4CnDaHTkLCIVKfL2TA= gitlab.com/xx_network/comms v0.0.4-0.20230214180029-5387fb85736d h1:AZf2h0fxyO1KxhZPP9//jG3Swb2BcuKbxtNXJgooLss= gitlab.com/xx_network/comms v0.0.4-0.20230214180029-5387fb85736d/go.mod h1:8cwPyH6G8C4qf/U5KDghn1ksOh79MrNqthjKDrfvbXY= gitlab.com/xx_network/crypto v0.0.5-0.20230214003943-8a09396e95dd h1:IleH6U5D/c2zF6YL/z3cBKqBPnI5ApNMCtU7ia4t228= diff --git a/indexedDb/impl/channels/init.go b/indexedDb/impl/channels/init.go index ecc16da447b0db684ca55031a26e6a3d19206320..980e7610b5b613750ec591650e4dee26cad6dc09 100644 --- a/indexedDb/impl/channels/init.go +++ b/indexedDb/impl/channels/init.go @@ -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 }) @@ -150,15 +142,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, }) diff --git a/indexedDb/impl/dm/implementation.go b/indexedDb/impl/dm/implementation.go index 227e96064f2fd7b48f9470f3a2c290d2f5e8e2ae..a92691878ebc4b6c21cd1d38297aca23e4109920 100644 --- a/indexedDb/impl/dm/implementation.go +++ b/indexedDb/impl/dm/implementation.go @@ -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 } @@ -349,14 +350,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). @@ -369,11 +376,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, } } @@ -411,11 +418,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 diff --git a/indexedDb/impl/dm/implementation_test.go b/indexedDb/impl/dm/implementation_test.go index bbd10cad99115fdc2f48fca5faf678de8f012d89..c8f42c3871bcfc841683e93b57e2ed4105ab000b 100644 --- a/indexedDb/impl/dm/implementation_test.go +++ b/indexedDb/impl/dm/implementation_test.go @@ -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") } } diff --git a/indexedDb/impl/dm/model.go b/indexedDb/impl/dm/model.go index dd4fee16205c9736936830bbb598252dc0774e05..774d011fe4987078808febd74a1657839e06dc8a 100644 --- a/indexedDb/impl/dm/model.go +++ b/indexedDb/impl/dm/model.go @@ -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"` }