From 9acdc48ac4a6c9879f2f3019450cea9cbeea05d2 Mon Sep 17 00:00:00 2001 From: Simon Esposito Date: Fri, 18 Oct 2024 17:06:57 +0100 Subject: [PATCH 1/2] Add notificationsList runtime function --- CHANGELOG.md | 3 +++ index.d.ts | 21 ++++++++++++++++++--- runtime/runtime.go | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac91990..5033c62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project are documented below. The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org). ## [Unreleased] +### Added +- New runtime function to list user notifications. + ### Fixed - Ensure optional TypeScript context fields are marked appropriately. diff --git a/index.d.ts b/index.d.ts index 674ac06..61e2aa5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1890,7 +1890,7 @@ declare namespace nkruntime { * @param fn - The function to execute after ListNotifications. * @throws {TypeError} */ - registerAfterListNotifications(fn: AfterHookFunction): void; + registerAfterListNotifications(fn: AfterHookFunction): void; /** * Register before Hook for RPC DeleteNotifications function. @@ -2637,7 +2637,7 @@ declare namespace nkruntime { code: number; content: {[key: string]: any}; persistent: boolean; - senderId: string; + sender: string; subject: string; createTime: number; } @@ -2666,11 +2666,16 @@ declare namespace nkruntime { userId: string; } - export interface NotificationList { + export interface ApiNotificationList { notifications?: NotificationApi[]; cacheableCursor?: string; } + export interface NotificationsList { + notifications: Notification[]; + cursor: string; + } + /** * Wallet Update */ @@ -4123,6 +4128,16 @@ declare namespace nkruntime { */ notificationSendAll(subject: string, content: {[key: string]: any}, code: number, persistent?: boolean): void; + /** + * List notifications by user ID. + * + * @param userId - User identifier. + * @param limit - Opt. Number of notifications per result page. Must be a value between 1 and 1000. Defaults to 100. + * @param cursor - Opt. Cursor to get next page of results, if any. + * @throws {TypeError, GoError} + */ + notificationsList(userId: string, limit?: number, cursor?: string): NotificationsList; + /** * Delete multiple notifications. * diff --git a/runtime/runtime.go b/runtime/runtime.go index 73b13cc..63f7a73 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -1102,6 +1102,7 @@ type NakamaModule interface { MatchSignal(ctx context.Context, id string, data string) (string, error) NotificationSend(ctx context.Context, userID, subject string, content map[string]interface{}, code int, sender string, persistent bool) error + NotificationsList(ctx context.Context, userID string, limit int, cursor string) ([]*api.Notification, string, error) NotificationsSend(ctx context.Context, notifications []*NotificationSend) error NotificationSendAll(ctx context.Context, subject string, content map[string]interface{}, code int, persistent bool) error NotificationsDelete(ctx context.Context, notifications []*NotificationDelete) error From 2baa78a2302289256888c5e47391194572389491 Mon Sep 17 00:00:00 2001 From: Simon Esposito Date: Mon, 21 Oct 2024 12:30:15 +0100 Subject: [PATCH 2/2] JS definitions fixes --- index.d.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index 61e2aa5..76f6672 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2633,21 +2633,23 @@ declare namespace nkruntime { /** * Notification Object */ - export interface NotificationApi { + export interface ApiNotification { + id: string; code: number; content: {[key: string]: any}; persistent: boolean; - sender: string; + senderId: string; subject: string; createTime: number; } export interface Notification { + id: string; code: number; content: {[key: string]: any}; persistent: boolean; - senderId: string; userId: string; + senderId: string; subject: string; createTime: number; } @@ -2667,13 +2669,13 @@ declare namespace nkruntime { } export interface ApiNotificationList { - notifications?: NotificationApi[]; + notifications?: ApiNotification[]; cacheableCursor?: string; } export interface NotificationsList { - notifications: Notification[]; - cursor: string; + notifications: ApiNotification[]; + cursor: string; } /**