@webinex/chatify 2.0.0-alpha13 → 2.0.0-alpha14
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/{Chatify-CwAfN1wu.js → Chatify-CP2jgo8d.js} +191 -118
- package/dist/Chatify-CP2jgo8d.js.map +1 -0
- package/dist/Chatify.css +28 -0
- package/dist/audit.js +3 -2
- package/dist/audit.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/audit/index.d.ts +17 -15
- package/dist/types/ui/Chat/ChatContext.d.ts +2 -0
- package/dist/types/ui/Chat/ChatPanel.d.ts +7 -0
- package/dist/types/ui/Chat/ChatView.d.ts +4 -2
- package/dist/types/ui/ChatGroup/ChatGroupContext.d.ts +4 -1
- package/dist/types/ui/ChatGroup/ChatGroupPanel.d.ts +21 -2
- package/dist/types/ui/Conversation/Conversation.d.ts +1 -0
- package/dist/types/ui/Conversation/ConversationContext.d.ts +1 -0
- package/dist/types/ui/Conversation/ConversationHeader.d.ts +4 -1
- package/dist/types/ui/localizer.d.ts +4 -1
- package/dist/types/ui/useCompact.d.ts +4 -0
- package/package.json +81 -81
- package/src/audit/AuditChatList.tsx +25 -25
- package/src/audit/AuditConversationPanel.tsx +49 -48
- package/src/audit/AuditPanel.tsx +76 -76
- package/src/audit/AuditPanelCustomizeValue.ts +11 -11
- package/src/audit/AuditSearch.tsx +89 -89
- package/src/audit/AuditSearchValue.tsx +42 -42
- package/src/audit/auditApi.tsx +113 -113
- package/src/audit/index.d.ts +18 -18
- package/src/audit/index.tsx +28 -28
- package/src/audit/styles.scss +72 -72
- package/src/core/api/api.ts +675 -675
- package/src/core/api/baseApi.ts +38 -38
- package/src/core/api/index.ts +1 -1
- package/src/core/client.ts +298 -298
- package/src/core/constants.ts +1 -1
- package/src/core/debounce.ts +90 -90
- package/src/core/index.ts +4 -4
- package/src/core/types.tsx +182 -182
- package/src/index.ts +2 -2
- package/src/styles/aside.scss +34 -26
- package/src/styles/chat-list.scss +138 -138
- package/src/styles/chat.scss +11 -11
- package/src/styles/conversation.scss +199 -200
- package/src/styles/index.scss +227 -220
- package/src/styles/input.scss +148 -148
- package/src/styles/keyframes.scss +14 -14
- package/src/styles/members.scss +30 -13
- package/src/styles/mixins.scss +38 -25
- package/src/styles/variables.scss +13 -13
- package/src/ui/Chat/ChatContext.tsx +32 -30
- package/src/ui/Chat/ChatEditableHeaderName.tsx +63 -63
- package/src/ui/Chat/ChatHeaderActions.tsx +19 -19
- package/src/ui/Chat/ChatPanel.tsx +46 -30
- package/src/ui/Chat/ChatView.tsx +122 -115
- package/src/ui/Chat/Members/ChatMembersButton.tsx +9 -9
- package/src/ui/Chat/Members/ChatMembersPanel.tsx +128 -112
- package/src/ui/Chat/Members/ChatMembersPreview.tsx +25 -25
- package/src/ui/Chat/Members/index.ts +13 -13
- package/src/ui/Chat/index.ts +6 -6
- package/src/ui/ChatGroup/AutoReply/AutoReplyButton.tsx +21 -21
- package/src/ui/ChatGroup/AutoReply/AutoReplyForm.tsx +50 -50
- package/src/ui/ChatGroup/AutoReply/AutoReplyPanel.tsx +94 -94
- package/src/ui/ChatGroup/AutoReply/AutoReplyPeriodInput.tsx +22 -22
- package/src/ui/ChatGroup/AutoReply/AutoReplyTextInput.tsx +22 -22
- package/src/ui/ChatGroup/AutoReply/index.ts +19 -19
- package/src/ui/ChatGroup/ChatGroupContext.tsx +63 -61
- package/src/ui/ChatGroup/ChatGroupPanel.tsx +110 -75
- package/src/ui/ChatGroup/Create/CreateChatButton.tsx +15 -15
- package/src/ui/ChatGroup/Create/CreateChatForm.tsx +36 -36
- package/src/ui/ChatGroup/Create/CreateChatMemberInput.tsx +65 -65
- package/src/ui/ChatGroup/Create/CreateChatNameInput.tsx +25 -25
- package/src/ui/ChatGroup/Create/CreateChatPanel.tsx +45 -45
- package/src/ui/ChatGroup/Create/index.ts +19 -19
- package/src/ui/ChatGroup/Layout/ChatGroupActions.tsx +15 -15
- package/src/ui/ChatGroup/Layout/ChatGroupAside.tsx +12 -12
- package/src/ui/ChatGroup/Layout/ChatGroupBody.tsx +17 -10
- package/src/ui/ChatGroup/Layout/ChatGroupFooter.tsx +3 -3
- package/src/ui/ChatGroup/Layout/ChatGroupHeader.tsx +5 -5
- package/src/ui/ChatGroup/Layout/ChatGroupMain.tsx +21 -19
- package/src/ui/ChatGroup/Layout/index.ts +22 -22
- package/src/ui/ChatGroup/List/ChatListPanel.tsx +28 -28
- package/src/ui/ChatGroup/List/index.ts +8 -8
- package/src/ui/ChatGroup/index.ts +6 -6
- package/src/ui/Chatify.tsx +15 -15
- package/src/ui/Conversation/Conversation.tsx +96 -92
- package/src/ui/Conversation/ConversationActions.tsx +12 -12
- package/src/ui/Conversation/ConversationBody.tsx +28 -28
- package/src/ui/Conversation/ConversationContext.ts +31 -30
- package/src/ui/Conversation/ConversationHeader.tsx +35 -19
- package/src/ui/Conversation/ConversationName.tsx +7 -7
- package/src/ui/Conversation/InputBox/InputBox.tsx +126 -126
- package/src/ui/Conversation/InputBox/InputBoxFile.tsx +38 -38
- package/src/ui/Conversation/InputBox/InputBoxFileList.tsx +21 -21
- package/src/ui/Conversation/InputBox/InputFilesBox.tsx +78 -78
- package/src/ui/Conversation/InputBox/InputSubmitButtonBox.tsx +26 -26
- package/src/ui/Conversation/InputBox/InputTextBox.tsx +63 -61
- package/src/ui/Conversation/InputBox/index.ts +23 -23
- package/src/ui/Conversation/Message/MessageAuthor.tsx +13 -13
- package/src/ui/Conversation/Message/MessageBox.tsx +20 -20
- package/src/ui/Conversation/Message/MessageContent.tsx +15 -15
- package/src/ui/Conversation/Message/MessageFile.tsx +54 -54
- package/src/ui/Conversation/Message/MessageFileList.tsx +14 -14
- package/src/ui/Conversation/Message/MessageInfoBox.tsx +28 -28
- package/src/ui/Conversation/Message/MessageRow.tsx +28 -28
- package/src/ui/Conversation/Message/MessageText.tsx +7 -7
- package/src/ui/Conversation/Message/index.ts +28 -28
- package/src/ui/Conversation/NextObserver/NextMessagesObserver.tsx +47 -47
- package/src/ui/Conversation/NextObserver/index.ts +1 -1
- package/src/ui/Conversation/ReadObserver/MessageReadObserver.tsx +49 -49
- package/src/ui/Conversation/ReadObserver/index.ts +1 -1
- package/src/ui/Conversation/SendingMessage/SendingMessageBox.tsx +16 -16
- package/src/ui/Conversation/SendingMessage/SendingMessageContent.tsx +13 -13
- package/src/ui/Conversation/SendingMessage/SendingMessageInfoBox.tsx +13 -13
- package/src/ui/Conversation/SendingMessage/SendingMessageText.tsx +7 -7
- package/src/ui/Conversation/SendingMessage/index.ts +16 -16
- package/src/ui/Conversation/SystemMessage/SystemMessageBox.tsx +20 -20
- package/src/ui/Conversation/SystemMessage/SystemMessageRow.tsx +28 -28
- package/src/ui/Conversation/SystemMessage/index.ts +10 -10
- package/src/ui/Conversation/index.ts +13 -13
- package/src/ui/Thread/ThreadActions.tsx +22 -22
- package/src/ui/Thread/ThreadContext.ts +13 -13
- package/src/ui/Thread/ThreadPanel.tsx +128 -127
- package/src/ui/Thread/index.tsx +3 -3
- package/src/ui/color.ts +20 -20
- package/src/ui/common/Avatar.tsx +20 -20
- package/src/ui/common/ChatList/ChatList.tsx +83 -84
- package/src/ui/common/ChatList/ChatListItemAvatar.tsx +22 -22
- package/src/ui/common/ChatList/ChatListItemBox.tsx +32 -32
- package/src/ui/common/ChatList/ChatListItemLastMessage.tsx +15 -15
- package/src/ui/common/ChatList/ChatListItemLastMessageAuthor.tsx +15 -15
- package/src/ui/common/ChatList/ChatListItemLastMessageContent.tsx +21 -21
- package/src/ui/common/ChatList/ChatListItemLastMessageSentAt.tsx +22 -22
- package/src/ui/common/ChatList/ChatListItemName.tsx +8 -8
- package/src/ui/common/ChatList/ChatListItemUnreadCount.tsx +12 -12
- package/src/ui/common/ChatList/ChatListValue.ts +9 -9
- package/src/ui/common/ChatList/index.ts +32 -32
- package/src/ui/common/Icon.tsx +48 -48
- package/src/ui/common/MessageSkeleton.tsx +20 -20
- package/src/ui/common/index.ts +14 -14
- package/src/ui/customize.tsx +51 -51
- package/src/ui/index.ts +11 -11
- package/src/ui/localizer.tsx +148 -137
- package/src/ui/useCompact.tsx +32 -0
- package/src/ui/useFormatter.tsx +17 -17
- package/dist/Chatify-CwAfN1wu.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from './InputBox';
|
|
2
|
-
export * from './Message';
|
|
3
|
-
export * from './NextObserver';
|
|
4
|
-
export * from './ReadObserver';
|
|
5
|
-
export * from './SendingMessage';
|
|
6
|
-
export * from './SystemMessage';
|
|
7
|
-
|
|
8
|
-
export * from './ConversationActions';
|
|
9
|
-
export * from './ConversationBody';
|
|
10
|
-
export * from './ConversationHeader';
|
|
11
|
-
export * from './ConversationName';
|
|
12
|
-
export * from './ConversationContext';
|
|
13
|
-
export * from './Conversation';
|
|
1
|
+
export * from './InputBox';
|
|
2
|
+
export * from './Message';
|
|
3
|
+
export * from './NextObserver';
|
|
4
|
+
export * from './ReadObserver';
|
|
5
|
+
export * from './SendingMessage';
|
|
6
|
+
export * from './SystemMessage';
|
|
7
|
+
|
|
8
|
+
export * from './ConversationActions';
|
|
9
|
+
export * from './ConversationBody';
|
|
10
|
+
export * from './ConversationHeader';
|
|
11
|
+
export * from './ConversationName';
|
|
12
|
+
export * from './ConversationContext';
|
|
13
|
+
export * from './Conversation';
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Button, Tooltip } from 'antd';
|
|
2
|
-
import { customize } from '../customize';
|
|
3
|
-
import { useThreadContext } from './ThreadContext';
|
|
4
|
-
import { Icon } from '../common/Icon';
|
|
5
|
-
|
|
6
|
-
export const ThreadActions = customize('ThreadActions', () => {
|
|
7
|
-
const { watch, onWatch } = useThreadContext();
|
|
8
|
-
|
|
9
|
-
if (!watch) {
|
|
10
|
-
return (
|
|
11
|
-
<Tooltip title="Watch thread">
|
|
12
|
-
<Button type="link" icon={<Icon type="watch" />} onClick={() => onWatch(true)} />
|
|
13
|
-
</Tooltip>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<Tooltip title="Unwatch thread">
|
|
19
|
-
<Button type="link" icon={<Icon type="unwatch" />} onClick={() => onWatch(false)} />
|
|
20
|
-
</Tooltip>
|
|
21
|
-
);
|
|
22
|
-
});
|
|
1
|
+
import { Button, Tooltip } from 'antd';
|
|
2
|
+
import { customize } from '../customize';
|
|
3
|
+
import { useThreadContext } from './ThreadContext';
|
|
4
|
+
import { Icon } from '../common/Icon';
|
|
5
|
+
|
|
6
|
+
export const ThreadActions = customize('ThreadActions', () => {
|
|
7
|
+
const { watch, onWatch } = useThreadContext();
|
|
8
|
+
|
|
9
|
+
if (!watch) {
|
|
10
|
+
return (
|
|
11
|
+
<Tooltip title="Watch thread">
|
|
12
|
+
<Button type="link" icon={<Icon type="watch" />} onClick={() => onWatch(true)} />
|
|
13
|
+
</Tooltip>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Tooltip title="Unwatch thread">
|
|
19
|
+
<Button type="link" icon={<Icon type="unwatch" />} onClick={() => onWatch(false)} />
|
|
20
|
+
</Tooltip>
|
|
21
|
+
);
|
|
22
|
+
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export interface ThreadContextValue {
|
|
4
|
-
id: string;
|
|
5
|
-
watch: boolean;
|
|
6
|
-
onWatch: (value: boolean) => void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const ThreadContext = React.createContext<ThreadContextValue>(null!);
|
|
10
|
-
|
|
11
|
-
export function useThreadContext() {
|
|
12
|
-
return React.useContext(ThreadContext);
|
|
13
|
-
}
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export interface ThreadContextValue {
|
|
4
|
+
id: string;
|
|
5
|
+
watch: boolean;
|
|
6
|
+
onWatch: (value: boolean) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const ThreadContext = React.createContext<ThreadContextValue>(null!);
|
|
10
|
+
|
|
11
|
+
export function useThreadContext() {
|
|
12
|
+
return React.useContext(ThreadContext);
|
|
13
|
+
}
|
|
@@ -1,127 +1,128 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
|
-
import { MessageBody, chatifyApi, parseThreadMessageId } from '../../core';
|
|
3
|
-
import { Conversation, ConversationCustomizeValue, ConversationProps } from '../Conversation';
|
|
4
|
-
import { ThreadContext, ThreadContextValue } from './ThreadContext';
|
|
5
|
-
import { Localizer, LocalizerContext, defaultLocalizer } from '../localizer';
|
|
6
|
-
import { CustomizeContext } from '../customize';
|
|
7
|
-
import { ThreadActions } from './ThreadActions';
|
|
8
|
-
import { CommonCustomizeValue } from '../common';
|
|
9
|
-
|
|
10
|
-
export interface ThreadCustomizeValue extends ConversationCustomizeValue, CommonCustomizeValue {
|
|
11
|
-
ThreadActions?: typeof ThreadActions.Component | null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface ThreadPanelProps {
|
|
15
|
-
threadId: string;
|
|
16
|
-
className?: string;
|
|
17
|
-
customize?: ThreadCustomizeValue;
|
|
18
|
-
localizer?: Localizer;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function usePanelState(props: ThreadPanelProps) {
|
|
22
|
-
const { threadId } = props;
|
|
23
|
-
const { data: thread } = chatifyApi.useGetThreadQuery({ id: threadId });
|
|
24
|
-
const { data: messageList } = chatifyApi.useGetThreadMessageListQuery({ threadId });
|
|
25
|
-
const { id, name, archive, lastReadMessageId, watch } = thread ?? {};
|
|
26
|
-
const { messages, hasMore } = messageList ?? {};
|
|
27
|
-
|
|
28
|
-
const [read] = chatifyApi.useReadThreadMessageMutation();
|
|
29
|
-
const onRead = useCallback((id: string) => read({ id }), [read]);
|
|
30
|
-
|
|
31
|
-
const [fetchNext, { isLoading: isFetchNextLoading }] = chatifyApi.useFetchNextThreadMessageListMutation();
|
|
32
|
-
const onNext = useCallback(() => fetchNext({ threadId }), [fetchNext, threadId]);
|
|
33
|
-
|
|
34
|
-
const [send] = chatifyApi.useSendThreadMessageMutation();
|
|
35
|
-
const onSend = useCallback(
|
|
36
|
-
(message: MessageBody) => send({ body: message, threadId }).unwrap(),
|
|
37
|
-
[threadId, send],
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const { data: readQueue } = chatifyApi.useGetThreadMessageReadQueueQuery();
|
|
41
|
-
|
|
42
|
-
const conversation = useMemo(() => {
|
|
43
|
-
if (!id) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const result: ConversationProps = {
|
|
48
|
-
value: { id: id!, name: name!, active: !archive, lastReadMessageId: lastReadMessageId ?? null },
|
|
49
|
-
messages,
|
|
50
|
-
hasMore,
|
|
51
|
-
onNext,
|
|
52
|
-
nextLoading: isFetchNextLoading,
|
|
53
|
-
onRead,
|
|
54
|
-
onSend,
|
|
55
|
-
noReadTracking: !watch,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
1
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
|
+
import { MessageBody, chatifyApi, parseThreadMessageId } from '../../core';
|
|
3
|
+
import { Conversation, ConversationCustomizeValue, ConversationProps } from '../Conversation';
|
|
4
|
+
import { ThreadContext, ThreadContextValue } from './ThreadContext';
|
|
5
|
+
import { Localizer, LocalizerContext, defaultLocalizer } from '../localizer';
|
|
6
|
+
import { CustomizeContext } from '../customize';
|
|
7
|
+
import { ThreadActions } from './ThreadActions';
|
|
8
|
+
import { CommonCustomizeValue } from '../common';
|
|
9
|
+
|
|
10
|
+
export interface ThreadCustomizeValue extends ConversationCustomizeValue, CommonCustomizeValue {
|
|
11
|
+
ThreadActions?: typeof ThreadActions.Component | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ThreadPanelProps {
|
|
15
|
+
threadId: string;
|
|
16
|
+
className?: string;
|
|
17
|
+
customize?: ThreadCustomizeValue;
|
|
18
|
+
localizer?: Localizer;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function usePanelState(props: ThreadPanelProps) {
|
|
22
|
+
const { threadId } = props;
|
|
23
|
+
const { data: thread } = chatifyApi.useGetThreadQuery({ id: threadId });
|
|
24
|
+
const { data: messageList } = chatifyApi.useGetThreadMessageListQuery({ threadId });
|
|
25
|
+
const { id, name, archive, lastReadMessageId, watch } = thread ?? {};
|
|
26
|
+
const { messages, hasMore } = messageList ?? {};
|
|
27
|
+
|
|
28
|
+
const [read] = chatifyApi.useReadThreadMessageMutation();
|
|
29
|
+
const onRead = useCallback((id: string) => read({ id }), [read]);
|
|
30
|
+
|
|
31
|
+
const [fetchNext, { isLoading: isFetchNextLoading }] = chatifyApi.useFetchNextThreadMessageListMutation();
|
|
32
|
+
const onNext = useCallback(() => fetchNext({ threadId }), [fetchNext, threadId]);
|
|
33
|
+
|
|
34
|
+
const [send] = chatifyApi.useSendThreadMessageMutation();
|
|
35
|
+
const onSend = useCallback(
|
|
36
|
+
(message: MessageBody) => send({ body: message, threadId }).unwrap(),
|
|
37
|
+
[threadId, send],
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const { data: readQueue } = chatifyApi.useGetThreadMessageReadQueueQuery();
|
|
41
|
+
|
|
42
|
+
const conversation = useMemo(() => {
|
|
43
|
+
if (!id) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const result: ConversationProps = {
|
|
48
|
+
value: { id: id!, name: name!, active: !archive, lastReadMessageId: lastReadMessageId ?? null },
|
|
49
|
+
messages,
|
|
50
|
+
hasMore,
|
|
51
|
+
onNext,
|
|
52
|
+
nextLoading: isFetchNextLoading,
|
|
53
|
+
onRead,
|
|
54
|
+
onSend,
|
|
55
|
+
noReadTracking: !watch,
|
|
56
|
+
compact: false,
|
|
57
|
+
isReading: (id: string) =>
|
|
58
|
+
readQueue!.some(
|
|
59
|
+
(unit) => parseThreadMessageId(unit.value)[0] === parseThreadMessageId(id)[0] && id <= unit.value,
|
|
60
|
+
),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return result;
|
|
64
|
+
}, [
|
|
65
|
+
onNext,
|
|
66
|
+
onRead,
|
|
67
|
+
onSend,
|
|
68
|
+
isFetchNextLoading,
|
|
69
|
+
id,
|
|
70
|
+
name,
|
|
71
|
+
archive,
|
|
72
|
+
messages,
|
|
73
|
+
hasMore,
|
|
74
|
+
lastReadMessageId,
|
|
75
|
+
readQueue,
|
|
76
|
+
watch,
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
const [watchThread] = chatifyApi.useWatchThreadMutation();
|
|
80
|
+
|
|
81
|
+
const threadContext = useMemo<ThreadContextValue | null>(
|
|
82
|
+
() =>
|
|
83
|
+
thread
|
|
84
|
+
? {
|
|
85
|
+
id: thread.id,
|
|
86
|
+
watch: thread.watch,
|
|
87
|
+
onWatch: (value) => watchThread({ id: thread.id, watch: value }).unwrap(),
|
|
88
|
+
}
|
|
89
|
+
: null,
|
|
90
|
+
[thread, watchThread],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return [conversation, threadContext] as const;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const DEFAULT_CUSTOMIZE: ThreadCustomizeValue = {
|
|
97
|
+
ConversationActions: () => <ThreadActions />,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export function ThreadPanel(props: ThreadPanelProps) {
|
|
101
|
+
const { threadId, customize, localizer = defaultLocalizer, className = '' } = props;
|
|
102
|
+
const [conversation, threadContext] = usePanelState(props);
|
|
103
|
+
const customizeMergeValue = useMemo(() => ({ ...DEFAULT_CUSTOMIZE, ...customize }), [customize]);
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
chatifyApi.settings.client.connectToThread(threadId);
|
|
107
|
+
|
|
108
|
+
return () => {
|
|
109
|
+
chatifyApi.settings.client.disconnectFromThread(threadId);
|
|
110
|
+
};
|
|
111
|
+
}, [threadId]);
|
|
112
|
+
|
|
113
|
+
if (!conversation || !threadContext) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<LocalizerContext.Provider value={localizer}>
|
|
119
|
+
<ThreadContext.Provider value={threadContext}>
|
|
120
|
+
<CustomizeContext.Provider value={customizeMergeValue as any}>
|
|
121
|
+
<div className={`wxchtf-chatify wxchtf-thread ${className}`}>
|
|
122
|
+
{conversation && <Conversation {...conversation} />}
|
|
123
|
+
</div>
|
|
124
|
+
</CustomizeContext.Provider>
|
|
125
|
+
</ThreadContext.Provider>
|
|
126
|
+
</LocalizerContext.Provider>
|
|
127
|
+
);
|
|
128
|
+
}
|
package/src/ui/Thread/index.tsx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './ThreadActions';
|
|
2
|
-
export * from './ThreadPanel';
|
|
3
|
-
export * from './ThreadContext';
|
|
1
|
+
export * from './ThreadActions';
|
|
2
|
+
export * from './ThreadPanel';
|
|
3
|
+
export * from './ThreadContext';
|
package/src/ui/color.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
interface ColorOptions {
|
|
2
|
-
saturation?: number;
|
|
3
|
-
lightness?: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const DEFAULT_COLOR_OPTIONS: ColorOptions = {
|
|
7
|
-
saturation: 100,
|
|
8
|
-
lightness: 75,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export function color(value: string, options: ColorOptions = {}) {
|
|
12
|
-
options = Object.assign({}, DEFAULT_COLOR_OPTIONS, options);
|
|
13
|
-
|
|
14
|
-
let hash = 0;
|
|
15
|
-
for (let i = 0; i < value.length; i++) {
|
|
16
|
-
hash = value.charCodeAt(i) + ((hash << 5) - hash);
|
|
17
|
-
hash = hash & hash;
|
|
18
|
-
}
|
|
19
|
-
return `hsl(${hash % 360}, ${options.saturation}%, ${options.lightness}%)`;
|
|
20
|
-
}
|
|
1
|
+
interface ColorOptions {
|
|
2
|
+
saturation?: number;
|
|
3
|
+
lightness?: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const DEFAULT_COLOR_OPTIONS: ColorOptions = {
|
|
7
|
+
saturation: 100,
|
|
8
|
+
lightness: 75,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function color(value: string, options: ColorOptions = {}) {
|
|
12
|
+
options = Object.assign({}, DEFAULT_COLOR_OPTIONS, options);
|
|
13
|
+
|
|
14
|
+
let hash = 0;
|
|
15
|
+
for (let i = 0; i < value.length; i++) {
|
|
16
|
+
hash = value.charCodeAt(i) + ((hash << 5) - hash);
|
|
17
|
+
hash = hash & hash;
|
|
18
|
+
}
|
|
19
|
+
return `hsl(${hash % 360}, ${options.saturation}%, ${options.lightness}%)`;
|
|
20
|
+
}
|
package/src/ui/common/Avatar.tsx
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { FC, ForwardedRef, forwardRef } from 'react';
|
|
2
|
-
import { Account } from '../../core';
|
|
3
|
-
import { Avatar as AntdAvatar } from 'antd';
|
|
4
|
-
import { customize } from '../customize';
|
|
5
|
-
|
|
6
|
-
export interface AvatarProps {
|
|
7
|
-
account: Account;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const _Avatar: FC<AvatarProps> = forwardRef(
|
|
11
|
-
(props: AvatarProps, forwardRef: ForwardedRef<HTMLSpanElement>) => {
|
|
12
|
-
const { account } = props;
|
|
13
|
-
|
|
14
|
-
return <AntdAvatar ref={forwardRef} src={account.avatar} />;
|
|
15
|
-
},
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
_Avatar.displayName = 'Avatar';
|
|
19
|
-
|
|
20
|
-
export const Avatar = customize('Avatar', _Avatar);
|
|
1
|
+
import { FC, ForwardedRef, forwardRef } from 'react';
|
|
2
|
+
import { Account } from '../../core';
|
|
3
|
+
import { Avatar as AntdAvatar } from 'antd';
|
|
4
|
+
import { customize } from '../customize';
|
|
5
|
+
|
|
6
|
+
export interface AvatarProps {
|
|
7
|
+
account: Account;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const _Avatar: FC<AvatarProps> = forwardRef(
|
|
11
|
+
(props: AvatarProps, forwardRef: ForwardedRef<HTMLSpanElement>) => {
|
|
12
|
+
const { account } = props;
|
|
13
|
+
|
|
14
|
+
return <AntdAvatar ref={forwardRef} src={account.avatar} />;
|
|
15
|
+
},
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
_Avatar.displayName = 'Avatar';
|
|
19
|
+
|
|
20
|
+
export const Avatar = customize('Avatar', _Avatar);
|
|
@@ -1,84 +1,83 @@
|
|
|
1
|
-
import { Menu, MenuProps } from 'antd';
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
|
-
import { ChatListItemBox } from './ChatListItemBox';
|
|
4
|
-
import { customize } from '../../customize';
|
|
5
|
-
import { ChatListValue } from './ChatListValue';
|
|
6
|
-
import { useLocalizer } from '../../localizer';
|
|
7
|
-
import { messageSequencePart } from '../../../core';
|
|
8
|
-
|
|
9
|
-
export interface ChatListProps {
|
|
10
|
-
className?: string;
|
|
11
|
-
items: ChatListValue[];
|
|
12
|
-
selected: string | null;
|
|
13
|
-
onSelect?: (id: string) => void;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* If true, do not show read status.
|
|
17
|
-
*/
|
|
18
|
-
noRead?: boolean;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* If set, shows a message at the bottom indicating that only the top N chats are shown.
|
|
22
|
-
*/
|
|
23
|
-
top?: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function useOnSelect(props: ChatListProps) {
|
|
27
|
-
const { onSelect } = props;
|
|
28
|
-
|
|
29
|
-
return useMemo(
|
|
30
|
-
() =>
|
|
31
|
-
onSelect
|
|
32
|
-
? (info: Parameters<NonNullable<MenuProps['onSelect']>>[0]) => onSelect(info.key as string)
|
|
33
|
-
: undefined,
|
|
34
|
-
[onSelect],
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function useMenuItems(props: ChatListProps) {
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
1
|
+
import { Menu, MenuProps } from 'antd';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { ChatListItemBox } from './ChatListItemBox';
|
|
4
|
+
import { customize } from '../../customize';
|
|
5
|
+
import { ChatListValue } from './ChatListValue';
|
|
6
|
+
import { useLocalizer } from '../../localizer';
|
|
7
|
+
import { messageSequencePart } from '../../../core';
|
|
8
|
+
|
|
9
|
+
export interface ChatListProps {
|
|
10
|
+
className?: string;
|
|
11
|
+
items: ChatListValue[];
|
|
12
|
+
selected: string | null;
|
|
13
|
+
onSelect?: (id: string) => void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* If true, do not show read status.
|
|
17
|
+
*/
|
|
18
|
+
noRead?: boolean;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* If set, shows a message at the bottom indicating that only the top N chats are shown.
|
|
22
|
+
*/
|
|
23
|
+
top?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function useOnSelect(props: ChatListProps) {
|
|
27
|
+
const { onSelect } = props;
|
|
28
|
+
|
|
29
|
+
return useMemo(
|
|
30
|
+
() =>
|
|
31
|
+
onSelect
|
|
32
|
+
? (info: Parameters<NonNullable<MenuProps['onSelect']>>[0]) => onSelect(info.key as string)
|
|
33
|
+
: undefined,
|
|
34
|
+
[onSelect],
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function useMenuItems(props: ChatListProps) {
|
|
39
|
+
const { items, noRead, top } = props;
|
|
40
|
+
const localizer = useLocalizer();
|
|
41
|
+
|
|
42
|
+
return useMemo<MenuProps['items']>(() => {
|
|
43
|
+
const result = items
|
|
44
|
+
?.slice()
|
|
45
|
+
.sort(
|
|
46
|
+
(a, b) => -messageSequencePart(a.lastMessage.id).localeCompare(messageSequencePart(b.lastMessage.id)),
|
|
47
|
+
)
|
|
48
|
+
.map((x) => ({ key: x.id, label: <ChatListItemBox chat={x} noRead={noRead} /> }));
|
|
49
|
+
|
|
50
|
+
if (top != null) {
|
|
51
|
+
return [
|
|
52
|
+
...result,
|
|
53
|
+
{
|
|
54
|
+
type: 'item',
|
|
55
|
+
key: 'top',
|
|
56
|
+
disabled: true,
|
|
57
|
+
label: (
|
|
58
|
+
<div style={{ textAlign: 'center', cursor: 'text', fontStyle: 'italic' }}>
|
|
59
|
+
{localizer.chatList.topShown(top)}
|
|
60
|
+
</div>
|
|
61
|
+
),
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return result;
|
|
67
|
+
}, [items, noRead, top, localizer]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const ChatList = customize('ChatList', (props: ChatListProps) => {
|
|
71
|
+
const { selected: selectedChatId } = props;
|
|
72
|
+
const selected = useMemo(() => (selectedChatId ? [selectedChatId] : []), [selectedChatId]);
|
|
73
|
+
const onSelect = useOnSelect(props);
|
|
74
|
+
const items = useMenuItems(props);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
{items && (
|
|
79
|
+
<Menu className="wxchtf-chat-list" selectedKeys={selected} onSelect={onSelect} items={items} />
|
|
80
|
+
)}
|
|
81
|
+
</>
|
|
82
|
+
);
|
|
83
|
+
});
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { color } from '../../color';
|
|
2
|
-
import { Icon } from '../../common/Icon';
|
|
3
|
-
import { customize } from '../../customize';
|
|
4
|
-
import type { ChatListItemBoxProps } from './ChatListItemBox';
|
|
5
|
-
|
|
6
|
-
export const ChatListItemAvatar = customize('ChatListItemAvatar', (props: ChatListItemBoxProps) => {
|
|
7
|
-
const { id } = props.chat;
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
<div
|
|
11
|
-
className="wxchtf-chat-avatar"
|
|
12
|
-
style={
|
|
13
|
-
{
|
|
14
|
-
'--background-color': color(id, { lightness: 90 }),
|
|
15
|
-
'--color': color(id, { saturation: 60, lightness: 65 }),
|
|
16
|
-
} as any
|
|
17
|
-
}
|
|
18
|
-
>
|
|
19
|
-
<Icon type="chat" />
|
|
20
|
-
</div>
|
|
21
|
-
);
|
|
22
|
-
});
|
|
1
|
+
import { color } from '../../color';
|
|
2
|
+
import { Icon } from '../../common/Icon';
|
|
3
|
+
import { customize } from '../../customize';
|
|
4
|
+
import type { ChatListItemBoxProps } from './ChatListItemBox';
|
|
5
|
+
|
|
6
|
+
export const ChatListItemAvatar = customize('ChatListItemAvatar', (props: ChatListItemBoxProps) => {
|
|
7
|
+
const { id } = props.chat;
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<div
|
|
11
|
+
className="wxchtf-chat-avatar"
|
|
12
|
+
style={
|
|
13
|
+
{
|
|
14
|
+
'--background-color': color(id, { lightness: 90 }),
|
|
15
|
+
'--color': color(id, { saturation: 60, lightness: 65 }),
|
|
16
|
+
} as any
|
|
17
|
+
}
|
|
18
|
+
>
|
|
19
|
+
<Icon type="chat" />
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
});
|