diff --git a/go.mod b/go.mod index d3632899dad4eac6b772b8857744321383387bd1..0015cceb894bd0ac191e23fb2f8c266e9325c78d 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ require ( github.com/hack-pad/go-indexeddb v0.2.0 github.com/pkg/errors v0.9.1 github.com/spf13/jwalterweatherman v1.1.0 - gitlab.com/elixxir/client/v4 v4.6.4-0.20230519223444-1d981a1d95aa - gitlab.com/elixxir/crypto v0.0.7-0.20230519214355-b10a9f95d395 + gitlab.com/elixxir/client/v4 v4.6.4-0.20230522213235-dc7d3feb05b9 + gitlab.com/elixxir/crypto v0.0.7-0.20230522190154-5cbcf67f4b39 gitlab.com/elixxir/primitives v0.0.3-0.20230214180039-9a25e2d3969c gitlab.com/xx_network/crypto v0.0.5-0.20230214003943-8a09396e95dd gitlab.com/xx_network/primitives v0.0.4-0.20230310205521-c440e68e34c4 diff --git a/go.sum b/go.sum index 4b62a6bdd22412f2d6cbff209ab437c999263572..82582a0c49a9b2f22f56b2cf88eaad35a1aeb9e1 100644 --- a/go.sum +++ b/go.sum @@ -529,6 +529,10 @@ gitlab.com/elixxir/client/v4 v4.6.3 h1:oUsm5cn2Vnfqz+xwGYKrqFkPNN3sDAyp00EPGhUIA gitlab.com/elixxir/client/v4 v4.6.3/go.mod h1:G+lN+LvQPGcm5BQnrhnqT1xiRIAzH3OffAM+5oI9SUg= gitlab.com/elixxir/client/v4 v4.6.4-0.20230519223444-1d981a1d95aa h1:PJylTJ4ol3p3Si9cipFmhhWo0YD4VXMrbHQODJ9ACKE= gitlab.com/elixxir/client/v4 v4.6.4-0.20230519223444-1d981a1d95aa/go.mod h1:rDC4sLKgj5kuuiJRp8bD1M7r0mlb0ib7q8q1Euct9/k= +gitlab.com/elixxir/client/v4 v4.6.4-0.20230522204511-a198ba2e5749 h1:mFhb9/TDAtmvuDtBL70vvQCwg7OGSWcCLxXcqcfG3rQ= +gitlab.com/elixxir/client/v4 v4.6.4-0.20230522204511-a198ba2e5749/go.mod h1:rDC4sLKgj5kuuiJRp8bD1M7r0mlb0ib7q8q1Euct9/k= +gitlab.com/elixxir/client/v4 v4.6.4-0.20230522213235-dc7d3feb05b9 h1:/g+OA8nsI0LwY1NgR7WPOAztengA2UqrY7xXZarmwgk= +gitlab.com/elixxir/client/v4 v4.6.4-0.20230522213235-dc7d3feb05b9/go.mod h1:trGefpFqH2+kx4/uEV+yyiEWpGq3AhRMnuBQDhDQKMM= gitlab.com/elixxir/comms v0.0.4-0.20230310205528-f06faa0d2f0b h1:8AVK93UEs/aufoqtFgyMVt9gf0oJ8F4pA60ZvEVvG+s= gitlab.com/elixxir/comms v0.0.4-0.20230310205528-f06faa0d2f0b/go.mod h1:z+qW0D9VpY5QKTd7wRlb5SK4kBNqLYsa4DXBcUXue9Q= gitlab.com/elixxir/comms v0.0.4-0.20230519211512-4a998f4b0938 h1:f27+QUFiGWrprKm+fstOg3ABkYLpWcZi3+8Lf5eDnqY= @@ -537,6 +541,8 @@ gitlab.com/elixxir/crypto v0.0.7-0.20230413162806-a99ec4bfea32 h1:Had0F7rMPgJJ2B gitlab.com/elixxir/crypto v0.0.7-0.20230413162806-a99ec4bfea32/go.mod h1:/SLOlvkYVVJf6IU+vEjMLnS7cjjcoTlPV45g6tv6INc= gitlab.com/elixxir/crypto v0.0.7-0.20230519214355-b10a9f95d395 h1:aOoL0oyocmLUbCBXgF52QhtBXvAi+eXM1d0DrDsFkIg= gitlab.com/elixxir/crypto v0.0.7-0.20230519214355-b10a9f95d395/go.mod h1:IYInxKr5Q7EH3oNhg1QX1/sTTRNi7L0JkcyfdRegoio= +gitlab.com/elixxir/crypto v0.0.7-0.20230522190154-5cbcf67f4b39 h1:cU8066kdJRH88GUetdoYfT4ATg+uzSyquhHbVcbxw7Q= +gitlab.com/elixxir/crypto v0.0.7-0.20230522190154-5cbcf67f4b39/go.mod h1:IYInxKr5Q7EH3oNhg1QX1/sTTRNi7L0JkcyfdRegoio= gitlab.com/elixxir/ekv v0.2.1 h1:dtwbt6KmAXG2Tik5d60iDz2fLhoFBgWwST03p7T+9Is= gitlab.com/elixxir/ekv v0.2.1/go.mod h1:USLD7xeDnuZEavygdrgzNEwZXeLQJK/w1a+htpN+JEU= gitlab.com/elixxir/ekv v0.3.1-0.20230504190918-f5e96603c2e0 h1:4d2vg4Sh3N5mR1ta152cg6ybPWHYqsPtkEyJKaDYGnw= diff --git a/main.go b/main.go index e6d4e05b63ad6560242ea0b7768f23ffce4c081f..81e946e4f25daa2ba483bdd66a43095b48da0bed 100644 --- a/main.go +++ b/main.go @@ -100,6 +100,11 @@ func setGlobals() { js.Global().Set("InitializeBackup", js.FuncOf(wasm.InitializeBackup)) js.Global().Set("ResumeBackup", js.FuncOf(wasm.ResumeBackup)) + // wasm/notifications.go + js.Global().Set("LoadNotifications", js.FuncOf(wasm.LoadNotifications)) + js.Global().Set("LoadNotificationsDummy", + js.FuncOf(wasm.LoadNotificationsDummy)) + // wasm/channels.go js.Global().Set("GenerateChannelIdentity", js.FuncOf(wasm.GenerateChannelIdentity)) diff --git a/wasm/channels.go b/wasm/channels.go index 92231d692a1cd7ab4c685665fa6738333adbc731..57b54f0b3eb767d5943d0e71d03946a0cf9a5b08 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -17,6 +17,7 @@ import ( "syscall/js" "gitlab.com/elixxir/client/v4/channels" + "gitlab.com/elixxir/primitives/notifications" channelsDb "gitlab.com/elixxir/xxdk-wasm/indexedDb/worker/channels" "gitlab.com/elixxir/client/v4/bindings" @@ -1454,6 +1455,88 @@ func (cm *ChannelsManager) GetMutedUsers(_ js.Value, args []js.Value) any { return utils.CopyBytesToJS(mutedUsers) } +//////////////////////////////////////////////////////////////////////////////// +// Notifications // +//////////////////////////////////////////////////////////////////////////////// + +// GetNotificationLevel implements +// [bindings.ChannelsManager.GetNotificationLevel] +// +// Parameters: +// - args[0] - channelIDBytes - The marshalled bytes of the +// channel's [id.ID] (Uint8Array) +// +// Returns: +// - int - The [channels.NotificationLevel] for the channel. +// throws an error if there is an issue +func (cm *ChannelsManager) GetNotificationLevel(_ js.Value, + args []js.Value) any { + channelIDBytes := utils.CopyBytesToGo(args[0]) + + level, err := cm.api.GetNotificationLevel(channelIDBytes) + if err != nil { + utils.Throw(utils.TypeError, err) + return nil + } + + return level +} + +// SetMobileNotificationsLevel implements +// [bindings.ChannelsManager.SetMobileNotificationsLevel] +// +// Parameters: +// - args[0] - channelIDBytes - The marshaled bytes of the channel's [id.ID] +// (Uint8Array). +// - args[1] - level - The [channels.NotificationLevel] to set for +// the channel. +// - args[2] - status - The [notifications.NotificationState] to set +// for the channel. +// - args[3] - push - True to enable push notifications and false to +// only have in-app notifications. +// +// Returns nothing or throws an error +func (cm *ChannelsManager) SetMobileNotificationsLevel(_ js.Value, + args []js.Value) any { + channelIDBytes := utils.CopyBytesToGo(args[0]) + level := args[1].Int() + status := args[2].Int() + push := args[3].Bool() + + err := cm.api.SetMobileNotificationsLevel(channelIDBytes, level, + status, push) + if err != nil { + utils.Throw(utils.TypeError, err) + } + return nil +} + +// GetNotificationReportsForMe implements +// [bindings.GetNotificationsReportsForMe] +// +// Parameters: +// - args[0] - notificationFilterJSON - JSON of a slice of +// [channels.NotificationFilter] (Uint8Array). +// - args[1] - notificationDataJSON - JSON of a slice of +// [notifications.Data] (Uint8Array). +// +// Returns: +// - []byte - JSON of a slice of [channels.NotificationReport]. +// Throws an error if one occurs +func GetNotificationReportsForMe(_ js.Value, args []js.Value) any { + notificationFilterJSON := utils.CopyBytesToGo(args[0]) + notificationDataJSON := utils.CopyBytesToGo(args[1]) + + nrs, err := bindings.GetNotificationReportsForMe(notificationFilterJSON, + notificationDataJSON) + if err != nil { + utils.Throw(utils.TypeError, err) + return nil + } + + return utils.CopyBytesToJS(nrs) +} + //////////////////////////////////////////////////////////////////////////////// // Admin Management // ////////////////////////////////////////////////////////////////////////////////