Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
client
Commits
52be5f4d
Commit
52be5f4d
authored
3 years ago
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
implemented the handling for batched notifications.go
parent
88431cc7
No related branches found
No related tags found
2 merge requests
!117
Release
,
!94
implemented the handling for batched notifications.go
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bindings/notifications.go
+76
-25
76 additions, 25 deletions
bindings/notifications.go
with
76 additions
and
25 deletions
bindings/notifications.go
+
76
−
25
View file @
52be5f4d
...
@@ -9,10 +9,13 @@ package bindings
...
@@ -9,10 +9,13 @@ package bindings
import
(
import
(
"encoding/base64"
"encoding/base64"
"encoding/csv"
"encoding/json"
"encoding/json"
"github.com/pkg/errors"
"github.com/pkg/errors"
"gitlab.com/elixxir/client/storage/edge"
"gitlab.com/elixxir/client/storage/edge"
pb
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/crypto/fingerprint"
"gitlab.com/elixxir/crypto/fingerprint"
"strings"
)
)
type
NotificationForMeReport
struct
{
type
NotificationForMeReport
struct
{
...
@@ -33,7 +36,24 @@ func (nfmr *NotificationForMeReport) Source() []byte {
...
@@ -33,7 +36,24 @@ func (nfmr *NotificationForMeReport) Source() []byte {
return
nfmr
.
source
return
nfmr
.
source
}
}
// NotificationForMe Check if a notification received is for me
type
ManyNotificationForMeReport
struct
{
many
[]
*
NotificationForMeReport
}
func
(
mnfmr
*
ManyNotificationForMeReport
)
Get
(
i
int
)
(
*
NotificationForMeReport
,
error
)
{
if
len
(
mnfmr
.
many
)
>=
i
{
return
nil
,
errors
.
New
(
"Cannot get, too long"
)
}
return
mnfmr
.
many
[
i
],
nil
}
func
(
mnfmr
*
ManyNotificationForMeReport
)
Len
()
int
{
return
len
(
mnfmr
.
many
)
}
// NotificationsForMe Check if a notification received is for me
// It returns a NotificationForMeReport which contains a ForMe bool stating if it is for the caller,
// It returns a NotificationForMeReport which contains a ForMe bool stating if it is for the caller,
// a Type, and a source. These are as follows:
// a Type, and a source. These are as follows:
// TYPE SOURCE DESCRIPTION
// TYPE SOURCE DESCRIPTION
...
@@ -44,17 +64,7 @@ func (nfmr *NotificationForMeReport) Source() []byte {
...
@@ -44,17 +64,7 @@ func (nfmr *NotificationForMeReport) Source() []byte {
// "e2e" sender user ID reception of an E2E message
// "e2e" sender user ID reception of an E2E message
// "group" group ID reception of a group chat message
// "group" group ID reception of a group chat message
// "endFT" sender user ID Last message sent confirming end of file transfer
// "endFT" sender user ID Last message sent confirming end of file transfer
func
NotificationForMe
(
messageHash
,
idFP
string
,
preimages
string
)
(
*
NotificationForMeReport
,
error
)
{
func
NotificationsForMe
(
notifCSV
,
preimages
string
)
(
*
ManyNotificationForMeReport
,
error
)
{
//handle message hash and idFP
messageHashBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
messageHash
)
if
err
!=
nil
{
return
nil
,
errors
.
WithMessage
(
err
,
"Failed to decode message ID"
)
}
idFpBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
idFP
)
if
err
!=
nil
{
return
nil
,
errors
.
WithMessage
(
err
,
"Failed to decode identity fingerprint"
)
}
//handle deserialization of preimages
//handle deserialization of preimages
var
preimageList
[]
edge
.
Preimage
var
preimageList
[]
edge
.
Preimage
if
err
:=
json
.
Unmarshal
([]
byte
(
preimages
),
&
preimageList
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
([]
byte
(
preimages
),
&
preimageList
);
err
!=
nil
{
...
@@ -62,23 +72,37 @@ func NotificationForMe(messageHash, idFP string, preimages string) (*Notificatio
...
@@ -62,23 +72,37 @@ func NotificationForMe(messageHash, idFP string, preimages string) (*Notificatio
"cannot check if notification is for me"
)
"cannot check if notification is for me"
)
}
}
//check if any preimages match with the passed in data
list
,
err
:=
DecodeNotificationsCSV
(
notifCSV
)
for
_
,
preimage
:=
range
preimageList
{
if
err
!=
nil
{
if
fingerprint
.
CheckIdentityFpFromMessageHash
(
idFpBytes
,
messageHashBytes
,
preimage
.
Data
)
{
return
nil
,
err
return
&
NotificationForMeReport
{
}
forMe
:
true
,
tYpe
:
preimage
.
Type
,
notifList
:=
make
(
[]
*
NotificationForMeReport
,
0
,
len
(
list
))
source
:
preimage
.
Source
,
},
nil
for
_
,
notifData
:=
range
list
{
n
:=
&
NotificationForMeReport
{
forMe
:
false
,
tYpe
:
""
,
source
:
nil
,
}
//check if any preimages match with the passed in data
for
_
,
preimage
:=
range
preimageList
{
if
fingerprint
.
CheckIdentityFpFromMessageHash
(
notifData
.
IdentityFP
,
notifData
.
MessageHash
,
preimage
.
Data
)
{
n
=
&
NotificationForMeReport
{
forMe
:
true
,
tYpe
:
preimage
.
Type
,
source
:
preimage
.
Source
,
}
}
break
}
}
notifList
=
append
(
notifList
,
n
)
}
}
return
&
NotificationForMeReport
{
forMe
:
false
,
return
&
ManyNotificationForMeReport
{
many
:
notifList
},
nil
tYpe
:
""
,
source
:
nil
,
},
nil
}
}
// RegisterForNotifications accepts firebase messaging token
// RegisterForNotifications accepts firebase messaging token
func
(
c
*
Client
)
RegisterForNotifications
(
token
string
)
error
{
func
(
c
*
Client
)
RegisterForNotifications
(
token
string
)
error
{
return
c
.
api
.
RegisterForNotifications
(
token
)
return
c
.
api
.
RegisterForNotifications
(
token
)
...
@@ -88,3 +112,30 @@ func (c *Client) RegisterForNotifications(token string) error {
...
@@ -88,3 +112,30 @@ func (c *Client) RegisterForNotifications(token string) error {
func
(
c
*
Client
)
UnregisterForNotifications
()
error
{
func
(
c
*
Client
)
UnregisterForNotifications
()
error
{
return
c
.
api
.
UnregisterForNotifications
()
return
c
.
api
.
UnregisterForNotifications
()
}
}
func
DecodeNotificationsCSV
(
data
string
)([]
*
pb
.
NotificationData
,
error
){
r
:=
csv
.
NewReader
(
strings
.
NewReader
(
data
))
read
,
err
:=
r
.
ReadAll
()
if
err
!=
nil
{
return
nil
,
errors
.
WithMessage
(
err
,
"Failed to decode notifications CSV"
)
}
l
:=
make
([]
*
pb
.
NotificationData
,
len
(
read
))
for
i
,
touple
:=
range
read
{
messageHash
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
touple
[
0
])
if
err
!=
nil
{
return
nil
,
errors
.
WithMessage
(
err
,
"Failed decode an element"
)
}
identityFP
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
touple
[
1
])
if
err
!=
nil
{
return
nil
,
errors
.
WithMessage
(
err
,
"Failed decode an element"
)
}
l
[
i
]
=
&
pb
.
NotificationData
{
EphemeralID
:
0
,
IdentityFP
:
identityFP
,
MessageHash
:
messageHash
,
}
}
return
l
,
nil
}
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