import { Conversation } from "@twilio/conversations"; import { Action } from "redux"; import { Channel, Member, Message } from "twilio-chat"; import { ChatState } from "./ChatState"; import { ConversationListener, ParticipantState, ParticipantType } from "./ConversationState"; export type MemberType = Map; /** * A state of remote client in a Channel. * @typedef {Object} ChatState.MemberState * @property {Member} source - Represents the remote client in a Channel. See structure [here](https://media.twiliocdn.com/sdk/js/chat/releases/3.4.0/docs/Member.html). * @property {string} friendlyName - It represents the friendly name of the remote client. * @property {boolean} online - It represents if the member is online or not. * @private * @deprecated * @deprecatedSince 2.0.0 * @altRecommendation This state can be accesed via the conversation state, as in the example below * @altRecommendationExample * Twilio.Flex.Manager.getInstance().store.getState().flex.chat.conversations.<{CHANNEL_SID}>.participants * @altRecommendationLink https://assets.flex.twilio.com/docs/releases/flex-ui/latest/advanced/state-management/AppState/ */ export interface MemberState { readonly source: Member; readonly friendlyName: string; readonly online: boolean; } type PendingMessage = Pick & { timestamp: Date; body: string | null; participantSid?: string; sid: null; }; export interface Paginator { hasNextPage: boolean; hasPrevPage: boolean; items: Array; nextPage(): Promise>; prevPage(): Promise>; } export type MessageSource = Message | PendingMessage; /** * An object which represents a state of a single message. * @typedef {Object} ChatState.MessageState * @property {boolean} isFromMe - Is the message from me. * @property {Message} source - Represents the message object. See structure [here](https://media.twiliocdn.com/sdk/js/chat/releases/3.4.0/docs/Message.html). * @property {boolean} groupWithNext - should the message be grouped with the next message. * @property {boolean} groupWithPrevious - should the message be grouped with the previous message. * @property {number} index - index of the message within the remote messages array. * @property {string} [authorName] - Represents the friendly name of the message author. * @property {boolean} [error] - If set to true, the message has failed to be delivered. * @private * @deprecated * @deprecatedSince 2.0.0 * @altRecommendation This state can be accesed via the conversation state, as in the example below * @altRecommendationExample * Twilio.Flex.Manager.getInstance().store.getState().flex.chat.conversations.<{CHANNEL_SID}>.messages * @altRecommendationLink https://assets.flex.twilio.com/docs/releases/flex-ui/latest/advanced/state-management/AppState/ */ export interface MessageState { readonly isFromMe: boolean; readonly source: MessageSource; readonly groupWithNext: boolean; readonly groupWithPrevious: boolean; readonly index?: number; readonly authorName?: string; readonly isSending?: boolean; readonly error?: boolean; } /** * An object which represents a state of a channel. * @typedef {Object} ChatState.ChannelState * @property {Paginator} [currentPaginator] Paginator class to request messages on previous or next pages. See structure [here](https://media.twiliocdn.com/sdk/js/chat/releases/3.4.0/docs/Paginator.html). * @property {number} selectionStart=0 Index of the selection start * @property {number} selectionEnd=0 Index of the selection end * @property {boolean} isLoadingMessages=false Indicates if messages are currently loading * @property {boolean} isLoadingMembers=false Indicates if members are currently loading * @property {boolean} isLoadingChannel=false Indicates if channel is currently loading * @property {number} lastConsumedMessageIndex=0 Index of the last read message * @property {Map} members Members of the chat * @property {ChatState.MessageState[]} messages=Map() Messages in the channel * @property {Channel} [source] Reference to the channel. See structure [here](https://media.twiliocdn.com/sdk/js/chat/releases/3.4.0/docs/Channel.html). * @property {Array.} typers Members, who are currently typing a message * @property {boolean} errorWhileLoadingChannel=false Indicates if there was an error while loading a channel * @private * @deprecated * @deprecatedSince 2.0.0 * @altRecommendation This state can be accesed via the conversation state, as in the example below * @altRecommendationExample * Twilio.Flex.Manager.getInstance().store.getState().flex.chat.conversations.<{CHANNEL_SID}> * @altRecommendationLink https://assets.flex.twilio.com/docs/releases/flex-ui/latest/advanced/state-management/AppState/ */ export interface ChannelState { readonly currentPaginator?: Paginator; readonly inputText: string; readonly isLoadingMessages: boolean; readonly isLoadingMembers: boolean; readonly lastConsumedMessageIndex: number; readonly lastConsumedMessageByCurrentUserIndex: number; readonly listener?: ConversationListener; readonly members: MemberType; readonly unconsumedMessages: Array; readonly messages: Array; readonly pendingMessages: Array; readonly source?: Channel; readonly typers: Array; readonly isLoadingChannel: boolean; readonly errorWhileLoadingChannel: boolean; } export interface InitConversationPayload { conversation: Conversation; identity: string; listener: ConversationListener; } export type ChannelActionPayload = InitConversationPayload | ParticipantType | Paginator | Message | ParticipantState | string; export interface ChannelAction extends Action { payload?: any; meta: { channelSid: string; chatState?: ChatState; }; } export declare function reduce(state: ChannelState, action: ChannelAction): ChannelState; export declare class ChannelHelper { static isUserMemberOfChannel(channel: ChannelState): boolean; } export {};