@webinex/chatify 2.0.0-build10 → 2.0.0-build3

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 (118) hide show
  1. package/dist/esm/index.js +2 -2
  2. package/dist/esm/index.js.map +1 -1
  3. package/dist/esm/types/core/api/accountApi.d.ts +2 -3
  4. package/dist/esm/types/core/api/api.d.ts +1752 -1592
  5. package/dist/esm/types/core/api/baseApi.d.ts +1 -5
  6. package/dist/esm/types/core/api/chatApi.d.ts +0 -2
  7. package/dist/esm/types/core/api/chatListApi.d.ts +3 -3
  8. package/dist/esm/types/core/api/chatMemberApi.d.ts +2 -3
  9. package/dist/esm/types/core/api/chatMessageApi.d.ts +22 -3
  10. package/dist/esm/types/core/api/threadApi.d.ts +87 -1
  11. package/dist/esm/types/core/api/threadMessageApi.d.ts +15 -2
  12. package/dist/index.d.ts +1760 -1588
  13. package/package.json +6 -5
  14. package/src/core/api/accountApi.ts +5 -5
  15. package/src/core/api/api.ts +42 -642
  16. package/src/core/api/baseApi.ts +1 -4
  17. package/src/core/api/chatApi.ts +1 -5
  18. package/src/core/api/chatListApi.ts +18 -5
  19. package/src/core/api/chatMemberApi.ts +5 -5
  20. package/src/core/api/chatMessageApi.ts +139 -4
  21. package/src/core/api/threadApi.ts +117 -1
  22. package/src/core/api/threadMessageApi.ts +99 -1
  23. package/src/ui/Conversation/NextObserver/NextMessagesObserver.tsx +2 -2
  24. package/src/types/core/api/accountApi.d.ts +0 -5
  25. package/src/types/core/api/api.d.ts +0 -2380
  26. package/src/types/core/api/baseApi.d.ts +0 -15
  27. package/src/types/core/api/chatApi.d.ts +0 -16
  28. package/src/types/core/api/chatListApi.d.ts +0 -5
  29. package/src/types/core/api/chatMemberApi.d.ts +0 -6
  30. package/src/types/core/api/chatMessageApi.d.ts +0 -3
  31. package/src/types/core/api/index.d.ts +0 -1
  32. package/src/types/core/api/threadApi.d.ts +0 -1
  33. package/src/types/core/api/threadMessageApi.d.ts +0 -6
  34. package/src/types/core/client.d.ts +0 -83
  35. package/src/types/core/constants.d.ts +0 -1
  36. package/src/types/core/debounce.d.ts +0 -27
  37. package/src/types/core/index.d.ts +0 -4
  38. package/src/types/core/types.d.ts +0 -105
  39. package/src/types/index.d.ts +0 -2
  40. package/src/types/ui/Chat/ChatContext.d.ts +0 -10
  41. package/src/types/ui/Chat/ChatEditableHeaderName.d.ts +0 -2
  42. package/src/types/ui/Chat/ChatHeaderActions.d.ts +0 -2
  43. package/src/types/ui/Chat/ChatPanel.d.ts +0 -13
  44. package/src/types/ui/Chat/ChatView.d.ts +0 -17
  45. package/src/types/ui/Chat/Members/ChatMembersButton.d.ts +0 -2
  46. package/src/types/ui/Chat/Members/ChatMembersPanel.d.ts +0 -2
  47. package/src/types/ui/Chat/Members/ChatMembersPreview.d.ts +0 -2
  48. package/src/types/ui/Chat/Members/index.d.ts +0 -11
  49. package/src/types/ui/Chat/index.d.ts +0 -6
  50. package/src/types/ui/ChatGroup/ChatGroupContext.d.ts +0 -12
  51. package/src/types/ui/ChatGroup/ChatGroupPanel.d.ts +0 -15
  52. package/src/types/ui/ChatGroup/Create/CreateChatButton.d.ts +0 -2
  53. package/src/types/ui/ChatGroup/Create/CreateChatForm.d.ts +0 -11
  54. package/src/types/ui/ChatGroup/Create/CreateChatMemberInput.d.ts +0 -5
  55. package/src/types/ui/ChatGroup/Create/CreateChatNameInput.d.ts +0 -5
  56. package/src/types/ui/ChatGroup/Create/CreateChatPanel.d.ts +0 -2
  57. package/src/types/ui/ChatGroup/Create/index.d.ts +0 -17
  58. package/src/types/ui/ChatGroup/Layout/ChatGroupAside.d.ts +0 -2
  59. package/src/types/ui/ChatGroup/Layout/ChatGroupBody.d.ts +0 -2
  60. package/src/types/ui/ChatGroup/Layout/ChatGroupFooter.d.ts +0 -2
  61. package/src/types/ui/ChatGroup/Layout/ChatGroupHeader.d.ts +0 -2
  62. package/src/types/ui/ChatGroup/Layout/ChatGroupMain.d.ts +0 -2
  63. package/src/types/ui/ChatGroup/Layout/index.d.ts +0 -17
  64. package/src/types/ui/ChatGroup/List/ChatList.d.ts +0 -2
  65. package/src/types/ui/ChatGroup/List/ChatListItemAvatar.d.ts +0 -3
  66. package/src/types/ui/ChatGroup/List/ChatListItemBox.d.ts +0 -6
  67. package/src/types/ui/ChatGroup/List/ChatListItemLastMessage.d.ts +0 -3
  68. package/src/types/ui/ChatGroup/List/ChatListItemLastMessageAuthor.d.ts +0 -3
  69. package/src/types/ui/ChatGroup/List/ChatListItemLastMessageContent.d.ts +0 -3
  70. package/src/types/ui/ChatGroup/List/ChatListItemLastMessageSentAt.d.ts +0 -3
  71. package/src/types/ui/ChatGroup/List/ChatListItemName.d.ts +0 -3
  72. package/src/types/ui/ChatGroup/List/ChatListItemUnreadCount.d.ts +0 -3
  73. package/src/types/ui/ChatGroup/List/index.d.ts +0 -29
  74. package/src/types/ui/ChatGroup/index.d.ts +0 -5
  75. package/src/types/ui/Chatify.d.ts +0 -8
  76. package/src/types/ui/Conversation/Conversation.d.ts +0 -21
  77. package/src/types/ui/Conversation/ConversationActions.d.ts +0 -2
  78. package/src/types/ui/Conversation/ConversationBody.d.ts +0 -2
  79. package/src/types/ui/Conversation/ConversationContext.d.ts +0 -20
  80. package/src/types/ui/Conversation/ConversationHeader.d.ts +0 -2
  81. package/src/types/ui/Conversation/ConversationName.d.ts +0 -2
  82. package/src/types/ui/Conversation/InputBox/InputBox.d.ts +0 -2
  83. package/src/types/ui/Conversation/InputBox/InputFilesBox.d.ts +0 -2
  84. package/src/types/ui/Conversation/InputBox/InputSubmitButtonBox.d.ts +0 -5
  85. package/src/types/ui/Conversation/InputBox/InputTextBox.d.ts +0 -8
  86. package/src/types/ui/Conversation/InputBox/index.d.ts +0 -14
  87. package/src/types/ui/Conversation/Message/MessageAuthor.d.ts +0 -3
  88. package/src/types/ui/Conversation/Message/MessageBox.d.ts +0 -6
  89. package/src/types/ui/Conversation/Message/MessageContent.d.ts +0 -3
  90. package/src/types/ui/Conversation/Message/MessageInfoBox.d.ts +0 -3
  91. package/src/types/ui/Conversation/Message/MessageRow.d.ts +0 -6
  92. package/src/types/ui/Conversation/Message/MessageText.d.ts +0 -3
  93. package/src/types/ui/Conversation/Message/index.d.ts +0 -20
  94. package/src/types/ui/Conversation/NextObserver/NextMessagesObserver.d.ts +0 -5
  95. package/src/types/ui/Conversation/NextObserver/index.d.ts +0 -1
  96. package/src/types/ui/Conversation/ReadObserver/MessageReadObserver.d.ts +0 -6
  97. package/src/types/ui/Conversation/ReadObserver/index.d.ts +0 -1
  98. package/src/types/ui/Conversation/SendingMessage/SendingMessageBox.d.ts +0 -7
  99. package/src/types/ui/Conversation/SendingMessage/SendingMessageContent.d.ts +0 -3
  100. package/src/types/ui/Conversation/SendingMessage/SendingMessageInfoBox.d.ts +0 -3
  101. package/src/types/ui/Conversation/SendingMessage/SendingMessageText.d.ts +0 -3
  102. package/src/types/ui/Conversation/SendingMessage/index.d.ts +0 -14
  103. package/src/types/ui/Conversation/SystemMessage/SystemMessageBox.d.ts +0 -6
  104. package/src/types/ui/Conversation/SystemMessage/SystemMessageRow.d.ts +0 -9
  105. package/src/types/ui/Conversation/SystemMessage/index.d.ts +0 -8
  106. package/src/types/ui/Conversation/index.d.ts +0 -12
  107. package/src/types/ui/Thread/ThreadActions.d.ts +0 -2
  108. package/src/types/ui/Thread/ThreadContext.d.ts +0 -8
  109. package/src/types/ui/Thread/ThreadPanel.d.ts +0 -14
  110. package/src/types/ui/Thread/index.d.ts +0 -3
  111. package/src/types/ui/color.d.ts +0 -6
  112. package/src/types/ui/common/Avatar.d.ts +0 -6
  113. package/src/types/ui/common/Icon.d.ts +0 -20
  114. package/src/types/ui/common/MessageSkeleton.d.ts +0 -5
  115. package/src/types/ui/common/index.d.ts +0 -11
  116. package/src/types/ui/customize.d.ts +0 -9
  117. package/src/types/ui/index.d.ts +0 -11
  118. package/src/types/ui/localizer.d.ts +0 -35
@@ -1,11 +1,7 @@
1
- import { BaseApiEndpointBuilder, __baseApi, __settings } from './baseApi';
1
+ import { __baseApi, __settings } from './baseApi';
2
2
  import { unsubscribe } from '../client';
3
3
  import { Chat } from '../types';
4
4
 
5
- export function chatEndpoints(builder: BaseApiEndpointBuilder) {
6
- return {};
7
- }
8
-
9
5
  const chatApi = __baseApi.injectEndpoints({
10
6
  endpoints: (builder) => ({
11
7
  getChat: builder.query<Chat, { id: string }>({
@@ -1,13 +1,14 @@
1
- import { BaseApiEndpointBuilder, __settings } from './baseApi';
1
+ import { __baseApi, __settings } from './baseApi';
2
2
  import { unsubscribe } from '../client';
3
3
  import { ChatListItem } from '../types';
4
+ import { useSelector } from 'react-redux';
4
5
 
5
- export function chatListEndpoints(builder: BaseApiEndpointBuilder) {
6
- return {
6
+ const chatListApi = __baseApi.injectEndpoints({
7
+ endpoints: (builder) => ({
7
8
  getChatList: builder.query<ChatListItem[], void>({
8
9
  queryFn: async () => ({ data: await __settings.client.chats() }),
9
10
  providesTags: ['chat', 'account'],
10
- onCacheEntryAdded: async (_, { cacheEntryRemoved, cacheDataLoaded, updateCachedData }) => {
11
+ onCacheEntryAdded: async (_, { dispatch, cacheEntryRemoved, cacheDataLoaded, updateCachedData }) => {
11
12
  await cacheDataLoaded;
12
13
 
13
14
  unsubscribe(
@@ -130,5 +131,17 @@ export function chatListEndpoints(builder: BaseApiEndpointBuilder) {
130
131
  ).when(cacheEntryRemoved);
131
132
  },
132
133
  }),
133
- };
134
+ }),
135
+ });
136
+
137
+ export function useChatListItem(id: string | null) {
138
+ return useSelector((state: any) =>
139
+ id != null
140
+ ? chatListApi.endpoints.getChatList
141
+ .select()(state)
142
+ .data?.find((x) => x.id === id)
143
+ : null,
144
+ );
134
145
  }
146
+
147
+ export const __chatListApi = chatListApi;
@@ -1,8 +1,8 @@
1
1
  import { AddChatMemberRequest, RemoveChatMemberRequest } from '../types';
2
- import { BaseApiEndpointBuilder, __settings } from './baseApi';
2
+ import { __baseApi, __settings } from './baseApi';
3
3
 
4
- export function chatMemberEndpoints(builder: BaseApiEndpointBuilder) {
5
- return {
4
+ export const __chatMemberApi = __baseApi.injectEndpoints({
5
+ endpoints: (builder) => ({
6
6
  removeChatMember: builder.mutation<void, RemoveChatMemberRequest>({
7
7
  queryFn: async (args) => {
8
8
  await __settings.client.removeChatMember(args);
@@ -16,5 +16,5 @@ export function chatMemberEndpoints(builder: BaseApiEndpointBuilder) {
16
16
  return { data: null! };
17
17
  },
18
18
  }),
19
- };
20
- }
19
+ }),
20
+ });
@@ -1,12 +1,147 @@
1
1
  import { unsubscribe } from '../client';
2
2
  import { Debounce, DebounceValue } from '../debounce';
3
3
  import { ChatMessage, chatId } from '../types';
4
- import { BaseApiEndpointBuilder, DEFAULT_MESSAGE_LIST_TAKE, __baseApi, __settings } from './baseApi';
4
+ import { DEFAULT_MESSAGE_LIST_TAKE, __baseApi, __settings } from './baseApi';
5
5
 
6
- export function chatMessageEndpoints(builder: BaseApiEndpointBuilder) {
7
- return {};
6
+ export interface ChatMessageListResult {
7
+ messages: ChatMessage[];
8
+ hasMore: boolean;
8
9
  }
9
10
 
11
+ const CHAT_MESSAGE_READ_QUEUE = new Debounce<string>({
12
+ callback: (id) => __settings.client.readChatMessage({ id }),
13
+ compare: (a, b) => -a.localeCompare(b),
14
+ groupBy: (id) => chatId(id),
15
+ timeout: 500,
16
+ });
17
+
10
18
  export const __chatMessageApi = __baseApi.injectEndpoints({
11
- endpoints: (builder) => ({}),
19
+ endpoints: (builder) => ({
20
+ getChatMessageList: builder.query<ChatMessageListResult, { chatId: string }>({
21
+ queryFn: async ({ chatId }) => {
22
+ const messages = await __settings.client.chatMessages({
23
+ chatId,
24
+ skip: 0,
25
+ take: DEFAULT_MESSAGE_LIST_TAKE + 1,
26
+ });
27
+ return {
28
+ data: {
29
+ messages: messages.slice(0, DEFAULT_MESSAGE_LIST_TAKE),
30
+ hasMore: messages.length === DEFAULT_MESSAGE_LIST_TAKE + 1,
31
+ },
32
+ };
33
+ },
34
+ providesTags: ['message', 'chat', 'account'],
35
+ onCacheEntryAdded: async ({ chatId }, { dispatch, cacheEntryRemoved, cacheDataLoaded }) => {
36
+ await cacheDataLoaded;
37
+
38
+ unsubscribe(
39
+ __settings.client.subscribe('chatify://chat-new-message', ([message]) => {
40
+ message.chatId === chatId &&
41
+ dispatch(
42
+ __chatMessageApi.util.updateQueryData('getChatMessageList', { chatId }, (draft) => {
43
+ draft.messages.unshift(message);
44
+ }),
45
+ );
46
+ }),
47
+
48
+ __settings.client.subscribe('chatify://chat-member-added', ([eventChatId, , , message]) => {
49
+ eventChatId === chatId &&
50
+ dispatch(
51
+ __chatMessageApi.util.updateQueryData('getChatMessageList', { chatId }, (draft) => {
52
+ draft.messages.unshift(message);
53
+ }),
54
+ );
55
+ }),
56
+
57
+ __settings.client.subscribe('chatify://chat-member-removed', ([eventChatId, , , message]) => {
58
+ eventChatId === chatId &&
59
+ dispatch(
60
+ __chatMessageApi.util.updateQueryData('getChatMessageList', { chatId }, (draft) => {
61
+ draft.messages.unshift(message);
62
+ }),
63
+ );
64
+ }),
65
+
66
+ __settings.client.subscribe('chatify://chat-name-changed', ([eventChatId, , message]) => {
67
+ eventChatId === chatId &&
68
+ dispatch(
69
+ __chatMessageApi.util.updateQueryData('getChatMessageList', { chatId }, (draft) => {
70
+ draft.messages.unshift(message);
71
+ }),
72
+ );
73
+ }),
74
+ ).when(cacheEntryRemoved);
75
+ },
76
+ }),
77
+
78
+ fetchNextChatMessageList: builder.mutation<void, { chatId: string }>({
79
+ queryFn: async ({ chatId }, { getState }) => {
80
+ const current = __chatMessageApi.endpoints.getChatMessageList.select({ chatId })(getState() as any);
81
+ const messages = await __settings.client.chatMessages({
82
+ chatId,
83
+ skip: current.data!.messages.length,
84
+ take: DEFAULT_MESSAGE_LIST_TAKE + 1,
85
+ });
86
+ return {
87
+ data: null!,
88
+ meta: {
89
+ messages: messages.slice(0, DEFAULT_MESSAGE_LIST_TAKE),
90
+ hasMore: messages.length === DEFAULT_MESSAGE_LIST_TAKE + 1,
91
+ },
92
+ };
93
+ },
94
+ onQueryStarted: async ({ chatId }, { dispatch, queryFulfilled }) => {
95
+ const result = await queryFulfilled;
96
+ const meta: ChatMessageListResult = result.meta! as any;
97
+
98
+ dispatch(
99
+ __chatMessageApi.util.updateQueryData('getChatMessageList', { chatId }, (draft) => {
100
+ draft.hasMore = meta.hasMore;
101
+ draft.messages.push(...meta!.messages);
102
+ }),
103
+ );
104
+ },
105
+ }),
106
+
107
+ sendChatMessage: builder.mutation<void, { chatId: string; text: string }>({
108
+ queryFn: async ({ chatId, text }) => {
109
+ const requestId = new Date().getTime().toString();
110
+
111
+ await __settings.client.sendChatMessage({
112
+ chatId,
113
+ text,
114
+ files: [],
115
+ requestId,
116
+ });
117
+
118
+ return { data: null!, meta: { requestId } };
119
+ },
120
+ }),
121
+
122
+ readChatMessage: builder.mutation<void, { id: string }>({
123
+ queryFn: async () => {
124
+ return { data: null! };
125
+ },
126
+ onQueryStarted: async ({ id }, { dispatch }) => {
127
+ CHAT_MESSAGE_READ_QUEUE.push(id);
128
+ dispatch(
129
+ __chatMessageApi.endpoints.getChatMessageReadQueue.initiate(undefined, { forceRefetch: true }),
130
+ );
131
+ },
132
+ }),
133
+
134
+ getChatMessageReadQueue: builder.query<DebounceValue<string>[], void>({
135
+ queryFn: async () => ({ data: CHAT_MESSAGE_READ_QUEUE.units }),
136
+ onCacheEntryAdded: async (_, { dispatch, cacheEntryRemoved }) => {
137
+ unsubscribe(
138
+ CHAT_MESSAGE_READ_QUEUE.subscribe((value) => {
139
+ dispatch(
140
+ __chatMessageApi.util.updateQueryData('getChatMessageReadQueue', undefined, () => value.units),
141
+ );
142
+ }),
143
+ ).when(cacheEntryRemoved);
144
+ },
145
+ }),
146
+ }),
12
147
  });
@@ -4,5 +4,121 @@ import { unsubscribe } from '../client';
4
4
  import { useMemo } from 'react';
5
5
 
6
6
  export const __threadApi = __baseApi.injectEndpoints({
7
- endpoints: (builder) => ({}),
7
+ endpoints: (builder) => ({
8
+ getWatchThreadList: builder.query<ThreadWatchListItem[], void>({
9
+ queryFn: async () => {
10
+ const threads = await __settings.client.watchThreads();
11
+ return { data: threads };
12
+ },
13
+ providesTags: ['account', 'thread'],
14
+ onCacheEntryAdded: async (_, { dispatch, cacheEntryRemoved, cacheDataLoaded, updateCachedData }) => {
15
+ await cacheDataLoaded;
16
+
17
+ unsubscribe(
18
+ __settings.client.subscribe(
19
+ 'chatify://thread-created',
20
+ ([thread, watch]) =>
21
+ watch &&
22
+ updateCachedData((threads) => {
23
+ threads.push(thread);
24
+ }),
25
+ ),
26
+ __settings.client.subscribe('chatify://thread-message-new', ([threadId, message, readForId]) =>
27
+ updateCachedData((threads) => {
28
+ const thread = threads.find((x) => x.id === threadId);
29
+ if (!thread) return;
30
+
31
+ thread.lastMessage = message;
32
+
33
+ if (readForId === __settings.me()) {
34
+ thread.lastReadMessageId = message.id;
35
+ }
36
+ }),
37
+ ),
38
+ __settings.client.subscribe('chatify://thread-message-read', ([threadId, messageId]) =>
39
+ updateCachedData((threads) => {
40
+ const thread = threads.find((x) => x.id === threadId);
41
+ if (!thread) return;
42
+
43
+ thread.lastReadMessageId = messageId;
44
+ }),
45
+ ),
46
+ __settings.client.subscribe('chatify://thread-watch-added', ([thread]) =>
47
+ updateCachedData((threads) => {
48
+ threads.push(thread);
49
+ }),
50
+ ),
51
+ __settings.client.subscribe('chatify://thread-watch-removed', ([id]) =>
52
+ updateCachedData((threads) => {
53
+ const index = threads.findIndex((x) => x.id === id);
54
+ if (index !== -1) threads.splice(index, 1);
55
+ }),
56
+ ),
57
+ ).when(cacheEntryRemoved);
58
+ },
59
+ }),
60
+
61
+ getThread: builder.query<Thread, { id: string }>({
62
+ queryFn: async ({ id }) => {
63
+ const threads = await __settings.client.thread(id);
64
+ return { data: threads };
65
+ },
66
+ providesTags: ['account', 'thread'],
67
+ onCacheEntryAdded: async ({ id }, { cacheEntryRemoved, cacheDataLoaded, updateCachedData }) => {
68
+ await cacheDataLoaded;
69
+
70
+ unsubscribe(
71
+ __settings.client.subscribe(
72
+ 'chatify://thread-message-read',
73
+ ([threadId, messageId]) =>
74
+ id === threadId &&
75
+ updateCachedData((t) => {
76
+ t.lastReadMessageId = messageId;
77
+ }),
78
+ ),
79
+ __settings.client.subscribe(
80
+ 'chatify://thread-message-new',
81
+ ([threadId, message, readForId]) =>
82
+ id === threadId &&
83
+ updateCachedData((thread) => {
84
+ thread.lastMessageId = message.id;
85
+ thread.lastReadMessageId =
86
+ readForId === __settings.me() ? message.id : thread.lastReadMessageId;
87
+ }),
88
+ ),
89
+ __settings.client.subscribe(
90
+ 'chatify://thread-watch-added',
91
+ ([threadListItem]) =>
92
+ id === threadListItem.id &&
93
+ updateCachedData((thread) => {
94
+ thread.watch = true;
95
+ thread.lastMessageId = threadListItem.lastMessage?.id ?? null;
96
+ thread.lastReadMessageId = threadListItem.lastReadMessageId ?? null;
97
+ }),
98
+ ),
99
+ __settings.client.subscribe(
100
+ 'chatify://thread-watch-removed',
101
+ ([threadId]) =>
102
+ id === threadId &&
103
+ updateCachedData((thread) => {
104
+ thread.watch = false;
105
+ }),
106
+ ),
107
+ ).when(cacheEntryRemoved);
108
+ },
109
+ }),
110
+
111
+ watchThread: builder.mutation<void, { id: string; watch: boolean }>({
112
+ queryFn: async ({ id, watch }) => {
113
+ await __settings.client.watchThread(id, watch);
114
+ return { data: null! };
115
+ },
116
+ }),
117
+ }),
8
118
  });
119
+
120
+ export function useUnreadThreadMessageCount() {
121
+ const { data: threads, ...state } = __threadApi.useGetWatchThreadListQuery();
122
+ const count = useMemo(() => (threads != null ? calcThreadListUnreadCount(threads) : null), [threads]);
123
+ return [count, state] as const;
124
+ }
@@ -16,5 +16,103 @@ const THREAD_MESSAGE_READ_QUEUE = new Debounce<string>({
16
16
  });
17
17
 
18
18
  export const __threadMessageApi = __baseApi.injectEndpoints({
19
- endpoints: (builder) => ({}),
19
+ endpoints: (builder) => ({
20
+ getThreadMessageList: builder.query<ThreadMessageList, { threadId: string }>({
21
+ queryFn: async (args) => {
22
+ const requestArgs = {
23
+ skip: 0,
24
+ take: DEFAULT_MESSAGE_LIST_TAKE + 1,
25
+ ...args,
26
+ };
27
+ const messages = await __settings.client.threadMessages(requestArgs);
28
+ return {
29
+ data: {
30
+ messages: messages.slice(0, DEFAULT_MESSAGE_LIST_TAKE),
31
+ hasMore: messages.length === DEFAULT_MESSAGE_LIST_TAKE + 1,
32
+ },
33
+ };
34
+ },
35
+ providesTags: ['account', 'thread', 'thread-message'],
36
+ onCacheEntryAdded: async ({ threadId }, { cacheEntryRemoved, cacheDataLoaded, updateCachedData }) => {
37
+ await cacheDataLoaded;
38
+
39
+ unsubscribe(
40
+ __settings.client.subscribe('chatify://thread-message-new', ([_threadId, message]) => {
41
+ threadId === _threadId &&
42
+ updateCachedData((messageList) => {
43
+ !messageList.messages.some((x) => x.id === message.id) &&
44
+ messageList.messages.unshift(message);
45
+ });
46
+ }),
47
+ ).when(cacheEntryRemoved);
48
+ },
49
+ }),
50
+
51
+ fetchNextThreadMessageList: builder.mutation<void, { threadId: string }>({
52
+ queryFn: async ({ threadId }, { getState }) => {
53
+ const current = __threadMessageApi.endpoints.getThreadMessageList.select({ threadId })(
54
+ getState() as any,
55
+ );
56
+ const messages = await __settings.client.threadMessages({
57
+ threadId,
58
+ skip: current.data!.messages.length,
59
+ take: DEFAULT_MESSAGE_LIST_TAKE + 1,
60
+ });
61
+ return {
62
+ data: null!,
63
+ meta: {
64
+ messages: messages.slice(0, DEFAULT_MESSAGE_LIST_TAKE),
65
+ hasMore: messages.length === DEFAULT_MESSAGE_LIST_TAKE + 1,
66
+ },
67
+ };
68
+ },
69
+ onQueryStarted: async ({ threadId }, { dispatch, queryFulfilled }) => {
70
+ const result = await queryFulfilled;
71
+ const meta: ThreadMessageList = result.meta! as any;
72
+
73
+ dispatch(
74
+ __threadMessageApi.util.updateQueryData('getThreadMessageList', { threadId }, (draft) => {
75
+ draft.hasMore = meta.hasMore;
76
+ draft.messages.push(...meta!.messages);
77
+ }),
78
+ );
79
+ },
80
+ }),
81
+
82
+ sendThreadMessage: builder.mutation<string, SendThreadMessageRequest>({
83
+ queryFn: async (args) => {
84
+ const id = await __settings.client.sendThreadMessage(args);
85
+ return { data: id };
86
+ },
87
+ }),
88
+
89
+ readThreadMessage: builder.mutation<void, { id: string }>({
90
+ queryFn: async () => {
91
+ return { data: null! };
92
+ },
93
+ onQueryStarted: async ({ id }, { dispatch }) => {
94
+ THREAD_MESSAGE_READ_QUEUE.push(id);
95
+ dispatch(
96
+ __threadMessageApi.endpoints.getThreadMessageReadQueue.initiate(undefined, { forceRefetch: true }),
97
+ );
98
+ },
99
+ }),
100
+
101
+ getThreadMessageReadQueue: builder.query<DebounceValue<string>[], void>({
102
+ queryFn: async () => ({ data: THREAD_MESSAGE_READ_QUEUE.units }),
103
+ onCacheEntryAdded: async (_, { dispatch, cacheEntryRemoved }) => {
104
+ unsubscribe(
105
+ THREAD_MESSAGE_READ_QUEUE.subscribe((value) => {
106
+ dispatch(
107
+ __threadMessageApi.util.updateQueryData(
108
+ 'getThreadMessageReadQueue',
109
+ undefined,
110
+ () => value.units,
111
+ ),
112
+ );
113
+ }),
114
+ ).when(cacheEntryRemoved);
115
+ },
116
+ }),
117
+ }),
20
118
  });
@@ -10,13 +10,13 @@ export function NextMessagesObserver(props: NextMessagesObserverProps) {
10
10
  const { onLoad, loading } = props;
11
11
  const [intersecting, setIntersecting] = useState(false);
12
12
  const ref = useRef<HTMLDivElement | null>(null);
13
- const timerRef = useRef<number>();
13
+ const timerRef = useRef<NodeJS.Timer>();
14
14
 
15
15
  const observer = useMemo(
16
16
  () =>
17
17
  new IntersectionObserver(([entry]) => {
18
18
  if (entry.isIntersecting) {
19
- timerRef.current = window.setTimeout(() => setIntersecting(true), 200);
19
+ timerRef.current = setTimeout(() => setIntersecting(true), 200);
20
20
  } else {
21
21
  clearTimeout(timerRef.current!);
22
22
  }
@@ -1,5 +0,0 @@
1
- import { BaseApiEndpointBuilder } from './baseApi';
2
- import { Account } from '../types';
3
- export declare function accountEndpoints(builder: BaseApiEndpointBuilder): {
4
- getAccountList: import("@reduxjs/toolkit/query").QueryDefinition<void, import("@reduxjs/toolkit/query").BaseQueryFn, "chat" | "account" | "message" | "thread" | "thread-message", Account[], "chatify">;
5
- };