Skip to main content

ChannelService#

The ChannelService provides data and interaction for the channel list and message list.

Type parameters#

NameType
Textends DefaultStreamChatGenerics = DefaultStreamChatGenerics

Properties#

activeChannel$#

activeChannel$: Observable<undefined | Channel<T>>

Emits the currently active channel.

important

If you want to subscribe to channel events, you need to manually reenter Angular's change detection zone, our Change detection guide explains this in detail.

The active channel will always be marked as read when a new message is received

Defined in#

lib/channel.service.ts:85


activeChannelMessages$#

activeChannelMessages$: Observable<StreamMessage<T>[]>

Emits the list of currently loaded messages of the active channel.

Defined in#

lib/channel.service.ts:89


activeChannelPinnedMessages$#

activeChannelPinnedMessages$: Observable<StreamMessage<T>[]>

Emits the list of pinned messages of the active channel.

Defined in#

lib/channel.service.ts:93


activeParentMessage$#

activeParentMessage$: Observable<undefined | StreamMessage<T>>

Emits the currently selected parent message. If no message is selected, it emits undefined.

Defined in#

lib/channel.service.ts:105


activeParentMessageId$#

activeParentMessageId$: Observable<undefined | string>

Emits the id of the currently selected parent message. If no message is selected, it emits undefined.

Defined in#

lib/channel.service.ts:97


activeThreadMessages$#

activeThreadMessages$: Observable<StreamMessage<T>[]>

Emits the list of currently loaded thread replies belonging to the selected parent message. If there is no currently active thread it emits an empty array.

Defined in#

lib/channel.service.ts:101


channels$#

channels$: Observable<undefined | Channel<T>[]>

Emits the currently loaded and watched channel list.

important

If you want to subscribe to channel events, you need to manually reenter Angular's change detection zone, our Change detection guide explains this in detail.

Apart from pagination, the channel list is also updated on the following events:

Event typeDefault behaviorCustom handler to override
channel.deletedRemove channel from the listcustomChannelDeletedHandler
channel.hiddenRemove channel from the listcustomChannelHiddenHandler
channel.truncatedUpdates the channelcustomChannelTruncatedHandler
channel.updatedUpdates the channelcustomChannelUpdatedHandler
channel.visibleAdds the channel to the listcustomChannelVisibleHandler
message.newMoves the channel to top of the listcustomNewMessageHandler
notification.added_to_channelAdds the new channel to the top of the list and starts watching itcustomAddedToChannelNotificationHandler
notification.message_newAdds the new channel to the top of the list and starts watching itcustomNewMessageNotificationHandler
notification.removed_from_channelRemoves the channel from the listcustomRemovedFromChannelNotificationHandler

It's important to note that filters don't apply to updates to the list from events.

Our platform documentation covers the topic of channel events in depth.

Defined in#

lib/channel.service.ts:75


customAddedToChannelNotificationHandler#

Optional customAddedToChannelNotificationHandler: (clientEvent: ClientEvent<DefaultStreamChatGenerics>, channelListSetter: (channels: (Channel<T> | ChannelResponse<T>)[]) => void) => void

Type declaration#

▸ (clientEvent, channelListSetter): void

Custom event handler to call when the user is added to a channel, provide an event handler if you want to override the default channel list ordering

Parameters#
NameType
clientEventClientEvent<DefaultStreamChatGenerics>
channelListSetter(channels: (Channel<T> | ChannelResponse<T>)[]) => void
Returns#

void

Defined in#

lib/channel.service.ts:136


customChannelDeletedHandler#

Optional customChannelDeletedHandler: (event: Event<DefaultGenerics>, channel: Channel<T>, channelListSetter: (channels: (Channel<T> | ChannelResponse<T>)[]) => void, messageListSetter: (messages: StreamMessage<T>[]) => void, threadListSetter: (messages: StreamMessage<T>[]) => void, parentMessageSetter: (message: undefined | StreamMessage<T>) => void) => void

Type declaration#

▸ (event, channel, channelListSetter, messageListSetter, threadListSetter, parentMessageSetter): void

Custom event handler to call when a channel is deleted, provide an event handler if you want to override the default channel list ordering

Parameters#
NameType
eventEvent<DefaultGenerics>
channelChannel<T>
channelListSetter(channels: (Channel<T> | ChannelResponse<T>)[]) => void
messageListSetter(messages: StreamMessage<T>[]) => void
threadListSetter(messages: StreamMessage<T>[]) => void
parentMessageSetter(message: undefined | StreamMessage<T>) => void
Returns#

void

Defined in#

lib/channel.service.ts:150


customChannelHiddenHandler#

Optional customChannelHiddenHandler: (event: Event<DefaultGenerics>, channel: Channel<T>, channelListSetter: (channels: (Channel<T> | ChannelResponse<T>)[]) => void, messageListSetter: (messages: StreamMessage<T>[]) => void, threadListSetter: (messages: StreamMessage<T>[]) => void, parentMessageSetter: (message: undefined | StreamMessage<T>) => void) => void

Type declaration#

▸ (event, channel, channelListSetter, messageListSetter, threadListSetter, parentMessageSetter): void

Custom event handler to call when a channel becomes hidden, provide an event handler if you want to override the default channel list ordering

Parameters#
NameType
eventEvent<DefaultGenerics>
channelChannel<T>
channelListSetter(channels: (Channel<T> | ChannelResponse<T>)[]) => void
messageListSetter(messages: StreamMessage<T>[]) => void
threadListSetter(messages: StreamMessage<T>[]) => void
parentMessageSetter(message: undefined | StreamMessage<T>) => void
Returns#

void

Defined in#

lib/channel.service.ts:183


customChannelTruncatedHandler#

Optional customChannelTruncatedHandler: (event: Event<DefaultGenerics>, channel: Channel<T>, channelListSetter: (channels: (Channel<T> | ChannelResponse<T>)[]) => void, messageListSetter: (messages: StreamMessage<T>[]) => void, threadListSetter: (messages: StreamMessage<T>[]) => void, parentMessageSetter: (message: undefined | StreamMessage<T>) => void) => void

Type declaration#

▸ (event, channel, channelListSetter, messageListSetter, threadListSetter, parentMessageSetter): void

Custom event handler to call when a channel is truncated, provide an event handler if you want to override the default channel list ordering

Parameters#
NameType
eventEvent<DefaultGenerics>
channelChannel<T>
channelListSetter(channels: (Channel<T> | ChannelResponse<T>)[]) => void
messageListSetter(messages: StreamMessage<T>[]) => void
threadListSetter(messages: StreamMessage<T>[]) => void
parentMessageSetter(message: undefined | StreamMessage<T>) => void
Returns#

void

Defined in#

lib/channel.service.ts:172


customChannelUpdatedHandler#

Optional customChannelUpdatedHandler: (event: Event<DefaultGenerics>, channel: Channel<T>, channelListSetter: (channels: (Channel<T> | ChannelResponse<T>)[]) => void, messageListSetter: (messages: StreamMessage<DefaultStreamChatGenerics>[]) => void, threadListSetter: (messages: StreamMessage<DefaultStreamChatGenerics>[]) => void, parentMessageSetter: (message: undefined | StreamMessage<DefaultStreamChatGenerics>) => void) => void

Type declaration#

▸ (event, channel, channelListSetter, messageListSetter, threadListSetter, parentMessageSetter): void

Custom event handler to call when a channel is updated, provide an event handler if you want to override the default channel list ordering

Parameters#
NameType
eventEvent<DefaultGenerics>
channelChannel<T>
channelListSetter(channels: (Channel<T> | ChannelResponse<T>)[]) => void
messageListSetter(messages: StreamMessage<DefaultStreamChatGenerics>[]) => void
threadListSetter(messages: StreamMessage<DefaultStreamChatGenerics>[]) => void
parentMessageSetter(message: undefined | StreamMessage<DefaultStreamChatGenerics>) => void
Returns#

void

Defined in#

lib/channel.service.ts:161


customChannelVisibleHandler#

Optional customChannelVisibleHandler: (event: Event<DefaultGenerics>, channel: Channel<T>, channelListSetter: (channels: (Channel<T> | ChannelResponse<T>)[]) => void, messageListSetter: (messages: StreamMessage<T>[]) => void, threadListSetter: (messages: StreamMessage<T>[]) => void, parentMessageSetter: (message: undefined | StreamMessage<T>) => void) => void

Type declaration#

▸ (event, channel, channelListSetter, messageListSetter, threadListSetter, parentMessageSetter): void

Custom event handler to call when a channel becomes visible, provide an event handler if you want to override the default channel list ordering

Parameters#
NameType
eventEvent<DefaultGenerics>
channelChannel<T>
channelListSetter(channels: (Channel<T> | ChannelResponse<T>)[]) => void
messageListSetter(messages: StreamMessage<T>[]) => void
threadListSetter(messages: StreamMessage<T>[]) => void
parentMessageSetter(message: undefined | StreamMessage<T>) => void
Returns#

void

Defined in#

lib/channel.service.ts:194


customFileDeleteRequest#

Optional customFileDeleteRequest: (url: string, channel: Channel<T>) => Promise<void>

Type declaration#

▸ (url, channel): Promise<void>

You can override the default file delete request - override this if you use your own CDN

Parameters#
NameType
urlstring
channelChannel<T>
Returns#

Promise<void>

Defined in#

lib/channel.service.ts:230


customFileUploadRequest#

Optional customFileUploadRequest: (file: File, channel: Channel<T>) => Promise<{}>

Type declaration#

▸ (file, channel): Promise<{}>

You can override the default file upload request - you can use this to upload files to your own CDN

Parameters#
NameType
fileFile
channelChannel<T>
Returns#

Promise<{}>

Defined in#

lib/channel.service.ts:216


customImageDeleteRequest#

Optional customImageDeleteRequest: (url: string, channel: Channel<T>) => Promise<void>

Type declaration#

▸ (url, channel): Promise<void>

You can override the default image delete request - override this if you use your own CDN

Parameters#
NameType
urlstring
channelChannel<T>
Returns#

Promise<void>

Defined in#

lib/channel.service.ts:234


customImageUploadRequest#

Optional customImageUploadRequest: (file: File, channel: Channel<T>) => Promise<{}>

Type declaration#

▸ (file, channel): Promise<{}>

You can override the default image upload request - you can use this to upload images to your own CDN

Parameters#
NameType
fileFile
channelChannel<T>
Returns#

Promise<{}>

Defined in#

lib/channel.service.ts:223


customNewMessageHandler#

Optional customNewMessageHandler: (event: Event<DefaultGenerics>, channel: Channel<T>, channelListSetter: (channels: (Channel<T> | ChannelResponse<T>)[]) => void, messageListSetter: (messages: StreamMessage<T>[]) => void, threadListSetter: (messages: StreamMessage<T>[]) => void, parentMessageSetter: (message: undefined | StreamMessage<T>) => void) => void

Type declaration#

▸ (event, channel, channelListSetter, messageListSetter, threadListSetter, parentMessageSetter): void

Custom event handler to call if a new message received from a channel that is being watched, provide an event handler if you want to override the default channel list ordering

Parameters#
NameType
eventEvent<DefaultGenerics>
channelChannel<T>
channelListSetter(channels: (Channel<T> | ChannelResponse<T>)[]) => void
messageListSetter(messages: StreamMessage<T>[]) => void
threadListSetter(messages: StreamMessage<T>[]) => void
parentMessageSetter(message: undefined | StreamMessage<T>) => void
Returns#

void

Defined in#

lib/channel.service.ts:205


customNewMessageNotificationHandler#

Optional customNewMessageNotificationHandler: (clientEvent: ClientEvent<DefaultStreamChatGenerics>, channelListSetter: (channels: (Channel<T> | ChannelResponse<T>)[]) => void) => void

Type declaration#

▸ (clientEvent, channelListSetter): void

Custom event handler to call if a new message received from a channel that is not being watched, provide an event handler if you want to override the default channel list ordering

Parameters#
NameType
clientEventClientEvent<DefaultStreamChatGenerics>
channelListSetter(channels: (Channel<T> | ChannelResponse<T>)[]) => void
Returns#

void

Defined in#

lib/channel.service.ts:129


customRemovedFromChannelNotificationHandler#

Optional customRemovedFromChannelNotificationHandler: (clientEvent: ClientEvent<DefaultStreamChatGenerics>, channelListSetter: (channels: (Channel<T> | ChannelResponse<T>)[]) => void) => void

Type declaration#

▸ (clientEvent, channelListSetter): void

Custom event handler to call when the user is removed from a channel, provide an event handler if you want to override the default channel list ordering

Parameters#
NameType
clientEventClientEvent<DefaultStreamChatGenerics>
channelListSetter(channels: (Channel<T> | ChannelResponse<T>)[]) => void
Returns#

void

Defined in#

lib/channel.service.ts:143


hasMoreChannels$#

hasMoreChannels$: Observable<boolean>

Emits false if there are no more pages of channels that can be loaded.

Defined in#

lib/channel.service.ts:49


jumpToMessage$#

jumpToMessage$: Observable<{}>

Emits the ID of the message the message list should jump to (can be a channel message or thread message)

Defined in#

lib/channel.service.ts:113


latestMessageDateByUserByChannels$#

latestMessageDateByUserByChannels$: Observable<{ [key: string]: Date; }>

Emits a map that contains the date of the latest message sent by the current user by channels (this is used to detect if slow mode countdown should be started)

Defined in#

lib/channel.service.ts:125


messageToQuote$#

messageToQuote$: Observable<undefined | StreamMessage<T>>

Emits the currently selected message to quote

Defined in#

lib/channel.service.ts:109


usersTypingInChannel$#

usersTypingInChannel$: Observable<UserResponse<T>[]>

Emits the list of users that are currently typing in the channel (current user is not included)

Defined in#

lib/channel.service.ts:117


usersTypingInThread$#

usersTypingInThread$: Observable<UserResponse<T>[]>

Emits the list of users that are currently typing in the active thread (current user is not included)

Defined in#

lib/channel.service.ts:121

Accessors#

shouldMarkActiveChannelAsRead#

get shouldMarkActiveChannelAsRead(): boolean

If set to false, read events won't be sent as new messages are received. If set to true active channel (if any) will immediately be marked as read.

Returns#

boolean

Defined in#

lib/channel.service.ts:374

set shouldMarkActiveChannelAsRead(shouldMarkActiveChannelAsRead): void

If set to false, read events won't be sent as new messages are received. If set to true active channel (if any) will immediately be marked as read.

Parameters#

NameType
shouldMarkActiveChannelAsReadboolean

Returns#

void

Defined in#

lib/channel.service.ts:381

Methods#

addReaction#

addReaction(messageId, reactionType, customData?): Promise<void>

Adds a reaction to a message.

Parameters#

NameTypeDescription
messageIdstringThe id of the message to add the reaction to
reactionTypestringThe type of the reaction
customData?T["reactionType"]

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:606


autocompleteMembers#

autocompleteMembers(searchTerm): Promise<ChannelMemberResponse<T>[]>

Returns the autocomplete options for current channel members. If the channel has less than 100 members, it returns the channel members, otherwise sends a search request with the given search term.

Parameters#

NameTypeDescription
searchTermstringText to search for in the names of members

Returns#

Promise<ChannelMemberResponse<T>[]>

The list of members matching the search filter

Defined in#

lib/channel.service.ts:758


deleteAttachment#

deleteAttachment(attachmentUpload): Promise<void>

Deletes an uploaded file by URL. If you want to know more about file uploads check out the platform documentation

Parameters#

NameTypeDescription
attachmentUploadAttachmentUpload<DefaultStreamChatGenerics>Attachment to be deleted (output of the AttachmentService)

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:742


deleteMessage#

deleteMessage(message): Promise<void>

Deletes the message from the active channel

Parameters#

NameTypeDescription
messageStreamMessage<DefaultStreamChatGenerics>Message to be deleted

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:693


deselectActiveChannel#

deselectActiveChannel(): void

Deselects the currently active (if any) channel

Returns#

void

Defined in#

lib/channel.service.ts:429


init#

init(filters, sort?, options?, shouldSetActiveChannel?): Promise<Channel<T>[]>

Queries the channels with the given filters, sorts and options. More info about channel querying can be found in the platform documentation. By default the first channel in the list will be set as active channel and will be marked as read.

Parameters#

NameTypeDefault valueDescription
filtersChannelFilters<T>undefined
sort?ChannelSort<T>undefined
options?ChannelOptionsundefined
shouldSetActiveChannelbooleantrueDecides if the first channel in the result should be made as an active channel, or no channel should be marked as active

Returns#

Promise<Channel<T>[]>

the list of channels found by the query

Defined in#

lib/channel.service.ts:551


jumpToMessage#

jumpToMessage(messageId, parentMessageId?): Promise<void>

Jumps to the selected message inside the message list, if the message is not yet loaded, it'll load the message (and it's surroundings) from the API.

Parameters#

NameTypeDescription
messageIdstringThe ID of the message to be loaded, 'latest' means jump to the latest messages
parentMessageId?stringThe ID of the parent message if we want to load a thread message

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:888


loadMoreChannels#

loadMoreChannels(): Promise<void>

Loads the next page of channels. The page size can be set in the query option object.

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:595


loadMoreMessages#

loadMoreMessages(direction?): Promise<void>

Loads the next page of messages of the active channel. The page size can be set in the query option object.

Parameters#

NameTypeDefault value
direction"older" | "newer"'older'

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:487


loadMoreThreadReplies#

loadMoreThreadReplies(direction?): Promise<void>

Loads the next page of messages of the active thread. The page size can be set in the query option object.

Parameters#

NameTypeDefault value
direction"older" | "newer"'older'

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:521


pinMessage#

pinMessage(message): Promise<void>

Pins the given message in the channel

Parameters#

NameType
messageStreamMessage<DefaultStreamChatGenerics>

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:915


removeReaction#

removeReaction(messageId, reactionType): Promise<void>

Removes a reaction from a message.

Parameters#

NameTypeDescription
messageIdstringThe id of the message to remove the reaction from
reactionTypestringThr type of reaction to remove

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:622


resendMessage#

resendMessage(message): Promise<void>

Resends the given message to the active channel

Parameters#

NameTypeDescription
messageStreamMessage<DefaultStreamChatGenerics>The message to resend

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:664


reset#

reset(): void

Resets the activeChannel$, channels$ and activeChannelMessages$ Observables. Useful when disconnecting a chat user, use in combination with disconnectUser.

Returns#

void

Defined in#

lib/channel.service.ts:586


selectMessageToQuote#

selectMessageToQuote(message): void

Selects or deselects the current message to quote reply to

Parameters#

NameTypeDescription
messageundefined | StreamMessage<DefaultStreamChatGenerics>The message to select, if called with undefined, it deselects the message

Returns#

void

Defined in#

lib/channel.service.ts:822


sendAction#

sendAction(messageId, formData, parentMessageId?): Promise<void>

Runs a message action in the current channel. Updates the message list based on the action result (if no message is returned, the message will be removed from the message list).

Parameters#

NameType
messageIdstring
formDataRecord<string, string>
parentMessageId?string

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:785


sendMessage#

sendMessage(text, attachments?, mentionedUsers?, parentId?, quotedMessageId?, customData?): Promise<void>

Sends a message to the active channel. The message is immediately added to the message list, if an error occurs and the message can't be sent, the error is indicated in state of the message.

Parameters#

NameTypeDefault valueDescription
textstringundefinedThe text of the message
attachmentsAttachment<T>[][]The attachments
mentionedUsersUserResponse<T>[][]Mentioned users
parentIdundefined | stringundefinedId of the parent message (if sending a thread reply)
quotedMessageIdundefined | stringundefinedId of the message to quote (if sending a quote reply)
customDataundefined | Partial<T["messageType"]>undefined

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:637


setAsActiveChannel#

setAsActiveChannel(channel): void

Sets the given channel as active and marks it as read.

Parameters#

NameType
channelChannel<T>

Returns#

void

Defined in#

lib/channel.service.ts:392


setAsActiveParentMessage#

setAsActiveParentMessage(message, loadMessagesForm?): Promise<void>

Sets the given message as an active parent message. If undefined is provided, it will deleselect the current parent message.

Parameters#

NameTypeDefault value
messageundefined | StreamMessage<T>undefined
loadMessagesForm"request" | "state"'request'

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:452


typingStarted#

typingStarted(parentId?): Promise<void>

Call this method if user started typing in the active channel

Parameters#

NameTypeDescription
parentId?stringThe id of the parent message, if user is typing in a thread

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:1146


typingStopped#

typingStopped(parentId?): Promise<void>

Call this method if user stopped typing in the active channel

Parameters#

NameTypeDescription
parentId?stringThe id of the parent message, if user were typing in a thread

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:1155


unpinMessage#

unpinMessage(message): Promise<void>

Removes the given message from pinned messages

Parameters#

NameType
messageStreamMessage<DefaultStreamChatGenerics>

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:934


updateMessage#

updateMessage(message): Promise<void>

Updates the message in the active channel

Parameters#

NameTypeDescription
messageStreamMessage<T>Mesage to be updated

Returns#

Promise<void>

Defined in#

lib/channel.service.ts:681


uploadAttachments#

uploadAttachments(uploads): Promise<AttachmentUpload<DefaultStreamChatGenerics>[]>

Uploads files to the channel. If you want to know more about file uploads check out the platform documentation.

Parameters#

NameTypeDescription
uploadsAttachmentUpload<DefaultStreamChatGenerics>[]the attachments to upload (output of the AttachmentService)

Returns#

Promise<AttachmentUpload<DefaultStreamChatGenerics>[]>

the result of file upload requests

Defined in#

lib/channel.service.ts:702

Did you find this page helpful?