@webinex/chatify 1.0.0-rc2 → 1.0.0-rc3

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 (267) hide show
  1. package/dist/css/chatify.css +183 -141
  2. package/dist/esm/index.js +1 -1
  3. package/dist/esm/index.js.map +1 -1
  4. package/dist/esm/types/core/action.d.ts +110 -42
  5. package/dist/esm/types/core/client.d.ts +2 -1
  6. package/dist/esm/types/core/index.d.ts +11 -8
  7. package/dist/esm/types/core/models.d.ts +10 -4
  8. package/dist/esm/types/core/state.d.ts +36 -7
  9. package/dist/esm/types/core/useAddChatMutation.d.ts +2 -0
  10. package/dist/esm/types/core/useAddMemberMutation.d.ts +2 -0
  11. package/dist/esm/types/core/useFetchNextMutation.d.ts +3 -0
  12. package/dist/esm/types/core/useGetAccountsQuery.d.ts +1 -0
  13. package/dist/esm/types/core/useGetChatListQuery.d.ts +1 -0
  14. package/dist/{cjs/types/core/useChat.d.ts → esm/types/core/useGetChatQuery.d.ts} +1 -1
  15. package/dist/esm/types/core/useGetMessagesQuery.d.ts +4 -0
  16. package/dist/esm/types/core/useRemoveMemberMutation.d.ts +2 -0
  17. package/dist/esm/types/core/useSendMutation.d.ts +2 -0
  18. package/dist/esm/types/core/useUpdateChatNameMutation.d.ts +2 -0
  19. package/dist/esm/types/ui/AddChatButton.d.ts +2 -2
  20. package/dist/esm/types/ui/Avatar.d.ts +2 -2
  21. package/dist/esm/types/ui/ChatList/ChatList.d.ts +2 -0
  22. package/dist/esm/types/ui/ChatList/ChatListItemBox.d.ts +6 -0
  23. package/dist/esm/types/ui/ChatList/ChatListItemLastMessage.d.ts +3 -0
  24. package/dist/esm/types/ui/ChatList/ChatListItemLastMessageAuthor.d.ts +3 -0
  25. package/dist/esm/types/ui/ChatList/ChatListItemLastMessageContent.d.ts +3 -0
  26. package/dist/esm/types/ui/ChatList/ChatListItemName.d.ts +3 -0
  27. package/dist/esm/types/ui/ChatList/ChatListItemUnreadCount.d.ts +3 -0
  28. package/dist/esm/types/ui/ChatList/index.d.ts +7 -0
  29. package/dist/esm/types/ui/ChatName.d.ts +2 -2
  30. package/dist/esm/types/ui/ChatPanel/ChatBody.d.ts +5 -0
  31. package/dist/esm/types/ui/ChatPanel/ChatHeader.d.ts +5 -0
  32. package/dist/esm/types/ui/ChatPanel/ChatHeaderMembers.d.ts +5 -0
  33. package/dist/esm/types/ui/ChatPanel/ChatHeaderName.d.ts +5 -0
  34. package/dist/esm/types/ui/ChatPanel/ChatMembersButton.d.ts +5 -0
  35. package/dist/esm/types/ui/ChatPanel/ChatMembersPanel.d.ts +5 -0
  36. package/dist/esm/types/ui/ChatPanel/ChatPanel.d.ts +5 -0
  37. package/dist/esm/types/ui/ChatPanel/index.d.ts +6 -0
  38. package/dist/esm/types/ui/Chatify.d.ts +45 -23
  39. package/dist/esm/types/ui/CreateChatPanel/CreateChatForm.d.ts +11 -0
  40. package/dist/esm/types/ui/CreateChatPanel/CreateChatMemberInput.d.ts +5 -0
  41. package/dist/esm/types/ui/CreateChatPanel/CreateChatNameInput.d.ts +5 -0
  42. package/dist/esm/types/ui/CreateChatPanel/CreateChatPanel.d.ts +2 -0
  43. package/dist/esm/types/ui/CreateChatPanel/index.d.ts +4 -0
  44. package/dist/esm/types/ui/Icon.d.ts +13 -4
  45. package/dist/esm/types/ui/InputBox/InputBox.d.ts +2 -0
  46. package/dist/esm/types/ui/InputBox/InputFilesBox.d.ts +2 -0
  47. package/dist/esm/types/ui/InputBox/InputSubmitButtonBox.d.ts +5 -0
  48. package/dist/esm/types/ui/InputBox/InputTextBox.d.ts +7 -0
  49. package/dist/esm/types/ui/InputBox/index.d.ts +4 -0
  50. package/dist/esm/types/ui/Layout/Aside.d.ts +2 -0
  51. package/dist/esm/types/ui/Layout/Body.d.ts +2 -0
  52. package/dist/esm/types/ui/Layout/Footer.d.ts +2 -0
  53. package/dist/esm/types/ui/Layout/Header.d.ts +2 -0
  54. package/dist/esm/types/ui/Layout/Main.d.ts +2 -0
  55. package/dist/esm/types/ui/Layout/index.d.ts +5 -0
  56. package/dist/esm/types/ui/Message/MessageAuthor.d.ts +3 -0
  57. package/dist/esm/types/ui/Message/MessageBox.d.ts +6 -0
  58. package/dist/esm/types/ui/Message/MessageContent.d.ts +3 -0
  59. package/dist/esm/types/ui/Message/MessageInfoBox.d.ts +3 -0
  60. package/dist/esm/types/ui/Message/MessageRow.d.ts +6 -0
  61. package/dist/esm/types/ui/Message/MessageText.d.ts +3 -0
  62. package/dist/esm/types/ui/Message/index.d.ts +6 -0
  63. package/dist/esm/types/ui/MessageReadObserver.d.ts +6 -0
  64. package/dist/esm/types/ui/Next.d.ts +4 -0
  65. package/dist/esm/types/ui/SendingMessage/SendingMessageBox.d.ts +7 -0
  66. package/dist/esm/types/ui/SendingMessage/SendingMessageContent.d.ts +3 -0
  67. package/dist/esm/types/ui/SendingMessage/SendingMessageInfoBox.d.ts +3 -0
  68. package/dist/esm/types/ui/SendingMessage/SendingMessageText.d.ts +3 -0
  69. package/dist/esm/types/ui/SendingMessage/index.d.ts +4 -0
  70. package/dist/esm/types/ui/SystemMessage/SystemMessageBox.d.ts +6 -0
  71. package/dist/esm/types/ui/SystemMessage/SystemMessageRow.d.ts +9 -0
  72. package/dist/esm/types/ui/SystemMessage/index.d.ts +2 -0
  73. package/dist/esm/types/{util → ui}/customize.d.ts +2 -3
  74. package/dist/esm/types/ui/index.d.ts +6 -6
  75. package/dist/esm/types/ui/localizer.d.ts +5 -0
  76. package/dist/esm/types/util/index.d.ts +0 -1
  77. package/dist/index.d.ts +353 -142
  78. package/package.json +3 -1
  79. package/src/core/action.tsx +319 -233
  80. package/src/core/client.ts +6 -0
  81. package/src/core/index.ts +11 -8
  82. package/src/core/models.tsx +11 -4
  83. package/src/core/reducer.tsx +2 -1
  84. package/src/core/state.ts +68 -14
  85. package/src/core/useAddChatMutation.tsx +22 -0
  86. package/src/core/useAddMemberMutation.tsx +25 -0
  87. package/src/core/useFetchNextMutation.tsx +28 -0
  88. package/src/core/useGetAccountsQuery.tsx +33 -0
  89. package/src/core/useGetChatListQuery.tsx +33 -0
  90. package/src/core/useGetChatQuery.tsx +34 -0
  91. package/src/core/useGetMessagesQuery.tsx +35 -0
  92. package/src/core/useReadMonitor.tsx +8 -7
  93. package/src/core/useRemoveMemberMutation.tsx +23 -0
  94. package/src/core/useSendMutation.tsx +24 -0
  95. package/src/core/useSignalRMonitor.tsx +19 -5
  96. package/src/core/useUpdateChatNameMutation.tsx +23 -0
  97. package/src/{ui/styles → styles}/aside.scss +1 -1
  98. package/src/styles/chat.scss +222 -0
  99. package/src/styles/index.scss +79 -0
  100. package/src/styles/settings.scss +5 -0
  101. package/src/ui/AddChatButton.tsx +4 -8
  102. package/src/ui/Avatar.tsx +1 -1
  103. package/src/ui/ChatList/ChatList.tsx +42 -0
  104. package/src/ui/ChatList/ChatListItemBox.tsx +22 -0
  105. package/src/ui/ChatList/ChatListItemLastMessage.tsx +13 -0
  106. package/src/ui/ChatList/ChatListItemLastMessageAuthor.tsx +20 -0
  107. package/src/ui/ChatList/ChatListItemLastMessageContent.tsx +21 -0
  108. package/src/ui/ChatList/ChatListItemName.tsx +13 -0
  109. package/src/ui/ChatList/ChatListItemUnreadCount.tsx +12 -0
  110. package/src/ui/ChatList/index.ts +7 -0
  111. package/src/ui/ChatName.tsx +3 -8
  112. package/src/ui/ChatPanel/ChatBody.tsx +44 -0
  113. package/src/ui/ChatPanel/ChatHeader.tsx +33 -0
  114. package/src/ui/{ChatHeaderMembers.tsx → ChatPanel/ChatHeaderMembers.tsx} +5 -9
  115. package/src/ui/ChatPanel/ChatHeaderName.tsx +67 -0
  116. package/src/ui/ChatPanel/ChatMembersButton.tsx +21 -0
  117. package/src/ui/ChatPanel/ChatMembersPanel.tsx +117 -0
  118. package/src/ui/ChatPanel/ChatPanel.tsx +27 -0
  119. package/src/ui/ChatPanel/index.ts +6 -0
  120. package/src/ui/Chatify.tsx +78 -36
  121. package/src/ui/CreateChatPanel/CreateChatForm.tsx +36 -0
  122. package/src/ui/CreateChatPanel/CreateChatMemberInput.tsx +66 -0
  123. package/src/ui/CreateChatPanel/CreateChatNameInput.tsx +25 -0
  124. package/src/ui/CreateChatPanel/CreateChatPanel.tsx +33 -0
  125. package/src/ui/CreateChatPanel/index.ts +4 -0
  126. package/src/ui/Icon.tsx +18 -6
  127. package/src/ui/InputBox/InputBox.tsx +38 -0
  128. package/src/ui/InputBox/InputFilesBox.tsx +9 -0
  129. package/src/ui/InputBox/InputSubmitButtonBox.tsx +17 -0
  130. package/src/ui/InputBox/InputTextBox.tsx +50 -0
  131. package/src/ui/InputBox/index.ts +4 -0
  132. package/src/ui/Layout/Aside.tsx +10 -0
  133. package/src/ui/Layout/Body.tsx +10 -0
  134. package/src/ui/Layout/Footer.tsx +3 -0
  135. package/src/ui/Layout/Header.tsx +10 -0
  136. package/src/ui/Layout/Main.tsx +15 -0
  137. package/src/ui/Layout/index.ts +5 -0
  138. package/src/ui/Message/MessageAuthor.tsx +13 -0
  139. package/src/ui/Message/MessageBox.tsx +20 -0
  140. package/src/ui/Message/MessageContent.tsx +13 -0
  141. package/src/ui/Message/MessageInfoBox.tsx +25 -0
  142. package/src/ui/Message/MessageRow.tsx +24 -0
  143. package/src/ui/Message/MessageText.tsx +7 -0
  144. package/src/ui/Message/index.ts +6 -0
  145. package/src/ui/MessageReadObserver.tsx +45 -0
  146. package/src/ui/{LoadMore.tsx → Next.tsx} +16 -8
  147. package/src/ui/SendingMessage/SendingMessageBox.tsx +16 -0
  148. package/src/ui/SendingMessage/SendingMessageContent.tsx +13 -0
  149. package/src/ui/SendingMessage/SendingMessageInfoBox.tsx +13 -0
  150. package/src/ui/SendingMessage/SendingMessageText.tsx +7 -0
  151. package/src/ui/SendingMessage/index.ts +4 -0
  152. package/src/ui/SystemMessage/SystemMessageBox.tsx +20 -0
  153. package/src/ui/SystemMessage/SystemMessageRow.tsx +43 -0
  154. package/src/ui/SystemMessage/index.ts +2 -0
  155. package/src/{util → ui}/customize.tsx +5 -5
  156. package/src/ui/index.ts +6 -6
  157. package/src/ui/localizer.tsx +12 -0
  158. package/src/util/index.ts +0 -1
  159. package/dist/cjs/index.js +0 -2
  160. package/dist/cjs/index.js.map +0 -1
  161. package/dist/cjs/types/ChatifyContext.d.ts +0 -11
  162. package/dist/cjs/types/core/action.d.ts +0 -76
  163. package/dist/cjs/types/core/client.d.ts +0 -35
  164. package/dist/cjs/types/core/index.d.ts +0 -14
  165. package/dist/cjs/types/core/models.d.ts +0 -64
  166. package/dist/cjs/types/core/reducer.d.ts +0 -11
  167. package/dist/cjs/types/core/state.d.ts +0 -25
  168. package/dist/cjs/types/core/useAccounts.d.ts +0 -1
  169. package/dist/cjs/types/core/useAddChat.d.ts +0 -2
  170. package/dist/cjs/types/core/useAddMember.d.ts +0 -2
  171. package/dist/cjs/types/core/useAddMessage.d.ts +0 -5
  172. package/dist/cjs/types/core/useChatList.d.ts +0 -1
  173. package/dist/cjs/types/core/useLoadMore.d.ts +0 -3
  174. package/dist/cjs/types/core/useMessages.d.ts +0 -15
  175. package/dist/cjs/types/core/useMutation.d.ts +0 -12
  176. package/dist/cjs/types/core/useQuery.d.ts +0 -7
  177. package/dist/cjs/types/core/useReadMonitor.d.ts +0 -1
  178. package/dist/cjs/types/core/useRemoveMember.d.ts +0 -2
  179. package/dist/cjs/types/core/useSignalRMonitor.d.ts +0 -2
  180. package/dist/cjs/types/index.d.ts +0 -3
  181. package/dist/cjs/types/ui/AddChat.d.ts +0 -1
  182. package/dist/cjs/types/ui/AddChatButton.d.ts +0 -2
  183. package/dist/cjs/types/ui/Aside.d.ts +0 -1
  184. package/dist/cjs/types/ui/Avatar.d.ts +0 -6
  185. package/dist/cjs/types/ui/Chat.d.ts +0 -4
  186. package/dist/cjs/types/ui/ChatBody.d.ts +0 -4
  187. package/dist/cjs/types/ui/ChatHeader.d.ts +0 -4
  188. package/dist/cjs/types/ui/ChatHeaderMembers.d.ts +0 -5
  189. package/dist/cjs/types/ui/ChatHeaderSettingsButton.d.ts +0 -5
  190. package/dist/cjs/types/ui/ChatListItem.d.ts +0 -11
  191. package/dist/cjs/types/ui/ChatName.d.ts +0 -5
  192. package/dist/cjs/types/ui/ChatSettings.d.ts +0 -1
  193. package/dist/cjs/types/ui/Chatify.d.ts +0 -49
  194. package/dist/cjs/types/ui/Footer.d.ts +0 -2
  195. package/dist/cjs/types/ui/Header.d.ts +0 -2
  196. package/dist/cjs/types/ui/Icon.d.ts +0 -7
  197. package/dist/cjs/types/ui/InputForm.d.ts +0 -1
  198. package/dist/cjs/types/ui/LoadMore.d.ts +0 -4
  199. package/dist/cjs/types/ui/Main.d.ts +0 -1
  200. package/dist/cjs/types/ui/Message.d.ts +0 -18
  201. package/dist/cjs/types/ui/MessageSkeleton.d.ts +0 -4
  202. package/dist/cjs/types/ui/SendingMessage.d.ts +0 -10
  203. package/dist/cjs/types/ui/SystemMessage.d.ts +0 -8
  204. package/dist/cjs/types/ui/index.d.ts +0 -11
  205. package/dist/cjs/types/ui/localizer.d.ts +0 -32
  206. package/dist/cjs/types/util/customize.d.ts +0 -12
  207. package/dist/cjs/types/util/index.d.ts +0 -3
  208. package/dist/cjs/types/util/uniqBy.d.ts +0 -1
  209. package/dist/cjs/types/util/uniqId.d.ts +0 -1
  210. package/dist/esm/types/core/useAccounts.d.ts +0 -1
  211. package/dist/esm/types/core/useAddChat.d.ts +0 -2
  212. package/dist/esm/types/core/useAddMember.d.ts +0 -2
  213. package/dist/esm/types/core/useAddMessage.d.ts +0 -5
  214. package/dist/esm/types/core/useChat.d.ts +0 -3
  215. package/dist/esm/types/core/useChatList.d.ts +0 -1
  216. package/dist/esm/types/core/useLoadMore.d.ts +0 -3
  217. package/dist/esm/types/core/useMessages.d.ts +0 -15
  218. package/dist/esm/types/core/useMutation.d.ts +0 -12
  219. package/dist/esm/types/core/useQuery.d.ts +0 -7
  220. package/dist/esm/types/core/useRemoveMember.d.ts +0 -2
  221. package/dist/esm/types/ui/AddChat.d.ts +0 -1
  222. package/dist/esm/types/ui/Aside.d.ts +0 -1
  223. package/dist/esm/types/ui/Chat.d.ts +0 -4
  224. package/dist/esm/types/ui/ChatBody.d.ts +0 -4
  225. package/dist/esm/types/ui/ChatHeader.d.ts +0 -4
  226. package/dist/esm/types/ui/ChatHeaderMembers.d.ts +0 -5
  227. package/dist/esm/types/ui/ChatHeaderSettingsButton.d.ts +0 -5
  228. package/dist/esm/types/ui/ChatListItem.d.ts +0 -11
  229. package/dist/esm/types/ui/ChatSettings.d.ts +0 -1
  230. package/dist/esm/types/ui/Footer.d.ts +0 -2
  231. package/dist/esm/types/ui/Header.d.ts +0 -2
  232. package/dist/esm/types/ui/InputForm.d.ts +0 -1
  233. package/dist/esm/types/ui/LoadMore.d.ts +0 -4
  234. package/dist/esm/types/ui/Main.d.ts +0 -1
  235. package/dist/esm/types/ui/Message.d.ts +0 -18
  236. package/dist/esm/types/ui/SendingMessage.d.ts +0 -10
  237. package/dist/esm/types/ui/SystemMessage.d.ts +0 -8
  238. package/src/core/useAccounts.tsx +0 -11
  239. package/src/core/useAddChat.tsx +0 -12
  240. package/src/core/useAddMember.tsx +0 -12
  241. package/src/core/useAddMessage.tsx +0 -40
  242. package/src/core/useChat.tsx +0 -12
  243. package/src/core/useChatList.tsx +0 -10
  244. package/src/core/useLoadMore.tsx +0 -42
  245. package/src/core/useMessages.tsx +0 -23
  246. package/src/core/useMutation.tsx +0 -48
  247. package/src/core/useQuery.tsx +0 -45
  248. package/src/core/useRemoveMember.tsx +0 -12
  249. package/src/ui/AddChat.tsx +0 -55
  250. package/src/ui/Aside.tsx +0 -41
  251. package/src/ui/Chat.tsx +0 -26
  252. package/src/ui/ChatBody.tsx +0 -43
  253. package/src/ui/ChatHeader.tsx +0 -33
  254. package/src/ui/ChatHeaderSettingsButton.tsx +0 -26
  255. package/src/ui/ChatListItem.tsx +0 -101
  256. package/src/ui/ChatSettings.tsx +0 -59
  257. package/src/ui/Footer.tsx +0 -7
  258. package/src/ui/Header.tsx +0 -14
  259. package/src/ui/InputForm.tsx +0 -51
  260. package/src/ui/Main.tsx +0 -16
  261. package/src/ui/Message.tsx +0 -118
  262. package/src/ui/SendingMessage.tsx +0 -50
  263. package/src/ui/SystemMessage.tsx +0 -32
  264. package/src/ui/styles/index.scss +0 -248
  265. /package/src/{ui/styles → styles}/keyframes.scss +0 -0
  266. /package/src/{ui/styles → styles}/mixins.scss +0 -0
  267. /package/src/{ui/styles → styles}/variables.scss +0 -0
package/src/core/index.ts CHANGED
@@ -2,13 +2,16 @@ export * from './models';
2
2
  export * from './client';
3
3
  export * from './action';
4
4
  export * from './reducer';
5
- export * from './useChat';
6
- export * from './useChatList';
7
- export * from './useLoadMore';
8
- export * from './useMessages';
5
+ export * from './state';
6
+ export * from './useGetChatQuery';
7
+ export * from './useGetChatListQuery';
8
+ export * from './useFetchNextMutation';
9
+ export * from './useGetMessagesQuery';
9
10
  export * from './useSignalRMonitor';
10
- export * from './useAccounts';
11
- export * from './useAddChat';
11
+ export * from './useGetAccountsQuery';
12
+ export * from './useAddChatMutation';
12
13
  export * from './useReadMonitor';
13
- export * from './useAddMember';
14
- export * from './useRemoveMember';
14
+ export * from './useAddMemberMutation';
15
+ export * from './useRemoveMemberMutation';
16
+ export * from './useSendMutation';
17
+ export * from './useUpdateChatNameMutation';
@@ -17,7 +17,6 @@ export interface Message {
17
17
  files: File[];
18
18
  sentAt: string;
19
19
  sentBy: Account;
20
- read: boolean;
21
20
  requestId?: string;
22
21
  }
23
22
 
@@ -31,7 +30,9 @@ export interface ChatListItem {
31
30
  id: string;
32
31
  name: string;
33
32
  message: Message;
34
- unreadCount: number;
33
+ totalUnreadCount: number;
34
+ active: boolean;
35
+ lastReadMessageId: string | null;
35
36
  }
36
37
 
37
38
  export interface SendMessageRequest {
@@ -54,12 +55,13 @@ export interface AddChatRequest {
54
55
  }
55
56
 
56
57
  export interface ReadRequest {
57
- ids: string[];
58
+ id: string;
58
59
  }
59
60
 
60
61
  export interface ReadEvent {
61
- messageId: string;
62
62
  chatId: string;
63
+ newLastReadMessageId: string;
64
+ readCount: number;
63
65
  }
64
66
 
65
67
  export interface RemoveMemberRequest {
@@ -73,3 +75,8 @@ export interface AddMemberRequest {
73
75
  accountId: string;
74
76
  withHistory: boolean;
75
77
  }
78
+
79
+ export interface UpdateChatNameRequest {
80
+ id: string;
81
+ name: string;
82
+ }
@@ -2,9 +2,10 @@ import React, { PropsWithChildren, useCallback, useContext, useEffect, useRef, u
2
2
  import { ACTIONS, Action } from './action';
3
3
  import { INITIAL_STATE, State } from './state';
4
4
  import { shallowEqual } from 'shallow-equal';
5
+ import { produce } from 'immer';
5
6
 
6
7
  function reducer(state: State, action: Action) {
7
- const result = ACTIONS[action.type](state, action.data as any);
8
+ const result = produce(state, (draft) => ACTIONS[action.type](draft, action.data as any));
8
9
  console.debug('[Chatify]: ', action, result);
9
10
  return result;
10
11
  }
package/src/core/state.ts CHANGED
@@ -1,5 +1,13 @@
1
+ import { Account, Chat, ChatListItem, Message, SendMessageRequest, File } from './models';
2
+
3
+ export type MessageState =
4
+ | ({ type: 'message' } & Message)
5
+ | { type: 'next' }
6
+ | { type: 'sending'; text: string; files: File[]; requestId: string };
7
+
1
8
  export interface UIState {
2
- view?: 'chat' | 'new-chat' | 'chat-settings';
9
+ view?: 'chat' | 'new-chat';
10
+ showMembers: boolean;
3
11
  chatId?: string;
4
12
  }
5
13
 
@@ -15,24 +23,70 @@ export interface MutationState {
15
23
  error?: any;
16
24
  }
17
25
 
26
+ export interface QueueState<TValue> {
27
+ queued: TValue[];
28
+ processing: TValue[];
29
+ timestamp: number;
30
+ }
31
+
18
32
  export interface State {
19
33
  ui: UIState;
20
- query: Record<string, QueryState<any>>;
21
- mutation: Record<string, MutationState>;
22
- read: {
23
- queued: string[];
24
- sent: string[];
25
- timestamp: number;
34
+ query: {
35
+ messages: Record<string, QueryState<MessageState[]>>;
36
+ chats: Record<string, QueryState<Chat>>;
37
+ chatList: QueryState<ChatListItem[]>;
38
+ accounts: QueryState<Account[]>;
39
+ };
40
+ mutation: {
41
+ fetchNext: MutationState;
42
+ removeMember: MutationState;
43
+ addMember: MutationState;
44
+ updateChatName: MutationState;
45
+ addChat: MutationState;
46
+ send: MutationState;
47
+ };
48
+ queue: {
49
+ read: QueueState<string>;
50
+ send: QueueState<SendMessageRequest>;
26
51
  };
27
52
  }
28
53
 
54
+ export const INITIAL_QUERY_STATE: QueryState<any> = {
55
+ uninitialized: false,
56
+ isFetching: true,
57
+ data: undefined,
58
+ error: undefined,
59
+ };
60
+
29
61
  export const INITIAL_STATE: State = {
30
- ui: {},
31
- query: {},
32
- mutation: {},
33
- read: {
34
- queued: [],
35
- sent: [],
36
- timestamp: 0,
62
+ ui: {
63
+ showMembers: false,
64
+ },
65
+ query: {
66
+ messages: {},
67
+ chats: {},
68
+ chatList: { uninitialized: true, isFetching: false, data: undefined, error: undefined },
69
+ accounts: { uninitialized: true, isFetching: false, data: undefined, error: undefined },
70
+ },
71
+ mutation: {
72
+ fetchNext: { isFetching: false, error: undefined },
73
+ removeMember: { isFetching: false, error: undefined },
74
+ addMember: { isFetching: false, error: undefined },
75
+ updateChatName: { isFetching: false, error: undefined },
76
+ addChat: { isFetching: false, error: undefined },
77
+ send: { isFetching: false, error: undefined },
78
+ },
79
+ queue: {
80
+ read: {
81
+ queued: [],
82
+ processing: [],
83
+ timestamp: 0,
84
+ },
85
+
86
+ send: {
87
+ queued: [],
88
+ processing: [],
89
+ timestamp: 0,
90
+ },
37
91
  },
38
92
  };
@@ -0,0 +1,22 @@
1
+ import { useCallback } from 'react';
2
+ import { useClient } from '../ChatifyContext';
3
+ import { AddChatRequest } from './models';
4
+ import { useDispatch, useStateRef } from './reducer';
5
+
6
+ export function useAddChatMutation() {
7
+ const client = useClient();
8
+ const dispatch = useDispatch();
9
+ const stateRef = useStateRef();
10
+
11
+ const invoke = useCallback((args: AddChatRequest) => {
12
+ dispatch({ type: 'addChat_fetch', data: void 0 });
13
+ client
14
+ .addChat(args)
15
+ .then(() => dispatch({ type: 'addChat_fulfilled', data: void 0 }))
16
+ .catch((error) => dispatch({ type: 'addChat_rejected', data: { error } }));
17
+
18
+ // eslint-disable-next-line react-hooks/exhaustive-deps
19
+ }, []);
20
+
21
+ return [invoke, stateRef.current.mutation.addChat] as const;
22
+ }
@@ -0,0 +1,25 @@
1
+ import { useCallback } from 'react';
2
+ import { useClient } from '../ChatifyContext';
3
+ import { AddMemberRequest } from './models';
4
+ import { useDispatch, useSelect, useStateRef } from './reducer';
5
+
6
+ export function useAddMemberMutation() {
7
+ const client = useClient();
8
+ const dispatch = useDispatch();
9
+ const state = useStateRef();
10
+ useSelect((x) => x.mutation.addMember, []);
11
+
12
+ const invoke = useCallback(
13
+ (args: AddMemberRequest) => {
14
+ dispatch({ type: 'addMember_fetch', data: void 0 });
15
+ client
16
+ .addMember(args)
17
+ .then(() => dispatch({ type: 'addMember_fulfilled', data: void 0 }))
18
+ .catch((error) => dispatch({ type: 'addMember_rejected', data: { error } }));
19
+ },
20
+ // eslint-disable-next-line react-hooks/exhaustive-deps
21
+ [dispatch],
22
+ );
23
+
24
+ return [invoke, state.current.mutation.addMember] as const;
25
+ }
@@ -0,0 +1,28 @@
1
+ import { useClient } from '../ChatifyContext';
2
+ import { useDispatch, useSelect, useStateRef } from './reducer';
3
+ import { useCallback } from 'react';
4
+
5
+ export function useFetchNextMutation({ chatId }: { chatId: string }) {
6
+ const state = useStateRef();
7
+ useSelect((x) => x.mutation.fetchNext, []);
8
+ const dispatch = useDispatch();
9
+ const client = useClient();
10
+
11
+ const fetchNext = useCallback(() => {
12
+ const skip = state.current.query.messages[chatId].data?.filter((x) => x.type === 'message').length;
13
+ dispatch({ type: 'fetchNext_fetch', data: { chatId } });
14
+ client
15
+ .messages({ chatId, skip, take: 16 })
16
+ .then((messages) =>
17
+ dispatch({
18
+ type: 'fetchNext_fulfilled',
19
+ data: { chatId, messages: messages.slice(0, 15), hasMore: messages.length === 16 },
20
+ }),
21
+ )
22
+ .catch((error) => dispatch({ type: 'fetchNext_rejected', data: { chatId, error } }));
23
+
24
+ // eslint-disable-next-line react-hooks/exhaustive-deps
25
+ }, [chatId]);
26
+
27
+ return [fetchNext, state.current.mutation.fetchNext] as const;
28
+ }
@@ -0,0 +1,33 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { useClient } from '../ChatifyContext';
3
+ import { useDispatch, useSelect, useStateRef } from './reducer';
4
+
5
+ export function useGetAccountsQuery() {
6
+ const client = useClient();
7
+ const stateRef = useStateRef();
8
+ useSelect((x) => x.query.accounts, []);
9
+ const dispatch = useDispatch();
10
+
11
+ const uninitialized = useMemo(() => {
12
+ const uninitialized = stateRef.current.query.accounts.uninitialized !== false;
13
+ uninitialized && dispatch({ type: 'accounts_fetch', data: void 0 });
14
+ return uninitialized;
15
+
16
+ // eslint-disable-next-line react-hooks/exhaustive-deps
17
+ }, []);
18
+
19
+ useEffect(() => {
20
+ if (!uninitialized) {
21
+ return;
22
+ }
23
+
24
+ client
25
+ .accounts()
26
+ .then((accounts) => dispatch({ type: 'accounts_fulfilled', data: { accounts } }))
27
+ .catch((error) => dispatch({ type: 'accounts_rejected', data: { error } }));
28
+
29
+ // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ }, [uninitialized]);
31
+
32
+ return stateRef.current.query.accounts;
33
+ }
@@ -0,0 +1,33 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { useClient } from '../ChatifyContext';
3
+ import { useDispatch, useSelect, useStateRef } from './reducer';
4
+
5
+ export function useGetChatListQuery() {
6
+ const stateRef = useStateRef();
7
+ const client = useClient();
8
+ useSelect((x) => x.query.chatList, []);
9
+ const dispatch = useDispatch();
10
+
11
+ const uninitialized = useMemo(() => {
12
+ const uninitialized = stateRef.current.query.chatList.uninitialized !== false;
13
+ uninitialized && dispatch({ type: 'chatList_fetch', data: void 0 });
14
+ return uninitialized;
15
+
16
+ // eslint-disable-next-line react-hooks/exhaustive-deps
17
+ }, []);
18
+
19
+ useEffect(() => {
20
+ if (!uninitialized) {
21
+ return;
22
+ }
23
+
24
+ client
25
+ .chats()
26
+ .then((chats) => dispatch({ type: 'chatList_fulfilled', data: { chats } }))
27
+ .catch((error) => dispatch({ type: 'chatList_rejected', data: { error } }));
28
+
29
+ // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ }, []);
31
+
32
+ return stateRef.current.query.chatList;
33
+ }
@@ -0,0 +1,34 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { useClient } from '../ChatifyContext';
3
+ import { useDispatch, useSelect, useStateRef } from './reducer';
4
+
5
+ export function useGetChatQuery(args: { chatId: string }) {
6
+ const { chatId } = args;
7
+ const client = useClient();
8
+ const stateRef = useStateRef();
9
+ useSelect((x) => x.query.chats[chatId], [chatId]);
10
+ const dispatch = useDispatch();
11
+
12
+ const uninitialized = useMemo(() => {
13
+ const uninitialized = stateRef.current.query.chats[chatId]?.uninitialized !== false;
14
+ uninitialized && dispatch({ type: 'chat_fetch', data: { chatId } });
15
+ return uninitialized;
16
+
17
+ // eslint-disable-next-line react-hooks/exhaustive-deps
18
+ }, [chatId]);
19
+
20
+ useEffect(() => {
21
+ if (!uninitialized) {
22
+ return;
23
+ }
24
+
25
+ client
26
+ .chat(chatId)
27
+ .then((chat) => dispatch({ type: 'chat_fulfilled', data: { chat } }))
28
+ .catch((error) => dispatch({ type: 'chat_rejected', data: { chatId, error } }));
29
+
30
+ // eslint-disable-next-line react-hooks/exhaustive-deps
31
+ }, [uninitialized, chatId]);
32
+
33
+ return stateRef.current.query.chats[chatId];
34
+ }
@@ -0,0 +1,35 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { useClient } from '../ChatifyContext';
3
+ import { MessageState, QueryState } from './state';
4
+ import { useDispatch, useSelect, useStateRef } from './reducer';
5
+
6
+ export function useGetMessagesQuery(args: { chatId: string }): QueryState<MessageState[]> {
7
+ const { chatId } = args;
8
+ const stateRef = useStateRef();
9
+ const dispatch = useDispatch();
10
+ useSelect((x) => x.query.messages[chatId], [chatId]);
11
+ const client = useClient();
12
+
13
+ const uninitialized = useMemo(() => {
14
+ const uninitialized = stateRef.current.query.messages[chatId]?.uninitialized !== false;
15
+ uninitialized && dispatch({ type: 'messages_fetch', data: { chatId } });
16
+ return uninitialized;
17
+ }, [chatId, dispatch, stateRef]);
18
+
19
+ useEffect(() => {
20
+ if (!uninitialized) {
21
+ return;
22
+ }
23
+
24
+ client.messages({ chatId, skip: 0, take: 16 }).then((messages) =>
25
+ dispatch({
26
+ type: 'messages_fulfilled',
27
+ data: { chatId, messages: messages.slice(0, 15), hasMore: messages.length === 16 },
28
+ }),
29
+ );
30
+
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ }, [chatId]);
33
+
34
+ return stateRef.current.query.messages[chatId];
35
+ }
@@ -4,7 +4,7 @@ import { useDispatch, useSelect } from './reducer';
4
4
 
5
5
  export function useReadMonitor() {
6
6
  const client = useClient();
7
- const [queued, timestamp] = useSelect((x) => [x.read.queued, x.read.timestamp], []);
7
+ const [queued, timestamp] = useSelect((x) => [x.queue.read.queued, x.queue.read.timestamp], []);
8
8
  const dispatch = useDispatch();
9
9
  const timer = useRef<NodeJS.Timeout | null>(null);
10
10
 
@@ -18,12 +18,13 @@ export function useReadMonitor() {
18
18
  }
19
19
 
20
20
  timer.current = setTimeout(() => {
21
- dispatch({ type: 'read_send', data: { ids: queued } });
22
- client
23
- .read({ ids: queued })
24
- .catch(() =>
25
- dispatch({ type: 'read_reject', data: { ids: queued, timestamp: new Date().getTime() } }),
26
- );
21
+ for (const id of queued) {
22
+ dispatch({ type: 'read_send', data: { id } });
23
+
24
+ client
25
+ .read({ id })
26
+ .catch(() => dispatch({ type: 'read_reject', data: { id, timestamp: new Date().getTime() } }));
27
+ }
27
28
  }, 100);
28
29
 
29
30
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -0,0 +1,23 @@
1
+ import { useCallback } from 'react';
2
+ import { useClient } from '../ChatifyContext';
3
+ import { RemoveMemberRequest } from './models';
4
+ import { useDispatch, useSelect, useStateRef } from './reducer';
5
+
6
+ export function useRemoveMemberMutation() {
7
+ const stateRef = useStateRef();
8
+ useSelect((x) => x.mutation.removeMember, []);
9
+ const dispatch = useDispatch();
10
+ const client = useClient();
11
+
12
+ const invoke = useCallback((args: RemoveMemberRequest) => {
13
+ dispatch({ type: 'removeMember_fetch', data: void 0 });
14
+ client
15
+ .removeMember(args)
16
+ .then(() => dispatch({ type: 'removeMember_fulfilled', data: void 0 }))
17
+ .catch((error) => dispatch({ type: 'removeMember_rejected', data: { error } }));
18
+
19
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20
+ }, []);
21
+
22
+ return [invoke, stateRef.current.mutation.removeMember] as const;
23
+ }
@@ -0,0 +1,24 @@
1
+ import { useCallback } from 'react';
2
+ import { useClient } from '../ChatifyContext';
3
+ import { SendMessageRequest } from './models';
4
+ import { useDispatch, useSelect, useStateRef } from './reducer';
5
+
6
+ export function useSendMutation() {
7
+ const stateRef = useStateRef();
8
+ useSelect((x) => x.mutation.send, []);
9
+ const dispatch = useDispatch();
10
+ const client = useClient();
11
+
12
+ const invoke = useCallback((args: SendMessageRequest) => {
13
+ const { chatId, requestId, files, text } = args;
14
+ dispatch({ type: 'send_fetch', data: { chatId, requestId, files, text } });
15
+ client
16
+ .send(args)
17
+ .then(() => dispatch({ type: 'send_fulfilled', data: { chatId, requestId } }))
18
+ .catch((error) => dispatch({ type: 'send_rejected', data: { chatId, requestId, error } }));
19
+
20
+ // eslint-disable-next-line react-hooks/exhaustive-deps
21
+ }, []);
22
+
23
+ return [invoke, stateRef.current.mutation.send] as const;
24
+ }
@@ -12,7 +12,7 @@ export function useSignalRMonitor(me: string, client: ChatifyClient) {
12
12
  client.connect().then(() => {
13
13
  unsubscribes.push(
14
14
  client.subscribe('chatify://new-message', ([message, requestId]: [Message, string]) => {
15
- dispatch({ type: 'message_received', data: { message, requestId } });
15
+ dispatch({ type: 'message_received', data: { message, requestId, me } });
16
16
  }),
17
17
  );
18
18
  unsubscribes.push(
@@ -28,16 +28,30 @@ export function useSignalRMonitor(me: string, client: ChatifyClient) {
28
28
  unsubscribes.push(
29
29
  client.subscribe(
30
30
  'chatify://member-added',
31
- ([chatId, chatName, account, message]: [string, string, Account, Message]) => {
32
- dispatch({ type: 'member_added', data: { chatId, chatName, account, me, message } });
31
+ ([chatId, chatName, account, message, withHistory]: [
32
+ string,
33
+ string,
34
+ Account,
35
+ Message,
36
+ boolean,
37
+ ]) => {
38
+ dispatch({ type: 'member_added', data: { chatId, chatName, account, me, message, withHistory } });
33
39
  },
34
40
  ),
35
41
  );
36
42
  unsubscribes.push(
37
43
  client.subscribe(
38
44
  'chatify://member-removed',
39
- ([chatId, accountId, deleteHistory]: [string, string, boolean]) => {
40
- dispatch({ type: 'member_removed', data: { chatId, accountId, deleteHistory, me } });
45
+ ([chatId, accountId, deleteHistory, message]: [string, string, boolean, Message]) => {
46
+ dispatch({ type: 'member_removed', data: { chatId, accountId, deleteHistory, me, message } });
47
+ },
48
+ ),
49
+ );
50
+ unsubscribes.push(
51
+ client.subscribe(
52
+ 'chatify://chat-name-changed',
53
+ ([chatId, newName, message]: [string, string, Message]) => {
54
+ dispatch({ type: 'chatNameChanged_received', data: { chatId, newName, message } });
41
55
  },
42
56
  ),
43
57
  );
@@ -0,0 +1,23 @@
1
+ import { useCallback } from 'react';
2
+ import { useClient } from '../ChatifyContext';
3
+ import { UpdateChatNameRequest } from './models';
4
+ import { useDispatch, useSelect, useStateRef } from './reducer';
5
+
6
+ export function useUpdateChatNameMutation() {
7
+ const stateRef = useStateRef();
8
+ useSelect((x) => x.mutation.updateChatName, []);
9
+ const dispatch = useDispatch();
10
+ const client = useClient();
11
+
12
+ const invoke = useCallback((args: UpdateChatNameRequest) => {
13
+ dispatch({ type: 'updateChatName_fetch', data: void 0 });
14
+ client
15
+ .updateChatName(args)
16
+ .then(() => dispatch({ type: 'updateChatName_fulfilled', data: void 0 }))
17
+ .catch((error) => dispatch({ type: 'updateChatName_rejected', data: { error } }));
18
+
19
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20
+ }, []);
21
+
22
+ return [invoke, stateRef.current.mutation.updateChatName] as const;
23
+ }
@@ -5,7 +5,7 @@
5
5
  display: flex;
6
6
  flex-flow: column nowrap;
7
7
 
8
- .wxchtf-chats.ant-menu {
8
+ .wxchtf-chat-list.ant-menu {
9
9
  flex: 1 1 auto;
10
10
  height: 100px;
11
11
  overflow-y: auto;