@webinex/chatify 1.0.0-rc2 → 1.0.1-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.
- package/dist/css/chatify.css +183 -141
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/core/action.d.ts +110 -42
- package/dist/esm/types/core/client.d.ts +2 -1
- package/dist/esm/types/core/index.d.ts +11 -8
- package/dist/esm/types/core/models.d.ts +10 -4
- package/dist/esm/types/core/state.d.ts +36 -7
- package/dist/esm/types/core/useAddChatMutation.d.ts +2 -0
- package/dist/esm/types/core/useAddMemberMutation.d.ts +2 -0
- package/dist/esm/types/core/useFetchNextMutation.d.ts +3 -0
- package/dist/esm/types/core/useGetAccountsQuery.d.ts +1 -0
- package/dist/esm/types/core/useGetChatListQuery.d.ts +1 -0
- package/dist/{cjs/types/core/useChat.d.ts → esm/types/core/useGetChatQuery.d.ts} +1 -1
- package/dist/esm/types/core/useGetMessagesQuery.d.ts +4 -0
- package/dist/esm/types/core/useRemoveMemberMutation.d.ts +2 -0
- package/dist/esm/types/core/useSendMutation.d.ts +2 -0
- package/dist/esm/types/core/useUpdateChatNameMutation.d.ts +2 -0
- package/dist/esm/types/ui/AddChatButton.d.ts +2 -2
- package/dist/esm/types/ui/Avatar.d.ts +2 -2
- package/dist/esm/types/ui/ChatList/ChatList.d.ts +2 -0
- package/dist/esm/types/ui/ChatList/ChatListItemBox.d.ts +6 -0
- package/dist/esm/types/ui/ChatList/ChatListItemLastMessage.d.ts +3 -0
- package/dist/esm/types/ui/ChatList/ChatListItemLastMessageAuthor.d.ts +3 -0
- package/dist/esm/types/ui/ChatList/ChatListItemLastMessageContent.d.ts +3 -0
- package/dist/esm/types/ui/ChatList/ChatListItemName.d.ts +3 -0
- package/dist/esm/types/ui/ChatList/ChatListItemUnreadCount.d.ts +3 -0
- package/dist/esm/types/ui/ChatList/index.d.ts +7 -0
- package/dist/esm/types/ui/ChatName.d.ts +2 -2
- package/dist/esm/types/ui/ChatPanel/ChatBody.d.ts +5 -0
- package/dist/esm/types/ui/ChatPanel/ChatHeader.d.ts +5 -0
- package/dist/esm/types/ui/ChatPanel/ChatHeaderMembers.d.ts +5 -0
- package/dist/esm/types/ui/ChatPanel/ChatHeaderName.d.ts +5 -0
- package/dist/esm/types/ui/ChatPanel/ChatMembersButton.d.ts +5 -0
- package/dist/esm/types/ui/ChatPanel/ChatMembersPanel.d.ts +5 -0
- package/dist/esm/types/ui/ChatPanel/ChatPanel.d.ts +5 -0
- package/dist/esm/types/ui/ChatPanel/index.d.ts +6 -0
- package/dist/esm/types/ui/Chatify.d.ts +45 -23
- package/dist/esm/types/ui/CreateChatPanel/CreateChatForm.d.ts +11 -0
- package/dist/esm/types/ui/CreateChatPanel/CreateChatMemberInput.d.ts +5 -0
- package/dist/esm/types/ui/CreateChatPanel/CreateChatNameInput.d.ts +5 -0
- package/dist/esm/types/ui/CreateChatPanel/CreateChatPanel.d.ts +2 -0
- package/dist/esm/types/ui/CreateChatPanel/index.d.ts +4 -0
- package/dist/esm/types/ui/Icon.d.ts +13 -4
- package/dist/esm/types/ui/InputBox/InputBox.d.ts +2 -0
- package/dist/esm/types/ui/InputBox/InputFilesBox.d.ts +2 -0
- package/dist/esm/types/ui/InputBox/InputSubmitButtonBox.d.ts +5 -0
- package/dist/esm/types/ui/InputBox/InputTextBox.d.ts +7 -0
- package/dist/esm/types/ui/InputBox/index.d.ts +4 -0
- package/dist/esm/types/ui/Layout/Aside.d.ts +2 -0
- package/dist/esm/types/ui/Layout/Body.d.ts +2 -0
- package/dist/esm/types/ui/Layout/Footer.d.ts +2 -0
- package/dist/esm/types/ui/Layout/Header.d.ts +2 -0
- package/dist/esm/types/ui/Layout/Main.d.ts +2 -0
- package/dist/esm/types/ui/Layout/index.d.ts +5 -0
- package/dist/esm/types/ui/Message/MessageAuthor.d.ts +3 -0
- package/dist/esm/types/ui/Message/MessageBox.d.ts +6 -0
- package/dist/esm/types/ui/Message/MessageContent.d.ts +3 -0
- package/dist/esm/types/ui/Message/MessageInfoBox.d.ts +3 -0
- package/dist/esm/types/ui/Message/MessageRow.d.ts +6 -0
- package/dist/esm/types/ui/Message/MessageText.d.ts +3 -0
- package/dist/esm/types/ui/Message/index.d.ts +6 -0
- package/dist/esm/types/ui/MessageReadObserver.d.ts +6 -0
- package/dist/esm/types/ui/Next.d.ts +4 -0
- package/dist/esm/types/ui/SendingMessage/SendingMessageBox.d.ts +7 -0
- package/dist/esm/types/ui/SendingMessage/SendingMessageContent.d.ts +3 -0
- package/dist/esm/types/ui/SendingMessage/SendingMessageInfoBox.d.ts +3 -0
- package/dist/esm/types/ui/SendingMessage/SendingMessageText.d.ts +3 -0
- package/dist/esm/types/ui/SendingMessage/index.d.ts +4 -0
- package/dist/esm/types/ui/SystemMessage/SystemMessageBox.d.ts +6 -0
- package/dist/esm/types/ui/SystemMessage/SystemMessageRow.d.ts +9 -0
- package/dist/esm/types/ui/SystemMessage/index.d.ts +2 -0
- package/dist/esm/types/{util → ui}/customize.d.ts +2 -3
- package/dist/esm/types/ui/index.d.ts +6 -6
- package/dist/esm/types/ui/localizer.d.ts +5 -0
- package/dist/esm/types/util/index.d.ts +0 -1
- package/dist/index.d.ts +353 -142
- package/package.json +92 -90
- package/src/ChatifyContext.tsx +41 -41
- package/src/core/action.tsx +405 -319
- package/src/core/client.ts +143 -137
- package/src/core/index.ts +17 -14
- package/src/core/models.tsx +82 -75
- package/src/core/reducer.tsx +87 -86
- package/src/core/state.ts +92 -38
- package/src/core/useAddChatMutation.tsx +22 -0
- package/src/core/useAddMemberMutation.tsx +25 -0
- package/src/core/useFetchNextMutation.tsx +28 -0
- package/src/core/useGetAccountsQuery.tsx +33 -0
- package/src/core/useGetChatListQuery.tsx +33 -0
- package/src/core/useGetChatQuery.tsx +34 -0
- package/src/core/useGetMessagesQuery.tsx +35 -0
- package/src/core/useReadMonitor.tsx +32 -31
- package/src/core/useRemoveMemberMutation.tsx +23 -0
- package/src/core/useSendMutation.tsx +24 -0
- package/src/core/useSignalRMonitor.tsx +66 -52
- package/src/core/useUpdateChatNameMutation.tsx +23 -0
- package/src/index.ts +3 -3
- package/src/{ui/styles → styles}/aside.scss +94 -94
- package/src/styles/chat.scss +222 -0
- package/src/styles/index.scss +79 -0
- package/src/{ui/styles → styles}/keyframes.scss +14 -14
- package/src/{ui/styles → styles}/mixins.scss +20 -20
- package/src/styles/settings.scss +5 -0
- package/src/{ui/styles → styles}/variables.scss +10 -10
- package/src/ui/AddChatButton.tsx +15 -19
- package/src/ui/Avatar.tsx +18 -18
- package/src/ui/ChatList/ChatList.tsx +42 -0
- package/src/ui/ChatList/ChatListItemBox.tsx +22 -0
- package/src/ui/ChatList/ChatListItemLastMessage.tsx +13 -0
- package/src/ui/ChatList/ChatListItemLastMessageAuthor.tsx +20 -0
- package/src/ui/ChatList/ChatListItemLastMessageContent.tsx +21 -0
- package/src/ui/ChatList/ChatListItemName.tsx +13 -0
- package/src/ui/ChatList/ChatListItemUnreadCount.tsx +12 -0
- package/src/ui/ChatList/index.ts +7 -0
- package/src/ui/ChatName.tsx +10 -15
- package/src/ui/ChatPanel/ChatBody.tsx +44 -0
- package/src/ui/ChatPanel/ChatHeader.tsx +33 -0
- package/src/ui/{ChatHeaderMembers.tsx → ChatPanel/ChatHeaderMembers.tsx} +26 -30
- package/src/ui/ChatPanel/ChatHeaderName.tsx +67 -0
- package/src/ui/ChatPanel/ChatMembersButton.tsx +21 -0
- package/src/ui/ChatPanel/ChatMembersPanel.tsx +117 -0
- package/src/ui/ChatPanel/ChatPanel.tsx +27 -0
- package/src/ui/ChatPanel/index.ts +6 -0
- package/src/ui/Chatify.tsx +148 -106
- package/src/ui/CreateChatPanel/CreateChatForm.tsx +36 -0
- package/src/ui/CreateChatPanel/CreateChatMemberInput.tsx +66 -0
- package/src/ui/CreateChatPanel/CreateChatNameInput.tsx +25 -0
- package/src/ui/CreateChatPanel/CreateChatPanel.tsx +33 -0
- package/src/ui/CreateChatPanel/index.ts +4 -0
- package/src/ui/Icon.tsx +33 -21
- package/src/ui/InputBox/InputBox.tsx +38 -0
- package/src/ui/InputBox/InputFilesBox.tsx +9 -0
- package/src/ui/InputBox/InputSubmitButtonBox.tsx +17 -0
- package/src/ui/InputBox/InputTextBox.tsx +50 -0
- package/src/ui/InputBox/index.ts +4 -0
- package/src/ui/Layout/Aside.tsx +10 -0
- package/src/ui/Layout/Body.tsx +10 -0
- package/src/ui/Layout/Footer.tsx +3 -0
- package/src/ui/Layout/Header.tsx +10 -0
- package/src/ui/Layout/Main.tsx +15 -0
- package/src/ui/Layout/index.ts +5 -0
- package/src/ui/Message/MessageAuthor.tsx +13 -0
- package/src/ui/Message/MessageBox.tsx +20 -0
- package/src/ui/Message/MessageContent.tsx +13 -0
- package/src/ui/Message/MessageInfoBox.tsx +25 -0
- package/src/ui/Message/MessageRow.tsx +24 -0
- package/src/ui/Message/MessageText.tsx +7 -0
- package/src/ui/Message/index.ts +6 -0
- package/src/ui/MessageReadObserver.tsx +45 -0
- package/src/ui/MessageSkeleton.tsx +19 -19
- package/src/ui/Next.tsx +48 -0
- package/src/ui/SendingMessage/SendingMessageBox.tsx +16 -0
- package/src/ui/SendingMessage/SendingMessageContent.tsx +13 -0
- package/src/ui/SendingMessage/SendingMessageInfoBox.tsx +13 -0
- package/src/ui/SendingMessage/SendingMessageText.tsx +7 -0
- package/src/ui/SendingMessage/index.ts +4 -0
- package/src/ui/SystemMessage/SystemMessageBox.tsx +20 -0
- package/src/ui/SystemMessage/SystemMessageRow.tsx +43 -0
- package/src/ui/SystemMessage/index.ts +2 -0
- package/src/{util → ui}/customize.tsx +45 -45
- package/src/ui/index.ts +11 -11
- package/src/ui/localizer.tsx +80 -68
- package/src/util/index.ts +2 -3
- package/src/util/uniqBy.tsx +17 -17
- package/src/util/uniqId.tsx +3 -3
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/types/ChatifyContext.d.ts +0 -11
- package/dist/cjs/types/core/action.d.ts +0 -76
- package/dist/cjs/types/core/client.d.ts +0 -35
- package/dist/cjs/types/core/index.d.ts +0 -14
- package/dist/cjs/types/core/models.d.ts +0 -64
- package/dist/cjs/types/core/reducer.d.ts +0 -11
- package/dist/cjs/types/core/state.d.ts +0 -25
- package/dist/cjs/types/core/useAccounts.d.ts +0 -1
- package/dist/cjs/types/core/useAddChat.d.ts +0 -2
- package/dist/cjs/types/core/useAddMember.d.ts +0 -2
- package/dist/cjs/types/core/useAddMessage.d.ts +0 -5
- package/dist/cjs/types/core/useChatList.d.ts +0 -1
- package/dist/cjs/types/core/useLoadMore.d.ts +0 -3
- package/dist/cjs/types/core/useMessages.d.ts +0 -15
- package/dist/cjs/types/core/useMutation.d.ts +0 -12
- package/dist/cjs/types/core/useQuery.d.ts +0 -7
- package/dist/cjs/types/core/useReadMonitor.d.ts +0 -1
- package/dist/cjs/types/core/useRemoveMember.d.ts +0 -2
- package/dist/cjs/types/core/useSignalRMonitor.d.ts +0 -2
- package/dist/cjs/types/index.d.ts +0 -3
- package/dist/cjs/types/ui/AddChat.d.ts +0 -1
- package/dist/cjs/types/ui/AddChatButton.d.ts +0 -2
- package/dist/cjs/types/ui/Aside.d.ts +0 -1
- package/dist/cjs/types/ui/Avatar.d.ts +0 -6
- package/dist/cjs/types/ui/Chat.d.ts +0 -4
- package/dist/cjs/types/ui/ChatBody.d.ts +0 -4
- package/dist/cjs/types/ui/ChatHeader.d.ts +0 -4
- package/dist/cjs/types/ui/ChatHeaderMembers.d.ts +0 -5
- package/dist/cjs/types/ui/ChatHeaderSettingsButton.d.ts +0 -5
- package/dist/cjs/types/ui/ChatListItem.d.ts +0 -11
- package/dist/cjs/types/ui/ChatName.d.ts +0 -5
- package/dist/cjs/types/ui/ChatSettings.d.ts +0 -1
- package/dist/cjs/types/ui/Chatify.d.ts +0 -49
- package/dist/cjs/types/ui/Footer.d.ts +0 -2
- package/dist/cjs/types/ui/Header.d.ts +0 -2
- package/dist/cjs/types/ui/Icon.d.ts +0 -7
- package/dist/cjs/types/ui/InputForm.d.ts +0 -1
- package/dist/cjs/types/ui/LoadMore.d.ts +0 -4
- package/dist/cjs/types/ui/Main.d.ts +0 -1
- package/dist/cjs/types/ui/Message.d.ts +0 -18
- package/dist/cjs/types/ui/MessageSkeleton.d.ts +0 -4
- package/dist/cjs/types/ui/SendingMessage.d.ts +0 -10
- package/dist/cjs/types/ui/SystemMessage.d.ts +0 -8
- package/dist/cjs/types/ui/index.d.ts +0 -11
- package/dist/cjs/types/ui/localizer.d.ts +0 -32
- package/dist/cjs/types/util/customize.d.ts +0 -12
- package/dist/cjs/types/util/index.d.ts +0 -3
- package/dist/cjs/types/util/uniqBy.d.ts +0 -1
- package/dist/cjs/types/util/uniqId.d.ts +0 -1
- package/dist/esm/types/core/useAccounts.d.ts +0 -1
- package/dist/esm/types/core/useAddChat.d.ts +0 -2
- package/dist/esm/types/core/useAddMember.d.ts +0 -2
- package/dist/esm/types/core/useAddMessage.d.ts +0 -5
- package/dist/esm/types/core/useChat.d.ts +0 -3
- package/dist/esm/types/core/useChatList.d.ts +0 -1
- package/dist/esm/types/core/useLoadMore.d.ts +0 -3
- package/dist/esm/types/core/useMessages.d.ts +0 -15
- package/dist/esm/types/core/useMutation.d.ts +0 -12
- package/dist/esm/types/core/useQuery.d.ts +0 -7
- package/dist/esm/types/core/useRemoveMember.d.ts +0 -2
- package/dist/esm/types/ui/AddChat.d.ts +0 -1
- package/dist/esm/types/ui/Aside.d.ts +0 -1
- package/dist/esm/types/ui/Chat.d.ts +0 -4
- package/dist/esm/types/ui/ChatBody.d.ts +0 -4
- package/dist/esm/types/ui/ChatHeader.d.ts +0 -4
- package/dist/esm/types/ui/ChatHeaderMembers.d.ts +0 -5
- package/dist/esm/types/ui/ChatHeaderSettingsButton.d.ts +0 -5
- package/dist/esm/types/ui/ChatListItem.d.ts +0 -11
- package/dist/esm/types/ui/ChatSettings.d.ts +0 -1
- package/dist/esm/types/ui/Footer.d.ts +0 -2
- package/dist/esm/types/ui/Header.d.ts +0 -2
- package/dist/esm/types/ui/InputForm.d.ts +0 -1
- package/dist/esm/types/ui/LoadMore.d.ts +0 -4
- package/dist/esm/types/ui/Main.d.ts +0 -1
- package/dist/esm/types/ui/Message.d.ts +0 -18
- package/dist/esm/types/ui/SendingMessage.d.ts +0 -10
- package/dist/esm/types/ui/SystemMessage.d.ts +0 -8
- package/src/core/useAccounts.tsx +0 -11
- package/src/core/useAddChat.tsx +0 -12
- package/src/core/useAddMember.tsx +0 -12
- package/src/core/useAddMessage.tsx +0 -40
- package/src/core/useChat.tsx +0 -12
- package/src/core/useChatList.tsx +0 -10
- package/src/core/useLoadMore.tsx +0 -42
- package/src/core/useMessages.tsx +0 -23
- package/src/core/useMutation.tsx +0 -48
- package/src/core/useQuery.tsx +0 -45
- package/src/core/useRemoveMember.tsx +0 -12
- package/src/ui/AddChat.tsx +0 -55
- package/src/ui/Aside.tsx +0 -41
- package/src/ui/Chat.tsx +0 -26
- package/src/ui/ChatBody.tsx +0 -43
- package/src/ui/ChatHeader.tsx +0 -33
- package/src/ui/ChatHeaderSettingsButton.tsx +0 -26
- package/src/ui/ChatListItem.tsx +0 -101
- package/src/ui/ChatSettings.tsx +0 -59
- package/src/ui/Footer.tsx +0 -7
- package/src/ui/Header.tsx +0 -14
- package/src/ui/InputForm.tsx +0 -51
- package/src/ui/LoadMore.tsx +0 -40
- package/src/ui/Main.tsx +0 -16
- package/src/ui/Message.tsx +0 -118
- package/src/ui/SendingMessage.tsx +0 -50
- package/src/ui/SystemMessage.tsx +0 -32
- package/src/ui/styles/index.scss +0 -248
package/src/core/action.tsx
CHANGED
|
@@ -1,319 +1,405 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { Account, ChatListItem, Message, ReadEvent } from './models';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
state:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
...
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
state.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
{
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
state
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
1
|
+
import type { State } from './state';
|
|
2
|
+
import { Account, Chat, ChatListItem, Message, ReadEvent, File } from './models';
|
|
3
|
+
|
|
4
|
+
export const ACTIONS = {
|
|
5
|
+
update: (state: State, { mutation }: { mutation: (state: State) => State }) => {
|
|
6
|
+
mutation(state);
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
messages_fetch: (state: State, { chatId }: { chatId: string }) => {
|
|
10
|
+
state.query.messages[chatId] = {
|
|
11
|
+
...state.query.messages[chatId],
|
|
12
|
+
uninitialized: false,
|
|
13
|
+
isFetching: true,
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
messages_fulfilled: (
|
|
18
|
+
state: State,
|
|
19
|
+
{ chatId, messages, hasMore }: { chatId: string; messages: Message[]; hasMore: boolean },
|
|
20
|
+
) => {
|
|
21
|
+
const qState = state.query.messages[chatId];
|
|
22
|
+
|
|
23
|
+
qState.error = undefined;
|
|
24
|
+
qState.isFetching = false;
|
|
25
|
+
qState.data = messages.map((x) => ({ type: 'message', ...x }));
|
|
26
|
+
|
|
27
|
+
if (hasMore) {
|
|
28
|
+
qState.data!.push({ type: 'next' });
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
messages_rejected: (state: State, { chatId, error }: { chatId: string; error: any }) => {
|
|
33
|
+
const qState = state.query.messages[chatId];
|
|
34
|
+
qState.error = error;
|
|
35
|
+
qState.isFetching = false;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
fetchNext_fetch: (state: State, { chatId }: { chatId: string }) => {
|
|
39
|
+
state.mutation.fetchNext = { isFetching: true };
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
fetchNext_fulfilled: (
|
|
43
|
+
state: State,
|
|
44
|
+
{ chatId, messages, hasMore }: { chatId: string; messages: Message[]; hasMore: boolean },
|
|
45
|
+
) => {
|
|
46
|
+
state.mutation.fetchNext = { isFetching: false, error: undefined };
|
|
47
|
+
state.query.messages[chatId].data = state.query.messages[chatId].data!.filter((x) => x.type !== 'next');
|
|
48
|
+
state.query.messages[chatId].data!.push(...messages.map((x) => ({ type: 'message' as const, ...x })));
|
|
49
|
+
|
|
50
|
+
if (hasMore) state.query.messages[chatId].data!.push({ type: 'next' });
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
fetchNext_rejected: (state: State, { chatId, error }: { chatId: string; error: any }) => {
|
|
54
|
+
state.mutation.fetchNext = { isFetching: false, error };
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
chatList_fetch: (state: State) => {
|
|
58
|
+
state.query.chatList.isFetching = true;
|
|
59
|
+
state.query.chatList.uninitialized = false;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
chatList_fulfilled: (state: State, { chats }: { chats: ChatListItem[] }) => {
|
|
63
|
+
chats = chats.sort((a, b) => -a.message.id.substring(47).localeCompare(b.message.id.substring(47)));
|
|
64
|
+
|
|
65
|
+
state.query.chatList.isFetching = false;
|
|
66
|
+
state.query.chatList.error = undefined;
|
|
67
|
+
state.query.chatList.data = chats;
|
|
68
|
+
|
|
69
|
+
if (state.ui.chatId === undefined && chats.length > 0) {
|
|
70
|
+
state.ui.view = 'chat';
|
|
71
|
+
state.ui.chatId = chats[0].id;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
chatList_rejected: (state: State, { error }: { error: any }) => {
|
|
76
|
+
state.query.chatList.isFetching = false;
|
|
77
|
+
state.query.chatList.error = error;
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
removeMember_fetch: (state: State) => {
|
|
81
|
+
state.mutation.removeMember = { isFetching: true };
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
removeMember_fulfilled: (state: State) => {
|
|
85
|
+
state.mutation.removeMember = { isFetching: false, error: undefined };
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
removeMember_rejected: (state: State, { error }: { error: any }) => {
|
|
89
|
+
state.mutation.removeMember = { isFetching: false, error };
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
addMember_fetch: (state: State) => {
|
|
93
|
+
state.mutation.addMember = { isFetching: true };
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
addMember_fulfilled: (state: State) => {
|
|
97
|
+
state.mutation.addMember = { isFetching: false, error: undefined };
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
addMember_rejected: (state: State, { error }: { error: any }) => {
|
|
101
|
+
state.mutation.addMember = { isFetching: false, error };
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
updateChatName_fetch: (state: State) => {
|
|
105
|
+
state.mutation.updateChatName = { isFetching: true };
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
updateChatName_fulfilled: (state: State) => {
|
|
109
|
+
state.mutation.updateChatName = { isFetching: false, error: undefined };
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
updateChatName_rejected: (state: State, { error }: { error: any }) => {
|
|
113
|
+
state.mutation.updateChatName = { isFetching: false, error };
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
addChat_fetch: (state: State) => {
|
|
117
|
+
state.mutation.addChat = { isFetching: true };
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
addChat_fulfilled: (state: State) => {
|
|
121
|
+
state.mutation.addChat = { isFetching: false, error: undefined };
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
addChat_rejected: (state: State, { error }: { error: any }) => {
|
|
125
|
+
state.mutation.addChat = { isFetching: false, error };
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
accounts_fetch: (state: State) => {
|
|
129
|
+
state.query.accounts = { isFetching: true, uninitialized: false };
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
accounts_fulfilled: (state: State, { accounts }: { accounts: Account[] }) => {
|
|
133
|
+
state.query.accounts.data = accounts;
|
|
134
|
+
state.query.accounts.isFetching = false;
|
|
135
|
+
state.query.accounts.error = undefined;
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
accounts_rejected: (state: State, { error }: { error: any }) => {
|
|
139
|
+
state.query.accounts.isFetching = false;
|
|
140
|
+
state.query.accounts.error = error;
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
chat_open: (state: State, { chatId }: { chatId: string }) => {
|
|
144
|
+
state.ui.chatId = chatId;
|
|
145
|
+
state.ui.view = 'chat';
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
new_chat_open: (state: State) => {
|
|
149
|
+
state.ui.chatId = undefined;
|
|
150
|
+
state.ui.view = 'new-chat';
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
toggle_members_view: (state: State) => {
|
|
154
|
+
state.ui.showMembers = !state.ui.showMembers;
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
message_received: (
|
|
158
|
+
state: State,
|
|
159
|
+
{ message, requestId, me }: { message: Message; requestId: string; me: string },
|
|
160
|
+
) => {
|
|
161
|
+
const messagesState = state.query.messages[message.chatId];
|
|
162
|
+
|
|
163
|
+
if (messagesState?.data) {
|
|
164
|
+
messagesState.data.unshift({ type: 'message', ...message });
|
|
165
|
+
messagesState.data = messagesState.data.filter(
|
|
166
|
+
(x) => x.type !== 'sending' || x.requestId !== requestId,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const chatListItemState = state.query.chatList?.data?.find((x) => x.id === message.chatId);
|
|
171
|
+
|
|
172
|
+
if (chatListItemState) {
|
|
173
|
+
chatListItemState.message = message;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (chatListItemState && message.sentBy.id !== me) {
|
|
177
|
+
chatListItemState.totalUnreadCount++;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (chatListItemState && message.sentBy.id === me) {
|
|
181
|
+
chatListItemState.lastReadMessageId = message.id;
|
|
182
|
+
chatListItemState.totalUnreadCount = 0;
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
chat_created: (state: State, { chat }: { chat: ChatListItem; requestId?: string }) => {
|
|
187
|
+
state.query.chatList?.data?.unshift(chat);
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
read: (state: State, { id, timestamp }: { id: string; timestamp: number }) => {
|
|
191
|
+
const queuedSameChat = state.queue.read.queued.filter((x) => x.substring(0, 36) === id.substring(0, 36));
|
|
192
|
+
|
|
193
|
+
if (queuedSameChat.some((x) => x.localeCompare(id) >= 0)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
state.queue.read.queued.filter((x) => queuedSameChat.includes(x));
|
|
198
|
+
state.queue.read.queued.push(id);
|
|
199
|
+
state.queue.read.timestamp = timestamp;
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
read_send: (state: State, { id }: { id: string }) => {
|
|
203
|
+
state.queue.read.queued = state.queue.read.queued.filter((x) => x !== id);
|
|
204
|
+
state.queue.read.processing.push(id);
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
read_reject: (state: State, { id, timestamp }: { id: string; timestamp: number }) => {
|
|
208
|
+
state.queue.read.queued.push(id);
|
|
209
|
+
state.queue.read.processing = state.queue.read.processing.filter((x) => x !== id);
|
|
210
|
+
state.queue.read.timestamp = timestamp;
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
read_received: (state: State, { events }: { events: ReadEvent[] }) => {
|
|
214
|
+
state.queue.read.processing = state.queue.read.processing.filter((item) => {
|
|
215
|
+
const event = events.find((x) => x.chatId === item.substring(0, 36));
|
|
216
|
+
return !event || event.newLastReadMessageId.localeCompare(item) >= 0;
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
for (const event of events) {
|
|
220
|
+
state.queue.read.processing = state.queue.read.processing.filter(
|
|
221
|
+
(x) => x.substring(0, 36) !== event.chatId || x.localeCompare(event.newLastReadMessageId) > 0,
|
|
222
|
+
);
|
|
223
|
+
const chatListItem = state.query.chatList.data?.find((x) => x.id === event.chatId);
|
|
224
|
+
|
|
225
|
+
if (chatListItem) {
|
|
226
|
+
chatListItem.lastReadMessageId = event.newLastReadMessageId;
|
|
227
|
+
chatListItem.totalUnreadCount = chatListItem.totalUnreadCount - event.readCount;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
member_added: (
|
|
233
|
+
state: State,
|
|
234
|
+
{
|
|
235
|
+
chatId,
|
|
236
|
+
chatName,
|
|
237
|
+
account,
|
|
238
|
+
me,
|
|
239
|
+
message,
|
|
240
|
+
withHistory,
|
|
241
|
+
}: {
|
|
242
|
+
chatId: string;
|
|
243
|
+
chatName: string;
|
|
244
|
+
account: Account;
|
|
245
|
+
me: string;
|
|
246
|
+
message: Message;
|
|
247
|
+
withHistory: boolean;
|
|
248
|
+
},
|
|
249
|
+
) => {
|
|
250
|
+
const { chats, messages, chatList } = state.query;
|
|
251
|
+
chats[chatId]?.data?.members.push(account);
|
|
252
|
+
const chatListItem = chatList?.data?.find((x) => x.id === chatId);
|
|
253
|
+
|
|
254
|
+
if (account.id !== me && chatListItem != null) {
|
|
255
|
+
chatListItem.message = message;
|
|
256
|
+
chatListItem.totalUnreadCount++;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
messages[chatId]?.data?.unshift({ type: 'message', ...message });
|
|
260
|
+
|
|
261
|
+
if (account.id === me && chatList.data !== undefined && !chatListItem) {
|
|
262
|
+
chatList.data.unshift({
|
|
263
|
+
id: chatId,
|
|
264
|
+
name: chatName,
|
|
265
|
+
message,
|
|
266
|
+
totalUnreadCount: 1,
|
|
267
|
+
active: true,
|
|
268
|
+
lastReadMessageId: null,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (account.id === me && chatListItem) {
|
|
273
|
+
chatListItem.active = true;
|
|
274
|
+
chatListItem.message = message;
|
|
275
|
+
chatListItem.totalUnreadCount++;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return state;
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
member_removed: (
|
|
282
|
+
state: State,
|
|
283
|
+
{
|
|
284
|
+
chatId,
|
|
285
|
+
accountId,
|
|
286
|
+
deleteHistory,
|
|
287
|
+
me,
|
|
288
|
+
message,
|
|
289
|
+
}: { chatId: string; accountId: string; deleteHistory: boolean; me: string; message: Message },
|
|
290
|
+
) => {
|
|
291
|
+
const { chats, chatList } = state.query;
|
|
292
|
+
const chat = chats[chatId];
|
|
293
|
+
|
|
294
|
+
if (chat?.data) {
|
|
295
|
+
chat.data.members = chat.data.members.filter((x) => x.id !== accountId);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (accountId === me && state.query.chats[chatId].data) {
|
|
299
|
+
delete state.query.chats[chatId];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (accountId === me && deleteHistory && chatList?.data) {
|
|
303
|
+
chatList.data = chatList.data.filter((x) => x.id !== chatId);
|
|
304
|
+
|
|
305
|
+
if (state.ui.chatId === chatId) {
|
|
306
|
+
state.ui.chatId = chatList.data.at(0)?.id;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (accountId === me && !deleteHistory && chatList?.data) {
|
|
311
|
+
const listItem = chatList.data.find((x) => x.id === chatId)!;
|
|
312
|
+
listItem.active = false;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if ((accountId !== me || !deleteHistory) && state.query.messages[chatId].data) {
|
|
316
|
+
state.query.messages[chatId].data!.unshift({ ...message, type: 'message' });
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if ((accountId !== me || !deleteHistory) && state.query.chatList.data) {
|
|
320
|
+
const listItem = state.query.chatList.data.find((x) => x.id === chatId)!;
|
|
321
|
+
listItem.message = message;
|
|
322
|
+
listItem.totalUnreadCount++;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (accountId === me && deleteHistory && state.query.messages[chatId].data) {
|
|
326
|
+
delete state.query.messages[chatId];
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
chat_fetch: (state: State, { chatId }: { chatId: string }) => {
|
|
331
|
+
state.query.chats[chatId] = { isFetching: true, uninitialized: false, data: undefined, error: undefined };
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
chat_fulfilled: (state: State, { chat }: { chat: Chat }) => {
|
|
335
|
+
const chatState = state.query.chats[chat.id];
|
|
336
|
+
chatState.isFetching = false;
|
|
337
|
+
chatState.error = undefined;
|
|
338
|
+
chatState.data = chat;
|
|
339
|
+
},
|
|
340
|
+
|
|
341
|
+
chat_rejected: (state: State, { chatId, error }: { chatId: string; error: any }) => {
|
|
342
|
+
const chatState = state.query.chats[chatId];
|
|
343
|
+
chatState.isFetching = false;
|
|
344
|
+
chatState.error = error;
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
send_fetch: (
|
|
348
|
+
state: State,
|
|
349
|
+
{
|
|
350
|
+
chatId,
|
|
351
|
+
text,
|
|
352
|
+
files,
|
|
353
|
+
requestId,
|
|
354
|
+
}: {
|
|
355
|
+
chatId: string;
|
|
356
|
+
text: string;
|
|
357
|
+
files: File[];
|
|
358
|
+
requestId: string;
|
|
359
|
+
},
|
|
360
|
+
) => {
|
|
361
|
+
state.mutation.send = { isFetching: true, error: undefined };
|
|
362
|
+
state.query.messages[chatId].data?.push({ type: 'sending', text, files, requestId });
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
send_fulfilled: (state: State, { chatId, requestId }: { chatId: string; requestId: string }) => {
|
|
366
|
+
state.mutation.send = { isFetching: false, error: undefined };
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
send_rejected: (
|
|
370
|
+
state: State,
|
|
371
|
+
{ chatId, requestId, error }: { chatId: string; requestId: string; error: any },
|
|
372
|
+
) => {
|
|
373
|
+
state.mutation.send = { isFetching: false, error };
|
|
374
|
+
state.query.messages[chatId].data = state.query.messages[chatId].data?.filter(
|
|
375
|
+
(x) => x.type !== 'sending' || x.requestId !== requestId,
|
|
376
|
+
);
|
|
377
|
+
},
|
|
378
|
+
|
|
379
|
+
chatNameChanged_received: (
|
|
380
|
+
state: State,
|
|
381
|
+
{ chatId, newName, message }: { chatId: string; newName: string; message: Message },
|
|
382
|
+
) => {
|
|
383
|
+
if (state.query.chatList.data) {
|
|
384
|
+
const chatListItem = state.query.chatList.data.find((x) => x.id === chatId);
|
|
385
|
+
chatListItem!.name = newName;
|
|
386
|
+
chatListItem!.message = message;
|
|
387
|
+
chatListItem!.totalUnreadCount++;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (state.query.chats[chatId].data) {
|
|
391
|
+
state.query.chats[chatId].data!.name = newName;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (state.query.messages[chatId].data) {
|
|
395
|
+
state.query.messages[chatId].data!.unshift({ type: 'message', ...message });
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
export type Action = {
|
|
401
|
+
[K in keyof typeof ACTIONS]: {
|
|
402
|
+
type: K;
|
|
403
|
+
data: Parameters<(typeof ACTIONS)[K]>[1];
|
|
404
|
+
};
|
|
405
|
+
}[keyof typeof ACTIONS];
|