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
9b9a2cb3
Commit
9b9a2cb3
authored
1 year ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added deleteMessage impl to dm EM impl
parent
e4ed3939
No related branches found
No related tags found
2 merge requests
!130
added deleteMessage impl to dm EM impl
,
!109
Project/haven beta
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
indexedDb/impl/dm/implementation.go
+46
-7
46 additions, 7 deletions
indexedDb/impl/dm/implementation.go
indexedDb/impl/dm/implementation_test.go
+34
-0
34 additions, 0 deletions
indexedDb/impl/dm/implementation_test.go
with
80 additions
and
7 deletions
indexedDb/impl/dm/implementation.go
+
46
−
7
View file @
9b9a2cb3
...
...
@@ -179,13 +179,7 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID message.ID,
}
// Extract the existing Message and update the Status
newMessage
:=
&
Message
{}
err
=
json
.
Unmarshal
([]
byte
(
utils
.
JsToJson
(
currentMsg
)),
newMessage
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Could not JSON unmarshal message: %+v"
,
err
))
return
}
newMessage
,
err
:=
valueToMessage
(
currentMsg
)
newMessage
.
Status
=
uint8
(
status
)
if
!
messageID
.
Equals
(
message
.
ID
{})
{
...
...
@@ -365,6 +359,45 @@ func (w *wasmModel) setBlocked(senderPubKey ed25519.PublicKey, isBlocked bool) e
resultConvo
.
Token
,
resultConvo
.
CodesetVersion
,
timeBlocked
)
}
// DeleteMessage deletes the message with the given message.ID belonging to
// the sender. If the message exists and belongs to the sender, then it is
// deleted and DeleteMessage returns true. If it does not exist, it returns
// false.
func
(
w
*
wasmModel
)
DeleteMessage
(
messageID
message
.
ID
,
senderPubKey
ed25519
.
PublicKey
)
bool
{
parentErr
:=
"failed to DeleteMessage"
msgId
:=
impl
.
EncodeBytes
(
messageID
.
Marshal
())
// Use the key to get the existing Message
currentMsg
,
err
:=
impl
.
GetIndex
(
w
.
db
,
messageStoreName
,
messageStoreMessageIndex
,
msgId
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%s: %+v"
,
parentErr
,
err
)
return
false
}
// Convert the js.Value to a proper object
msgObj
,
err
:=
valueToMessage
(
currentMsg
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%s: %+v"
,
parentErr
,
err
)
return
false
}
// Ensure the public keys match
if
!
bytes
.
Equal
(
msgObj
.
SenderPubKey
,
senderPubKey
)
{
jww
.
ERROR
.
Printf
(
"%s: %s"
,
parentErr
,
"Public keys do not match"
)
return
false
}
// Perform the delete
err
=
impl
.
DeleteIndex
(
w
.
db
,
messageStoreName
,
messageStoreMessageIndex
,
msgPkeyName
,
msgId
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%s: %+v"
,
parentErr
,
err
)
return
false
}
return
true
}
// GetConversation returns the conversation held by the model (receiver).
func
(
w
*
wasmModel
)
GetConversation
(
senderPubKey
ed25519
.
PublicKey
)
*
dm
.
ModelConversation
{
parentErr
:=
"failed to GetConversation"
...
...
@@ -426,3 +459,9 @@ func (w *wasmModel) GetConversations() []dm.ModelConversation {
}
return
conversations
}
// valueToMessage is a helper for converting js.Value to Message.
func
valueToMessage
(
msgObj
js
.
Value
)
(
*
Message
,
error
)
{
resultMsg
:=
&
Message
{}
return
resultMsg
,
json
.
Unmarshal
([]
byte
(
utils
.
JsToJson
(
msgObj
)),
resultMsg
)
}
This diff is collapsed.
Click to expand it.
indexedDb/impl/dm/implementation_test.go
+
34
−
0
View file @
9b9a2cb3
...
...
@@ -14,6 +14,7 @@ import (
"crypto/ed25519"
"encoding/json"
"fmt"
"github.com/stretchr/testify/require"
"gitlab.com/elixxir/client/v4/cmix/rounds"
"gitlab.com/elixxir/client/v4/dm"
"gitlab.com/elixxir/crypto/message"
...
...
@@ -158,3 +159,36 @@ func TestWasmModel_BlockSender(t *testing.T) {
t
.
Fatal
(
"Expected blocked to be false"
)
}
}
// Test failed and successful deletes
func
TestWasmModel_DeleteMessage
(
t
*
testing
.
T
)
{
m
,
err
:=
newWASMModel
(
"TestWasmModel_DeleteMessage"
,
nil
,
dummyReceivedMessageCB
)
if
err
!=
nil
{
t
.
Fatal
(
err
.
Error
())
}
// Insert test message
testBytes
:=
[]
byte
(
"test"
)
testBadBytes
:=
[]
byte
(
"uwu"
)
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
1
},
0
,
testBytes
)
testMsg
:=
&
Message
{
MessageID
:
testMsgId
.
Marshal
(),
ConversationPubKey
:
testBytes
,
ParentMessageID
:
nil
,
Timestamp
:
time
.
Now
(),
SenderPubKey
:
testBytes
,
CodesetVersion
:
5
,
Status
:
5
,
Text
:
""
,
Type
:
5
,
Round
:
5
,
}
_
,
err
=
m
.
upsertMessage
(
testMsg
)
require
.
NoError
(
t
,
err
)
// Non-matching pub key, should fail to delete
require
.
False
(
t
,
m
.
DeleteMessage
(
testMsgId
,
testBadBytes
))
// Correct pub key, should have deleted
require
.
True
(
t
,
m
.
DeleteMessage
(
testMsgId
,
testBytes
))
}
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