UNPKG

@qonsoll/chat-core

Version:
264 lines (229 loc) 7.21 kB
import firebase$1 from 'firebase/app'; import firebase from 'firebase'; import { Dispatch, FC } from 'react'; type createNotificationArgsType = { oppositeUserData: UserType user: UserType messageText: string | boolean | null messageId: string } type createNotificationType = ( args: createNotificationArgsType ) => Promise<void> | void declare enum CHATS_CONTEXT_ACTIONS { UPDATE_CHATS = 'UPDATE_CHATS', UPDATE_CHAT_DATA = 'UPDATE_CHAT_DATA', DELETE_CHAT = 'DELETE_CHAT', SET_CURRENT_CHAT_ID = 'SET_CURRENT_CHAT_ID', CLEAR_CHATS = 'CLEAR_CHATS' } type ChatsContextType = { chatId: string typeOfChat: CHAT_TYPES collectionName: CHAT_COLLECTIONS.CHATS | CHAT_COLLECTIONS.GROUPS isChatExist: boolean unreadMessagesAmount: number isOppositeUserOnline: boolean isOppositeUserTyping: boolean lastActiveTime: firebase.firestore.Timestamp oppositeUserPermissions: Omit<PermissionsType, keyof ServiceFields> myPermissions: Omit<PermissionsType, keyof ServiceFields> groupMembersIds?: string[] oppositeUserData: MemberType & UserType } & Omit<ChatType, keyof ServiceFields> & Omit<UserChatType, keyof ServiceFields | 'type'> type ChatContextType = { oppositeUserData: UserType oppositeUserDataLoading: boolean currentChatId: null | string currentChatData: ChatsContextType chats: ChatsContextType[] } type ChatDispatchType = | { type: CHATS_CONTEXT_ACTIONS.DELETE_CHAT payload: { chatId: string } } | { type: CHATS_CONTEXT_ACTIONS.UPDATE_CHAT_DATA payload: { chatData: object; chatId: string } } | { type: CHATS_CONTEXT_ACTIONS.SET_CURRENT_CHAT_ID payload: { chatId: string } } | { type: CHATS_CONTEXT_ACTIONS.CLEAR_CHATS payload: { oppositeUserId: string } } declare function useChatsContext(): ChatContextType declare function useChatsDispatch(): Dispatch<ChatDispatchType> declare function useChats(): [ChatContextType, Dispatch<ChatDispatchType>] declare const ChatsProvider: FC<{ oppositeUserId: string oppositeUser: { data: UserType; loading: boolean } userData: UserType onSendNotification: createNotificationType }> declare enum MESSAGES_CONTEXT_ACTIONS { SET_END_OF_LIST = 'SET_END_OF_LIST', SET_MESSAGES = 'SET_MESSAGES', CLEAR_MESSAGES = 'CLEAR_MESSAGES', SET_INIT_LOADING = 'SET_INIT_LOADING' } type MessagesArrayType = MessageType[] type onUploadMessagesReturnType = | { fetchedData: MessagesArrayType; data?: undefined } | { data: MessagesArrayType; fetchedData: MessagesArrayType } | undefined type MessagesContextType = { messages: MessageType[] isInitLoading: boolean isEndOfList: boolean onUploadMessages?: () => Promise<onUploadMessagesReturnType> } type MessagesDispatchType = | { type: MESSAGES_CONTEXT_ACTIONS.CLEAR_MESSAGES } | { type: MESSAGES_CONTEXT_ACTIONS.SET_MESSAGES payload: { newFetchedMessages: MessageType[] deletedMessageId?: string | null } } | { type: MESSAGES_CONTEXT_ACTIONS.SET_END_OF_LIST payload: boolean } | { type: MESSAGES_CONTEXT_ACTIONS.SET_INIT_LOADING payload: boolean } declare function useMessagesContext(): MessagesContextType declare function useMessagesDispatch(): Dispatch<MessagesDispatchType> declare function useMessages(): [ MessagesContextType, Dispatch<MessagesDispatchType> ] declare const MessagesProvider: FC declare enum MESSAGE_ACTION_CONTEXT_ACTIONS { MESSAGE_DELETED = 'MESSAGE_DELETED' } type MessageActionContextType = { isMassageDeleting: MessageType | boolean } type MessageActionDispatchType = { type: MESSAGE_ACTION_CONTEXT_ACTIONS.MESSAGE_DELETED payload: MessageType | boolean } declare function useMessageActionContext(): MessageActionContextType declare function useMessageActionDispatch(): Dispatch<MessageActionDispatchType> declare function useMessageAction(): [ MessageActionContextType, Dispatch<MessageActionDispatchType> ] declare const MessageActionProvider: FC declare enum CHAT_COLLECTIONS { FOLDERS = 'folders', CHAT_USERS = 'chat_users', USER_STATUSES = 'user_statuses', USERS_STATUS_REFERENCES = 'users_status_references', CHATS = 'chats', GROUPS = 'groups', MESSAGES = 'messages', MESSAGES_VIEWS = 'messages_views', MEMBERS = 'members', MEMBERS_STATUSES = 'members_statuses', SCHEDULED_MESSAGES = 'scheduledMessages', RTDB_MESSENGER_ROOT = 'disqussMessenger', PERMISSIONS = 'permissions' } declare enum CHAT_TYPES { CHAT = 'CHAT', GROUPS = 'GROUPS' } declare enum ATTACH_TYPES { PHOTO = 'PHOTO', FILE = 'FILE', VIDEO = 'VIDEO' } declare enum MESSAGE_STATUS { SEEN = 'SEEN', SEND = 'SEND' } declare enum MESSAGE_TYPES { TEXT = 'TEXT', MEDIA = 'MEDIA', FILE = 'FILE', LIVE_VIDEO = 'LIVE_VIDEO' } declare type ATTACHMENT_FILES = 'disquss-attached-files' declare type DEFAULT_FOLDER_ID = 'ALL_CHATS' type ServiceFields = { _id: string _createdAt: firebase$1.firestore.Timestamp _createdBy: string _isUpdated?: boolean _updatedAt: firebase$1.firestore.Timestamp _updatedBy?: string } declare type MessageType = ServiceFields & { attachedFiles?: AttachFileType[] | null qVideoId: null | string status: MESSAGE_STATUS text: null | string messageType: MESSAGE_TYPES // Group message fields senderAvatarUrl?: string senderName?: string } declare type AttachFileType = { height?: null | number width?: null | number size?: number id: string name: string url: string videoUrl?: null | string qVideoId?: string type: ATTACH_TYPES | 'video/' } declare type ChatType = ServiceFields & { lastMessageAttachedFiles: AttachFileType[] lastMessageDateAndTime: firebase$1.firestore.Timestamp lastMessageId: string lastMessageSenderId: string lastMessageText: null | string lastMessageType: MESSAGE_TYPES } declare type UserChatType = ServiceFields & { order: null | number type: CHAT_TYPES oppositeUserId?: string displayName?: string chatPhotoUrl?: null | string } declare type UserType = ServiceFields & { firstName: string lastName: string avatarUrl: string email: string lastActiveTime: firebase$1.firestore.Timestamp phone: string isOnline: boolean role: string folders: [DEFAULT_FOLDER_ID, ...string[]] } declare type MemberType = Omit< UserType, 'folders' | 'role' | 'email' | 'phone' > & { isTyping: boolean lastMessageStatus: MESSAGE_STATUS } declare type PermissionsType = ServiceFields & { allowWrite: boolean } export { ATTACH_TYPES as A, ChatsProvider as C, DEFAULT_FOLDER_ID as D, MessagesProvider as M, UserChatType as U, useMessagesDispatch as a, useMessages as b, useMessageActionDispatch as c, useMessageAction as d, useMessageActionContext as e, MessageActionProvider as f, useChatsDispatch as g, useChatsContext as h, useChats as i, CHATS_CONTEXT_ACTIONS as j, CHAT_COLLECTIONS as k, CHAT_TYPES as l, MESSAGE_STATUS as m, MESSAGE_TYPES as n, ATTACHMENT_FILES as o, MESSAGES_CONTEXT_ACTIONS as p, MESSAGE_ACTION_CONTEXT_ACTIONS as q, MessageType as r, AttachFileType as s, MessagesContextType as t, useMessagesContext as u, ChatsContextType as v, ChatContextType as w, UserType as x };