diff --git a/bindings/notifications.go b/bindings/notifications.go index 6d36a96ef780d6dd785c060e48ff34d5ba9273cd..e028ae0ce7a2186a2afd67873e668e7109a33022 100644 --- a/bindings/notifications.go +++ b/bindings/notifications.go @@ -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)