UNPKG

softchatjs-core

Version:
267 lines (265 loc) 7.43 kB
declare enum ClientActions { INCOMING_MESSAGE = "incomingMessage", MESSAGES_READ = "messagesRead", USER_IS_TYPING = "userIsTyping", MESSAGE_ERROR = "sendMessageError", NEW_MESSAGE_REACTION = "newMessageReaction", ACK_HEALTH_CHECK = "acknowledgeHealthCheck", EDITED_MESSAGE = "editedMessage", MESSAGE_DELETED = "deletedMessage", MESSAGE_SENT = "messageSent" } declare enum ServerActions { INITIALIZE = "initialize", SEND_MESSAGE = "sendMessage", CREATE_CONVERSATION = "createConversation", SEND_MESSAGE_REPLY = "sendMessageReply", USER_TYPING = "userTyping", HEALTH_CHECK = "healthCheck", SEND_LOCATION = "sendLocation", READ_MESSAGES = "readMessages", DELETE_MESSAGE = "deleteMessage", EDIT_MESSAGE = "editMessage", SEND_MESSAGE_REACTION = "sendMessageReaction", CONNECTION_CLOSED = "clearUserSession", CREATE_BROADCAST_LIST = "createBroadcastList", BROADCAST_MESSAGE = "sendMessageToBroadcastList", UPDATE_BROADCAST_LIST = "updateUserBroadcastList", DELETE_BROADCAST_LIST = "deleteBroadcastList" } type Timetamps = { createdAt: string | Date; updatedAt: string | Date; deletedAt?: string | Date; }; type Prettify<T> = { [K in keyof T]: T[K]; } & {}; declare enum AttachmentTypes { NONE = "none", MAP = "map", MEDIA = "media", STICKER = "sticker" } interface Participant extends User { meta: UserMeta; } type User = { uid: string; connectionId?: string; projectId?: string; meta: UserMeta; } & Timetamps; type UserMeta = { username: string; uid: string; firstname?: string; lastname?: string; profileUrl?: string; custom?: Record<string, string>; color?: string; }; declare enum MediaType { VIDEO = "video", AUDIO = "audio", IMAGE = "image", DOCUMENT = "document", STICKER = "sticker" } type Media = { type: MediaType; ext: string; mediaId: string; mediaUrl: string; mimeType?: string; meta?: { aspectRatio?: number; height?: number; width?: number; size?: number; audioDurationSec?: number; }; uploading?: boolean; }; type Point = { lng: number; lat: number; }; type QuotedMessage = Message | null; type Message = { conversationId: string; from: string; to: string; quotedMessage: QuotedMessage | null; message: string; messageState: number; messageId: string; attachmentType?: AttachmentTypes; messageOwner: UserMeta; replyTo?: string; sharedLocation?: Point; sharedImage?: { url: string; aspectRatio?: number; }; attachedMedia: Media[]; token?: string; quotedMessageId?: string; reactions: Reaction[]; lastEdited: Date | string | null; broadcastListId?: string; isBroadcast?: boolean; } & Timetamps; type ParticipantListInfo = { id: string; uid: string; projectId?: string | null; connectionId?: string; participantId: string; participantDetails: UserMeta; } & Timetamps; type ConversationType = 'private-chat' | 'group-chat' | "admin-chat" | "broadcast-chat"; type GroupChatMeta = { groupName: string; groupIcon?: string; groupWallpaper?: string; groupBanner?: string; }; type PrivateChatMeta = { chatWallpaper?: string; }; type Conversation = { participants: string[]; admins: string[]; conversationId: string; messages: Message[]; conversationType: ConversationType; participantList: ParticipantListInfo[]; meta: PrivateChatMeta | null; groupMeta: GroupChatMeta | null; name?: string; } & Timetamps; type UploadContent = { base64: string; conversationId: string; key: string; }; type IncomingMessage = { action: ClientActions.INCOMING_MESSAGE; message: Message; }; type WsPayLoad<Action, Data> = { action: Action; message: Data; }; type ReceivedAction = ServerActions; type ReadMessages = { uid: string; messageIds: string[]; }; type UserTyping = { uid: string; }; type InitiateConnection = { from: string; to: string; newConversation: boolean; userDetails: UserMeta; recipientMeta: UserMeta; }; type StringOrNumber = string | number; type Config = { /** * - `projectId`: The ID of the project. */ projectId: string; /** * - `subId`: The subscriber ID. */ subId: string; }; type StartConversation = { from: string; recipientMeta: UserMeta; message: string; }; type Reaction = { emoji: string; uid: string; }; declare enum MessageStates { NONE = 0, FAILED = 1, LOADING = 2, SENT = 3, DELIVERED = 4, READ = 5 } type WsAccessConfig = { url: string; token: string; }; declare enum Screens { CHAT = "chat", CONVERSATIONS = "conversations" } type EditedMessage = { from: string; to: string; conversationId: string; messageId: string; textMessage: string; shouldEdit: boolean; isBroadcast?: boolean; }; type DeletedMessage = { conversationId: string; messageId: string; }; type ConversationWithTypingIndicator = { conversationId: string; timer: NodeJS.Timeout; timeActive: Date | string; }; type MessageReactionPayload = { action: ServerActions; message: { conversationId: string; messageId: string; from: string; to: string; reactions: Array<Reaction>; }; }; type ConversationMap = { [key: string]: Conversation; }; type ConversationListItem = { conversation: Conversation; lastMessage: Message | null; unread: string[]; }; type ConversationListMeta = { [key: string]: ConversationListItem; }; type BroadcastListMeta = { [key: string]: Conversation; }; type ChatEventGenerics<T> = T; type ConnectionEvent = { connecting: boolean; fetchingConversations: boolean; isConnected: boolean; }; type SendMessageGenerics<M> = Omit<M, 'from' | 'messageState' | 'messageId' | 'messageOwner' | 'token' | 'lastEdit' | 'lastEdited' | 'deletedAt' | 'createdAt' | 'updatedAt' | 'quotedMessageId'>; type SendGroupMessageGenerics<M> = Omit<M, 'to' | 'from' | 'messageState' | 'messageId' | 'messageOwner' | 'token' | 'lastEdit' | 'lastEdited' | 'deletedAt' | 'createdAt' | 'updatedAt' | 'replyTo' | 'quotedMessageId' | 'quotedMessage' | 'conversationId' | 'attachedMedia'>; type Emoji = { emoji: string; description: string; category: string; aliases: string[]; tags: string[]; unicode_version: string; ios_version: string; }; export { AttachmentTypes, type BroadcastListMeta, type ChatEventGenerics, ClientActions, type Config, type ConnectionEvent, type Conversation, type ConversationListItem, type ConversationListMeta, type ConversationMap, type ConversationType, type ConversationWithTypingIndicator, type DeletedMessage, type EditedMessage, type Emoji, type GroupChatMeta, type IncomingMessage, type InitiateConnection, type Media, MediaType, type Message, type MessageReactionPayload, MessageStates, type Participant, type ParticipantListInfo, type Point, type Prettify, type PrivateChatMeta, type Reaction, type ReadMessages, type ReceivedAction, Screens, type SendGroupMessageGenerics, type SendMessageGenerics, ServerActions, type StartConversation, type StringOrNumber, type UploadContent, type UserMeta, type UserTyping, type WsAccessConfig, type WsPayLoad };