Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
ChannelFilters,
ChannelMemberAPIResponse,
ChannelMemberResponse,
ChannelPushPreference,
ChannelQueryOptions,
ChannelResponse,
ChannelUpdateOptions,
Expand Down Expand Up @@ -56,7 +57,6 @@ import type {
PinnedMessagePaginationOptions,
PinnedMessagesSort,
PollVoteData,
PushPreference,
QueryChannelAPIResponse,
QueryMembersOptions,
Reaction,
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Channel {
lastTypingEvent: Date | null;
isTyping: boolean;
disconnected: boolean;
push_preferences?: PushPreference;
push_preferences?: ChannelPushPreference;
public readonly messageComposer: MessageComposer;
public readonly messageReceiptsTracker: MessageReceiptsTracker;
public readonly cooldownTimer: CooldownTimer;
Expand Down
68 changes: 55 additions & 13 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export type ChannelAPIResponse = {
hidden?: boolean;
membership?: ChannelMemberResponse | null;
pending_messages?: PendingMessageResponse[];
push_preferences?: PushPreference;
push_preferences?: ChannelPushPreference;
read?: ReadResponse[];
threads?: ThreadResponse[];
watcher_count?: number;
Expand Down Expand Up @@ -685,25 +685,67 @@ export type GetUnreadCountAPIResponse = APIResponse & {
total_unread_count_by_team?: Record<string, number>;
};

export type ChatLevelPushPreference = 'all' | 'none' | 'mentions' | (string & {});
export type ChatLevelPushPreference =
| 'all'
| 'mentions' // deprecated by the API in favor of 'direct_mentions'
| 'direct_mentions'
| 'all_mentions'
| 'none'
| 'default'
| (string & {});

export type CallLevelPushPreference = 'all' | 'none' | 'default' | (string & {});

/** Granular all/none toggle used by the chat sub-preferences. */
export type PushPreferenceLevel = 'all' | 'none' | (string & {});

/** Per-mention-type chat push preferences (matches OpenAPI `ChatPreferencesInput`). */
export type ChatPreferences = {
channel_mentions?: PushPreferenceLevel;
default_preference?: PushPreferenceLevel;
direct_mentions?: PushPreferenceLevel;
group_mentions?: PushPreferenceLevel;
here_mentions?: PushPreferenceLevel;
role_mentions?: PushPreferenceLevel;
thread_replies?: PushPreferenceLevel;
};

/**
* Input accepted by {@link StreamChat.setPushPreferences} (matches OpenAPI `PushPreferenceInput`).
*
* Set `channel_cid` to scope the preference to a single channel; leave it empty to
* set the user-level default. `user_id` is required for server-side auth and
* defaults to the connected user for client-side auth.
*/
export type PushPreference = {
callLevel?: 'all' | 'none' | (string & {});
chatLevel?: ChatLevelPushPreference;
disabledUntil?: string; // snooze till this time
removeDisable?: boolean; // Temporary flag for resetting disabledUntil
call_level?: CallLevelPushPreference;
channel_cid?: string;
chat_level?: ChatLevelPushPreference;
chat_preferences?: ChatPreferences;
disabled_until?: string; // snooze until this time
remove_disable?: boolean; // stop snoozing (clears disabled_until)
user_id?: string;
};

/** Per-user push preferences returned by the API (matches OpenAPI `PushPreferencesResponse`). */
export type PushPreferencesResponse = {
call_level?: CallLevelPushPreference;
chat_level?: ChatLevelPushPreference;
chat_preferences?: ChatPreferences;
disabled_until?: string;
};

/** Per-channel push preferences returned by the API (matches OpenAPI `ChannelPushPreferencesResponse`). */
export type ChannelPushPreference = {
chatLevel?: ChatLevelPushPreference; // "all", "none", "mentions", or other custom strings
disabledUntil?: string;
removeDisable?: boolean; // Temporary flag for resetting disabledUntil
chat_level?: ChatLevelPushPreference; // "all", "mentions", "direct_mentions", "all_mentions", "none", "default" or other custom strings
disabled_until?: string;
};

export type UpsertPushPreferencesResponse = APIResponse & {
// Mapping of user IDs to their push preferences
userChannelPreferences: Record<string, Record<string, ChannelPushPreference>>;
userPreferences: Record<string, PushPreference>; // Mapping of user -> channel id -> push preferences
// Mapping of user id -> channel cid -> channel push preferences
user_channel_preferences: Record<string, Record<string, ChannelPushPreference>>;
// Mapping of user id -> user push preferences
user_preferences: Record<string, PushPreferencesResponse>;
};

export type GetUnreadCountBatchAPIResponse = APIResponse & {
Expand Down Expand Up @@ -862,7 +904,7 @@ export type OwnUserBase = {
unread_threads: number;
invisible?: boolean;
privacy_settings?: PrivacySettings;
push_preferences?: PushPreference;
push_preferences?: PushPreferencesResponse;
roles?: string[];
total_unread_count_by_team?: Record<string, number> | null;
};
Expand Down
Loading