discourse/plugins/chat/docs/FRONTEND.md

12 KiB

Modules

Collection
ChatApi

Collection


module.exports ⏏

Handles a paginated API response.

Kind: Exported class


new module.exports(resourceURL, handler)

Create a Collection instance

Param Type Description
resourceURL string the API endpoint to call
handler callback anonymous function used to handle the response

module.exports.load() ⇒ Promise

Loads first batch of results

Kind: instance method of module.exports


module.exports.loadMore() ⇒ Promise

Attempts to load more results

Kind: instance method of module.exports


ChatApi


module.exports ⏏

Chat API service. Provides methods to interact with the chat API.

Kind: Exported class
Implements: {@ember/service}


module.exports.channel(channelId) ⇒ Promise

Get a channel by its ID.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the channel.

Example

this.chatApi.channel(1).then(channel => { ... })

module.exports.channels() ⇒ module.exports

List all accessible category channels of the current user.

Kind: instance method of module.exports
Example

this.chatApi.channels.then(channels => { ... })

module.exports.moveChannelMessages(channelId, data) ⇒ Promise

Moves messages from one channel to another.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the original channel.
data object Params of the move.
data.message_ids Array.<number> IDs of the moved messages.
data.destination_channel_id number ID of the channel where the messages are moved to.

Example

this.chatApi
    .moveChannelMessages(1, {
      message_ids: [2, 3],
      destination_channel_id: 4,
    }).then(() => { ... })

module.exports.destroyChannel(channelId, channelName) ⇒ Promise

Destroys a channel.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the channel.
channelName string The name of the channel to be destroyed, used as confirmation.

Example

this.chatApi.destroyChannel(1, "foo").then(() => { ... })

module.exports.createChannel(data) ⇒ Promise

Creates a channel.

Kind: instance method of module.exports

Param Type Description
data object Params of the channel.
data.name string The name of the channel.
data.chatable_id string The category of the channel.
data.description string The description of the channel.
[data.auto_join_users] boolean Should users join this channel automatically.

Example

this.chatApi
     .createChannel({ name: "foo", chatable_id: 1, description "bar" })
     .then((channel) => { ... })

module.exports.categoryPermissions(categoryId) ⇒ Promise

Lists chat permissions for a category.

Kind: instance method of module.exports

Param Type Description
categoryId number ID of the category.

module.exports.sendMessage(channelId, data) ⇒ Promise

Sends a message.

Kind: instance method of module.exports

Param Type Description
channelId number ID of the channel.
data object Params of the message.
data.message string The raw content of the message in markdown.
data.cooked string The cooked content of the message.
[data.in_reply_to_id] number The ID of the replied-to message.
[data.staged_id] number The staged ID of the message before it was persisted.
[data.upload_ids] Array.<number> Array of upload ids linked to the message.

module.exports.createChannelArchive(channelId, data) ⇒ Promise

Creates a channel archive.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the channel.
data object Params of the archive.
data.selection string "new_topic" or "existing_topic".
[data.title] string Title of the topic when creating a new topic.
[data.category_id] string ID of the category used when creating a new topic.
[data.tags] Array.<string> tags used when creating a new topic.
[data.topic_id] string ID of the topic when using an existing topic.

module.exports.updateChannel(channelId, data) ⇒ Promise

Updates a channel.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the channel.
data object Params of the archive.
[data.description] string Description of the channel.
[data.name] string Name of the channel.

module.exports.updateChannelStatus(channelId, status) ⇒ Promise

Updates the status of a channel.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the channel.
status string The new status, can be "open" or "closed".

module.exports.listChannelMemberships(channelId) ⇒ module.exports

Lists members of a channel.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the channel.

module.exports.listCurrentUserChannels() ⇒ Promise

Lists public and direct message channels of the current user.

Kind: instance method of module.exports


module.exports.followChannel(channelId) ⇒ Promise

Makes current user follow a channel.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the channel.

module.exports.unfollowChannel(channelId) ⇒ Promise

Makes current user unfollow a channel.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the channel.

module.exports.updateCurrentUserChannelNotificationsSettings(channelId, data) ⇒ Promise

Update notifications settings of current user for a channel.

Kind: instance method of module.exports

Param Type Description
channelId number The ID of the channel.
data object The settings to modify.
[data.muted] boolean Mutes the channel.
[data.desktop_notification_level] string Notifications level on desktop: never, mention or always.
[data.mobile_notification_level] string Notifications level on mobile: never, mention or always.