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
Merge requests
!360
Implement Notifications for bindings
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Implement Notifications for bindings
XX-4082/Notifications
into
release
Overview
0
Commits
5
Pipelines
0
Changes
5
Merged
Josh Brooks
requested to merge
XX-4082/Notifications
into
release
2 years ago
Overview
0
Commits
5
Pipelines
0
Changes
5
Expand
0
0
Merge request reports
Compare
release
version 2
32d79d4e
2 years ago
version 1
b5c88b43
2 years ago
release (base)
and
version 1
latest version
d8abdf19
5 commits,
2 years ago
version 2
32d79d4e
4 commits,
2 years ago
version 1
b5c88b43
1 commit,
2 years ago
5 files
+
162
−
51
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
bindings/notifications.go
+
108
−
45
Options
@@ -7,67 +7,130 @@
package
bindings
// FIXME: This is the old NotificationsForMe code that needs to be fixed
/*
type NotificationForMeReport struct {
ForMe bool
Type string
Source []byte
}
import
(
"encoding/json"
"gitlab.com/elixxir/primitives/notifications"
)
// NotificationReports is a list of NotificationReport's. This will be returned
// via NotificationsForMe as a JSON marshalled byte data.
//
// Example JSON:
//
// [
// {
// "ForMe": true,
// "Type": "e2e",
// "Source": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD"
// },
// {
// "ForMe": true,
// "Type": "e2e",
// "Source": "AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD"
// },
// {
// "ForMe": true,
// "Type": "e2e",
// "Source": "AAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD"
// }
//]
type
NotificationReports
[]
NotificationReport
type ManyNotificationForMeReport struct {
Many []*NotificationForMeReport
// NotificationReport is the bindings' representation for notifications for
// this user.
//
// Example NotificationReport JSON:
//
// {
// "ForMe": true,
// "Type": "e2e",
// "Source": "dGVzdGVyMTIzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
//}
//
// Given the Type, the Source value will have specific contextual meanings.
// Below is a table that will define the contextual meaning of the Source field
// given all possible Type fields.
//
// TYPE SOURCE DESCRIPTION
// "default" recipient user ID A message with no association.
// "request" sender user ID A channel request has been received, from Source.
// "reset" sender user ID A channel reset has been received.
// "confirm" sender user ID A channel request has been accepted.
// "silent" sender user ID A message where the user should not be notified.
// "e2e" sender user ID A reception of an E2E message.
// "group" group ID A reception of a group chat message.
// "endFT" sender user ID The last message sent confirming end of file transfer.
// "groupRQ" sender user ID A request from Source to join a group chat.
// todo iterate over this docstring, ensure descriptions/sources are accurate
type
NotificationReport
struct
{
// ForMe determines whether this value is for the user. If it is
// false, this report may be ignored.
ForMe
bool
// Type is the type of notification. The list can be seen
Type
string
// Source is the source of the notification.
Source
[]
byte
}
// 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,
// a Type, and a source. These are as follows:
// TYPE SOURCE DESCRIPTION
// "default" recipient user ID A message with no association
// "request" sender user ID A channel request has been received
// "reset" sender user ID A channel reset has been received
// "confirm" sender user ID A channel request has been accepted
// "silent" sender user ID A message which should not be notified on
// "e2e" sender user ID reception of an E2E message
// "group" group ID reception of a group chat message
// "endFT" sender user ID Last message sent confirming end of file transfer
// "groupRQ" sender user ID Request from sender to join a group chat
func NotificationsForMe(notifCSV, preimages string) (*ManyNotificationForMeReport, error) {
// Handle deserialization of preimages
var preimageList []edge.Preimage
if err := json.Unmarshal([]byte(preimages), &preimageList); err != nil {
return nil, errors.WithMessagef(err, "Failed to unmarshal the " +
"preimages list, cannot check if notification is for me")
// NotificationsForMe parses the received notification data to determine which
// notifications are for this user. // This returns the JSON-marshalled
// NotificationReports.
//
// Parameters:
// - e2eID - e2e object ID in the tracker
// - notificationCSV - the notification data received from the
// notifications' server.
//
// Returns:
// - []byte - A JSON marshalled NotificationReports. Some NotificationReport's
// within in this structure may have their NotificationReport.ForMe
// set to false. These may be ignored.
func
NotificationsForMe
(
e2eId
int
,
notificationCSV
string
)
([]
byte
,
error
)
{
// Retrieve user
user
,
err
:=
e2eTrackerSingleton
.
get
(
e2eId
)
if
err
!=
nil
{
return
nil
,
err
}
list, err := notifications.DecodeNotificationsCSV(notifCSV)
// Retrieve the services for this user
serviceMap
:=
user
.
api
.
GetCmix
()
.
GetServices
()
services
:=
serviceMap
[
*
user
.
api
.
GetReceptionIdentity
()
.
ID
]
// Decode notifications' server data
notificationList
,
err
:=
notifications
.
DecodeNotificationsCSV
(
notificationCSV
)
if
err
!=
nil
{
return
nil
,
err
}
notifList := make([]*NotificationForMeReport, len(list))
// Construct a report list
reportList
:=
make
([]
*
NotificationReport
,
len
(
notificationList
))
for i, notifData := range list {
notifList[i] = &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) {
notifList[i] = &NotificationForMeReport{
// Iterate over data provided by server
for
i
:=
range
notificationList
{
notifData
:=
notificationList
[
i
]
// Iterate over all services
for
j
:=
range
services
{
// Pull data from services and from notification data
service
:=
services
[
j
]
messageHash
:=
notifData
.
MessageHash
hash
:=
service
.
HashFromMessageHash
(
notifData
.
MessageHash
)
// Check if this notification data is recognized by
// this service, ie "ForMe"
if
service
.
ForMeFromMessageHash
(
messageHash
,
hash
)
{
// Fill report list with service data
reportList
[
i
]
=
&
NotificationReport
{
ForMe
:
true
,
Type:
preimage.Type
,
Source:
preimage.Source
,
Type
:
service
.
Tag
,
Source
:
service
.
Identifier
,
}
break
}
}
}
return
&ManyNotificationForMeReport{notifList}, nil
}
*/
return
json
.
Marshal
(
reportList
)
}
// RegisterForNotifications allows a client to register for push notifications.
// The token is a firebase messaging token.
Loading