Skip to content
Snippets Groups Projects
Commit 219a3da6 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Merge branch 'hotfix/multiListeners' into 'project/HavenBeta'

Add Support for Multiple Listeners

See merge request !132
parents 51a59b2a 3db3dcf5
No related branches found
No related tags found
2 merge requests!132Add Support for Multiple Listeners,!109Project/haven beta
...@@ -48,6 +48,16 @@ func newRemoteKvJS(api *bindings.RemoteKV) map[string]any { ...@@ -48,6 +48,16 @@ func newRemoteKvJS(api *bindings.RemoteKV) map[string]any {
"GetMapElement": js.FuncOf(rkv.GetMapElement), "GetMapElement": js.FuncOf(rkv.GetMapElement),
"ListenOnRemoteKey": js.FuncOf(rkv.ListenOnRemoteKey), "ListenOnRemoteKey": js.FuncOf(rkv.ListenOnRemoteKey),
"ListenOnRemoteMap": js.FuncOf(rkv.ListenOnRemoteMap), "ListenOnRemoteMap": js.FuncOf(rkv.ListenOnRemoteMap),
"GetAllRemoteKeyListeners": js.FuncOf(
rkv.GetAllRemoteKeyListeners),
"GetRemoteKeyListeners": js.FuncOf(rkv.GetRemoteKeyListeners),
"DeleteRemoteKeyListener": js.FuncOf(
rkv.DeleteRemoteKeyListener),
"GetAllRemoteMapListeners": js.FuncOf(
rkv.GetAllRemoteMapListeners),
"GetRemoteMapListeners": js.FuncOf(rkv.GetRemoteMapListeners),
"DeleteRemoteMapListener": js.FuncOf(
rkv.DeleteRemoteMapListener),
} }
return rkvMap return rkvMap
...@@ -411,7 +421,8 @@ func (r *RemoteKV) ListenOnRemoteKey(_ js.Value, args []js.Value) any { ...@@ -411,7 +421,8 @@ func (r *RemoteKV) ListenOnRemoteKey(_ js.Value, args []js.Value) any {
} }
promiseFn := func(resolve, reject func(args ...any) js.Value) { promiseFn := func(resolve, reject func(args ...any) js.Value) {
id, err := r.api.ListenOnRemoteKey(key, version, cb, localEvents) id, err := r.api.ListenOnRemoteKey(key, version, cb,
localEvents)
if err != nil { if err != nil {
reject(exception.NewTrace(err)) reject(exception.NewTrace(err))
} else { } else {
...@@ -446,7 +457,8 @@ func (r *RemoteKV) ListenOnRemoteMap(_ js.Value, args []js.Value) any { ...@@ -446,7 +457,8 @@ func (r *RemoteKV) ListenOnRemoteMap(_ js.Value, args []js.Value) any {
} }
promiseFn := func(resolve, reject func(args ...any) js.Value) { promiseFn := func(resolve, reject func(args ...any) js.Value) {
id, err := r.api.ListenOnRemoteMap(mapName, version, cb, localEvents) id, err := r.api.ListenOnRemoteMap(mapName, version, cb,
localEvents)
if err != nil { if err != nil {
reject(exception.NewTrace(err)) reject(exception.NewTrace(err))
} else { } else {
...@@ -457,6 +469,80 @@ func (r *RemoteKV) ListenOnRemoteMap(_ js.Value, args []js.Value) any { ...@@ -457,6 +469,80 @@ func (r *RemoteKV) ListenOnRemoteMap(_ js.Value, args []js.Value) any {
return utils.CreatePromise(promiseFn) return utils.CreatePromise(promiseFn)
} }
// GetAllRemoteKeyListeners returns a JSON list of { key: [id, id, id, ...] },
// where key is the key for the listener and the list is an list of integer ids
// of each listener.
func (r *RemoteKV) GetAllRemoteKeyListeners(_ js.Value, args []js.Value) any {
return r.api.GetAllRemoteKeyListeners()
}
// GeRemoteKeyListeners returns a JSON list of [id, id, id, ...],
// where the list is an list of integer ids of each listener.
//
// Parameters:
// - args[0] - the key to look at
func (r *RemoteKV) GetRemoteKeyListeners(_ js.Value, args []js.Value) any {
key := args[0].String()
return r.api.GetRemoteKeyListeners(key)
}
// DeleteRemoteKeyListener deletes a specific listener for a key.
//
// Parameters:
// - args[0] - the key to delete for
// - args[1] - the id of the listener
func (r *RemoteKV) DeleteRemoteKeyListener(_ js.Value, args []js.Value) any {
key := args[0].String()
id := args[1].Int()
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := r.api.DeleteRemoteKeyListener(key, id)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve()
}
}
return utils.CreatePromise(promiseFn)
}
// GetAllRemoteMapListeners returns a JSON list of { key: [id, id, id, ...] },
// where key is the key for the listener and the list is an list of integer ids
// of each listener.
func (r *RemoteKV) GetAllRemoteMapListeners(_ js.Value, args []js.Value) any {
return r.api.GetAllRemoteMapListeners()
}
// GeRemoteMapListeners returns a JSON list of [id, id, id, ...],
// where the list is an list of integer ids of each listener.
//
// Parameters:
// - args[0] - the key to look at
func (r *RemoteKV) GetRemoteMapListeners(_ js.Value, args []js.Value) any {
key := args[0].String()
return r.api.GetRemoteMapListeners(key)
}
// DeleteRemoteMapListener deletes a specific listener for a key.
//
// Parameters:
// - args[0] - the mapName to delete for
// - args[1] - the id of the listener
func (r *RemoteKV) DeleteRemoteMapListener(_ js.Value, args []js.Value) any {
mapName := args[0].String()
id := args[1].Int()
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := r.api.DeleteRemoteMapListener(mapName, id)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve()
}
}
return utils.CreatePromise(promiseFn)
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// RemoteStore // // RemoteStore //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -65,6 +65,11 @@ func newDMClientJS(api *bindings.DMClient) map[string]any { ...@@ -65,6 +65,11 @@ func newDMClientJS(api *bindings.DMClient) map[string]any {
"SendReaction": js.FuncOf(cm.SendReaction), "SendReaction": js.FuncOf(cm.SendReaction),
"SendSilent": js.FuncOf(cm.SendSilent), "SendSilent": js.FuncOf(cm.SendSilent),
"Send": js.FuncOf(cm.Send), "Send": js.FuncOf(cm.Send),
// Notifications
"GetNotificationLevel": js.FuncOf(cm.GetNotificationLevel),
"SetMobileNotificationsLevel": js.FuncOf(
cm.SetMobileNotificationsLevel),
} }
return dmClientMap return dmClientMap
...@@ -737,6 +742,53 @@ func (dmc *DMClient) GetShareURL(_ js.Value, args []js.Value) any { ...@@ -737,6 +742,53 @@ func (dmc *DMClient) GetShareURL(_ js.Value, args []js.Value) any {
return utils.CopyBytesToJS(urlReport) return utils.CopyBytesToJS(urlReport)
} }
// GetNotificationLevel Gets the notification level for a given dm pubkey
//
// Parameters:
// - args[0] - partnerPublic key (Uint8Array)
//
// Returns:
// - int of notification level
func (d *DMClient) GetNotificationLevel(_ js.Value, args []js.Value) any {
partnerPubKey := utils.CopyBytesToGo(args[0])
promiseFn := func(resolve, reject func(args ...any) js.Value) {
level, err := d.api.GetNotificationLevel(partnerPubKey)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve(level)
}
}
return utils.CreatePromise(promiseFn)
}
// SetMobileNotificationsLevel sets the notification level for a given pubkey.
//
// Parameters:
// - args[0] - partnerPublicKey (Uint8Array)
// - args[1] - the notification level (integer)
//
// Returns:
// - error or nothing
func (d *DMClient) SetMobileNotificationsLevel(_ js.Value,
args []js.Value) any {
partnerPubKey := utils.CopyBytesToGo(args[0])
level := args[1].Int()
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := d.api.SetMobileNotificationsLevel(partnerPubKey, level)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve()
}
}
return utils.CreatePromise(promiseFn)
}
// DecodeDMShareURL decodes the user's URL into a [DMUser]. // DecodeDMShareURL decodes the user's URL into a [DMUser].
// //
// Parameters: // Parameters:
...@@ -756,6 +808,59 @@ func DecodeDMShareURL(_ js.Value, args []js.Value) any { ...@@ -756,6 +808,59 @@ func DecodeDMShareURL(_ js.Value, args []js.Value) any {
return utils.CopyBytesToJS(report) return utils.CopyBytesToJS(report)
} }
// GetDmNotificationReportsForMe checks the notification data against the filter
// list to determine which notifications belong to the user. A list of
// notification reports is returned detailing all notifications for the user.
//
// Parameters:
// - args[0] - notificationFilterJSON - JSON (Uint8Array) of
// [dm.NotificationFilter].
// - args[1] - notificationDataCSV - CSV containing notification data.
//
// Example JSON of a slice of [dm.NotificationFilter]:
//
// {
// "identifier": "MWL6mvtZ9UUm7jP3ainyI4erbRl+wyVaO5MOWboP0rA=",
// "myID": "AqDqg6Tcs359dBNRBCX7XHaotRDhz1ZRQNXIsGaubvID",
// "tags": [
// "61334HtH85DPIifvrM+JzRmLqfV5R4AMEmcPelTmFX0=",
// "zc/EPwtx5OKTVdwLcI15bghjJ7suNhu59PcarXE+m9o=",
// "FvArzVJ/082UEpMDCWJsopCLeLnxJV6NXINNkJTk3k8="
// ],
// "PublicKeys": {
// "61334HtH85DPIifvrM+JzRmLqfV5R4AMEmcPelTmFX0=": "b3HygDv8gjteune9wgBm3YtVuAo2foOusRmj0m5nl6E=",
// "FvArzVJ/082UEpMDCWJsopCLeLnxJV6NXINNkJTk3k8=": "uOLitBZcCh2TEW406jXHJ+Rsi6LybsH8R1u4Mxv/7hA=",
// "zc/EPwtx5OKTVdwLcI15bghjJ7suNhu59PcarXE+m9o=": "lqLD1EzZBxB8PbILUJIfFq4JI0RKThpUQuNlTNgZAWk="
// },
// "allowedTypes": {"1": {}, "2": {}}
// }
//
// Returns:
// - []byte - JSON of a slice of [dm.NotificationReport].
//
// Example return:
//
// [
// {"partner": "WUSO3trAYeBf4UeJ5TEL+Q4usoyFf0shda0YUmZ3z8k=", "type": 1},
// {"partner": "5MY652JsVv5YLE6wGRHIFZBMvLklACnT5UtHxmEOJ4o=", "type": 2}
// ]
func GetDmNotificationReportsForMe(_ js.Value, args []js.Value) any {
notificationFilterJson := utils.CopyBytesToGo(args[0])
notificationDataCsv := args[1].String()
promiseFn := func(resolve, reject func(args ...any) js.Value) {
forme, err := bindings.GetDmNotificationReportsForMe(
notificationFilterJson, notificationDataCsv)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve(utils.CopyBytesToJS(forme))
}
}
return utils.CreatePromise(promiseFn)
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Event Model Logic // // Event Model Logic //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment