///
import { ChannelState } from './channel_state';
import { StreamChat } from './client';
import { APIResponse, BanUserOptions, ChannelAPIResponse, ChannelData, ChannelUpdateOptions, ChannelMemberAPIResponse, ChannelQueryOptions, ChannelResponse, DeleteChannelAPIResponse, Event, EventAPIResponse, EventHandler, EventTypes, FormatMessageResponse, GetMultipleMessagesAPIResponse, GetReactionsAPIResponse, GetRepliesAPIResponse, InviteOptions, MarkReadOptions, MemberSort, Message, MessageFilters, MessageResponse, MessageSetType, MuteChannelAPIResponse, PartialUpdateChannel, PartialUpdateChannelAPIResponse, QueryMembersOptions, Reaction, ReactionAPIResponse, SearchAPIResponse, SearchOptions, SendMessageAPIResponse, TruncateChannelAPIResponse, TruncateOptions, UpdateChannelAPIResponse, UserFilters, UserResponse, ExtendableGenerics, DefaultGenerics, PinnedMessagePaginationOptions, PinnedMessagesSort, MessagePaginationOptions } from './types';
import { Role } from './permissions';
/**
* Channel - The Channel class manages it's own state.
*/
export declare class Channel {
_client: StreamChat;
type: string;
id: string | undefined;
data: ChannelData | ChannelResponse | undefined;
_data: ChannelData | ChannelResponse;
cid: string;
listeners: {
[key: string]: (string | EventHandler)[];
};
state: ChannelState;
initialized: boolean;
lastKeyStroke?: Date;
lastTypingEvent: Date | null;
isTyping: boolean;
disconnected: boolean;
/**
* constructor - Create a channel
*
* @param {StreamChat} client the chat client
* @param {string} type the type of channel
* @param {string} [id] the id of the chat
* @param {ChannelData} data any additional custom params
*
* @return {Channel} Returns a new uninitialized channel
*/
constructor(client: StreamChat, type: string, id: string | undefined, data: ChannelData);
/**
* getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
*
* @return {StreamChat}
*/
getClient(): StreamChat;
/**
* getConfig - Get the configs for this channel type
*
* @return {Record}
*/
getConfig(): import("./types").ChannelConfigWithInfo | undefined;
/**
* sendMessage - Send a message to this channel
*
* @param {Message} message The Message object
* @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
* @param {boolean} [options.skip_push] Skip sending push notifications
*
* @return {Promise>} The Server Response
*/
sendMessage(message: Message, options?: {
skip_enrich_url?: boolean;
skip_push?: boolean;
}): Promise>;
sendFile(uri: string | NodeJS.ReadableStream | Buffer | File, name?: string, contentType?: string, user?: UserResponse): Promise;
sendImage(uri: string | NodeJS.ReadableStream | File, name?: string, contentType?: string, user?: UserResponse): Promise;
deleteFile(url: string): Promise;
deleteImage(url: string): Promise;
/**
* sendEvent - Send an event on this channel
*
* @param {Event} event for example {type: 'message.read'}
*
* @return {Promise>} The Server Response
*/
sendEvent(event: Event): Promise>;
/**
* search - Query messages
*
* @param {MessageFilters | string} query search query or object MongoDB style filters
* @param {{client_id?: string; connection_id?: string; query?: string; message_filter_conditions?: MessageFilters}} options Option object, {user_id: 'tommaso'}
*
* @return {Promise>} search messages response
*/
search(query: MessageFilters | string, options?: SearchOptions & {
client_id?: string;
connection_id?: string;
message_filter_conditions?: MessageFilters;
query?: string;
}): Promise>;
/**
* queryMembers - Query Members
*
* @param {UserFilters} filterConditions object MongoDB style filters
* @param {MemberSort} [sort] Sort options, for instance [{created_at: -1}].
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{name: -1}, {created_at: 1}]
* @param {{ limit?: number; offset?: number }} [options] Option object, {limit: 10, offset:10}
*
* @return {Promise>} Query Members response
*/
queryMembers(filterConditions: UserFilters, sort?: MemberSort, options?: QueryMembersOptions): Promise>;
/**
* sendReaction - Send a reaction about a message
*
* @param {string} messageID the message id
* @param {Reaction} reaction the reaction object for instance {type: 'love'}
* @param {{ enforce_unique?: boolean, skip_push?: boolean }} [options] Option object, {enforce_unique: true, skip_push: true} to override any existing reaction or skip sending push notifications
*
* @return {Promise>} The Server Response
*/
sendReaction(messageID: string, reaction: Reaction, options?: {
enforce_unique?: boolean;
skip_push?: boolean;
}): Promise>;
/**
* deleteReaction - Delete a reaction by user and type
*
* @param {string} messageID the id of the message from which te remove the reaction
* @param {string} reactionType the type of reaction that should be removed
* @param {string} [user_id] the id of the user (used only for server side request) default null
*
* @return {Promise>} The Server Response
*/
deleteReaction(messageID: string, reactionType: string, user_id?: string): Promise>;
/**
* update - Edit the channel's custom properties
*
* @param {ChannelData} channelData The object to update the custom properties of this channel with
* @param {Message} [updateMessage] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise>} The server response
*/
update(channelData?: Partial> | Partial>, updateMessage?: Message, options?: ChannelUpdateOptions): Promise>;
/**
* updatePartial - partial update channel properties
*
* @param {PartialUpdateChannel} partial update request
*
* @return {Promise>}
*/
updatePartial(update: PartialUpdateChannel): Promise>;
/**
* enableSlowMode - enable slow mode
*
* @param {number} coolDownInterval the cooldown interval in seconds
* @return {Promise>} The server response
*/
enableSlowMode(coolDownInterval: number): Promise>;
/**
* disableSlowMode - disable slow mode
*
* @return {Promise>} The server response
*/
disableSlowMode(): Promise>;
/**
* delete - Delete the channel. Messages are permanently removed.
*
* @param {boolean} [options.hard_delete] Defines if the channel is hard deleted or not
*
* @return {Promise>} The server response
*/
delete(options?: {
hard_delete?: boolean;
}): Promise>;
/**
* truncate - Removes all messages from the channel
* @param {TruncateOptions} [options] Defines truncation options
* @return {Promise>} The server response
*/
truncate(options?: TruncateOptions): Promise>;
/**
* acceptInvite - accept invitation to the channel
*
* @param {InviteOptions} [options] The object to update the custom properties of this channel with
*
* @return {Promise>} The server response
*/
acceptInvite(options?: InviteOptions): Promise>;
/**
* rejectInvite - reject invitation to the channel
*
* @param {InviteOptions} [options] The object to update the custom properties of this channel with
*
* @return {Promise>} The server response
*/
rejectInvite(options?: InviteOptions): Promise>;
/**
* addMembers - add members to the channel
*
* @param {{user_id: string, channel_role?: Role}[]} members An array of members to add to the channel
* @param {Message} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise>} The server response
*/
addMembers(members: string[] | {
user_id: string;
channel_role?: Role;
}[], message?: Message, options?: ChannelUpdateOptions): Promise>;
/**
* addModerators - add moderators to the channel
*
* @param {string[]} members An array of member identifiers
* @param {Message} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise>} The server response
*/
addModerators(members: string[], message?: Message, options?: ChannelUpdateOptions): Promise>;
/**
* assignRoles - sets member roles in a channel
*
* @param {{channel_role: Role, user_id: string}[]} roles List of role assignments
* @param {Message} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise>} The server response
*/
assignRoles(roles: {
channel_role: Role;
user_id: string;
}[], message?: Message, options?: ChannelUpdateOptions): Promise>;
/**
* inviteMembers - invite members to the channel
*
* @param {{user_id: string, channel_role?: Role}[]} members An array of members to invite to the channel
* @param {Message} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise>} The server response
*/
inviteMembers(members: {
user_id: string;
channel_role?: Role;
}[] | string[], message?: Message, options?: ChannelUpdateOptions): Promise>;
/**
* removeMembers - remove members from channel
*
* @param {string[]} members An array of member identifiers
* @param {Message} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise>} The server response
*/
removeMembers(members: string[], message?: Message, options?: ChannelUpdateOptions): Promise>;
/**
* demoteModerators - remove moderator role from channel members
*
* @param {string[]} members An array of member identifiers
* @param {Message} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise>} The server response
*/
demoteModerators(members: string[], message?: Message, options?: ChannelUpdateOptions): Promise>;
/**
* _update - executes channel update request
* @param payload Object Update Channel payload
* @return {Promise>} The server response
* TODO: introduce new type instead of Object in the next major update
*/
_update(payload: Object): Promise>;
/**
* mute - mutes the current channel
* @param {{ user_id?: string, expiration?: string }} opts expiration in minutes or user_id
* @return {Promise>} The server response
*
* example with expiration:
* await channel.mute({expiration: moment.duration(2, 'weeks')});
*
* example server side:
* await channel.mute({user_id: userId});
*
*/
mute(opts?: {
expiration?: number;
user_id?: string;
}): Promise>;
/**
* unmute - mutes the current channel
* @param {{ user_id?: string}} opts user_id
* @return {Promise} The server response
*
* example server side:
* await channel.unmute({user_id: userId});
*/
unmute(opts?: {
user_id?: string;
}): Promise;
/**
* muteStatus - returns the mute status for the current channel
* @return {{ muted: boolean; createdAt: Date | null; expiresAt: Date | null }} { muted: true | false, createdAt: Date | null, expiresAt: Date | null}
*/
muteStatus(): {
createdAt: Date | null;
expiresAt: Date | null;
muted: boolean;
};
sendAction(messageID: string, formData: Record): Promise>;
/**
* keystroke - First of the typing.start and typing.stop events based on the users keystrokes.
* Call this on every keystroke
* @see {@link https://getstream.io/chat/docs/typing_indicators/?language=js|Docs}
* @param {string} [parent_id] set this field to `message.id` to indicate that typing event is happening in a thread
*/
keystroke(parent_id?: string): Promise;
/**
* stopTyping - Sets last typing to null and sends the typing.stop event
* @see {@link https://getstream.io/chat/docs/typing_indicators/?language=js|Docs}
* @param {string} [parent_id] set this field to `message.id` to indicate that typing event is happening in a thread
*/
stopTyping(parent_id?: string): Promise;
/**
* lastMessage - return the last message, takes into account that last few messages might not be perfectly sorted
*
* @return {ReturnType['formatMessage']> | undefined} Description
*/
lastMessage(): FormatMessageResponse;
/**
* markRead - Send the mark read event for this user, only works if the `read_events` setting is enabled
*
* @param {MarkReadOptions} data
* @return {Promise | null>} Description
*/
markRead(data?: MarkReadOptions): Promise | null>;
/**
* clean - Cleans the channel state and fires stop typing if needed
*/
clean(): void;
/**
* watch - Loads the initial channel state and watches for changes
*
* @param {ChannelQueryOptions} options additional options for the query endpoint
*
* @return {Promise>} The server response
*/
watch(options?: ChannelQueryOptions): Promise>;
/**
* stopWatching - Stops watching the channel
*
* @return {Promise} The server response
*/
stopWatching(): Promise;
/**
* getReplies - List the message replies for a parent message
*
* @param {string} parent_id The message parent id, ie the top of the thread
* @param {MessagePaginationOptions & { user?: UserResponse; user_id?: string }} options Pagination params, ie {limit:10, id_lte: 10}
*
* @return {Promise>} A response with a list of messages
*/
getReplies(parent_id: string, options: MessagePaginationOptions & {
user?: UserResponse;
user_id?: string;
}): Promise>;
/**
* getPinnedMessages - List list pinned messages of the channel
*
* @param {PinnedMessagePaginationOptions & { user?: UserResponse; user_id?: string }} options Pagination params, ie {limit:10, id_lte: 10}
* @param {PinnedMessagesSort} sort defines sorting direction of pinned messages
*
* @return {Promise>} A response with a list of messages
*/
getPinnedMessages(options: PinnedMessagePaginationOptions & {
user?: UserResponse;
user_id?: string;
}, sort?: PinnedMessagesSort): Promise>;
/**
* getReactions - List the reactions, supports pagination
*
* @param {string} message_id The message id
* @param {{ limit?: number; offset?: number }} options The pagination options
*
* @return {Promise>} Server response
*/
getReactions(message_id: string, options: {
limit?: number;
offset?: number;
}): Promise>;
/**
* getMessagesById - Retrieves a list of messages by ID
*
* @param {string[]} messageIds The ids of the messages to retrieve from this channel
*
* @return {Promise>} Server response
*/
getMessagesById(messageIds: string[]): Promise>;
/**
* lastRead - returns the last time the user marked the channel as read if the user never marked the channel as read, this will return null
* @return {Date | null | undefined}
*/
lastRead(): Date | null | undefined;
_countMessageAsUnread(message: FormatMessageResponse | MessageResponse): boolean;
/**
* countUnread - Count of unread messages
*
* @param {Date | null} [lastRead] lastRead the time that the user read a message, defaults to current user's read state
*
* @return {number} Unread count
*/
countUnread(lastRead?: Date | null): number;
/**
* countUnreadMentions - Count the number of unread messages mentioning the current user
*
* @return {number} Unread mentions count
*/
countUnreadMentions(): number;
/**
* create - Creates a new channel
*
* @return {Promise>} The Server Response
*/
create: () => Promise>;
/**
* query - Query the API, get messages, members or other channel fields
*
* @param {ChannelQueryOptions} options The query options
* @param {MessageSetType} messageSetToAddToIfDoesNotExist It's possible to load disjunct sets of a channel's messages into state, use `current` to load the initial channel state or if you want to extend the currently displayed messages, use `latest` if you want to load/extend the latest messages, `new` is used for loading a specific message and it's surroundings
*
* @return {Promise>} Returns a query response
*/
query(options: ChannelQueryOptions, messageSetToAddToIfDoesNotExist?: MessageSetType): Promise>;
/**
* banUser - Bans a user from a channel
*
* @param {string} targetUserID
* @param {BanUserOptions} options
* @returns {Promise}
*/
banUser(targetUserID: string, options: BanUserOptions): Promise;
/**
* hides the channel from queryChannels for the user until a message is added
* If clearHistory is set to true - all messages will be removed for the user
*
* @param {string | null} userId
* @param {boolean} clearHistory
* @returns {Promise}
*/
hide(userId?: string | null, clearHistory?: boolean): Promise;
/**
* removes the hidden status for a channel
*
* @param {string | null} userId
* @returns {Promise}
*/
show(userId?: string | null): Promise;
/**
* unbanUser - Removes the bans for a user on a channel
*
* @param {string} targetUserID
* @returns {Promise}
*/
unbanUser(targetUserID: string): Promise;
/**
* shadowBan - Shadow bans a user from a channel
*
* @param {string} targetUserID
* @param {BanUserOptions} options
* @returns {Promise}
*/
shadowBan(targetUserID: string, options: BanUserOptions): Promise;
/**
* removeShadowBan - Removes the shadow ban for a user on a channel
*
* @param {string} targetUserID
* @returns {Promise}
*/
removeShadowBan(targetUserID: string): Promise;
/**
* on - Listen to events on this channel.
*
* channel.on('message.new', event => {console.log("my new message", event, channel.state.messages)})
* or
* channel.on(event => {console.log(event.type)})
*
* @param {EventHandler | EventTypes} callbackOrString The event type to listen for (optional)
* @param {EventHandler} [callbackOrNothing] The callback to call
*/
on(eventType: EventTypes, callback: EventHandler): {
unsubscribe: () => void;
};
on(callback: EventHandler): {
unsubscribe: () => void;
};
/**
* off - Remove the event handler
*
*/
off(eventType: EventTypes, callback: EventHandler): void;
off(callback: EventHandler): void;
_handleChannelEvent(event: Event): void;
_callChannelListeners: (event: Event) => void;
/**
* _channelURL - Returns the channel url
*
* @return {string} The channel url
*/
_channelURL: () => string;
_checkInitialized(): void;
_initializeState(state: ChannelAPIResponse, messageSetToAddToIfDoesNotExist?: MessageSetType): void;
_disconnect(): void;
}
//# sourceMappingURL=channel.d.ts.map