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
import (
"encoding/json"
"gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/primitives/notifications"
)
// 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:
//
......@@ -51,17 +52,19 @@ type NotificationReports []NotificationReport
// 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 | 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
// still accurate (they are from the old implementation
type NotificationReport struct {
// ForMe determines whether this value is for the user. If it is
// false, this report may be ignored.
......@@ -72,7 +75,7 @@ type NotificationReport struct {
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
// NotificationReports.
//
......@@ -80,21 +83,29 @@ type NotificationReport struct {
// - e2eID - e2e object ID in the tracker
// - notificationCSV - the notification data received from the
// notifications' server.
// - marshalledServices - the JSON-marshalled list of services the backend
// keeps track of. Refer to Cmix.TrackServices for information about this.
//
// 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) {
func GetNotificationsReport(e2eId int, notificationCSV string,
marshalledServices []byte) ([]byte, error) {
// Retrieve user
user, err := e2eTrackerSingleton.get(e2eId)
if err != nil {
return nil, err
}
serviceList := message.ServiceList{}
err = json.Unmarshal(marshalledServices, &serviceList)
if err != nil {
return nil, err
}
// Retrieve the services for this user
serviceMap := user.api.GetCmix().GetServices()
services := serviceMap[*user.api.GetReceptionIdentity().ID]
services := serviceList[*user.api.GetReceptionIdentity().ID]
// Decode notifications' server data
notificationList, err := notifications.DecodeNotificationsCSV(notificationCSV)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment