@webinex/chatify 2.0.0-build2 → 2.0.0-build4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3176 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/types → types}/core/api/accountApi.d.ts +0 -1
- package/dist/{esm/types → types}/core/api/api.d.ts +2 -0
- package/dist/{esm/types → types}/core/api/baseApi.d.ts +2 -1
- package/dist/types/core/api/chatApi.d.ts +14 -0
- package/dist/{esm/types → types}/core/api/chatListApi.d.ts +0 -1
- package/dist/{esm/types → types}/core/api/chatMemberApi.d.ts +0 -1
- package/dist/types/core/api/chatMessageApi.d.ts +22 -0
- package/dist/types/core/api/index.d.ts +1 -0
- package/dist/{esm/types → types}/core/api/threadApi.d.ts +2 -10
- package/dist/types/core/api/threadMessageApi.d.ts +19 -0
- package/package.json +3 -5
- package/src/core/api/accountApi.ts +0 -2
- package/src/core/api/api.ts +2 -2
- package/src/core/api/baseApi.ts +12 -7
- package/src/core/api/chatApi.ts +1 -7
- package/src/core/api/chatListApi.ts +0 -2
- package/src/core/api/chatMemberApi.ts +0 -2
- package/src/core/api/chatMessageApi.ts +0 -9
- package/src/core/api/index.ts +0 -8
- package/src/core/api/threadApi.ts +1 -9
- package/src/core/api/threadMessageApi.ts +0 -9
- package/src/ui/Chat/ChatEditableHeaderName.tsx +2 -2
- package/src/ui/Chat/ChatPanel.tsx +2 -2
- package/src/ui/Chat/ChatView.tsx +6 -14
- package/src/ui/Chat/Members/ChatMembersPanel.tsx +7 -12
- package/src/ui/Chat/Members/ChatMembersPreview.tsx +2 -2
- package/src/ui/ChatGroup/ChatGroupPanel.tsx +2 -2
- package/src/ui/ChatGroup/Create/CreateChatMemberInput.tsx +2 -2
- package/src/ui/ChatGroup/Create/CreateChatPanel.tsx +2 -2
- package/src/ui/ChatGroup/Layout/ChatGroupMain.tsx +2 -2
- package/src/ui/ChatGroup/List/ChatList.tsx +2 -2
- package/src/ui/Thread/ThreadPanel.tsx +8 -19
- package/dist/esm/index.js +0 -11
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/types/core/api/chatApi.d.ts +0 -25
- package/dist/esm/types/core/api/chatMessageApi.d.ts +0 -34
- package/dist/esm/types/core/api/index.d.ts +0 -9
- package/dist/esm/types/core/api/threadMessageApi.d.ts +0 -28
- /package/dist/{esm/types → types}/core/client.d.ts +0 -0
- /package/dist/{esm/types → types}/core/constants.d.ts +0 -0
- /package/dist/{esm/types → types}/core/debounce.d.ts +0 -0
- /package/dist/{esm/types → types}/core/index.d.ts +0 -0
- /package/dist/{esm/types → types}/core/types.d.ts +0 -0
- /package/dist/{esm/types → types}/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/ChatContext.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/ChatEditableHeaderName.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/ChatHeaderActions.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/ChatPanel.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/ChatView.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/Members/ChatMembersButton.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/Members/ChatMembersPanel.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/Members/ChatMembersPreview.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/Members/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chat/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/ChatGroupContext.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/ChatGroupPanel.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Create/CreateChatButton.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Create/CreateChatForm.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Create/CreateChatMemberInput.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Create/CreateChatNameInput.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Create/CreateChatPanel.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Create/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Layout/ChatGroupAside.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Layout/ChatGroupBody.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Layout/ChatGroupFooter.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Layout/ChatGroupHeader.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Layout/ChatGroupMain.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/Layout/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/ChatList.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/ChatListItemAvatar.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/ChatListItemBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/ChatListItemLastMessage.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/ChatListItemLastMessageAuthor.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/ChatListItemLastMessageContent.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/ChatListItemLastMessageSentAt.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/ChatListItemName.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/ChatListItemUnreadCount.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/List/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/ChatGroup/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Chatify.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/Conversation.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/ConversationActions.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/ConversationBody.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/ConversationContext.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/ConversationHeader.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/ConversationName.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/InputBox/InputBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/InputBox/InputFilesBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/InputBox/InputSubmitButtonBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/InputBox/InputTextBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/InputBox/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/Message/MessageAuthor.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/Message/MessageBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/Message/MessageContent.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/Message/MessageInfoBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/Message/MessageRow.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/Message/MessageText.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/Message/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/NextObserver/NextMessagesObserver.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/NextObserver/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/ReadObserver/MessageReadObserver.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/ReadObserver/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/SendingMessage/SendingMessageBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/SendingMessage/SendingMessageContent.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/SendingMessage/SendingMessageInfoBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/SendingMessage/SendingMessageText.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/SendingMessage/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/SystemMessage/SystemMessageBox.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/SystemMessage/SystemMessageRow.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/SystemMessage/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Conversation/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Thread/ThreadActions.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Thread/ThreadContext.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Thread/ThreadPanel.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/Thread/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/color.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/common/Avatar.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/common/Icon.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/common/MessageSkeleton.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/common/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/customize.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/index.d.ts +0 -0
- /package/dist/{esm/types → types}/ui/localizer.d.ts +0 -0
package/src/core/api/baseApi.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createApi, fakeBaseQuery } from '@reduxjs/toolkit/query/react';
|
|
1
|
+
import { BaseQueryFn, createApi, fakeBaseQuery } from '@reduxjs/toolkit/query/react';
|
|
2
2
|
import { ChatifyClient } from '../client';
|
|
3
3
|
import { Debounce } from '../debounce';
|
|
4
4
|
import { chatId } from '../types';
|
|
@@ -22,9 +22,14 @@ export const __settings: ChatifyApiSettings = {
|
|
|
22
22
|
client: null!,
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const TAG_TYPES = ['chat', 'account', 'message', 'thread', 'thread-message'] as const;
|
|
26
|
+
|
|
27
|
+
const baseApi: ReturnType<typeof createApi<BaseQueryFn, {}, 'chatify', (typeof TAG_TYPES)[number]>> =
|
|
28
|
+
createApi({
|
|
29
|
+
baseQuery: fakeBaseQuery(),
|
|
30
|
+
reducerPath: 'chatify',
|
|
31
|
+
tagTypes: TAG_TYPES,
|
|
32
|
+
endpoints: (_) => ({}),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const __baseApi = baseApi;
|
package/src/core/api/chatApi.ts
CHANGED
|
@@ -7,10 +7,7 @@ const chatApi = __baseApi.injectEndpoints({
|
|
|
7
7
|
getChat: builder.query<Chat, { id: string }>({
|
|
8
8
|
queryFn: async ({ id }) => ({ data: await __settings.client.chat(id) }),
|
|
9
9
|
providesTags: ['chat', 'account'],
|
|
10
|
-
onCacheEntryAdded: async (
|
|
11
|
-
{ id },
|
|
12
|
-
{ dispatch, cacheEntryRemoved, cacheDataLoaded, updateCachedData },
|
|
13
|
-
) => {
|
|
10
|
+
onCacheEntryAdded: async ({ id }, { cacheEntryRemoved, cacheDataLoaded, updateCachedData }) => {
|
|
14
11
|
await cacheDataLoaded;
|
|
15
12
|
|
|
16
13
|
unsubscribe(
|
|
@@ -84,6 +81,3 @@ const chatApi = __baseApi.injectEndpoints({
|
|
|
84
81
|
});
|
|
85
82
|
|
|
86
83
|
export const __chatApi = chatApi;
|
|
87
|
-
|
|
88
|
-
export const { useGetChatQuery, useLazyGetChatQuery, useAddChatMutation, useUpdateChatNameMutation } =
|
|
89
|
-
chatApi;
|
|
@@ -145,12 +145,3 @@ export const __chatMessageApi = __baseApi.injectEndpoints({
|
|
|
145
145
|
}),
|
|
146
146
|
}),
|
|
147
147
|
});
|
|
148
|
-
|
|
149
|
-
export const {
|
|
150
|
-
useFetchNextChatMessageListMutation,
|
|
151
|
-
useGetChatMessageListQuery,
|
|
152
|
-
useReadChatMessageMutation,
|
|
153
|
-
useSendChatMessageMutation,
|
|
154
|
-
useGetChatMessageReadQueueQuery,
|
|
155
|
-
useLazyGetChatMessageListQuery,
|
|
156
|
-
} = __chatMessageApi;
|
package/src/core/api/index.ts
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export * from './baseApi';
|
|
2
|
-
export * from './accountApi';
|
|
3
|
-
export * from './chatApi';
|
|
4
|
-
export * from './chatListApi';
|
|
5
|
-
export * from './chatMemberApi';
|
|
6
|
-
export * from './chatMessageApi';
|
|
7
|
-
export * from './threadApi';
|
|
8
|
-
export * from './threadMessageApi';
|
|
9
1
|
export * from './api';
|
|
@@ -118,15 +118,7 @@ export const __threadApi = __baseApi.injectEndpoints({
|
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
export function useUnreadThreadMessageCount() {
|
|
121
|
-
const { data: threads, ...state } = useGetWatchThreadListQuery();
|
|
121
|
+
const { data: threads, ...state } = __threadApi.useGetWatchThreadListQuery();
|
|
122
122
|
const count = useMemo(() => (threads != null ? calcThreadListUnreadCount(threads) : null), [threads]);
|
|
123
123
|
return [count, state] as const;
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
export const {
|
|
127
|
-
useGetWatchThreadListQuery,
|
|
128
|
-
useGetThreadQuery,
|
|
129
|
-
useLazyGetThreadQuery,
|
|
130
|
-
useLazyGetWatchThreadListQuery,
|
|
131
|
-
useWatchThreadMutation,
|
|
132
|
-
} = __threadApi;
|
|
@@ -116,12 +116,3 @@ export const __threadMessageApi = __baseApi.injectEndpoints({
|
|
|
116
116
|
}),
|
|
117
117
|
}),
|
|
118
118
|
});
|
|
119
|
-
|
|
120
|
-
export const {
|
|
121
|
-
useFetchNextThreadMessageListMutation,
|
|
122
|
-
useGetThreadMessageListQuery,
|
|
123
|
-
useLazyGetThreadMessageListQuery,
|
|
124
|
-
useReadThreadMessageMutation,
|
|
125
|
-
useSendThreadMessageMutation,
|
|
126
|
-
useGetThreadMessageReadQueueQuery,
|
|
127
|
-
} = __threadMessageApi;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Input, Tooltip } from 'antd';
|
|
2
|
-
import {
|
|
2
|
+
import { chatifyApi } from '../../core';
|
|
3
3
|
import { customize } from '../customize';
|
|
4
4
|
import { useEffect, useState } from 'react';
|
|
5
5
|
import isHotkey from 'is-hotkey';
|
|
@@ -9,7 +9,7 @@ const isEscape = isHotkey('escape');
|
|
|
9
9
|
const isEnter = isHotkey('enter');
|
|
10
10
|
|
|
11
11
|
function useUpdateChatName(id: string, value: string) {
|
|
12
|
-
const [updateChatName] = useUpdateChatNameMutation();
|
|
12
|
+
const [updateChatName] = chatifyApi.useUpdateChatNameMutation();
|
|
13
13
|
return () => updateChatName({ id, name: value });
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -2,7 +2,7 @@ import { CSSProperties } from 'react';
|
|
|
2
2
|
import { Localizer, LocalizerContext, defaultLocalizer } from '../localizer';
|
|
3
3
|
import { CustomizeContext } from '../customize';
|
|
4
4
|
import { ChatView, ChatViewCustomizeValue } from './ChatView';
|
|
5
|
-
import {
|
|
5
|
+
import { chatifyApi } from '../../core';
|
|
6
6
|
|
|
7
7
|
export interface ChatPanelCustomizeValue extends ChatViewCustomizeValue {}
|
|
8
8
|
|
|
@@ -16,7 +16,7 @@ export interface ChatPanelProps {
|
|
|
16
16
|
|
|
17
17
|
export function ChatPanel(props: ChatPanelProps) {
|
|
18
18
|
const { id, className = '', customize, localizer = defaultLocalizer, style } = props;
|
|
19
|
-
const { data: chat } = useGetChatQuery({ id });
|
|
19
|
+
const { data: chat } = chatifyApi.useGetChatQuery({ id });
|
|
20
20
|
|
|
21
21
|
return (
|
|
22
22
|
<div className={`wxchtf-chatify wxchtf-chat-panel ${className}`} style={style}>
|
package/src/ui/Chat/ChatView.tsx
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { CustomizeContext, customize, useCustomizeContext } from '../customize';
|
|
2
|
-
import {
|
|
3
|
-
MessageBody,
|
|
4
|
-
chatId,
|
|
5
|
-
useFetchNextChatMessageListMutation,
|
|
6
|
-
useGetChatMessageListQuery,
|
|
7
|
-
useGetChatMessageReadQueueQuery,
|
|
8
|
-
useReadChatMessageMutation,
|
|
9
|
-
useSendChatMessageMutation,
|
|
10
|
-
} from '../../core';
|
|
2
|
+
import { MessageBody, chatId, chatifyApi } from '../../core';
|
|
11
3
|
import {
|
|
12
4
|
Conversation,
|
|
13
5
|
ConversationCustomizeValue,
|
|
@@ -41,19 +33,19 @@ function useConversation(props: ChatProps) {
|
|
|
41
33
|
const { value: chat } = props;
|
|
42
34
|
const { id, name, active, lastReadMessageId } = chat;
|
|
43
35
|
|
|
44
|
-
const { data: messageList } = useGetChatMessageListQuery({ chatId: id });
|
|
36
|
+
const { data: messageList } = chatifyApi.useGetChatMessageListQuery({ chatId: id });
|
|
45
37
|
const { messages, hasMore } = messageList ?? {};
|
|
46
38
|
|
|
47
|
-
const [fetchNext, { isLoading: isFetchNextLoading }] = useFetchNextChatMessageListMutation();
|
|
39
|
+
const [fetchNext, { isLoading: isFetchNextLoading }] = chatifyApi.useFetchNextChatMessageListMutation();
|
|
48
40
|
const onNext = useCallback(() => fetchNext({ chatId: id }), [fetchNext, id]);
|
|
49
41
|
|
|
50
|
-
const [read] = useReadChatMessageMutation();
|
|
42
|
+
const [read] = chatifyApi.useReadChatMessageMutation();
|
|
51
43
|
const onRead = useCallback((id: string) => read({ id }), [read]);
|
|
52
44
|
|
|
53
|
-
const [send] = useSendChatMessageMutation();
|
|
45
|
+
const [send] = chatifyApi.useSendChatMessageMutation();
|
|
54
46
|
const onSend = useCallback((message: MessageBody) => send({ ...message, chatId: id }).unwrap(), [id, send]);
|
|
55
47
|
|
|
56
|
-
const { data: readQueue } = useGetChatMessageReadQueueQuery();
|
|
48
|
+
const { data: readQueue } = chatifyApi.useGetChatMessageReadQueueQuery();
|
|
57
49
|
|
|
58
50
|
const conversation = useMemo(() => {
|
|
59
51
|
if (!id) {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { Button, List, Space, Tooltip } from 'antd';
|
|
2
|
-
import {
|
|
3
|
-
useAddChatMemberMutation,
|
|
4
|
-
useGetAccountListQuery,
|
|
5
|
-
useGetChatQuery,
|
|
6
|
-
useRemoveChatMemberMutation,
|
|
7
|
-
} from '../../../core';
|
|
2
|
+
import { chatifyApi } from '../../../core';
|
|
8
3
|
import { customize } from '../../customize';
|
|
9
4
|
import { useCallback, useMemo } from 'react';
|
|
10
5
|
import { Icon } from '../../common/Icon';
|
|
@@ -17,7 +12,7 @@ interface ChatMemberListItemProps {
|
|
|
17
12
|
}
|
|
18
13
|
|
|
19
14
|
function useAdd(chatId: string, accountId: string, withHistory: boolean) {
|
|
20
|
-
const [add, state] = useAddChatMemberMutation();
|
|
15
|
+
const [add, state] = chatifyApi.useAddChatMemberMutation();
|
|
21
16
|
const onAdd = useCallback(
|
|
22
17
|
() => add({ chatId, accountId, withHistory }),
|
|
23
18
|
[add, chatId, accountId, withHistory],
|
|
@@ -26,7 +21,7 @@ function useAdd(chatId: string, accountId: string, withHistory: boolean) {
|
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
function useRemove(chatId: string, accountId: string, deleteHistory: boolean) {
|
|
29
|
-
const [remove, state] = useRemoveChatMemberMutation();
|
|
24
|
+
const [remove, state] = chatifyApi.useRemoveChatMemberMutation();
|
|
30
25
|
const onRemove = useCallback(
|
|
31
26
|
() => remove({ chatId, accountId, deleteHistory }),
|
|
32
27
|
[remove, chatId, accountId, deleteHistory],
|
|
@@ -36,8 +31,8 @@ function useRemove(chatId: string, accountId: string, deleteHistory: boolean) {
|
|
|
36
31
|
|
|
37
32
|
const ChatMemberListItem = customize('ChatMemberListItem', (props: ChatMemberListItemProps) => {
|
|
38
33
|
const { chatId } = props;
|
|
39
|
-
const { data: chat } = useGetChatQuery({ id: chatId });
|
|
40
|
-
const { data: accounts } = useGetAccountListQuery();
|
|
34
|
+
const { data: chat } = chatifyApi.useGetChatQuery({ id: chatId });
|
|
35
|
+
const { data: accounts } = chatifyApi.useGetAccountListQuery();
|
|
41
36
|
const account = accounts!.find((x) => x.id === props.id)!;
|
|
42
37
|
const isMember = chat!.members.some((x) => x.id === account.id);
|
|
43
38
|
const [onAddWithoutHistory] = useAdd(chatId, account.id, false);
|
|
@@ -86,8 +81,8 @@ const ChatMemberListItem = customize('ChatMemberListItem', (props: ChatMemberLis
|
|
|
86
81
|
|
|
87
82
|
export const ChatMembersPanel = customize('ChatMembersPanel', () => {
|
|
88
83
|
const { id } = useChatContext();
|
|
89
|
-
const { data: chat } = useGetChatQuery({ id });
|
|
90
|
-
const { data: accounts } = useGetAccountListQuery();
|
|
84
|
+
const { data: chat } = chatifyApi.useGetChatQuery({ id });
|
|
85
|
+
const { data: accounts } = chatifyApi.useGetAccountListQuery();
|
|
91
86
|
const ordered = useMemo(
|
|
92
87
|
() =>
|
|
93
88
|
accounts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { chatifyApi } from '../../../core';
|
|
2
2
|
import { Tooltip } from 'antd';
|
|
3
3
|
import { customize } from '../../customize';
|
|
4
4
|
import { Avatar as AntdAvatar } from 'antd';
|
|
@@ -7,7 +7,7 @@ import { useChatContext } from '../ChatContext';
|
|
|
7
7
|
|
|
8
8
|
export const ChatMembersPreview = customize('ChatMembersPreview', () => {
|
|
9
9
|
const { id } = useChatContext();
|
|
10
|
-
const { data: chat } = useGetChatQuery({ id });
|
|
10
|
+
const { data: chat } = chatifyApi.useGetChatQuery({ id });
|
|
11
11
|
|
|
12
12
|
if (!chat?.members) {
|
|
13
13
|
return null;
|
|
@@ -4,7 +4,7 @@ import { CreateChatPanelCustomizeValue } from './Create';
|
|
|
4
4
|
import { ChatGroupBody, ChatGroupFooter, ChatGroupHeader, ChatGroupLayoutCustomizeValue } from './Layout';
|
|
5
5
|
import { ChatListCustomizeValue } from './List';
|
|
6
6
|
import { ChatGroupContext, useChatGroupContext } from './ChatGroupContext';
|
|
7
|
-
import {
|
|
7
|
+
import { chatifyApi } from '../../core';
|
|
8
8
|
import { CustomizeContext } from '../customize';
|
|
9
9
|
import { ChatViewCustomizeValue } from '../Chat';
|
|
10
10
|
|
|
@@ -23,7 +23,7 @@ export interface ChatifyProps {
|
|
|
23
23
|
|
|
24
24
|
function Content(props: Pick<ChatifyProps, 'className' | 'style'>) {
|
|
25
25
|
const { className = '', style } = props;
|
|
26
|
-
const { data: chats } = useGetChatListQuery();
|
|
26
|
+
const { data: chats } = chatifyApi.useGetChatListQuery();
|
|
27
27
|
const { openChat, none, chatId } = useChatGroupContext();
|
|
28
28
|
const openFirstChatRef = useRef(false);
|
|
29
29
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import { chatifyApi
|
|
2
|
+
import { chatifyApi } from '../../../core';
|
|
3
3
|
import { customize } from '../../customize';
|
|
4
4
|
import { Checkbox, Form, List } from 'antd';
|
|
5
5
|
import { useLocalizer } from '../../localizer';
|
|
@@ -16,7 +16,7 @@ interface CheckboxListProps {
|
|
|
16
16
|
|
|
17
17
|
function CheckboxList(props: CheckboxListProps) {
|
|
18
18
|
const { value, onChange } = props;
|
|
19
|
-
const { data: accounts, isFetching } = useGetAccountListQuery();
|
|
19
|
+
const { data: accounts, isFetching } = chatifyApi.useGetAccountListQuery();
|
|
20
20
|
const me = chatifyApi.settings.me();
|
|
21
21
|
const dataSource = useMemo(() => accounts?.filter((x) => x.id !== me) ?? [], [accounts, me]);
|
|
22
22
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { chatifyApi } from '../../../core';
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
3
|
import { useLocalizer } from '../../localizer';
|
|
4
4
|
import { CreateChatForm, CreateChatFormValue } from './CreateChatForm';
|
|
@@ -8,7 +8,7 @@ import { Icon } from '../../common/Icon';
|
|
|
8
8
|
import { useChatGroupContext } from '../ChatGroupContext';
|
|
9
9
|
|
|
10
10
|
function useSubmit() {
|
|
11
|
-
const [add, { isLoading }] = useAddChatMutation();
|
|
11
|
+
const [add, { isLoading }] = chatifyApi.useAddChatMutation();
|
|
12
12
|
const { openChat } = useChatGroupContext();
|
|
13
13
|
|
|
14
14
|
const onSubmit = useCallback(
|
|
@@ -2,11 +2,11 @@ import { customize } from '../../customize';
|
|
|
2
2
|
import { CreateChatPanel } from '../Create';
|
|
3
3
|
import { ChatView } from '../../Chat';
|
|
4
4
|
import { useChatGroupContext } from '../ChatGroupContext';
|
|
5
|
-
import {
|
|
5
|
+
import { chatifyApi } from '../../../core';
|
|
6
6
|
|
|
7
7
|
export const ChatGroupMain = customize('ChatGroupMain', () => {
|
|
8
8
|
const { chatId, view } = useChatGroupContext();
|
|
9
|
-
const chat = useChatListItem(chatId);
|
|
9
|
+
const chat = chatifyApi.useChatListItem(chatId);
|
|
10
10
|
|
|
11
11
|
return (
|
|
12
12
|
<div className="wxchtf-main">
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Menu, MenuProps } from 'antd';
|
|
2
2
|
import { useCallback, useMemo } from 'react';
|
|
3
3
|
import type { MenuItemType } from 'antd/es/menu/hooks/useItems';
|
|
4
|
-
import {
|
|
4
|
+
import { chatifyApi } from '../../../core';
|
|
5
5
|
import { ChatListItemBox } from './ChatListItemBox';
|
|
6
6
|
import { customize } from '../../customize';
|
|
7
7
|
import { useChatGroupContext } from '../ChatGroupContext';
|
|
@@ -16,7 +16,7 @@ function useOnSelect() {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function useMenuItems() {
|
|
19
|
-
const { data: chats } = useGetChatListQuery();
|
|
19
|
+
const { data: chats } = chatifyApi.useGetChatListQuery();
|
|
20
20
|
|
|
21
21
|
return useMemo<MenuItemType[] | undefined>(() => {
|
|
22
22
|
return chats
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
MessageBody,
|
|
4
|
-
chatifyApi,
|
|
5
|
-
parseThreadMessageId,
|
|
6
|
-
useFetchNextThreadMessageListMutation,
|
|
7
|
-
useGetThreadMessageListQuery,
|
|
8
|
-
useGetThreadMessageReadQueueQuery,
|
|
9
|
-
useGetThreadQuery,
|
|
10
|
-
useReadThreadMessageMutation,
|
|
11
|
-
useSendThreadMessageMutation,
|
|
12
|
-
useWatchThreadMutation,
|
|
13
|
-
} from '../../core';
|
|
2
|
+
import { MessageBody, chatifyApi, parseThreadMessageId } from '../../core';
|
|
14
3
|
import { Conversation, ConversationCustomizeValue, ConversationProps } from '../Conversation';
|
|
15
4
|
import { ThreadContext, ThreadContextValue } from './ThreadContext';
|
|
16
5
|
import { Localizer, LocalizerContext, defaultLocalizer } from '../localizer';
|
|
@@ -31,24 +20,24 @@ export interface ThreadPanelProps {
|
|
|
31
20
|
|
|
32
21
|
function usePanelState(props: ThreadPanelProps) {
|
|
33
22
|
const { threadId } = props;
|
|
34
|
-
const { data: thread } = useGetThreadQuery({ id: threadId });
|
|
35
|
-
const { data: messageList } = useGetThreadMessageListQuery({ threadId });
|
|
23
|
+
const { data: thread } = chatifyApi.useGetThreadQuery({ id: threadId });
|
|
24
|
+
const { data: messageList } = chatifyApi.useGetThreadMessageListQuery({ threadId });
|
|
36
25
|
const { id, name, archive, lastReadMessageId, watch } = thread ?? {};
|
|
37
26
|
const { messages, hasMore } = messageList ?? {};
|
|
38
27
|
|
|
39
|
-
const [read] = useReadThreadMessageMutation();
|
|
28
|
+
const [read] = chatifyApi.useReadThreadMessageMutation();
|
|
40
29
|
const onRead = useCallback((id: string) => read({ id }), [read]);
|
|
41
30
|
|
|
42
|
-
const [fetchNext, { isLoading: isFetchNextLoading }] = useFetchNextThreadMessageListMutation();
|
|
31
|
+
const [fetchNext, { isLoading: isFetchNextLoading }] = chatifyApi.useFetchNextThreadMessageListMutation();
|
|
43
32
|
const onNext = useCallback(() => fetchNext({ threadId }), [fetchNext, threadId]);
|
|
44
33
|
|
|
45
|
-
const [send] = useSendThreadMessageMutation();
|
|
34
|
+
const [send] = chatifyApi.useSendThreadMessageMutation();
|
|
46
35
|
const onSend = useCallback(
|
|
47
36
|
(message: MessageBody) => send({ body: message, threadId }).unwrap(),
|
|
48
37
|
[threadId, send],
|
|
49
38
|
);
|
|
50
39
|
|
|
51
|
-
const { data: readQueue } = useGetThreadMessageReadQueueQuery();
|
|
40
|
+
const { data: readQueue } = chatifyApi.useGetThreadMessageReadQueueQuery();
|
|
52
41
|
|
|
53
42
|
const conversation = useMemo(() => {
|
|
54
43
|
if (!id) {
|
|
@@ -86,7 +75,7 @@ function usePanelState(props: ThreadPanelProps) {
|
|
|
86
75
|
watch,
|
|
87
76
|
]);
|
|
88
77
|
|
|
89
|
-
const [watchThread] = useWatchThreadMutation();
|
|
78
|
+
const [watchThread] = chatifyApi.useWatchThreadMutation();
|
|
90
79
|
|
|
91
80
|
const threadContext = useMemo<ThreadContextValue | null>(
|
|
92
81
|
() =>
|
package/dist/esm/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as a from"react";import s,{useContext as i,useState as r,useMemo as c,forwardRef as o,useCallback as d,memo as u,useRef as h,useLayoutEffect as l,useEffect as m}from"react";import{Button as g,Avatar as f,List as v,Tooltip as y,Space as p,Input as b,Skeleton as C,Row as w,Col as x,Form as M,Checkbox as I,Menu as O}from"antd";import R from"@ant-design/icons/SendOutlined";import N from"@ant-design/icons/PaperClipOutlined";import _ from"@ant-design/icons/UserAddOutlined";import S from"@ant-design/icons/UsergroupAddOutlined";import T from"@ant-design/icons/UserDeleteOutlined";import E from"@ant-design/icons/UsergroupDeleteOutlined";import L from"@ant-design/icons/TeamOutlined";import k from"@ant-design/icons/EditOutlined";import j from"@ant-design/icons/CloseOutlined";import q from"@ant-design/icons/EyeInvisibleOutlined";import A from"@ant-design/icons/EyeOutlined";import{createApi as B,fakeBaseQuery as D}from"@reduxjs/toolkit/query/react";import*as F from"@microsoft/signalr";import Q from"is-hotkey";import U from"dayjs";const G={saturation:100,lightness:75};function P(e,t={}){t=Object.assign({},G,t);let n=0;for(let t=0;t<e.length;t++)n=e.charCodeAt(t)+((n<<5)-n),n&=n;return`hsl(${n%360}, ${t.saturation}%, ${t.lightness}%)`}const V=s.createContext(null);function H(){return i(V)}function $(e){const t=i(V);return t?t[e]:void 0}function z(e){const t=$(e.key);return null==t?null:null!=t?t:e.Component}function K(t,n){const a=s.forwardRef(((a,s)=>{const i=$(t);return null===i?null:e(i||n,Object.assign({},a,{ref:s}))}));return n.displayName=n.displayName||t,a.displayName="Customizable."+n.displayName,Object.assign(a,{key:t,Component:n})}const W={attach:N,send:R,"remove-member":T,"remove-member-delete-history":E,"add-member":_,"add-member-with-history":S,members:L,edit:k,close:j,chat:L,watch:A,unwatch:q},Y=K("Icon",(t=>{const{type:n}=t,a=W[n];return a?e(a,{}):null})),J=s.createContext(null);function X(){return i(J)}function Z(t){const{id:n,children:a}=t,[s,i]=r(!1),o=c((()=>({id:n,showMembers:s,onShowMembers:i})),[n,s]);return e(J.Provider,{value:o,children:a})}const ee=K("ChatMembersButton",(()=>{const{showMembers:t,onShowMembers:n}=X();return e(g,{onClick:()=>n(!t),type:"link",icon:e(Y,{type:"members"})})})),te="chatify::system";function ne(e){return e.slice(0,36)}function ae(e){const[t,n]=e.split("::",2);return[t,parseInt(n,10)]}function se(e){var t,n;const a=null!=e.lastReadMessageId?ae(e.lastReadMessageId)[1]:-1;return(null!=(null===(t=e.lastMessage)||void 0===t?void 0:t.id)?ae(null===(n=e.lastMessage)||void 0===n?void 0:n.id)[1]:-1)-a}function ie(e){return e.reduce(((e,t)=>e+se(t)),0)}class re{constructor(e){this.config=e,this._enqueued=[],this._processing=[],this._timeoutByGroup={},this._subscribers=[],this.subscribe=e=>(this._subscribers.push(e),()=>{this._subscribers=this._subscribers.filter((t=>t!==e))}),this.notify=()=>{this._subscribers.forEach((e=>e(this)))}}get units(){return[...this._enqueued.map((e=>Object.assign(Object.assign({},e),{state:"enqueued"}))),...this._processing.map((e=>Object.assign(Object.assign({},e),{state:"processing"})))]}push(e){const t=this.config.groupBy(e),n=this._enqueued.find((e=>this.config.groupBy(e.value)===t));n?this.config.compare(n.value,e)>=0&&(n.value=e,n.enqueueTime=Date.now()):this._enqueued.push({value:e,enqueueTime:Date.now()}),this._process(t)}_process(e){if(!this._enqueued.some((t=>this.config.groupBy(t.value)===e)))return;let t=this._timeoutByGroup[e];t&&clearTimeout(t),this._processing.some((t=>this.config.groupBy(t.value)===e))||(t=setTimeout((()=>{const t=this._enqueued.find((t=>this.config.groupBy(t.value)===e));this._processing.push(t),this._enqueued.splice(this._enqueued.indexOf(t),1),this.notify(),this.config.callback(t.value).then((()=>{this._processing.splice(this._processing.indexOf(t),1),this.notify(),this._process(e)})).catch((()=>{this._processing.splice(this._processing.indexOf(t),1),this.push(t.value)}))}),this.config.timeout),this._timeoutByGroup[e]=t)}}const ce=20,oe=new re({callback:e=>de.client.readChatMessage({id:e}),compare:(e,t)=>-e.localeCompare(t),groupBy:e=>ne(e),timeout:500}),de={me:null,client:null},ue=B({baseQuery:D(),reducerPath:"chatify",tagTypes:["chat","account","message","thread","thread-message"],endpoints:e=>({})});function he(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(a=Object.getOwnPropertySymbols(e);s<a.length;s++)t.indexOf(a[s])<0&&Object.prototype.propertyIsEnumerable.call(e,a[s])&&(n[a[s]]=e[a[s]])}return n}function le(e,t,n,a){return new(n||(n=Promise))((function(s,i){function r(e){try{o(a.next(e))}catch(e){i(e)}}function c(e){try{o(a.throw(e))}catch(e){i(e)}}function o(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,c)}o((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const me=ue.injectEndpoints({endpoints:e=>({getAccountList:e.query({queryFn:()=>le(void 0,void 0,void 0,(function*(){return{data:yield de.client.accounts()}})),providesTags:["account"]})})}),{useGetAccountListQuery:ge}=me,fe={hubUri:"/api/chatify/hub",headersFactory:()=>Promise.resolve({})},ve=["chatify://chat-new-message","chatify://chat-created","chatify://chat-message-read","chatify://chat-member-added","chatify://chat-member-removed","chatify://chat-name-changed","chatify://thread-created","chatify://thread-message-new","chatify://thread-message-read","chatify://thread-watch-added","chatify://thread-watch-removed"];class ye{constructor(e){this._connection=null,this._connectionPromise=null,this._subscribers={},this._reconnectSubscribers=[],this.connect=()=>le(this,void 0,void 0,(function*(){if(!this._connection){if(this._connectionPromise)return yield this._connectionPromise;this._connectionPromise=this.createAndStartConnection(),this._connection=yield this._connectionPromise}})),this.createAndStartConnection=()=>le(this,void 0,void 0,(function*(){const e=yield this._config.signalR.headersFactory(),t=(new F.HubConnectionBuilder).withUrl(this._config.signalR.hubUri,{accessTokenFactory:this._config.signalR.accessTokenFactory?this._config.signalR.accessTokenFactory:void 0,headers:e}).withAutomaticReconnect().build();return ve.forEach((e=>{t.on(e,((...t)=>{var n;null===(n=this._subscribers[e])||void 0===n||n.forEach((e=>{try{e(t)}catch(e){console.error("Failed to notify subscriber",e)}}))}))})),t.onreconnected((()=>this._reconnectSubscribers.forEach((e=>e())))),yield t.start(),t})),this.subscribe=(e,t)=>(this.connect().then((()=>{var n;this._subscribers[e]=null!==(n=this._subscribers[e])&&void 0!==n?n:[],this._subscribers[e].push(t)})),()=>this._subscribers[e].filter((e=>e!==t))),this.subscribeReconnect=e=>(this._reconnectSubscribers.push(e),()=>this._reconnectSubscribers.filter((t=>t!==e))),this.accounts=()=>le(this,void 0,void 0,(function*(){const{data:e}=yield this.axios.get("account");return e})),this.chats=()=>le(this,void 0,void 0,(function*(){const{data:e}=yield this.axios.get("chat");return e})),this.chat=e=>le(this,void 0,void 0,(function*(){const{data:t}=yield this.axios.get(`chat/${encodeURIComponent(e)}`);return t})),this.addChat=e=>le(this,void 0,void 0,(function*(){const{data:t}=yield this.axios.post("chat",e);return t})),this.chatMessages=e=>le(this,void 0,void 0,(function*(){const{chatId:t,skip:n=0,take:a=20}=e,s=encodeURIComponent(JSON.stringify({skip:n,take:a})),{data:i}=yield this.axios.get(`chat/${encodeURIComponent(t)}/message?pagingRule=${s}`);return i})),this.sendChatMessage=e=>le(this,void 0,void 0,(function*(){const{chatId:t}=e,n=he(e,["chatId"]);yield this.axios.post(`chat/${encodeURIComponent(t)}/message`,n)})),this.readChatMessage=e=>le(this,void 0,void 0,(function*(){yield this.axios.put("chat/message/read",e)})),this.removeChatMember=e=>le(this,void 0,void 0,(function*(){yield this.axios.delete(`chat/${encodeURIComponent(e.chatId)}/member`,{data:e})})),this.updateChatName=e=>le(this,void 0,void 0,(function*(){yield this.axios.put(`chat/${encodeURIComponent(e.id)}/name`,e)})),this.addChatMember=e=>le(this,void 0,void 0,(function*(){yield this.axios.post(`chat/${encodeURIComponent(e.chatId)}/member`,e)})),this.sendThreadMessage=({body:e,threadId:t})=>le(this,void 0,void 0,(function*(){const{data:n}=yield this.axios.post(`thread/${encodeURIComponent(t)}/message`,{body:e});return n})),this.readThreadMessage=e=>le(this,void 0,void 0,(function*(){yield this.axios.put(`thread/message/${encodeURIComponent(e)}/read`)})),this.watchThreads=()=>le(this,void 0,void 0,(function*(){const{data:e}=yield this.axios.get("thread/watch");return e})),this.thread=e=>le(this,void 0,void 0,(function*(){const{data:t}=yield this.axios.get(`thread/${encodeURIComponent(e)}`);return t})),this.threadMessages=({threadId:e,skip:t,take:n})=>le(this,void 0,void 0,(function*(){const a=new URLSearchParams;a.append("skip",t.toString()),a.append("take",n.toString());const{data:s}=yield this.axios.get(`thread/${encodeURIComponent(e)}/message?${a.toString()}`);return s})),this.watchThread=(e,t)=>le(this,void 0,void 0,(function*(){yield this.axios.put(`thread/${encodeURIComponent(e)}/watch`,{watch:t})})),this.connectToThread=e=>le(this,void 0,void 0,(function*(){this.connect().then((()=>this._connection.invoke("ConnectToThread",e)))})),this.disconnectFromThread=e=>le(this,void 0,void 0,(function*(){this.connect().then((()=>this._connection.invoke("DisconnectFromThread",e)))})),this._config=Object.assign(Object.assign({},e),{signalR:Object.assign(Object.assign({},fe),e.signalR)})}get axios(){return this._config.axios}}function pe(...e){const t=()=>e.forEach((e=>e()));return t.when=e=>e.then(t),t}const be=ue.injectEndpoints({endpoints:e=>({getChat:e.query({queryFn:({id:e})=>le(void 0,void 0,void 0,(function*(){return{data:yield de.client.chat(e)}})),providesTags:["chat","account"],onCacheEntryAdded:({id:e},{dispatch:t,cacheEntryRemoved:n,cacheDataLoaded:a,updateCachedData:s})=>le(void 0,void 0,void 0,(function*(){yield a,pe(de.client.subscribe("chatify://chat-member-added",(([t,n,a,i,,r])=>t===e&&s((e=>{e.members.push(a),e.lastReadMessageId=r?i.id:e.lastReadMessageId})))),de.client.subscribe("chatify://chat-member-removed",(([t,n,,a,i])=>e===t&&s((e=>{e.members=e.members.filter((e=>e.id!==n)),e.lastReadMessageId=i?a.id:e.lastReadMessageId})))),de.client.subscribe("chatify://chat-name-changed",(([t,n,a,i])=>e===t&&s((e=>{e.name=n,e.lastReadMessageId=i?a.id:e.lastReadMessageId})))),de.client.subscribe("chatify://chat-new-message",(([t])=>e===t.chatId&&s((e=>{e.lastReadMessageId=t.sentBy.id===de.me()?t.id:e.lastReadMessageId})))),de.client.subscribe("chatify://chat-message-read",(([t])=>t.find((t=>t.chatId===e))&&s((n=>{const a=t.find((t=>t.chatId===e));n.lastReadMessageId=a.newLastReadMessageId}))))).when(n)}))}),addChat:e.mutation({queryFn:({name:e,members:t})=>le(void 0,void 0,void 0,(function*(){return{data:yield de.client.addChat({name:e,members:t,requestId:(new Date).getTime().toString()})}}))}),updateChatName:e.mutation({queryFn:({id:e,name:t})=>le(void 0,void 0,void 0,(function*(){return yield de.client.updateChatName({id:e,name:t}),{data:null}}))})})}),Ce=be,{useGetChatQuery:we,useLazyGetChatQuery:xe,useAddChatMutation:Me,useUpdateChatNameMutation:Ie}=be;var Oe,Re={exports:{}},Ne={};var _e,Se={};
|
|
2
|
-
/**
|
|
3
|
-
* @license React
|
|
4
|
-
* use-sync-external-store-with-selector.development.js
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
-
*
|
|
8
|
-
* This source code is licensed under the MIT license found in the
|
|
9
|
-
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/"production"===process.env.NODE_ENV?Re.exports=function(){if(Oe)return Ne;Oe=1;var e=s,t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=e.useSyncExternalStore,a=e.useRef,i=e.useEffect,r=e.useMemo,c=e.useDebugValue;return Ne.useSyncExternalStoreWithSelector=function(e,s,o,d,u){var h=a(null);if(null===h.current){var l={hasValue:!1,value:null};h.current=l}else l=h.current;h=r((function(){function e(e){if(!i){if(i=!0,n=e,e=d(e),void 0!==u&&l.hasValue){var s=l.value;if(u(s,e))return a=s}return a=e}if(s=a,t(n,e))return s;var r=d(e);return void 0!==u&&u(s,r)?s:(n=e,a=r)}var n,a,i=!1,r=void 0===o?null:o;return[function(){return e(s())},null===r?void 0:function(){return e(r())}]}),[s,o,d,u]);var m=n(e,h[0],h[1]);return i((function(){l.hasValue=!0,l.value=m}),[m]),c(m),m},Ne}():Re.exports=(_e||(_e=1,"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=s,t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=e.useSyncExternalStore,a=e.useRef,i=e.useEffect,r=e.useMemo,c=e.useDebugValue;Se.useSyncExternalStoreWithSelector=function(e,s,o,d,u){var h,l=a(null);null===l.current?(h={hasValue:!1,value:null},l.current=h):h=l.current;var m=r((function(){var e,n,a=!1,i=function(s){if(!a){a=!0,e=s;var i=d(s);if(void 0!==u&&h.hasValue){var r=h.value;if(u(r,i))return n=r,r}return n=i,i}var c=n;if(t(e,s))return c;var o=d(s);return void 0!==u&&u(c,o)?c:(e=s,n=o,o)},r=void 0===o?null:o;return[function(){return i(s())},null===r?void 0:function(){return i(r())}]}),[s,o,d,u]),g=m[0],f=m[1],v=n(e,g,f);return i((function(){h.hasValue=!0,h.value=v}),[v]),c(v),v},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),Se);var Te=Re.exports,Ee="default"in a?a.default:a,Le=Symbol.for("react-redux-context"),ke="undefined"!=typeof globalThis?globalThis:{};function je(){if(!Ee.createContext)return{};const e=ke[Le]??(ke[Le]=new Map);let t=e.get(Ee.createContext);return t||(t=Ee.createContext(null),"production"!==process.env.NODE_ENV&&(t.displayName="ReactRedux"),e.set(Ee.createContext,t)),t}var qe=je();function Ae(e=qe){return function(){const t=Ee.useContext(e);if("production"!==process.env.NODE_ENV&&!t)throw new Error("could not find react-redux context value; please ensure the component is wrapped in a <Provider>");return t}}var Be=Ae(),De=()=>{throw new Error("uSES not initialized!")},Fe=(e,t)=>e===t;function Qe(e=qe){const t=e===qe?Be:Ae(e),n=(e,n={})=>{const{equalityFn:a=Fe,devModeChecks:s={}}="function"==typeof n?{equalityFn:n}:n;if("production"!==process.env.NODE_ENV){if(!e)throw new Error("You must pass a selector to useSelector");if("function"!=typeof e)throw new Error("You must pass a function as a selector to useSelector");if("function"!=typeof a)throw new Error("You must pass a function as an equality function to useSelector")}const{store:i,subscription:r,getServerState:c,stabilityCheck:o,identityFunctionCheck:d}=t(),u=Ee.useRef(!0),h=Ee.useCallback({[e.name](t){const n=e(t);if("production"!==process.env.NODE_ENV){const{identityFunctionCheck:i,stabilityCheck:r}={stabilityCheck:o,identityFunctionCheck:d,...s};if("always"===r||"once"===r&&u.current){const s=e(t);if(!a(n,s)){let a;try{throw new Error}catch(e){({stack:a}=e)}console.warn("Selector "+(e.name||"unknown")+" returned a different result when called with the same parameters. This can lead to unnecessary rerenders.\nSelectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization",{state:t,selected:n,selected2:s,stack:a})}}if(("always"===i||"once"===i&&u.current)&&n===t){let t;try{throw new Error}catch(e){({stack:t}=e)}console.warn("Selector "+(e.name||"unknown")+" returned the root state when called. This can lead to unnecessary rerenders.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.",{stack:t})}u.current&&(u.current=!1)}return n}}[e.name],[e,o,s.stabilityCheck]),l=De(r.addNestedSub,i.getState,c||i.getState,h,a);return Ee.useDebugValue(l),l};return Object.assign(n,{withTypes:()=>n}),n}var Ue,Ge=Qe(),Pe=!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement),Ve="undefined"!=typeof navigator&&"ReactNative"===navigator.product;Pe||Ve?Ee.useLayoutEffect:Ee.useEffect,Ue=Te.useSyncExternalStoreWithSelector,De=Ue;const He=ue.injectEndpoints({endpoints:e=>({getChatList:e.query({queryFn:()=>le(void 0,void 0,void 0,(function*(){return{data:yield de.client.chats()}})),providesTags:["chat","account"],onCacheEntryAdded:(e,{dispatch:t,cacheEntryRemoved:n,cacheDataLoaded:a,updateCachedData:s})=>le(void 0,void 0,void 0,(function*(){yield a,pe(de.client.subscribe("chatify://chat-created",(([e])=>s((t=>{t.push(e)})))),de.client.subscribe("chatify://chat-new-message",(([e])=>s((t=>{const n=t.find((t=>t.id===e.chatId));n&&(n.message=e,e.sentBy.id===de.me()&&(n.lastReadMessageId=e.id,n.totalUnreadCount=0),e.sentBy.id!==de.me()&&n.totalUnreadCount++)})))),de.client.subscribe("chatify://chat-message-read",(([e])=>s((t=>{for(const n of e){const e=t.find((e=>e.id===n.chatId));if(!e)return;e.lastReadMessageId=n.newLastReadMessageId,e.totalUnreadCount=e.totalUnreadCount-n.readCount}})))),de.client.subscribe("chatify://chat-member-added",(([e,t,n,a,,i])=>s((s=>{const r=s.find((t=>t.id===e));n.id!==de.me()||r||s.push({id:e,name:t,message:a,totalUnreadCount:i?0:1,active:!0,lastReadMessageId:i?a.id:null}),r&&(r.message=a,r.active=!0,i?(r.totalUnreadCount=0,r.lastReadMessageId=a.id):r.totalUnreadCount++)})))),de.client.subscribe("chatify://chat-member-removed",(([e,t,n,a,i])=>s((s=>{if(t===de.me()&&n)return s.filter((t=>t.id!==e));const r=s.find((t=>t.id===e));r&&(r.message=a,t===de.me()&&(r.active=!1),i?(r.totalUnreadCount=0,r.lastReadMessageId=a.id):r.totalUnreadCount++)})))),de.client.subscribe("chatify://chat-name-changed",(([e,t,n,a])=>s((s=>{const i=s.find((t=>t.id===e));i&&(i.name=t,i.message=n,a?(i.totalUnreadCount=0,i.lastReadMessageId=n.id):i.totalUnreadCount++)}))))).when(n)}))})})});function $e(e){return Ge((t=>{var n;return null!=e?null===(n=He.endpoints.getChatList.select()(t).data)||void 0===n?void 0:n.find((t=>t.id===e)):null}))}const ze=He,{useGetChatListQuery:Ke,useLazyGetChatListQuery:We}=He,Ye=ue.injectEndpoints({endpoints:e=>({removeChatMember:e.mutation({queryFn:e=>le(void 0,void 0,void 0,(function*(){return yield de.client.removeChatMember(e),{data:null}}))}),addChatMember:e.mutation({queryFn:e=>le(void 0,void 0,void 0,(function*(){return yield de.client.addChatMember(e),{data:null}}))})})}),{useAddChatMemberMutation:Je,useRemoveChatMemberMutation:Xe}=Ye,Ze=new re({callback:e=>de.client.readChatMessage({id:e}),compare:(e,t)=>-e.localeCompare(t),groupBy:e=>ne(e),timeout:500}),et=ue.injectEndpoints({endpoints:e=>({getChatMessageList:e.query({queryFn:({chatId:e})=>le(void 0,void 0,void 0,(function*(){const t=yield de.client.chatMessages({chatId:e,skip:0,take:21});return{data:{messages:t.slice(0,ce),hasMore:21===t.length}}})),providesTags:["message","chat","account"],onCacheEntryAdded:({chatId:e},{dispatch:t,cacheEntryRemoved:n,cacheDataLoaded:a})=>le(void 0,void 0,void 0,(function*(){yield a,pe(de.client.subscribe("chatify://chat-new-message",(([n])=>{n.chatId===e&&t(et.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(n)})))})),de.client.subscribe("chatify://chat-member-added",(([n,,,a])=>{n===e&&t(et.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(a)})))})),de.client.subscribe("chatify://chat-member-removed",(([n,,,a])=>{n===e&&t(et.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(a)})))})),de.client.subscribe("chatify://chat-name-changed",(([n,,a])=>{n===e&&t(et.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(a)})))}))).when(n)}))}),fetchNextChatMessageList:e.mutation({queryFn:({chatId:e},{getState:t})=>le(void 0,void 0,void 0,(function*(){const n=et.endpoints.getChatMessageList.select({chatId:e})(t()),a=yield de.client.chatMessages({chatId:e,skip:n.data.messages.length,take:21});return{data:null,meta:{messages:a.slice(0,ce),hasMore:21===a.length}}})),onQueryStarted:({chatId:e},{dispatch:t,queryFulfilled:n})=>le(void 0,void 0,void 0,(function*(){const a=(yield n).meta;t(et.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.hasMore=a.hasMore,e.messages.push(...a.messages)})))}))}),sendChatMessage:e.mutation({queryFn:({chatId:e,text:t})=>le(void 0,void 0,void 0,(function*(){const n=(new Date).getTime().toString();return yield de.client.sendChatMessage({chatId:e,text:t,files:[],requestId:n}),{data:null,meta:{requestId:n}}}))}),readChatMessage:e.mutation({queryFn:()=>le(void 0,void 0,void 0,(function*(){return{data:null}})),onQueryStarted:({id:e},{dispatch:t})=>le(void 0,void 0,void 0,(function*(){Ze.push(e),t(et.endpoints.getChatMessageReadQueue.initiate(void 0,{forceRefetch:!0}))}))}),getChatMessageReadQueue:e.query({queryFn:()=>le(void 0,void 0,void 0,(function*(){return{data:Ze.units}})),onCacheEntryAdded:(e,{dispatch:t,cacheEntryRemoved:n})=>le(void 0,void 0,void 0,(function*(){pe(Ze.subscribe((e=>{t(et.util.updateQueryData("getChatMessageReadQueue",void 0,(()=>e.units)))}))).when(n)}))})})}),{useFetchNextChatMessageListMutation:tt,useGetChatMessageListQuery:nt,useReadChatMessageMutation:at,useSendChatMessageMutation:st,useGetChatMessageReadQueueQuery:it,useLazyGetChatMessageListQuery:rt}=et,ct=ue.injectEndpoints({endpoints:e=>({getWatchThreadList:e.query({queryFn:()=>le(void 0,void 0,void 0,(function*(){return{data:yield de.client.watchThreads()}})),providesTags:["account","thread"],onCacheEntryAdded:(e,{dispatch:t,cacheEntryRemoved:n,cacheDataLoaded:a,updateCachedData:s})=>le(void 0,void 0,void 0,(function*(){yield a,pe(de.client.subscribe("chatify://thread-created",(([e,t])=>t&&s((t=>{t.push(e)})))),de.client.subscribe("chatify://thread-message-new",(([e,t,n])=>s((a=>{const s=a.find((t=>t.id===e));s&&(s.lastMessage=t,n===de.me()&&(s.lastReadMessageId=t.id))})))),de.client.subscribe("chatify://thread-message-read",(([e,t])=>s((n=>{const a=n.find((t=>t.id===e));a&&(a.lastReadMessageId=t)})))),de.client.subscribe("chatify://thread-watch-added",(([e])=>s((t=>{t.push(e)})))),de.client.subscribe("chatify://thread-watch-removed",(([e])=>s((t=>{const n=t.findIndex((t=>t.id===e));-1!==n&&t.splice(n,1)}))))).when(n)}))}),getThread:e.query({queryFn:({id:e})=>le(void 0,void 0,void 0,(function*(){return{data:yield de.client.thread(e)}})),providesTags:["account","thread"],onCacheEntryAdded:({id:e},{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>le(void 0,void 0,void 0,(function*(){yield n,pe(de.client.subscribe("chatify://thread-message-read",(([t,n])=>e===t&&a((e=>{e.lastReadMessageId=n})))),de.client.subscribe("chatify://thread-message-new",(([t,n,s])=>e===t&&a((e=>{e.lastMessageId=n.id,e.lastReadMessageId=s===de.me()?n.id:e.lastReadMessageId})))),de.client.subscribe("chatify://thread-watch-added",(([t])=>e===t.id&&a((e=>{var n,a,s;e.watch=!0,e.lastMessageId=null!==(a=null===(n=t.lastMessage)||void 0===n?void 0:n.id)&&void 0!==a?a:null,e.lastReadMessageId=null!==(s=t.lastReadMessageId)&&void 0!==s?s:null})))),de.client.subscribe("chatify://thread-watch-removed",(([t])=>e===t&&a((e=>{e.watch=!1}))))).when(t)}))}),watchThread:e.mutation({queryFn:({id:e,watch:t})=>le(void 0,void 0,void 0,(function*(){return yield de.client.watchThread(e,t),{data:null}}))})})});function ot(){const e=dt(),{data:t}=e,n=he(e,["data"]);return[c((()=>null!=t?ie(t):null),[t]),n]}const{useGetWatchThreadListQuery:dt,useGetThreadQuery:ut,useLazyGetThreadQuery:ht,useLazyGetWatchThreadListQuery:lt,useWatchThreadMutation:mt}=ct,gt=new re({callback:e=>de.client.readThreadMessage(e),compare:(e,t)=>-e.localeCompare(t),groupBy:e=>ae(e)[0],timeout:500}),ft=ue.injectEndpoints({endpoints:e=>({getThreadMessageList:e.query({queryFn:e=>le(void 0,void 0,void 0,(function*(){const t=Object.assign({skip:0,take:21},e),n=yield de.client.threadMessages(t);return{data:{messages:n.slice(0,ce),hasMore:21===n.length}}})),providesTags:["account","thread","thread-message"],onCacheEntryAdded:({threadId:e},{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>le(void 0,void 0,void 0,(function*(){yield n,pe(de.client.subscribe("chatify://thread-message-new",(([t,n])=>{e===t&&a((e=>{!e.messages.some((e=>e.id===n.id))&&e.messages.unshift(n)}))}))).when(t)}))}),fetchNextThreadMessageList:e.mutation({queryFn:({threadId:e},{getState:t})=>le(void 0,void 0,void 0,(function*(){const n=ft.endpoints.getThreadMessageList.select({threadId:e})(t()),a=yield de.client.threadMessages({threadId:e,skip:n.data.messages.length,take:21});return{data:null,meta:{messages:a.slice(0,ce),hasMore:21===a.length}}})),onQueryStarted:({threadId:e},{dispatch:t,queryFulfilled:n})=>le(void 0,void 0,void 0,(function*(){const a=(yield n).meta;t(ft.util.updateQueryData("getThreadMessageList",{threadId:e},(e=>{e.hasMore=a.hasMore,e.messages.push(...a.messages)})))}))}),sendThreadMessage:e.mutation({queryFn:e=>le(void 0,void 0,void 0,(function*(){return{data:yield de.client.sendThreadMessage(e)}}))}),readThreadMessage:e.mutation({queryFn:()=>le(void 0,void 0,void 0,(function*(){return{data:null}})),onQueryStarted:({id:e},{dispatch:t})=>le(void 0,void 0,void 0,(function*(){gt.push(e),t(ft.endpoints.getThreadMessageReadQueue.initiate(void 0,{forceRefetch:!0}))}))}),getThreadMessageReadQueue:e.query({queryFn:()=>le(void 0,void 0,void 0,(function*(){return{data:gt.units}})),onCacheEntryAdded:(e,{dispatch:t,cacheEntryRemoved:n})=>le(void 0,void 0,void 0,(function*(){pe(gt.subscribe((e=>{t(ft.util.updateQueryData("getThreadMessageReadQueue",void 0,(()=>e.units)))}))).when(n)}))})})}),{useFetchNextThreadMessageListMutation:vt,useGetThreadMessageListQuery:yt,useLazyGetThreadMessageListQuery:pt,useReadThreadMessageMutation:bt,useSendThreadMessageMutation:Ct,useGetThreadMessageReadQueueQuery:wt}=ft,xt=ue,Mt=Object.assign(xt,{settings:de}),It=o(((t,n)=>{const{account:a}=t;return e(f,{ref:n,src:a.avatar})}));It.displayName="Avatar";const Ot=K("Avatar",It);function Rt(e,t,n){const[a,s]=Je();return[d((()=>a({chatId:e,accountId:t,withHistory:n})),[a,e,t,n]),s]}function Nt(e,t,n){const[a,s]=Xe();return[d((()=>a({chatId:e,accountId:t,deleteHistory:n})),[a,e,t,n]),s]}const _t=K("ChatMemberListItem",(n=>{const{chatId:a}=n,{data:s}=we({id:a}),{data:i}=ge(),r=i.find((e=>e.id===n.id)),c=s.members.some((e=>e.id===r.id)),[o]=Rt(a,r.id,!1),[d]=Rt(a,r.id,!0),[u]=Nt(a,r.id,!1),[h]=Nt(a,r.id,!0);return e(v.Item,{className:"wxchtf-chat-members-list-item",actions:c?[e(y,{title:"Remove (keep history)",children:e(g,{onClick:u,type:"link",icon:e(Y,{type:"remove-member"})})},"remove"),e(y,{title:"Remove (delete history)",children:e(g,{onClick:h,type:"link",icon:e(Y,{type:"remove-member-delete-history"})})},"remove_delete_history")]:[e(y,{title:"Add (no history)",children:e(g,{onClick:o,type:"link",icon:e(Y,{type:"add-member"})})},"add_no_history"),e(y,{title:"Add (share history)",children:e(g,{onClick:d,type:"link",icon:e(Y,{type:"add-member-with-history"})})},"add")],children:t(p,{children:[e(Ot,{account:r}),e("span",{children:r.name})]})})})),St=K("ChatMembersPanel",(()=>{const{id:t}=X(),{data:n}=we({id:t}),{data:a}=ge(),s=c((()=>null==a?void 0:a.slice().sort(((e,t)=>((null==n?void 0:n.members.some((t=>t.id===e.id)))?-100:0)-((null==n?void 0:n.members.some((e=>e.id===t.id)))?-100:0)+e.name.localeCompare(t.name)))),[a,n]);return(null==n?void 0:n.members)&&a?e("div",{className:"wxchtf-chat-members-panel",children:e(v,{className:"wxchtf-chat-members-list",dataSource:s,renderItem:n=>e(_t,{id:n.id,chatId:t})})}):null})),Tt=K("ChatMembersPreview",(()=>{const{id:t}=X(),{data:n}=we({id:t});return(null==n?void 0:n.members)?e(f.Group,{maxCount:5,children:n.members.map((t=>e(y,{title:t.name,children:e(Ot,{account:t})},t.id)))}):null})),Et=K("InputFilesBox",(()=>e("div",{className:"wxchtf-add-files-box",children:e(g,{type:"link",icon:e(Y,{type:"attach"}),className:"wxchtf-add-files-btn"})}))),Lt=s.createContext(null);function kt(){return i(Lt)}const jt={isToday:e=>U(e).isSame(U(),"day"),timestamp:e=>U(e).format("HH:mm"),dateTime:e=>U(e).format("DD/MM/YYYY HH:mm"),message:{read:()=>"Read",reading:()=>"Reading...",sending:()=>"Sending..."},addChat:{title:()=>"Add chat",name:{label:()=>"Name",required:()=>"Name is required",max250:()=>"Max 250 characters allowed"},members:{label:()=>"Members",required:()=>"Members is required"},submitBtn:()=>"Submit"},system:{"chatify://chat-created":()=>"Chat created","chatify://member-added":()=>"New member added","chatify://member-removed":()=>"Member removed","chatify://chat-name-changed":(e,{newName:t})=>`Chat name changed to '${t}'`},input:{placeholder:()=>"Start typing (Ctrl/⌘Cmd + Enter to send) ..."},settings:{members:()=>"Members"}},qt=Q("ctrl+enter"),At={maxRows:5,minRows:1},Bt=K("InputTextBox",u((t=>{const{value:n,onChange:a,onSend:s,inputRef:i}=t,r=kt(),c=d((e=>a(e.target.value)),[a]),o=d((e=>{qt(e)&&s(n)}),[s,n]);return e("div",{className:"wxchtf-text-input-box",children:e(b.TextArea,{ref:i,value:n,onChange:c,autoSize:At,className:"wxchtf-text-input-textarea",placeholder:r.input.placeholder(),onKeyDown:o})})}))),Dt=K("InputSubmitButtonBox",(t=>{const{onSubmit:n}=t;return e("div",{className:"wxchtf-submit-btn-box",children:e(g,{onClick:n,type:"link",icon:e(Y,{type:"send"}),className:"wxchtf-submit-btn"})})})),Ft=s.createContext(void 0);function Qt(){return s.useContext(Ft)}const Ut=K("InputBox",(()=>{const[n,{text:a,setText:s}]=function(){const{onSend:e}=Qt(),[t,n]=r("");return[d((()=>{0!==t.length&&(n(""),Promise.resolve(e({text:t,files:[]})).catch((()=>n(t))))}),[t,e]),{text:t,setText:n}]}(),i=h(null);return l((()=>{var e;return null===(e=i.current)||void 0===e?void 0:e.focus()}),[]),e("div",{className:"wxchtf-input-form",children:t("div",{className:"wxchtf-input-box",children:[e(Et,{}),e(Bt,{value:a,onSend:n,onChange:s,inputRef:i}),e(Dt,{onSubmit:n})]})})})),Gt=K("MessageAuthor",(t=>{const{sentBy:n}=t.message;return e("div",{className:"wxchtf-message-author",children:e(Ot,{account:n})})})),Pt=t=>{const{message:a,messageRef:s}=t,{onRead:i,lastReadMessageId:r}=Qt(),o=null!=r&&a.id.localeCompare(r)<=0,d=h(o);m((()=>{d.current=d.current||o}),[o]);const u=c((()=>new IntersectionObserver((([e])=>{e.isIntersecting&&!d.current&&(d.current=!0,i(a.id))}))),[]);return m((()=>(u.observe(s.current),()=>u.disconnect())),[u]),e(n,{})};function Vt(t){const{noReadTracking:n}=Qt();return!0===n?null:e(Pt,Object.assign({},t))}const Ht=K("MessageText",(t=>{const{text:n}=t.message;return e("div",{className:"wxchtf-message-text",children:n})})),$t=K("MessageContent",(t=>e("div",{className:"wxchtf-message-content",children:e(Ht,Object.assign({},t))}))),zt=K("MessageInfoBox",(n=>{const{message:a}=n,{id:s,sentBy:i,sentAt:r}=a,{lastReadMessageId:c,isReading:o,noReadTracking:d}=Qt(),u=Mt.settings.me(),h=i.id===u,l=kt(),m=!(null!=c&&s.localeCompare(c)<=0)&&o(s);return t("div",{className:"wxchtf-message-info-box",children:[!h&&t("div",{className:"wxchtf-message-author-name",children:[i.name,","]}),e("div",{className:"wxchtf-message-sent-at",children:l.timestamp(r)}),!h&&!d&&e("div",{className:"wxchtf-message-read-box",children:m?l.message.reading():l.message.read()})]})})),Kt=K("MessageRow",(n=>{const{message:a,containerRef:s}=n,{sentBy:i}=a,r=Mt.settings.me(),c=i.id===r;return t("div",{ref:s,className:"wxchtf-message"+(c?" --my":""),children:[e(Gt,Object.assign({},n)),t("div",{children:[e(zt,Object.assign({},n)),e($t,Object.assign({},n))]})]})})),Wt=K("MessageBox",(a=>{const s=h(null);return t(n,{children:[e(Vt,Object.assign({messageRef:s},a)),e(Kt,Object.assign({containerRef:s},a))]})})),Yt=K("MessageSkeleton",(a=>{const{count:s=1}=a;return e(n,{children:Array.from(Array(s)).map(((n,a)=>t("div",{className:"wxchtf-message-skeleton",children:[e(C.Avatar,{className:"wxchtf-avatar",active:!0}),e(C.Button,{active:!0,className:"wxchtf-content"})]},a)))})}));function Jt(t){const{onLoad:n,loading:a}=t,[s,i]=r(!1),o=h(null),d=h(),u=c((()=>new IntersectionObserver((([e])=>{e.isIntersecting?d.current=setTimeout((()=>i(!0)),200):clearTimeout(d.current)}))),[]);return m((()=>(u.observe(o.current),()=>u.disconnect())),[u]),m((()=>{s&&n()}),[s]),a||s?e(Yt,{count:4}):e("div",{className:"wxchtf-next",ref:o})}const Xt=K("SendingMessageText",(t=>{const{text:n}=t;return e("div",{className:"wxchtf-sending-message-text",children:n})})),Zt=K("SendingMessageInfoBox",(t=>{const n=kt();return e("div",{className:"wxchtf-sending-message-info-box",children:e("div",{className:"wxchtf-sending-message-sending-box",children:n.message.sending()})})})),en=K("SendingMessageContent",(n=>t("div",{className:"wxchtf-sending-message-content",children:[e(Xt,Object.assign({},n)),e(Zt,Object.assign({},n))]}))),tn=K("SendingMessageBox",(t=>e("div",{className:"wxchtf-sending-message",children:e(en,Object.assign({},t))})));function nn(e,t){const[n,a]=t.split("::",2),s=a?JSON.parse(a):null;return e.system[n](n,s)}const an=K("SystemMessageRow",(n=>{const{message:a,containerRef:s}=n,{text:i,sentAt:r}=a,c=kt();return t("div",{ref:s,className:"wxchtf-system-message",children:[e("div",{className:"wxchtf-text",children:nn(c,i)}),e("div",{className:"wxchtf-timestamp",children:c.timestamp(r)})]})})),sn=K("SystemMessageBox",(a=>{const s=h(null);return t(n,{children:[e(Vt,Object.assign({messageRef:s},a)),e(an,Object.assign({containerRef:s},a))]})})),rn=K("ConversationActions",(()=>null)),cn=K("ConversationBody",(()=>{const{id:n,messages:a=[],hasMore:s,onNext:i,nextLoading:r}=Qt();return t("div",{className:"wxchtf-conversation-body",children:[!a&&e(Yt,{count:5}),null==a?void 0:a.map((t=>t.sentBy.id===te?e(sn,{message:t},t.id):e(Wt,{message:t},t.id))),s&&e(Jt,{onLoad:i,loading:r},a.length+n)]})})),on=K("ConversationName",(()=>{const{name:t}=Qt();return e("span",{className:"wxchtf-conversation-name",children:t})})),dn=K("ConversationHeader",(()=>{const n=z(rn);return e("div",{className:"wxchtf-conversation-header",children:t(w,{justify:"space-between",align:"middle",children:[e(x,{children:e(on,{})}),n&&e(x,{className:"wxchtf-conversation-actions",children:e(n,{})})]})})})),un=K("Conversation",(n=>{const{value:a,hasMore:s,messages:i,nextLoading:r,onNext:o,onRead:d,onSend:u,isReading:h,noReadTracking:l}=n,{id:m,active:g,name:f,lastReadMessageId:v}=a,y=c((()=>({id:m,name:f,active:g,lastReadMessageId:v,hasMore:s,messages:i,nextLoading:r,onNext:o,onRead:d,onSend:u,isReading:h,noReadTracking:l})),[m,f,g,o,d,u,s,i,r,v,h,l]);return e(Ft.Provider,{value:y,children:e("div",{className:"wxchtf-conversation",children:t("div",{className:"wxchtf-conversation-main",children:[e(dn,{}),e(cn,{}),g&&e(Ut,{})]})})})})),hn=Q("escape"),ln=Q("enter");const mn=K("ChatEditableHeaderName",(()=>{const{id:t,name:n,active:a}=Qt(),[s,i]=r(""),[c,o]=r(!1),d=function(e,t){const[n]=Ie();return()=>n({id:e,name:t})}(t,s);return m((()=>{c&&i(null!=n?n:"")}),[c,n]),a?e(y,c?{defaultOpen:!0,title:"Press Enter to save new chat name or Escape to cancel editing",children:e(b,{value:s,onChange:e=>i(e.target.value),onBlur:()=>o(!1),onKeyDown:e=>{hn(e)?o(!1):ln(e)&&(o(!1),s!==n&&""!==s.trim()&&d())},autoFocus:!0})}:{title:"Click to edit name...",children:e("span",{className:"wxchtf-conversation-name --editable",onClick:()=>o(!0),children:n})}):e("span",{className:"wxchtf-conversation-name",children:n})})),gn=K("ChatHeaderActions",(()=>{const{active:n}=Qt();return n?t("div",{className:"wxchtf-chat-members",children:[e(Tt,{}),e(ee,{})]}):null})),fn={ConversationName:()=>e(mn,{}),ConversationActions:()=>e(gn,{})};function vn(n){const a=function(e){const{value:t}=e,{id:n,name:a,active:s,lastReadMessageId:i}=t,{data:r}=nt({chatId:n}),{messages:o,hasMore:u}=null!=r?r:{},[h,{isLoading:l}]=tt(),m=d((()=>h({chatId:n})),[h,n]),[g]=at(),f=d((e=>g({id:e})),[g]),[v]=st(),y=d((e=>v(Object.assign(Object.assign({},e),{chatId:n})).unwrap()),[n,v]),{data:p}=it();return c((()=>{if(!n)return null;const e={value:{id:n,name:a,active:s,lastReadMessageId:i},messages:o,hasMore:u,onNext:m,nextLoading:l,onRead:f,onSend:y,isReading:e=>p.some((t=>ne(t.value)===ne(e)&&e<=t.value))};return e}),[m,f,y,l,n,a,s,o,u,i,p])}(n),{showMembers:s}=X();return a?t("div",{className:"wxchtf-chat",children:[e(un,Object.assign({},a)),s&&e(St,{})]}):null}const yn=K("ChatView",(t=>{const{value:n}=t,a=H(),s=c((()=>Object.assign(Object.assign({},null!=a?a:{}),fn)),[a]);return e(V.Provider,{value:s,children:e(Z,{id:n.id,children:e(vn,{value:n})})})}));function pn(t){const{id:n,className:a="",customize:s,localizer:i=jt,style:r}=t,{data:c}=we({id:n});return e("div",{className:`wxchtf-chatify wxchtf-chat-panel ${a}`,style:r,children:e(Lt.Provider,{value:i,children:e(V.Provider,{value:s,children:c&&e(yn,{value:c},n)})})})}const bn=K("CreateChatNameInput",(t=>{const{name:n}=t,a=kt();return e(M.Item,{name:n,label:a.addChat.name.label(),rules:[{required:!0,message:a.addChat.name.required()},{max:250,message:a.addChat.name.max250()}],children:e(b,{})})}));function Cn(t){const{value:n,onChange:a}=t,{data:s,isFetching:i}=ge(),r=Mt.settings.me(),o=c((()=>{var e;return null!==(e=null==s?void 0:s.filter((e=>e.id!==r)))&&void 0!==e?e:[]}),[s,r]);return e(v,{rowKey:"id",className:"wxchtf-create-chat-member-input-list",loading:i,dataSource:o,renderItem:t=>{const s=n.includes(t.id);return e(v.Item,{className:s?"--selected":"",children:e(I,{checked:s,onChange:()=>a(n.includes(t.id)?n.filter((e=>e!==t.id)):[...n,t.id]),children:e(v.Item.Meta,{avatar:e(Ot,{account:t}),title:t.name})})})}})}const wn=K("CreateChatMemberInput",(t=>{const{name:n}=t,a=kt();return e(M.Item,{label:a.addChat.members.label(),rules:[{required:!0,message:a.addChat.members.required()}],name:n,children:e(Cn,{})})})),xn={name:"",members:[]},Mn=K("CreateChatForm",(n=>{const{value:a=xn,onSubmit:s,busy:i=!1}=n,r=kt();return t(M,{onFinish:s,layout:"vertical",disabled:i,initialValues:a,children:[e(bn,{name:"name"}),e(wn,{name:"members"}),e(g,{loading:i,type:"primary",block:!0,htmlType:"submit",children:r.addChat.submitBtn()})]})})),In=s.createContext(null);function On(){return i(In)}function Rn(t){const{children:n}=t,[a,s]=r({chatId:null,view:null,showMembers:!1}),i=c((()=>Object.assign(Object.assign({},a),{openChat:e=>s((t=>Object.assign(Object.assign({},t),{view:"chat",chatId:e}))),none:()=>s((e=>Object.assign(Object.assign({},e),{view:null,chatId:null}))),toggleMembers:()=>s((e=>Object.assign(Object.assign({},e),{showMembers:!e.showMembers}))),toggleNewChat:()=>s((e=>"new-chat"!==e.view||e.chatId?"new-chat"===e.view&&e.chatId?Object.assign(Object.assign({},e),{view:"chat"}):Object.assign(Object.assign({},e),{view:"new-chat"}):Object.assign(Object.assign({},e),{view:null})))})),[a]);return e(In.Provider,{value:i,children:n})}const Nn=K("CreateChatPanel",(()=>{const n=kt(),[a,s]=function(){const[e,{isLoading:t}]=Me(),{openChat:n}=On();return[d((t=>e({name:t.name,members:t.members}).unwrap().then((e=>n(e)))),[e,n]),t]}(),{toggleNewChat:i}=On();return t("div",{className:"wxchtf-create-chat-panel",children:[e(g,{onClick:()=>i(),className:"wxchtf-create-chat-panel-close",type:"link",icon:e(Y,{type:"close"})}),e("h3",{children:n.addChat.title()}),e(Mn,{busy:null!=s&&s,onSubmit:a})]})})),_n=K("CreateChatButton",(()=>{const{toggleNewChat:t}=On();return e("span",{className:"wxchtf-add-btn-wrapper",children:e(g,{className:"wxchtf-add-btn",onClick:t,icon:"+",children:"Add chat"})})})),Sn=K("ChatListItemName",(t=>{const{chat:n}=t;return e("div",{className:"wxchtf-chat-name",children:n.name})})),Tn=K("ChatListItemUnreadCount",(t=>{const{totalUnreadCount:n}=t.chat;return n<=0?null:e("div",{className:"wxchtf-unread-count",children:n})})),En=K("ChatListItemLastMessageContent",(t=>{const{message:n}=t.chat,a=kt();return e("div",{className:"wxchtf-chat-last-message",children:"chatify::system"===n.sentBy.id?nn(a,n.text):n.text})})),Ln=K("ChatListItemLastMessageAuthor",(t=>{const{message:n}=t.chat;return"chatify::system"===n.sentBy.id?null:e("div",{className:"wxchtf-chat-last-author",children:n.sentBy.name})})),kn=K("ChatListItemLastMessageSentAt",(t=>{const{chat:{message:{sentAt:n}}}=t,a=kt();return e("div",{className:"wxchtf-chat-last-sent-at",children:a.isToday(n)?a.timestamp(n):a.dateTime(n)})})),jn=K("ChatListItemLastMessage",(n=>t("div",{className:"wxchtf-chat-last",children:[e(Ln,Object.assign({},n)),e(En,Object.assign({},n)),e(kn,Object.assign({},n))]}))),qn=K("ChatListItemAvatar",(t=>{const{id:n}=t.chat;return e("div",{className:"wxchtf-chat-avatar",style:{"--background-color":P(n,{lightness:90}),"--color":P(n,{saturation:60,lightness:65})},children:e(Y,{type:"chat"})})})),An=K("ChatListItemBox",(n=>{const{message:a,lastReadMessageId:s}=n.chat,i=null!=s&&s.localeCompare(a.id)>=0;return t("div",{className:"wxchtf-chat"+(i?"":" --unread"),children:[e(qn,Object.assign({},n)),t("span",{className:"wxchtf-chat-info",children:[e(Sn,Object.assign({},n)),e(Tn,Object.assign({},n)),e(jn,Object.assign({},n))]})]})}));const Bn=K("ChatList",(()=>{const{chatId:t}=On(),a=c((()=>t?[t]:[]),[t]),s=function(){const{openChat:e}=On();return d((t=>e(t.key)),[e])}(),i=function(){const{data:t}=Ke();return c((()=>null==t?void 0:t.slice().sort(((e,t)=>-e.message.id.substring(47).localeCompare(t.message.id.substring(47)))).map((t=>({key:t.id,label:e(An,{chat:t})})))),[t])}();return e(n,{children:i&&e(O,{className:"wxchtf-chat-list",selectedKeys:a,onSelect:s,items:i})})})),Dn=K("ChatGroupAside",(()=>t("div",{className:"wxchtf-aside",children:[e(_n,{}),e(Bn,{})]}))),Fn=K("ChatGroupHeader",(()=>e("div",{className:"wxchtf-header"}))),Qn=K("ChatGroupFooter",(()=>e("div",{className:"wxchtf-footer"}))),Un=K("ChatGroupMain",(()=>{const{chatId:n,view:a}=On(),s=$e(n);return t("div",{className:"wxchtf-main",children:["chat"===a&&s&&e(yn,{value:s},n),"new-chat"===a&&e(Nn,{})]})})),Gn=K("ChatGroupBody",(()=>t("div",{className:"wxchtf-body",children:[e(Dn,{}),e(Un,{})]})));function Pn(n){const{className:a="",style:s}=n,{data:i}=Ke(),{openChat:r,none:c,chatId:o}=On(),d=h(!1);return m((()=>{i&&!i.some((e=>e.id===o))&&(i.length?r(i[0].id):c())}),[i,o]),m((()=>{i&&!d.current&&(d.current=!0,i.length&&r(i[0].id))}),[i]),t("div",{className:a+" wxchtf-chatify wxchtf-chat-group",style:s,children:[e(Fn,{}),e(Gn,{}),e(Qn,{})]})}const Vn={ChatGroupHeader:null,ChatGroupFooter:null},Hn=t=>{const{localizer:n=jt,customize:a=Vn}=t,s=c((()=>Object.assign({},Vn,a)),[a]);return e(Lt.Provider,{value:n,children:e(V.Provider,{value:s,children:e(Rn,{children:e(Pn,Object.assign({},t))})})})},$n=s.createContext(null);function zn(){return s.useContext($n)}const Kn=K("ThreadActions",(()=>{const{watch:t,onWatch:n}=zn();return e(y,t?{title:"Unwatch thread",children:e(g,{type:"link",icon:e(Y,{type:"unwatch"}),onClick:()=>n(!1)})}:{title:"Watch thread",children:e(g,{type:"link",icon:e(Y,{type:"watch"}),onClick:()=>n(!0)})})}));const Wn={ConversationActions:()=>e(Kn,{})};function Yn(t){const{threadId:n,customize:a,localizer:s=jt,className:i=""}=t,[r,o]=function(e){const{threadId:t}=e,{data:n}=ut({id:t}),{data:a}=yt({threadId:t}),{id:s,name:i,archive:r,lastReadMessageId:o,watch:u}=null!=n?n:{},{messages:h,hasMore:l}=null!=a?a:{},[m]=bt(),g=d((e=>m({id:e})),[m]),[f,{isLoading:v}]=vt(),y=d((()=>f({threadId:t})),[f,t]),[p]=Ct(),b=d((e=>p({body:e,threadId:t}).unwrap()),[t,p]),{data:C}=wt(),w=c((()=>{if(!s)return null;const e={value:{id:s,name:i,active:!r,lastReadMessageId:null!=o?o:null},messages:h,hasMore:l,onNext:y,nextLoading:v,onRead:g,onSend:b,noReadTracking:!u,isReading:e=>C.some((t=>ae(t.value)[0]===ae(e)[0]&&e<=t.value))};return e}),[y,g,b,v,s,i,r,h,l,o,C,u]),[x]=mt();return[w,c((()=>n?{id:n.id,watch:n.watch,onWatch:e=>x({id:n.id,watch:e}).unwrap()}:null),[n,x])]}(t),u=c((()=>Object.assign(Object.assign({},Wn),a)),[a]);return m((()=>(Mt.settings.client.connectToThread(n),()=>{Mt.settings.client.disconnectFromThread(n)})),[n]),r&&o?e(Lt.Provider,{value:s,children:e($n.Provider,{value:o,children:e(V.Provider,{value:u,children:e("div",{className:`wxchtf-chatify wxchtf-thread ${i}`,children:r&&e(un,Object.assign({},r))})})})}):null}const Jn={Thread:Yn,ChatGroup:Hn,Chat:pn};export{Ot as Avatar,ve as CHATIFY_SIGNALR_METHODS,oe as CHAT_MESSAGE_READ_QUEUE,Z as ChatContext,mn as ChatEditableHeaderName,Dn as ChatGroupAside,Gn as ChatGroupBody,Rn as ChatGroupContext,Qn as ChatGroupFooter,Fn as ChatGroupHeader,Un as ChatGroupMain,Hn as ChatGroupPanel,gn as ChatHeaderActions,Bn as ChatList,qn as ChatListItemAvatar,An as ChatListItemBox,jn as ChatListItemLastMessage,Ln as ChatListItemLastMessageAuthor,En as ChatListItemLastMessageContent,kn as ChatListItemLastMessageSentAt,Sn as ChatListItemName,Tn as ChatListItemUnreadCount,ee as ChatMembersButton,St as ChatMembersPanel,Tt as ChatMembersPreview,pn as ChatPanel,yn as ChatView,Jn as Chatify,ye as ChatifyClient,un as Conversation,rn as ConversationActions,cn as ConversationBody,Ft as ConversationContext,dn as ConversationHeader,on as ConversationName,_n as CreateChatButton,Mn as CreateChatForm,wn as CreateChatMemberInput,bn as CreateChatNameInput,Nn as CreateChatPanel,V as CustomizeContext,fn as DEFAULT_CHAT_VIEW_CUSTOMIZE_VALUE,ce as DEFAULT_MESSAGE_LIST_TAKE,W as ICONS,Y as Icon,Ut as InputBox,Et as InputFilesBox,Dt as InputSubmitButtonBox,Bt as InputTextBox,Lt as LocalizerContext,Gt as MessageAuthor,Wt as MessageBox,$t as MessageContent,zt as MessageInfoBox,Vt as MessageReadObserver,Kt as MessageRow,Yt as MessageSkeleton,Ht as MessageText,Jt as NextMessagesObserver,te as SYSTEM_ID,tn as SendingMessageBox,en as SendingMessageContent,Zt as SendingMessageInfoBox,Xt as SendingMessageText,sn as SystemMessageBox,an as SystemMessageRow,Kn as ThreadActions,$n as ThreadContext,Yn as ThreadPanel,me as __accountApi,ue as __baseApi,Ce as __chatApi,ze as __chatListApi,Ye as __chatMemberApi,et as __chatMessageApi,de as __settings,ct as __threadApi,ft as __threadMessageApi,ie as calcThreadListUnreadCount,se as calcThreadUnreadCount,ne as chatId,Mt as chatifyApi,P as color,K as customize,jt as defaultLocalizer,nn as formatSystemMessage,ae as parseThreadMessageId,pe as unsubscribe,Je as useAddChatMemberMutation,Me as useAddChatMutation,X as useChatContext,On as useChatGroupContext,$e as useChatListItem,Qt as useConversation,z as useCustomize,H as useCustomizeContext,tt as useFetchNextChatMessageListMutation,vt as useFetchNextThreadMessageListMutation,ge as useGetAccountListQuery,Ke as useGetChatListQuery,nt as useGetChatMessageListQuery,it as useGetChatMessageReadQueueQuery,we as useGetChatQuery,yt as useGetThreadMessageListQuery,wt as useGetThreadMessageReadQueueQuery,ut as useGetThreadQuery,dt as useGetWatchThreadListQuery,We as useLazyGetChatListQuery,rt as useLazyGetChatMessageListQuery,xe as useLazyGetChatQuery,pt as useLazyGetThreadMessageListQuery,ht as useLazyGetThreadQuery,lt as useLazyGetWatchThreadListQuery,kt as useLocalizer,at as useReadChatMessageMutation,bt as useReadThreadMessageMutation,Xe as useRemoveChatMemberMutation,st as useSendChatMessageMutation,Ct as useSendThreadMessageMutation,zn as useThreadContext,ot as useUnreadThreadMessageCount,Ie as useUpdateChatNameMutation,mt as useWatchThreadMutation};
|
|
11
|
-
//# sourceMappingURL=index.js.map
|