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..76f6672 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. @@ -2633,7 +2633,8 @@ declare namespace nkruntime { /** * Notification Object */ - export interface NotificationApi { + export interface ApiNotification { + id: string; code: number; content: {[key: string]: any}; persistent: boolean; @@ -2643,11 +2644,12 @@ declare namespace nkruntime { } export interface Notification { + id: string; code: number; content: {[key: string]: any}; persistent: boolean; - senderId: string; userId: string; + senderId: string; subject: string; createTime: number; } @@ -2666,11 +2668,16 @@ declare namespace nkruntime { userId: string; } - export interface NotificationList { - notifications?: NotificationApi[]; + export interface ApiNotificationList { + notifications?: ApiNotification[]; cacheableCursor?: string; } + export interface NotificationsList { + notifications: ApiNotification[]; + cursor: string; + } + /** * Wallet Update */ @@ -4123,6 +4130,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