@webinex/chatify 2.0.0-alpha12 → 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.
Files changed (144) hide show
  1. package/dist/{Chatify-CwAfN1wu.js → Chatify-CP2jgo8d.js} +191 -118
  2. package/dist/Chatify-CP2jgo8d.js.map +1 -0
  3. package/dist/Chatify.css +28 -0
  4. package/dist/audit.js +3 -2
  5. package/dist/audit.js.map +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/types/audit/index.d.ts +17 -15
  8. package/dist/types/core/api/api.d.ts +146 -0
  9. package/dist/types/ui/Chat/ChatContext.d.ts +2 -0
  10. package/dist/types/ui/Chat/ChatPanel.d.ts +7 -0
  11. package/dist/types/ui/Chat/ChatView.d.ts +4 -2
  12. package/dist/types/ui/ChatGroup/ChatGroupContext.d.ts +4 -1
  13. package/dist/types/ui/ChatGroup/ChatGroupPanel.d.ts +21 -2
  14. package/dist/types/ui/Conversation/Conversation.d.ts +1 -0
  15. package/dist/types/ui/Conversation/ConversationContext.d.ts +1 -0
  16. package/dist/types/ui/Conversation/ConversationHeader.d.ts +4 -1
  17. package/dist/types/ui/localizer.d.ts +4 -1
  18. package/dist/types/ui/useCompact.d.ts +4 -0
  19. package/package.json +81 -81
  20. package/src/audit/AuditChatList.tsx +25 -25
  21. package/src/audit/AuditConversationPanel.tsx +49 -48
  22. package/src/audit/AuditPanel.tsx +76 -76
  23. package/src/audit/AuditPanelCustomizeValue.ts +11 -11
  24. package/src/audit/AuditSearch.tsx +89 -89
  25. package/src/audit/AuditSearchValue.tsx +42 -42
  26. package/src/audit/auditApi.tsx +113 -113
  27. package/src/audit/index.d.ts +18 -18
  28. package/src/audit/index.tsx +28 -28
  29. package/src/audit/styles.scss +72 -72
  30. package/src/core/api/api.ts +675 -669
  31. package/src/core/api/baseApi.ts +38 -38
  32. package/src/core/api/index.ts +1 -1
  33. package/src/core/client.ts +298 -298
  34. package/src/core/constants.ts +1 -1
  35. package/src/core/debounce.ts +90 -90
  36. package/src/core/index.ts +4 -4
  37. package/src/core/types.tsx +182 -182
  38. package/src/index.ts +2 -2
  39. package/src/styles/aside.scss +34 -26
  40. package/src/styles/chat-list.scss +138 -138
  41. package/src/styles/chat.scss +11 -11
  42. package/src/styles/conversation.scss +199 -200
  43. package/src/styles/index.scss +227 -220
  44. package/src/styles/input.scss +148 -148
  45. package/src/styles/keyframes.scss +14 -14
  46. package/src/styles/members.scss +30 -13
  47. package/src/styles/mixins.scss +38 -25
  48. package/src/styles/variables.scss +13 -13
  49. package/src/ui/Chat/ChatContext.tsx +32 -30
  50. package/src/ui/Chat/ChatEditableHeaderName.tsx +63 -63
  51. package/src/ui/Chat/ChatHeaderActions.tsx +19 -19
  52. package/src/ui/Chat/ChatPanel.tsx +46 -30
  53. package/src/ui/Chat/ChatView.tsx +122 -115
  54. package/src/ui/Chat/Members/ChatMembersButton.tsx +9 -9
  55. package/src/ui/Chat/Members/ChatMembersPanel.tsx +128 -112
  56. package/src/ui/Chat/Members/ChatMembersPreview.tsx +25 -25
  57. package/src/ui/Chat/Members/index.ts +13 -13
  58. package/src/ui/Chat/index.ts +6 -6
  59. package/src/ui/ChatGroup/AutoReply/AutoReplyButton.tsx +21 -21
  60. package/src/ui/ChatGroup/AutoReply/AutoReplyForm.tsx +50 -50
  61. package/src/ui/ChatGroup/AutoReply/AutoReplyPanel.tsx +94 -94
  62. package/src/ui/ChatGroup/AutoReply/AutoReplyPeriodInput.tsx +22 -22
  63. package/src/ui/ChatGroup/AutoReply/AutoReplyTextInput.tsx +22 -22
  64. package/src/ui/ChatGroup/AutoReply/index.ts +19 -19
  65. package/src/ui/ChatGroup/ChatGroupContext.tsx +63 -61
  66. package/src/ui/ChatGroup/ChatGroupPanel.tsx +110 -75
  67. package/src/ui/ChatGroup/Create/CreateChatButton.tsx +15 -15
  68. package/src/ui/ChatGroup/Create/CreateChatForm.tsx +36 -36
  69. package/src/ui/ChatGroup/Create/CreateChatMemberInput.tsx +65 -65
  70. package/src/ui/ChatGroup/Create/CreateChatNameInput.tsx +25 -25
  71. package/src/ui/ChatGroup/Create/CreateChatPanel.tsx +45 -45
  72. package/src/ui/ChatGroup/Create/index.ts +19 -19
  73. package/src/ui/ChatGroup/Layout/ChatGroupActions.tsx +15 -15
  74. package/src/ui/ChatGroup/Layout/ChatGroupAside.tsx +12 -12
  75. package/src/ui/ChatGroup/Layout/ChatGroupBody.tsx +17 -10
  76. package/src/ui/ChatGroup/Layout/ChatGroupFooter.tsx +3 -3
  77. package/src/ui/ChatGroup/Layout/ChatGroupHeader.tsx +5 -5
  78. package/src/ui/ChatGroup/Layout/ChatGroupMain.tsx +21 -19
  79. package/src/ui/ChatGroup/Layout/index.ts +22 -22
  80. package/src/ui/ChatGroup/List/ChatListPanel.tsx +28 -28
  81. package/src/ui/ChatGroup/List/index.ts +8 -8
  82. package/src/ui/ChatGroup/index.ts +6 -6
  83. package/src/ui/Chatify.tsx +15 -15
  84. package/src/ui/Conversation/Conversation.tsx +96 -92
  85. package/src/ui/Conversation/ConversationActions.tsx +12 -12
  86. package/src/ui/Conversation/ConversationBody.tsx +28 -28
  87. package/src/ui/Conversation/ConversationContext.ts +31 -30
  88. package/src/ui/Conversation/ConversationHeader.tsx +35 -19
  89. package/src/ui/Conversation/ConversationName.tsx +7 -7
  90. package/src/ui/Conversation/InputBox/InputBox.tsx +126 -126
  91. package/src/ui/Conversation/InputBox/InputBoxFile.tsx +38 -38
  92. package/src/ui/Conversation/InputBox/InputBoxFileList.tsx +21 -21
  93. package/src/ui/Conversation/InputBox/InputFilesBox.tsx +78 -78
  94. package/src/ui/Conversation/InputBox/InputSubmitButtonBox.tsx +26 -26
  95. package/src/ui/Conversation/InputBox/InputTextBox.tsx +63 -61
  96. package/src/ui/Conversation/InputBox/index.ts +23 -23
  97. package/src/ui/Conversation/Message/MessageAuthor.tsx +13 -13
  98. package/src/ui/Conversation/Message/MessageBox.tsx +20 -20
  99. package/src/ui/Conversation/Message/MessageContent.tsx +15 -15
  100. package/src/ui/Conversation/Message/MessageFile.tsx +54 -54
  101. package/src/ui/Conversation/Message/MessageFileList.tsx +14 -14
  102. package/src/ui/Conversation/Message/MessageInfoBox.tsx +28 -28
  103. package/src/ui/Conversation/Message/MessageRow.tsx +28 -28
  104. package/src/ui/Conversation/Message/MessageText.tsx +7 -7
  105. package/src/ui/Conversation/Message/index.ts +28 -28
  106. package/src/ui/Conversation/NextObserver/NextMessagesObserver.tsx +47 -47
  107. package/src/ui/Conversation/NextObserver/index.ts +1 -1
  108. package/src/ui/Conversation/ReadObserver/MessageReadObserver.tsx +49 -49
  109. package/src/ui/Conversation/ReadObserver/index.ts +1 -1
  110. package/src/ui/Conversation/SendingMessage/SendingMessageBox.tsx +16 -16
  111. package/src/ui/Conversation/SendingMessage/SendingMessageContent.tsx +13 -13
  112. package/src/ui/Conversation/SendingMessage/SendingMessageInfoBox.tsx +13 -13
  113. package/src/ui/Conversation/SendingMessage/SendingMessageText.tsx +7 -7
  114. package/src/ui/Conversation/SendingMessage/index.ts +16 -16
  115. package/src/ui/Conversation/SystemMessage/SystemMessageBox.tsx +20 -20
  116. package/src/ui/Conversation/SystemMessage/SystemMessageRow.tsx +28 -28
  117. package/src/ui/Conversation/SystemMessage/index.ts +10 -10
  118. package/src/ui/Conversation/index.ts +13 -13
  119. package/src/ui/Thread/ThreadActions.tsx +22 -22
  120. package/src/ui/Thread/ThreadContext.ts +13 -13
  121. package/src/ui/Thread/ThreadPanel.tsx +128 -127
  122. package/src/ui/Thread/index.tsx +3 -3
  123. package/src/ui/color.ts +20 -20
  124. package/src/ui/common/Avatar.tsx +20 -20
  125. package/src/ui/common/ChatList/ChatList.tsx +83 -84
  126. package/src/ui/common/ChatList/ChatListItemAvatar.tsx +22 -22
  127. package/src/ui/common/ChatList/ChatListItemBox.tsx +32 -32
  128. package/src/ui/common/ChatList/ChatListItemLastMessage.tsx +15 -15
  129. package/src/ui/common/ChatList/ChatListItemLastMessageAuthor.tsx +15 -15
  130. package/src/ui/common/ChatList/ChatListItemLastMessageContent.tsx +21 -21
  131. package/src/ui/common/ChatList/ChatListItemLastMessageSentAt.tsx +22 -22
  132. package/src/ui/common/ChatList/ChatListItemName.tsx +8 -8
  133. package/src/ui/common/ChatList/ChatListItemUnreadCount.tsx +12 -12
  134. package/src/ui/common/ChatList/ChatListValue.ts +9 -9
  135. package/src/ui/common/ChatList/index.ts +32 -32
  136. package/src/ui/common/Icon.tsx +48 -48
  137. package/src/ui/common/MessageSkeleton.tsx +20 -20
  138. package/src/ui/common/index.ts +14 -14
  139. package/src/ui/customize.tsx +51 -51
  140. package/src/ui/index.ts +11 -11
  141. package/src/ui/localizer.tsx +148 -137
  142. package/src/ui/useCompact.tsx +32 -0
  143. package/src/ui/useFormatter.tsx +17 -17
  144. package/dist/Chatify-CwAfN1wu.js.map +0 -1
@@ -1,19 +1,19 @@
1
- import { ChatMembersPreview } from './Members';
2
- import { ChatMembersButton } from './Members';
3
- import { customize } from '../customize';
4
- import { useConversation } from '../Conversation';
5
-
6
- export const ChatHeaderActions = customize('ChatHeaderActions', () => {
7
- const { active } = useConversation();
8
-
9
- if (!active) {
10
- return null;
11
- }
12
-
13
- return (
14
- <div className="wxchtf-chat-members">
15
- <ChatMembersPreview />
16
- <ChatMembersButton />
17
- </div>
18
- );
19
- });
1
+ import { ChatMembersPreview } from './Members';
2
+ import { ChatMembersButton } from './Members';
3
+ import { customize } from '../customize';
4
+ import { useConversation } from '../Conversation';
5
+
6
+ export const ChatHeaderActions = customize('ChatHeaderActions', () => {
7
+ const { active, compact } = useConversation();
8
+
9
+ if (!active) {
10
+ return null;
11
+ }
12
+
13
+ return (
14
+ <div className="wxchtf-chat-members">
15
+ {!compact && <ChatMembersPreview />}
16
+ <ChatMembersButton />
17
+ </div>
18
+ );
19
+ });
@@ -1,30 +1,46 @@
1
- import { CSSProperties } from 'react';
2
- import { Localizer, LocalizerContext, defaultLocalizer } from '../localizer';
3
- import { CustomizeContext } from '../customize';
4
- import { ChatView, ChatViewCustomizeValue } from './ChatView';
5
- import { chatifyApi } from '../../core';
6
-
7
- export interface ChatPanelCustomizeValue extends ChatViewCustomizeValue {}
8
-
9
- export interface ChatPanelProps {
10
- id: string;
11
- className?: string;
12
- style?: CSSProperties;
13
- localizer?: Localizer;
14
- customize?: ChatPanelCustomizeValue;
15
- }
16
-
17
- export function ChatPanel(props: ChatPanelProps) {
18
- const { id, className = '', customize, localizer = defaultLocalizer, style } = props;
19
- const { data: chat } = chatifyApi.useGetChatQuery({ id });
20
-
21
- return (
22
- <div className={`wxchtf-chatify wxchtf-chat-panel ${className}`} style={style}>
23
- <LocalizerContext.Provider value={localizer}>
24
- <CustomizeContext.Provider value={customize as any}>
25
- {chat && <ChatView value={chat} key={id} />}
26
- </CustomizeContext.Provider>
27
- </LocalizerContext.Provider>
28
- </div>
29
- );
30
- }
1
+ import { CSSProperties } from 'react';
2
+ import { Localizer, LocalizerContext, defaultLocalizer } from '../localizer';
3
+ import { CustomizeContext } from '../customize';
4
+ import { ChatView, ChatViewCustomizeValue } from './ChatView';
5
+ import { chatifyApi } from '../../core';
6
+ import { useCompact } from '../useCompact';
7
+
8
+ export interface ChatPanelCustomizeValue extends ChatViewCustomizeValue {}
9
+
10
+ export interface ChatPanelProps {
11
+ id: string;
12
+ className?: string;
13
+ style?: CSSProperties;
14
+ localizer?: Localizer;
15
+ customize?: ChatPanelCustomizeValue;
16
+
17
+ /**
18
+ * If true, the chat panel will be displayed in compact mode.
19
+ * If a number is provided, the chat panel will be displayed in compact mode if its width is less than the provided number of pixels.
20
+ *
21
+ * @default 768
22
+ */
23
+ compact?: boolean | number;
24
+ }
25
+
26
+ export function ChatPanel(props: ChatPanelProps) {
27
+ const { id, className = '', customize, localizer = defaultLocalizer, style, compact: compactProp } = props;
28
+ const { data: chat } = chatifyApi.useGetChatQuery({ id });
29
+ const [ref, compact] = useCompact(compactProp);
30
+
31
+ return (
32
+ <div
33
+ className={['wxchtf-chatify', 'wxchtf-chat-panel', compact && '--compact', className]
34
+ .filter(Boolean)
35
+ .join(' ')}
36
+ style={style}
37
+ ref={ref}
38
+ >
39
+ <LocalizerContext.Provider value={localizer}>
40
+ <CustomizeContext.Provider value={customize as any}>
41
+ {chat && <ChatView value={chat} key={id} compact={compact} />}
42
+ </CustomizeContext.Provider>
43
+ </LocalizerContext.Provider>
44
+ </div>
45
+ );
46
+ }
@@ -1,115 +1,122 @@
1
- import { CustomizeContext, customize, useCustomizeContext } from '../customize';
2
- import { MessageBody, chatId, chatifyApi } from '../../core';
3
- import {
4
- Conversation,
5
- ConversationCustomizeValue,
6
- ConversationProps,
7
- ConversationValue,
8
- } from '../Conversation';
9
- import { useCallback, useMemo } from 'react';
10
- import { ChatEditableHeaderName } from './ChatEditableHeaderName';
11
- import { ChatHeaderActions } from './ChatHeaderActions';
12
- import { ChatMembersCustomizeValue, ChatMembersPanel } from './Members';
13
- import { ChatContext, useChatContext } from './ChatContext';
14
-
15
- export interface ChatProps {
16
- value: ChatValue;
17
- }
18
-
19
- export interface ChatValue extends ConversationValue {}
20
-
21
- export interface ChatViewCustomizeValue extends ConversationCustomizeValue, ChatMembersCustomizeValue {
22
- ChatEditableHeaderName?: typeof ChatEditableHeaderName.Component | null;
23
- ChatHeaderActions?: typeof ChatHeaderActions.Component | null;
24
- ChatView?: typeof ChatView.Component | null;
25
- }
26
-
27
- export const DEFAULT_CHAT_VIEW_CUSTOMIZE_VALUE: ConversationCustomizeValue = {
28
- ConversationName: () => <ChatEditableHeaderName />,
29
- ConversationActions: () => <ChatHeaderActions />,
30
- };
31
-
32
- function useConversation(props: ChatProps) {
33
- const { value: chat } = props;
34
- const { id, name, active, lastReadMessageId } = chat;
35
-
36
- const { data: messageList } = chatifyApi.useGetChatMessageListQuery({ chatId: id });
37
- const { messages, hasMore } = messageList ?? {};
38
-
39
- const [fetchNext, { isLoading: isFetchNextLoading }] = chatifyApi.useFetchNextChatMessageListMutation();
40
- const onNext = useCallback(() => fetchNext({ chatId: id }), [fetchNext, id]);
41
-
42
- const [read] = chatifyApi.useReadChatMessageMutation();
43
- const onRead = useCallback((id: string) => read({ id }), [read]);
44
-
45
- const [send] = chatifyApi.useSendChatMessageMutation();
46
- const onSend = useCallback((message: MessageBody) => send({ ...message, chatId: id }).unwrap(), [id, send]);
47
-
48
- const { data: readQueue } = chatifyApi.useGetChatMessageReadQueueQuery();
49
-
50
- const conversation = useMemo(() => {
51
- if (!id) {
52
- return null;
53
- }
54
-
55
- const result: ConversationProps = {
56
- value: { id: id!, name: name!, active: active!, lastReadMessageId: lastReadMessageId! },
57
- messages,
58
- hasMore,
59
- onNext,
60
- nextLoading: isFetchNextLoading,
61
- onRead,
62
- onSend,
63
- isReading: (id: string) => readQueue!.some((x) => chatId(x.value) === chatId(id) && id <= x.value),
64
- };
65
-
66
- return result;
67
- }, [
68
- onNext,
69
- onRead,
70
- onSend,
71
- isFetchNextLoading,
72
- id,
73
- name,
74
- active,
75
- messages,
76
- hasMore,
77
- lastReadMessageId,
78
- readQueue,
79
- ]);
80
-
81
- return conversation;
82
- }
83
-
84
- function Content(props: ChatProps) {
85
- const conversation = useConversation(props);
86
- const { showMembers } = useChatContext();
87
-
88
- if (!conversation) {
89
- return null;
90
- }
91
-
92
- return (
93
- <div className="wxchtf-chat">
94
- <Conversation {...conversation} />
95
- {showMembers && <ChatMembersPanel />}
96
- </div>
97
- );
98
- }
99
-
100
- export const ChatView = customize('ChatView', (props: ChatProps) => {
101
- const { value } = props;
102
- const customized = useCustomizeContext();
103
- const customize: ChatViewCustomizeValue = useMemo(
104
- () => ({ ...(customized ?? {}), ...DEFAULT_CHAT_VIEW_CUSTOMIZE_VALUE }),
105
- [customized],
106
- );
107
-
108
- return (
109
- <CustomizeContext.Provider value={customize}>
110
- <ChatContext id={value.id}>
111
- <Content value={value} />
112
- </ChatContext>
113
- </CustomizeContext.Provider>
114
- );
115
- });
1
+ import { CustomizeContext, customize, useCustomizeContext } from '../customize';
2
+ import { MessageBody, chatId, chatifyApi } from '../../core';
3
+ import {
4
+ Conversation,
5
+ ConversationCustomizeValue,
6
+ ConversationProps,
7
+ ConversationValue,
8
+ } from '../Conversation';
9
+ import { useCallback, useMemo } from 'react';
10
+ import { ChatEditableHeaderName } from './ChatEditableHeaderName';
11
+ import { ChatHeaderActions } from './ChatHeaderActions';
12
+ import { ChatMembersCustomizeValue, ChatMembersPanel } from './Members';
13
+ import { ChatContext, useChatContext } from './ChatContext';
14
+
15
+ export interface ChatViewProps {
16
+ value: ChatValue;
17
+ compact?: boolean;
18
+ onBackClick?: () => void;
19
+ }
20
+
21
+ export interface ChatValue extends ConversationValue {}
22
+
23
+ export interface ChatViewCustomizeValue extends ConversationCustomizeValue, ChatMembersCustomizeValue {
24
+ ChatEditableHeaderName?: typeof ChatEditableHeaderName.Component | null;
25
+ ChatHeaderActions?: typeof ChatHeaderActions.Component | null;
26
+ ChatView?: typeof ChatView.Component | null;
27
+ }
28
+
29
+ export const DEFAULT_CHAT_VIEW_CUSTOMIZE_VALUE: ConversationCustomizeValue = {
30
+ ConversationName: () => <ChatEditableHeaderName />,
31
+ ConversationActions: () => <ChatHeaderActions />,
32
+ };
33
+
34
+ function useConversation(props: Pick<ChatViewProps, 'value' | 'onBackClick'>) {
35
+ const { value: chat, onBackClick } = props;
36
+ const { compact } = useChatContext();
37
+ const { id, name, active, lastReadMessageId } = chat;
38
+
39
+ const { data: messageList } = chatifyApi.useGetChatMessageListQuery({ chatId: id });
40
+ const { messages, hasMore } = messageList ?? {};
41
+
42
+ const [fetchNext, { isLoading: isFetchNextLoading }] = chatifyApi.useFetchNextChatMessageListMutation();
43
+ const onNext = useCallback(() => fetchNext({ chatId: id }), [fetchNext, id]);
44
+
45
+ const [read] = chatifyApi.useReadChatMessageMutation();
46
+ const onRead = useCallback((id: string) => read({ id }), [read]);
47
+
48
+ const [send] = chatifyApi.useSendChatMessageMutation();
49
+ const onSend = useCallback((message: MessageBody) => send({ ...message, chatId: id }).unwrap(), [id, send]);
50
+
51
+ const { data: readQueue } = chatifyApi.useGetChatMessageReadQueueQuery();
52
+
53
+ const conversation = useMemo(() => {
54
+ if (!id) {
55
+ return null;
56
+ }
57
+
58
+ const result: ConversationProps = {
59
+ value: { id: id!, name: name!, active: active!, lastReadMessageId: lastReadMessageId! },
60
+ messages,
61
+ hasMore,
62
+ onNext,
63
+ nextLoading: isFetchNextLoading,
64
+ onRead,
65
+ onSend,
66
+ isReading: (id: string) => readQueue!.some((x) => chatId(x.value) === chatId(id) && id <= x.value),
67
+ compact: compact ?? false,
68
+ onBackClick,
69
+ };
70
+
71
+ return result;
72
+ }, [
73
+ onNext,
74
+ onRead,
75
+ onSend,
76
+ isFetchNextLoading,
77
+ id,
78
+ name,
79
+ active,
80
+ messages,
81
+ hasMore,
82
+ lastReadMessageId,
83
+ readQueue,
84
+ compact,
85
+ onBackClick,
86
+ ]);
87
+
88
+ return conversation;
89
+ }
90
+
91
+ function Content(props: Pick<ChatViewProps, 'value' | 'onBackClick'>) {
92
+ const conversation = useConversation(props);
93
+ const { compact, showMembers } = useChatContext();
94
+
95
+ if (!conversation) {
96
+ return null;
97
+ }
98
+
99
+ return (
100
+ <div className="wxchtf-chat">
101
+ {(!compact || !showMembers) && <Conversation {...conversation} />}
102
+ {showMembers && <ChatMembersPanel />}
103
+ </div>
104
+ );
105
+ }
106
+
107
+ export const ChatView = customize('ChatView', (props: ChatViewProps) => {
108
+ const { value, compact, onBackClick } = props;
109
+ const customized = useCustomizeContext();
110
+ const customize: ChatViewCustomizeValue = useMemo(
111
+ () => ({ ...(customized ?? {}), ...DEFAULT_CHAT_VIEW_CUSTOMIZE_VALUE }),
112
+ [customized],
113
+ );
114
+
115
+ return (
116
+ <CustomizeContext.Provider value={customize}>
117
+ <ChatContext id={value.id} compact={compact ?? false}>
118
+ <Content value={value} onBackClick={onBackClick} />
119
+ </ChatContext>
120
+ </CustomizeContext.Provider>
121
+ );
122
+ });
@@ -1,9 +1,9 @@
1
- import { Button } from 'antd';
2
- import { customize } from '../../customize';
3
- import { Icon } from '../../common/Icon';
4
- import { useChatContext } from '../ChatContext';
5
-
6
- export const ChatMembersButton = customize('ChatMembersButton', () => {
7
- const { showMembers, onShowMembers } = useChatContext();
8
- return <Button onClick={() => onShowMembers(!showMembers)} type="link" icon={<Icon type="members" />} />;
9
- });
1
+ import { Button } from 'antd';
2
+ import { customize } from '../../customize';
3
+ import { Icon } from '../../common/Icon';
4
+ import { useChatContext } from '../ChatContext';
5
+
6
+ export const ChatMembersButton = customize('ChatMembersButton', () => {
7
+ const { showMembers, onShowMembers } = useChatContext();
8
+ return <Button onClick={() => onShowMembers(!showMembers)} type="link" icon={<Icon type="members" />} />;
9
+ });
@@ -1,112 +1,128 @@
1
- import { Button, List, Space, Tooltip } from 'antd';
2
- import { chatifyApi } from '../../../core';
3
- import { customize } from '../../customize';
4
- import { useCallback, useMemo } from 'react';
5
- import { Icon } from '../../common/Icon';
6
- import { Avatar } from '../../common/Avatar';
7
- import { useChatContext } from '../ChatContext';
8
-
9
- interface ChatMemberListItemProps {
10
- id: string;
11
- chatId: string;
12
- }
13
-
14
- function useAdd(chatId: string, accountId: string, withHistory: boolean) {
15
- const [add, state] = chatifyApi.useAddChatMemberMutation();
16
- const onAdd = useCallback(
17
- () => add({ chatId, accountId, withHistory }),
18
- [add, chatId, accountId, withHistory],
19
- );
20
- return [onAdd, state] as const;
21
- }
22
-
23
- function useRemove(chatId: string, accountId: string, deleteHistory: boolean) {
24
- const [remove, state] = chatifyApi.useRemoveChatMemberMutation();
25
- const onRemove = useCallback(
26
- () => remove({ chatId, accountId, deleteHistory }),
27
- [remove, chatId, accountId, deleteHistory],
28
- );
29
- return [onRemove, state] as const;
30
- }
31
-
32
- const ChatMemberListItem = customize('ChatMemberListItem', (props: ChatMemberListItemProps) => {
33
- const { chatId } = props;
34
- const { data: chat } = chatifyApi.useGetChatQuery({ id: chatId });
35
- const { data: accounts } = chatifyApi.useGetAccountListQuery({});
36
- const account = accounts!.find((x) => x.id === props.id)!;
37
- const isMember = chat!.members.some((x) => x.id === account.id);
38
- const [onAddWithoutHistory] = useAdd(chatId, account.id, false);
39
- const [onAddWithHistory] = useAdd(chatId, account.id, true);
40
- const [onRemoveKeepHistory] = useRemove(chatId, account.id, false);
41
- const [onRemoveDeleteHistory] = useRemove(chatId, account.id, true);
42
-
43
- return (
44
- <List.Item
45
- className="wxchtf-chat-members-list-item"
46
- actions={
47
- isMember
48
- ? [
49
- <Tooltip key="remove" title="Remove (keep history)">
50
- <Button onClick={onRemoveKeepHistory} type="link" icon={<Icon type="remove-member" />} />
51
- </Tooltip>,
52
- <Tooltip key="remove_delete_history" title="Remove (delete history)">
53
- <Button
54
- onClick={onRemoveDeleteHistory}
55
- type="link"
56
- icon={<Icon type="remove-member-delete-history" />}
57
- />
58
- </Tooltip>,
59
- ]
60
- : [
61
- <Tooltip key="add_no_history" title="Add (no history)">
62
- <Button onClick={onAddWithoutHistory} type="link" icon={<Icon type="add-member" />} />
63
- </Tooltip>,
64
- <Tooltip key="add" title="Add (share history)">
65
- <Button
66
- onClick={onAddWithHistory}
67
- type="link"
68
- icon={<Icon type="add-member-with-history" />}
69
- />
70
- </Tooltip>,
71
- ]
72
- }
73
- >
74
- <Space>
75
- <Avatar account={account} />
76
- <span>{account.name}</span>
77
- </Space>
78
- </List.Item>
79
- );
80
- });
81
-
82
- export const ChatMembersPanel = customize('ChatMembersPanel', () => {
83
- const { id } = useChatContext();
84
- const { data: chat } = chatifyApi.useGetChatQuery({ id });
85
- const { data: accounts } = chatifyApi.useGetAccountListQuery({});
86
- const ordered = useMemo(
87
- () =>
88
- accounts
89
- ?.slice()
90
- .sort(
91
- (a, b) =>
92
- (chat?.members.some((m) => m.id === a.id) ? -100 : 0) -
93
- (chat?.members.some((m) => m.id === b.id) ? -100 : 0) +
94
- a.name.localeCompare(b.name),
95
- ),
96
- [accounts, chat],
97
- );
98
-
99
- if (!chat?.members || !accounts) {
100
- return null;
101
- }
102
-
103
- return (
104
- <div className="wxchtf-chat-members-panel">
105
- <List
106
- className="wxchtf-chat-members-list"
107
- dataSource={ordered}
108
- renderItem={(item) => <ChatMemberListItem id={item.id} chatId={id} />}
109
- />
110
- </div>
111
- );
112
- });
1
+ import { Button, Col, List, Row, Space, Tooltip } from 'antd';
2
+ import { chatifyApi } from '../../../core';
3
+ import { customize } from '../../customize';
4
+ import { useCallback, useMemo } from 'react';
5
+ import { Icon } from '../../common/Icon';
6
+ import { Avatar } from '../../common/Avatar';
7
+ import { useChatContext } from '../ChatContext';
8
+ import { LeftOutlined } from '@ant-design/icons';
9
+ import { useLocalizer } from '@/ui/localizer';
10
+
11
+ interface ChatMemberListItemProps {
12
+ id: string;
13
+ chatId: string;
14
+ }
15
+
16
+ function useAdd(chatId: string, accountId: string, withHistory: boolean) {
17
+ const [add, state] = chatifyApi.useAddChatMemberMutation();
18
+ const onAdd = useCallback(
19
+ () => add({ chatId, accountId, withHistory }),
20
+ [add, chatId, accountId, withHistory],
21
+ );
22
+ return [onAdd, state] as const;
23
+ }
24
+
25
+ function useRemove(chatId: string, accountId: string, deleteHistory: boolean) {
26
+ const [remove, state] = chatifyApi.useRemoveChatMemberMutation();
27
+ const onRemove = useCallback(
28
+ () => remove({ chatId, accountId, deleteHistory }),
29
+ [remove, chatId, accountId, deleteHistory],
30
+ );
31
+ return [onRemove, state] as const;
32
+ }
33
+
34
+ const ChatMemberListItem = customize('ChatMemberListItem', (props: ChatMemberListItemProps) => {
35
+ const { chatId } = props;
36
+ const { data: chat } = chatifyApi.useGetChatQuery({ id: chatId });
37
+ const { data: accounts } = chatifyApi.useGetAccountListQuery({});
38
+ const account = accounts!.find((x) => x.id === props.id)!;
39
+ const isMember = chat!.members.some((x) => x.id === account.id);
40
+ const [onAddWithoutHistory] = useAdd(chatId, account.id, false);
41
+ const [onAddWithHistory] = useAdd(chatId, account.id, true);
42
+ const [onRemoveKeepHistory] = useRemove(chatId, account.id, false);
43
+ const [onRemoveDeleteHistory] = useRemove(chatId, account.id, true);
44
+
45
+ return (
46
+ <List.Item
47
+ className="wxchtf-chat-members-list-item"
48
+ actions={
49
+ isMember
50
+ ? [
51
+ <Tooltip key="remove" title="Remove (keep history)">
52
+ <Button onClick={onRemoveKeepHistory} type="link" icon={<Icon type="remove-member" />} />
53
+ </Tooltip>,
54
+ <Tooltip key="remove_delete_history" title="Remove (delete history)">
55
+ <Button
56
+ onClick={onRemoveDeleteHistory}
57
+ type="link"
58
+ icon={<Icon type="remove-member-delete-history" />}
59
+ />
60
+ </Tooltip>,
61
+ ]
62
+ : [
63
+ <Tooltip key="add_no_history" title="Add (no history)">
64
+ <Button onClick={onAddWithoutHistory} type="link" icon={<Icon type="add-member" />} />
65
+ </Tooltip>,
66
+ <Tooltip key="add" title="Add (share history)">
67
+ <Button
68
+ onClick={onAddWithHistory}
69
+ type="link"
70
+ icon={<Icon type="add-member-with-history" />}
71
+ />
72
+ </Tooltip>,
73
+ ]
74
+ }
75
+ >
76
+ <Space>
77
+ <Avatar account={account} />
78
+ <span>{account.name}</span>
79
+ </Space>
80
+ </List.Item>
81
+ );
82
+ });
83
+
84
+ export const ChatMembersPanel = customize('ChatMembersPanel', () => {
85
+ const { id, compact, onShowMembers } = useChatContext();
86
+ const localizer = useLocalizer();
87
+ const { data: chat } = chatifyApi.useGetChatQuery({ id });
88
+ const { data: accounts } = chatifyApi.useGetAccountListQuery({});
89
+
90
+ const ordered = useMemo(
91
+ () =>
92
+ accounts
93
+ ?.slice()
94
+ .sort(
95
+ (a, b) =>
96
+ (chat?.members.some((m) => m.id === a.id) ? -100 : 0) -
97
+ (chat?.members.some((m) => m.id === b.id) ? -100 : 0) +
98
+ a.name.localeCompare(b.name),
99
+ ),
100
+ [accounts, chat],
101
+ );
102
+
103
+ if (!chat?.members || !accounts) {
104
+ return null;
105
+ }
106
+
107
+ return (
108
+ <div className="wxchtf-chat-members-panel">
109
+ {compact && (
110
+ <div className="wxchtf-chat-members-panel-header">
111
+ <Row wrap={false} align="middle" gutter={10}>
112
+ <Col flex="none">
113
+ <Button type="text" icon={<LeftOutlined />} onClick={() => onShowMembers(false)} />
114
+ </Col>
115
+ <Col>
116
+ <span className="wxchtf-chat-members-panel-title">{localizer.members.title(chat.name)}</span>
117
+ </Col>
118
+ </Row>
119
+ </div>
120
+ )}
121
+ <List
122
+ className="wxchtf-chat-members-list"
123
+ dataSource={ordered}
124
+ renderItem={(item) => <ChatMemberListItem id={item.id} chatId={id} />}
125
+ />
126
+ </div>
127
+ );
128
+ });