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
bf1abbd0
Commit
bf1abbd0
authored
2 years ago
by
Jake Taylor
Committed by
Richard T. Carback III
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix reactions not having parent; fixed joining duplicate conversations on message recieve
parent
985e8bfb
No related branches found
No related tags found
2 merge requests
!78
fix reactions not having parent; fixed joining duplicate conversations on message recieve
,
!67
fix for latest client release
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indexedDb/impl/dm/implementation.go
+70
-166
70 additions, 166 deletions
indexedDb/impl/dm/implementation.go
with
70 additions
and
166 deletions
indexedDb/impl/dm/implementation.go
+
70
−
166
View file @
bf1abbd0
...
@@ -99,209 +99,63 @@ func buildMessage(messageID, parentID, text []byte, partnerKey, senderKey ed2551
...
@@ -99,209 +99,63 @@ func buildMessage(messageID, parentID, text []byte, partnerKey, senderKey ed2551
func
(
w
*
wasmModel
)
Receive
(
messageID
message
.
ID
,
nickname
string
,
text
[]
byte
,
func
(
w
*
wasmModel
)
Receive
(
messageID
message
.
ID
,
nickname
string
,
text
[]
byte
,
partnerKey
,
senderKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
partnerKey
,
senderKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
mType
dm
.
MessageType
,
status
dm
.
Status
)
uint64
{
round
rounds
.
Round
,
mType
dm
.
MessageType
,
status
dm
.
Status
)
uint64
{
parentErr
:=
errors
.
New
(
"
failed to Receive"
)
parentErr
:=
"[DM indexedDB]
failed to Receive"
jww
.
TRACE
.
Printf
(
"[DM indexedDB] Receive(%s)"
,
messageID
)
jww
.
TRACE
.
Printf
(
"[DM indexedDB] Receive(%s)"
,
messageID
)
// If there is no extant Conversation, create one.
uuid
,
err
:=
w
.
receiveWrapper
(
messageID
,
nil
,
nickname
,
string
(
text
),
_
,
err
:=
impl
.
Get
(
w
.
db
,
conversationStoreN
am
e
,
utils
.
CopyBytesToJS
(
partnerKey
)
)
partnerKey
,
senderKey
,
dmToken
,
codeset
,
timest
am
p
,
round
,
mType
,
status
)
if
err
!=
nil
{
if
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
impl
.
ErrDoesNotExist
)
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
err
,
parentErr
))
err
=
w
.
joinConversation
(
nickname
,
partnerKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] %+v"
,
err
)
return
0
}
}
else
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] %+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
return
0
}
}
else
{
jww
.
DEBUG
.
Printf
(
"[DM indexedDB] Conversation with %s already joined"
,
nickname
)
}
// Handle encryption, if it is present
if
w
.
cipher
!=
nil
{
text
,
err
=
w
.
cipher
.
Encrypt
(
text
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] Failed to encrypt Message: %+v"
,
err
)
return
0
}
}
msgToInsert
:=
buildMessage
(
messageID
.
Bytes
(),
nil
,
text
,
partnerKey
,
senderKey
,
timestamp
,
round
.
ID
,
mType
,
codeset
,
status
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
,
false
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] Failed to receive Message: %+v"
,
err
)
return
0
return
0
}
}
jww
.
TRACE
.
Printf
(
"[DM indexedDB] Calling ReceiveMessageCB(%v, %v, f)"
,
uuid
,
partnerKey
)
go
w
.
receivedMessageCB
(
uuid
,
partnerKey
,
false
)
return
uuid
return
uuid
}
}
func
(
w
*
wasmModel
)
ReceiveText
(
messageID
message
.
ID
,
nickname
,
text
string
,
func
(
w
*
wasmModel
)
ReceiveText
(
messageID
message
.
ID
,
nickname
,
text
string
,
partnerKey
,
senderKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
partnerKey
,
senderKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
parentErr
:=
errors
.
New
(
"
failed to ReceiveText"
)
parentErr
:=
"[DM indexedDB]
failed to ReceiveText"
jww
.
TRACE
.
Printf
(
"[DM indexedDB] ReceiveText(%s)"
,
messageID
)
jww
.
TRACE
.
Printf
(
"[DM indexedDB] ReceiveText(%s)"
,
messageID
)
// If there is no extant Conversation, create one.
uuid
,
err
:=
w
.
receiveWrapper
(
messageID
,
nil
,
nickname
,
text
,
_
,
err
:=
impl
.
Get
(
w
.
db
,
conversationStoreName
,
utils
.
CopyBytesToJS
(
partnerKey
))
partnerKey
,
senderKey
,
dmToken
,
codeset
,
timestamp
,
round
,
if
err
!=
nil
{
dm
.
TextType
,
status
)
if
strings
.
Contains
(
err
.
Error
(),
impl
.
ErrDoesNotExist
)
{
err
=
w
.
joinConversation
(
nickname
,
partnerKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] %+v"
,
err
)
return
0
}
}
else
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] %+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
return
0
}
}
else
{
jww
.
DEBUG
.
Printf
(
"[DM indexedDB] Conversation with %s already joined"
,
nickname
)
return
0
}
// Handle encryption, if it is present
textBytes
:=
[]
byte
(
text
)
if
w
.
cipher
!=
nil
{
textBytes
,
err
=
w
.
cipher
.
Encrypt
(
textBytes
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] Failed to encrypt Message: %+v"
,
err
)
return
0
}
}
msgToInsert
:=
buildMessage
(
messageID
.
Bytes
(),
nil
,
textBytes
,
partnerKey
,
senderKey
,
timestamp
,
round
.
ID
,
dm
.
TextType
,
codeset
,
status
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"
[DM indexedDB] Failed to receive Message: %+v"
,
e
rr
)
jww
.
ERROR
.
Printf
(
"
%+v"
,
errors
.
WithMessagef
(
err
,
parentE
rr
)
)
return
0
return
0
}
}
jww
.
TRACE
.
Printf
(
"[DM indexedDB] Calling ReceiveMessageCB(%v, %v, f)"
,
uuid
,
partnerKey
)
go
w
.
receivedMessageCB
(
uuid
,
partnerKey
,
false
)
return
uuid
return
uuid
}
}
func
(
w
*
wasmModel
)
ReceiveReply
(
messageID
,
reactionTo
message
.
ID
,
nickname
,
func
(
w
*
wasmModel
)
ReceiveReply
(
messageID
,
reactionTo
message
.
ID
,
nickname
,
text
string
,
partnerKey
,
senderKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
text
string
,
partnerKey
,
senderKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
parentErr
:=
errors
.
New
(
"
failed to ReceiveReply"
)
parentErr
:=
"[DM indexedDB]
failed to ReceiveReply"
jww
.
TRACE
.
Printf
(
"[DM indexedDB] ReceiveReply(%s)"
,
messageID
)
jww
.
TRACE
.
Printf
(
"[DM indexedDB] ReceiveReply(%s)"
,
messageID
)
// If there is no extant Conversation, create one.
uuid
,
err
:=
w
.
receiveWrapper
(
messageID
,
&
reactionTo
,
nickname
,
text
,
_
,
err
:=
impl
.
Get
(
w
.
db
,
conversationStoreName
,
utils
.
CopyBytesToJS
(
partnerKey
))
partnerKey
,
senderKey
,
dmToken
,
codeset
,
timestamp
,
round
,
if
err
!=
nil
{
dm
.
TextType
,
status
)
if
strings
.
Contains
(
err
.
Error
(),
impl
.
ErrDoesNotExist
)
{
err
=
w
.
joinConversation
(
nickname
,
partnerKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] %+v"
,
err
)
return
0
}
}
else
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] %+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
return
0
}
}
else
{
jww
.
DEBUG
.
Printf
(
"[DM indexedDB] Conversation with %s already joined"
,
nickname
)
}
// Handle encryption, if it is present
textBytes
:=
[]
byte
(
text
)
if
w
.
cipher
!=
nil
{
textBytes
,
err
=
w
.
cipher
.
Encrypt
(
textBytes
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] Failed to encrypt Message: %+v"
,
err
)
return
0
}
}
msgToInsert
:=
buildMessage
(
messageID
.
Bytes
(),
reactionTo
.
Marshal
(),
textBytes
,
partnerKey
,
senderKey
,
timestamp
,
round
.
ID
,
dm
.
TextType
,
codeset
,
status
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"
[DM indexedDB] Failed to receive Message: %+v"
,
e
rr
)
jww
.
ERROR
.
Printf
(
"
%+v"
,
errors
.
WithMessagef
(
err
,
parentE
rr
)
)
return
0
return
0
}
}
jww
.
TRACE
.
Printf
(
"[DM indexedDB] Calling ReceiveMessageCB(%v, %v, f)"
,
uuid
,
partnerKey
)
go
w
.
receivedMessageCB
(
uuid
,
partnerKey
,
false
)
return
uuid
return
uuid
}
}
func
(
w
*
wasmModel
)
ReceiveReaction
(
messageID
,
_
message
.
ID
,
nickname
,
func
(
w
*
wasmModel
)
ReceiveReaction
(
messageID
,
reactionTo
message
.
ID
,
nickname
,
reaction
string
,
partnerKey
,
senderKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
reaction
string
,
partnerKey
,
senderKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
parentErr
:=
errors
.
New
(
"
failed to Receive
Text"
)
parentErr
:=
"[DM indexedDB]
failed to Receive
Reaction"
jww
.
TRACE
.
Printf
(
"[DM indexedDB] ReceiveReaction(%s)"
,
messageID
)
jww
.
TRACE
.
Printf
(
"[DM indexedDB] ReceiveReaction(%s)"
,
messageID
)
// If there is no extant Conversation, create one.
uuid
,
err
:=
w
.
receiveWrapper
(
messageID
,
&
reactionTo
,
nickname
,
reaction
,
_
,
err
:=
impl
.
Get
(
w
.
db
,
conversationStoreName
,
utils
.
CopyBytesToJS
(
partnerKey
))
partnerKey
,
senderKey
,
dmToken
,
codeset
,
timestamp
,
round
,
dm
.
ReactionType
,
status
)
if
err
!=
nil
{
if
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
impl
.
ErrDoesNotExist
)
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
err
,
parentErr
))
err
=
w
.
joinConversation
(
nickname
,
partnerKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] %+v"
,
err
)
return
0
}
}
else
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] %+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to get Conversation: %+v"
,
err
))
return
0
}
}
else
{
jww
.
DEBUG
.
Printf
(
"[DM indexedDB] Conversation with %s already joined"
,
nickname
)
}
// Handle encryption, if it is present
textBytes
:=
[]
byte
(
reaction
)
if
w
.
cipher
!=
nil
{
textBytes
,
err
=
w
.
cipher
.
Encrypt
(
textBytes
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] Failed to encrypt Message: %+v"
,
err
)
return
0
}
}
msgToInsert
:=
buildMessage
(
messageID
.
Bytes
(),
nil
,
textBytes
,
partnerKey
,
senderKey
,
timestamp
,
round
.
ID
,
dm
.
ReactionType
,
codeset
,
status
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
,
false
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"[DM indexedDB] Failed to receive Message: %+v"
,
err
)
return
0
return
0
}
}
jww
.
TRACE
.
Printf
(
"[DM indexedDB] Calling ReceiveMessageCB(%v, %v, f)"
,
uuid
,
partnerKey
)
go
w
.
receivedMessageCB
(
uuid
,
partnerKey
,
false
)
return
uuid
return
uuid
}
}
...
@@ -363,6 +217,56 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID message.ID,
...
@@ -363,6 +217,56 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64, messageID message.ID,
go
w
.
receivedMessageCB
(
uuid
,
newMessage
.
ConversationPubKey
,
true
)
go
w
.
receivedMessageCB
(
uuid
,
newMessage
.
ConversationPubKey
,
true
)
}
}
// receiveWrapper is a higher-level wrapper of receiveHelper.
func
(
w
*
wasmModel
)
receiveWrapper
(
messageID
message
.
ID
,
parentID
*
message
.
ID
,
nickname
,
data
string
,
partnerKey
,
senderKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
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
,
js
.
ValueOf
(
partnerKey
))
if
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
impl
.
ErrDoesNotExist
)
{
err
=
w
.
joinConversation
(
nickname
,
partnerKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
return
0
,
err
}
}
else
{
return
0
,
err
}
}
else
{
jww
.
DEBUG
.
Printf
(
"[DM indexedDB] Conversation with %s already joined"
,
nickname
)
}
// Handle encryption, if it is present
textBytes
:=
[]
byte
(
data
)
if
w
.
cipher
!=
nil
{
textBytes
,
err
=
w
.
cipher
.
Encrypt
(
textBytes
)
if
err
!=
nil
{
return
0
,
err
}
}
var
parentIdBytes
[]
byte
if
parentID
!=
nil
{
parentIdBytes
=
parentID
.
Marshal
()
}
msgToInsert
:=
buildMessage
(
messageID
.
Bytes
(),
parentIdBytes
,
textBytes
,
senderKey
,
timestamp
,
round
.
ID
,
mType
,
codeset
,
status
)
uuid
,
err
:=
w
.
receiveHelper
(
msgToInsert
,
false
)
if
err
!=
nil
{
return
0
,
err
}
jww
.
TRACE
.
Printf
(
"[DM indexedDB] Calling ReceiveMessageCB(%v, %v, f)"
,
uuid
,
partnerKey
)
go
w
.
receivedMessageCB
(
uuid
,
partnerKey
,
false
)
return
uuid
,
nil
}
// receiveHelper is a private helper for receiving any sort of message.
// receiveHelper is a private helper for receiving any sort of message.
func
(
w
*
wasmModel
)
receiveHelper
(
func
(
w
*
wasmModel
)
receiveHelper
(
newMessage
*
Message
,
isUpdate
bool
)
(
uint64
,
error
)
{
newMessage
*
Message
,
isUpdate
bool
)
(
uint64
,
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