Skip to content
Snippets Groups Projects
Commit 32d79d4e authored by Josh Brooks's avatar Josh Brooks
Browse files

Refactor bindings' notification implementation

parent ed81d3ab
No related branches found
No related tags found
2 merge requests!510Release,!360Implement Notifications for bindings
...@@ -9,11 +9,12 @@ package bindings ...@@ -9,11 +9,12 @@ package bindings
import ( import (
"encoding/json" "encoding/json"
"gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/primitives/notifications" "gitlab.com/elixxir/primitives/notifications"
) )
// NotificationReports is a list of NotificationReport's. This will be returned // NotificationReports is a list of NotificationReport's. This will be returned
// via NotificationsForMe as a JSON marshalled byte data. // via GetNotificationsReport as a JSON marshalled byte data.
// //
// Example JSON: // Example JSON:
// //
...@@ -51,17 +52,19 @@ type NotificationReports []NotificationReport ...@@ -51,17 +52,19 @@ type NotificationReports []NotificationReport
// Below is a table that will define the contextual meaning of the Source field // Below is a table that will define the contextual meaning of the Source field
// given all possible Type fields. // given all possible Type fields.
// //
// TYPE SOURCE DESCRIPTION // TYPE | SOURCE | DESCRIPTION
// "default" recipient user ID A message with no association. // ________________________________________________________________________________________
// "request" sender user ID A channel request has been received, from Source. // "default" | recipient user ID | A message with no association.
// "reset" sender user ID A channel reset has been received. // "request" | sender user ID | A channel request has been received, from Source.
// "confirm" sender user ID A channel request has been accepted. // "reset" | sender user ID | A channel reset has been received.
// "silent" sender user ID A message where the user should not be notified. // "confirm" | sender user ID | A channel request has been accepted.
// "e2e" sender user ID A reception of an E2E message. // "silent" | sender user ID | A message where the user should not be notified.
// "group" group ID A reception of a group chat message. // "e2e" | sender user ID | A reception of an E2E message.
// "endFT" sender user ID The last message sent confirming end of file transfer. // "group" | group ID | A reception of a group chat message.
// "groupRQ" sender user ID A request from Source to join a group chat. // "endFT" | sender user ID | The last message sent confirming end of file transfer.
// todo iterate over this docstring, ensure descriptions/sources are accurate // "groupRQ" | sender user ID | A request from Source to join a group chat.
// todo iterate over this docstring, ensure descriptions/sources are
// still accurate (they are from the old implementation
type NotificationReport struct { type NotificationReport struct {
// ForMe determines whether this value is for the user. If it is // ForMe determines whether this value is for the user. If it is
// false, this report may be ignored. // false, this report may be ignored.
...@@ -72,7 +75,7 @@ type NotificationReport struct { ...@@ -72,7 +75,7 @@ type NotificationReport struct {
Source []byte Source []byte
} }
// NotificationsForMe parses the received notification data to determine which // GetNotificationsReport parses the received notification data to determine which
// notifications are for this user. // This returns the JSON-marshalled // notifications are for this user. // This returns the JSON-marshalled
// NotificationReports. // NotificationReports.
// //
...@@ -80,21 +83,29 @@ type NotificationReport struct { ...@@ -80,21 +83,29 @@ type NotificationReport struct {
// - e2eID - e2e object ID in the tracker // - e2eID - e2e object ID in the tracker
// - notificationCSV - the notification data received from the // - notificationCSV - the notification data received from the
// notifications' server. // notifications' server.
// - marshalledServices - the JSON-marshalled list of services the backend
// keeps track of. Refer to Cmix.TrackServices for information about this.
// //
// Returns: // Returns:
// - []byte - A JSON marshalled NotificationReports. Some NotificationReport's // - []byte - A JSON marshalled NotificationReports. Some NotificationReport's
// within in this structure may have their NotificationReport.ForMe // within in this structure may have their NotificationReport.ForMe
// set to false. These may be ignored. // set to false. These may be ignored.
func NotificationsForMe(e2eId int, notificationCSV string) ([]byte, error) { func GetNotificationsReport(e2eId int, notificationCSV string,
marshalledServices []byte) ([]byte, error) {
// Retrieve user // Retrieve user
user, err := e2eTrackerSingleton.get(e2eId) user, err := e2eTrackerSingleton.get(e2eId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
serviceList := message.ServiceList{}
err = json.Unmarshal(marshalledServices, &serviceList)
if err != nil {
return nil, err
}
// Retrieve the services for this user // Retrieve the services for this user
serviceMap := user.api.GetCmix().GetServices() services := serviceList[*user.api.GetReceptionIdentity().ID]
services := serviceMap[*user.api.GetReceptionIdentity().ID]
// Decode notifications' server data // Decode notifications' server data
notificationList, err := notifications.DecodeNotificationsCSV(notificationCSV) notificationList, err := notifications.DecodeNotificationsCSV(notificationCSV)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment