@droppii-org/chat-mobile 0.2.47 → 0.2.48

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 (63) hide show
  1. package/lib/module/config/api-endpoints.js +1 -1
  2. package/lib/module/config/api-endpoints.js.map +1 -1
  3. package/lib/module/core/useChatListener.js +3 -2
  4. package/lib/module/core/useChatListener.js.map +1 -1
  5. package/lib/module/hooks/message/useSendMessage.js +5 -4
  6. package/lib/module/hooks/message/useSendMessage.js.map +1 -1
  7. package/lib/module/hooks/query-keys.js +6 -1
  8. package/lib/module/hooks/query-keys.js.map +1 -1
  9. package/lib/module/hooks/useChatCompose.js +18 -1
  10. package/lib/module/hooks/useChatCompose.js.map +1 -1
  11. package/lib/module/hooks/users/useGetUsersInfo.js +14 -0
  12. package/lib/module/hooks/users/useGetUsersInfo.js.map +1 -0
  13. package/lib/module/screens/chat-detail/ChatDetail.js +4 -5
  14. package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -1
  15. package/lib/module/screens/chat-detail/ChatDetailHeader.js +21 -4
  16. package/lib/module/screens/chat-detail/ChatDetailHeader.js.map +1 -1
  17. package/lib/module/screens/inbox/Inbox.js +3 -3
  18. package/lib/module/screens/inbox/Inbox.js.map +1 -1
  19. package/lib/module/services/endpoints.js +6 -5
  20. package/lib/module/services/endpoints.js.map +1 -1
  21. package/lib/module/store/conversation.js +24 -3
  22. package/lib/module/store/conversation.js.map +1 -1
  23. package/lib/module/utils/message.js +2 -2
  24. package/lib/module/utils/message.js.map +1 -1
  25. package/lib/typescript/src/config/api-endpoints.d.ts +1 -1
  26. package/lib/typescript/src/config/api-endpoints.d.ts.map +1 -1
  27. package/lib/typescript/src/core/useChatListener.d.ts.map +1 -1
  28. package/lib/typescript/src/hooks/message/useSendMessage.d.ts.map +1 -1
  29. package/lib/typescript/src/hooks/query-keys.d.ts +5 -0
  30. package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -1
  31. package/lib/typescript/src/hooks/useChatCompose.d.ts.map +1 -1
  32. package/lib/typescript/src/hooks/users/useGetUsersInfo.d.ts +2 -0
  33. package/lib/typescript/src/hooks/users/useGetUsersInfo.d.ts.map +1 -0
  34. package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -1
  35. package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts +1 -1
  36. package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts.map +1 -1
  37. package/lib/typescript/src/screens/chat-detail/types.d.ts +1 -0
  38. package/lib/typescript/src/screens/chat-detail/types.d.ts.map +1 -1
  39. package/lib/typescript/src/screens/inbox/Inbox.d.ts +2 -2
  40. package/lib/typescript/src/screens/inbox/Inbox.d.ts.map +1 -1
  41. package/lib/typescript/src/services/endpoints.d.ts +1 -0
  42. package/lib/typescript/src/services/endpoints.d.ts.map +1 -1
  43. package/lib/typescript/src/store/conversation.d.ts +6 -1
  44. package/lib/typescript/src/store/conversation.d.ts.map +1 -1
  45. package/lib/typescript/src/types/chat.d.ts +19 -0
  46. package/lib/typescript/src/types/chat.d.ts.map +1 -1
  47. package/lib/typescript/src/utils/message.d.ts +1 -1
  48. package/lib/typescript/src/utils/message.d.ts.map +1 -1
  49. package/package.json +1 -1
  50. package/src/config/api-endpoints.ts +2 -2
  51. package/src/core/useChatListener.ts +3 -2
  52. package/src/hooks/message/useSendMessage.ts +8 -2
  53. package/src/hooks/query-keys.ts +6 -0
  54. package/src/hooks/useChatCompose.ts +19 -0
  55. package/src/hooks/users/useGetUsersInfo.ts +13 -0
  56. package/src/screens/chat-detail/ChatDetail.tsx +8 -5
  57. package/src/screens/chat-detail/ChatDetailHeader.tsx +20 -4
  58. package/src/screens/chat-detail/types.ts +1 -0
  59. package/src/screens/inbox/Inbox.tsx +9 -4
  60. package/src/services/endpoints.ts +5 -5
  61. package/src/store/conversation.ts +37 -3
  62. package/src/types/chat.ts +21 -0
  63. package/src/utils/message.ts +7 -2
@@ -1,12 +1,27 @@
1
1
  import { create } from 'zustand';
2
2
  import { sortConversation } from '../utils/conversation';
3
3
  import type { ConversationItem } from '@droppii/openim-rn-client-sdk';
4
+ import type {
5
+ CreateConversationParams,
6
+ CreateConversationResponse,
7
+ } from '../types/chat';
8
+ import { apiInstance } from '../services/apis';
9
+ import { ENDPOINTS } from '../services/endpoints';
10
+ import type { BaseResponse } from '../types/auth';
4
11
 
5
12
  type ConversationID = string;
6
13
 
7
14
  export interface ConversationStore {
8
15
  currentConversationId?: ConversationID;
9
- setCurrentConversation(id?: ConversationID): void;
16
+ currentUserId?: string;
17
+ currentGroupId?: string;
18
+ isCreatingConversation?: boolean;
19
+ createConversation: (params: CreateConversationParams) => Promise<void>;
20
+ setCurrentConversation(
21
+ id?: ConversationID,
22
+ userId?: string,
23
+ groupId?: string
24
+ ): void;
10
25
  getCurrentConversation(): ConversationItem | undefined;
11
26
  list: ConversationID[];
12
27
  map: Record<ConversationID, ConversationItem>;
@@ -26,8 +41,12 @@ export const useConversationStore = create<ConversationStore>()((set, get) => ({
26
41
  list: [],
27
42
  map: {},
28
43
  newConversationSignal: 0,
29
- setCurrentConversation(id) {
30
- set({ currentConversationId: id });
44
+ setCurrentConversation(id, userId, groupId) {
45
+ set({
46
+ currentConversationId: id,
47
+ currentUserId: userId,
48
+ currentGroupId: groupId,
49
+ });
31
50
  },
32
51
  getCurrentConversation() {
33
52
  const id = get().currentConversationId;
@@ -68,12 +87,27 @@ export const useConversationStore = create<ConversationStore>()((set, get) => ({
68
87
  list: get().list.filter((item) => item !== id),
69
88
  });
70
89
  },
90
+ createConversation: async (params) => {
91
+ set({ isCreatingConversation: true });
92
+ const res = await apiInstance?.post<
93
+ BaseResponse<CreateConversationResponse>
94
+ >(ENDPOINTS.chatService.createConversation(), params);
95
+ if (res?.data?.data?.conversationId) {
96
+ set({
97
+ currentConversationId: res?.data?.data?.conversationId,
98
+ isCreatingConversation: false,
99
+ });
100
+ } else {
101
+ set({ isCreatingConversation: false });
102
+ }
103
+ },
71
104
  reset() {
72
105
  set({
73
106
  currentConversationId: undefined,
74
107
  list: [],
75
108
  map: {},
76
109
  newConversationSignal: 0,
110
+ isCreatingConversation: false,
77
111
  });
78
112
  },
79
113
  }));
package/src/types/chat.ts CHANGED
@@ -218,3 +218,24 @@ export type CustomElemOrderData = {
218
218
  export type CustomMessagePayload =
219
219
  | { type: typeof CustomMessageType.Order; data: CustomElemOrderData }
220
220
  | { type: typeof CustomMessageType.Product; data: Record<string, unknown> };
221
+
222
+ export interface CreateConversationParams {
223
+ peerUserId: string;
224
+ chatCategory: DChatCategory;
225
+ applicationType: DChatApplicationType;
226
+ chatType: 'SINGLE' | 'GROUP';
227
+ }
228
+
229
+ export interface CreateConversationResponse {
230
+ conversationId: string;
231
+ groupId?: string;
232
+ groupName?: string;
233
+ groupAvatar?: string;
234
+ chatCategory: DChatCategory;
235
+ applicationType: DChatApplicationType;
236
+ chatType: 'SINGLE' | 'GROUP';
237
+ members?: {
238
+ userId: string;
239
+ memberRole?: string;
240
+ }[];
241
+ }
@@ -100,7 +100,8 @@ export const hasNewHistoryMessages = (
100
100
 
101
101
  export const belongsToConversation = (
102
102
  message: MessageItem,
103
- conversationId: string
103
+ conversationId?: string,
104
+ targetUserId?: string
104
105
  ): boolean => {
105
106
  switch (message.sessionType) {
106
107
  case SessionType.Single: {
@@ -114,7 +115,11 @@ export const belongsToConversation = (
114
115
  message.recvID,
115
116
  message.sendID
116
117
  );
117
- return conversationId === forwardId || conversationId === reverseId;
118
+ return conversationId
119
+ ? conversationId === forwardId || conversationId === reverseId
120
+ : targetUserId
121
+ ? message.sendID === targetUserId || message.recvID === targetUserId
122
+ : false;
118
123
  }
119
124
 
120
125
  case SessionType.Group: {