@droppii-org/chat-mobile 0.2.48 → 0.2.50

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/components/ThreadCard/MuteThread.js +4 -28
  2. package/lib/module/components/ThreadCard/MuteThread.js.map +1 -1
  3. package/lib/module/components/ThreadCard/PinThread.js +45 -0
  4. package/lib/module/components/ThreadCard/PinThread.js.map +1 -0
  5. package/lib/module/components/ThreadCard/ThreadCard.js +14 -9
  6. package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -1
  7. package/lib/module/config/api-endpoints.js +2 -1
  8. package/lib/module/config/api-endpoints.js.map +1 -1
  9. package/lib/module/context/ChatContext.js +3 -0
  10. package/lib/module/context/ChatContext.js.map +1 -1
  11. package/lib/module/core/notification/pushToken.js +37 -18
  12. package/lib/module/core/notification/pushToken.js.map +1 -1
  13. package/lib/module/hooks/message/useSendMessage.js +1 -1
  14. package/lib/module/hooks/message/useSendMessage.js.map +1 -1
  15. package/lib/module/hooks/useMuteConversation.js +34 -15
  16. package/lib/module/hooks/useMuteConversation.js.map +1 -1
  17. package/lib/module/hooks/usePinConversation.js +72 -0
  18. package/lib/module/hooks/usePinConversation.js.map +1 -0
  19. package/lib/module/screens/chat-detail/ChatDetail.js +5 -1
  20. package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -1
  21. package/lib/module/services/endpoints.js +3 -0
  22. package/lib/module/services/endpoints.js.map +1 -1
  23. package/lib/module/store/user.js +5 -0
  24. package/lib/module/store/user.js.map +1 -1
  25. package/lib/module/translation/resources/i18n.js +7 -0
  26. package/lib/module/translation/resources/i18n.js.map +1 -1
  27. package/lib/module/types/chat.js +11 -0
  28. package/lib/module/types/chat.js.map +1 -1
  29. package/lib/typescript/src/components/ThreadCard/MuteThread.d.ts.map +1 -1
  30. package/lib/typescript/src/components/ThreadCard/PinThread.d.ts +10 -0
  31. package/lib/typescript/src/components/ThreadCard/PinThread.d.ts.map +1 -0
  32. package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -1
  33. package/lib/typescript/src/config/api-endpoints.d.ts +1 -0
  34. package/lib/typescript/src/config/api-endpoints.d.ts.map +1 -1
  35. package/lib/typescript/src/context/ChatContext.d.ts.map +1 -1
  36. package/lib/typescript/src/core/notification/pushToken.d.ts +3 -13
  37. package/lib/typescript/src/core/notification/pushToken.d.ts.map +1 -1
  38. package/lib/typescript/src/hooks/useMuteConversation.d.ts.map +1 -1
  39. package/lib/typescript/src/hooks/usePinConversation.d.ts +6 -0
  40. package/lib/typescript/src/hooks/usePinConversation.d.ts.map +1 -0
  41. package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -1
  42. package/lib/typescript/src/services/endpoints.d.ts +1 -0
  43. package/lib/typescript/src/services/endpoints.d.ts.map +1 -1
  44. package/lib/typescript/src/store/user.d.ts +2 -0
  45. package/lib/typescript/src/store/user.d.ts.map +1 -1
  46. package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
  47. package/lib/typescript/src/types/chat.d.ts +9 -0
  48. package/lib/typescript/src/types/chat.d.ts.map +1 -1
  49. package/package.json +2 -2
  50. package/src/components/ThreadCard/MuteThread.tsx +4 -28
  51. package/src/components/ThreadCard/PinThread.tsx +58 -0
  52. package/src/components/ThreadCard/ThreadCard.tsx +11 -5
  53. package/src/config/api-endpoints.ts +2 -0
  54. package/src/context/ChatContext.tsx +3 -0
  55. package/src/core/notification/pushToken.ts +52 -16
  56. package/src/hooks/message/useSendMessage.ts +1 -1
  57. package/src/hooks/useMuteConversation.ts +32 -17
  58. package/src/hooks/usePinConversation.ts +87 -0
  59. package/src/screens/chat-detail/ChatDetail.tsx +6 -1
  60. package/src/services/endpoints.ts +3 -0
  61. package/src/store/user.ts +5 -0
  62. package/src/translation/resources/i18n.ts +8 -0
  63. package/src/types/chat.ts +11 -0
@@ -3,22 +3,30 @@ import OpenIMSDK, {
3
3
  MessageReceiveOptType,
4
4
  } from '@droppii/openim-rn-client-sdk';
5
5
  import type { ConversationItem } from '@droppii/openim-rn-client-sdk';
6
- import { useConversationStore } from '../store';
6
+ import { UIUtils } from '../utils/UIUtils';
7
+ import { trans } from '../translation';
7
8
 
8
9
  export function useMuteConversation() {
9
10
  const muteConversation = useCallback(
10
11
  async (conversation?: ConversationItem) => {
11
12
  if (conversation == null) return;
12
13
 
13
- await OpenIMSDK.setConversationRecvMessageOpt({
14
- conversationID: conversation.conversationID,
15
- opt: MessageReceiveOptType.NotNotify,
16
- });
17
- useConversationStore
18
- .getState()
19
- .updateConversation(conversation.conversationID, {
20
- recvMsgOpt: MessageReceiveOptType.NotNotify,
14
+ try {
15
+ await OpenIMSDK.setConversationRecvMessageOpt({
16
+ conversationID: conversation.conversationID,
17
+ opt: MessageReceiveOptType.NotNotify,
21
18
  });
19
+ UIUtils.toast.open({
20
+ title: trans('chat:mute_toast_success'),
21
+ theme: 'light',
22
+ });
23
+ } catch (error) {
24
+ console.error('muteConversation failed', error);
25
+ UIUtils.toast.open({
26
+ title: trans('chat:generic_error'),
27
+ theme: 'error',
28
+ });
29
+ }
22
30
  },
23
31
  []
24
32
  );
@@ -27,15 +35,22 @@ export function useMuteConversation() {
27
35
  async (conversation?: ConversationItem) => {
28
36
  if (conversation == null) return;
29
37
 
30
- await OpenIMSDK.setConversationRecvMessageOpt({
31
- conversationID: conversation.conversationID,
32
- opt: MessageReceiveOptType.Normal,
33
- });
34
- useConversationStore
35
- .getState()
36
- .updateConversation(conversation.conversationID, {
37
- recvMsgOpt: MessageReceiveOptType.Normal,
38
+ try {
39
+ await OpenIMSDK.setConversationRecvMessageOpt({
40
+ conversationID: conversation.conversationID,
41
+ opt: MessageReceiveOptType.Normal,
42
+ });
43
+ UIUtils.toast.open({
44
+ title: trans('chat:unmute_toast_success'),
45
+ theme: 'light',
46
+ });
47
+ } catch (error) {
48
+ console.error('unmuteConversation failed', error);
49
+ UIUtils.toast.open({
50
+ title: trans('chat:generic_error'),
51
+ theme: 'error',
38
52
  });
53
+ }
39
54
  },
40
55
  []
41
56
  );
@@ -0,0 +1,87 @@
1
+ import { useCallback } from 'react';
2
+ import OpenIMSDK from '@droppii/openim-rn-client-sdk';
3
+ import type { ConversationItem } from '@droppii/openim-rn-client-sdk';
4
+ import { useConversationStore } from '../store';
5
+ import { UIUtils } from '../utils/UIUtils';
6
+ import { trans } from '../translation';
7
+
8
+ const MAX_PINNED_THREADS = 5;
9
+
10
+ const showPinThreadLimitModal = () => {
11
+ UIUtils.alert.open({
12
+ title: trans('chat:pin_thread_limit_title'),
13
+ message: trans('chat:pin_thread_limit_desc', {
14
+ maxCount: MAX_PINNED_THREADS,
15
+ }),
16
+ primaryIndex: 0,
17
+ buttonType: 'horizontal-button',
18
+ buttons: [
19
+ {
20
+ label: trans('chat:pin_thread_limit_button'),
21
+ kind: 'primary',
22
+ },
23
+ ],
24
+ });
25
+ };
26
+
27
+ export function usePinConversation() {
28
+ const pinConversation = useCallback(
29
+ async (conversation?: ConversationItem) => {
30
+ if (conversation == null) return;
31
+
32
+ try {
33
+ const pinnedCount = Object.values(
34
+ useConversationStore.getState().map
35
+ ).filter((c) => c.isPinned).length;
36
+ if (pinnedCount >= MAX_PINNED_THREADS) {
37
+ showPinThreadLimitModal();
38
+ return;
39
+ }
40
+
41
+ await OpenIMSDK.pinConversation({
42
+ conversationID: conversation.conversationID,
43
+ isPinned: true,
44
+ });
45
+
46
+ UIUtils.toast.open({
47
+ title: trans('chat:pin_thread_success'),
48
+ theme: 'light',
49
+ });
50
+ } catch (error) {
51
+ console.error('pinConversation failed', error);
52
+ UIUtils.toast.open({
53
+ title: trans('chat:generic_error'),
54
+ theme: 'error',
55
+ });
56
+ }
57
+ },
58
+ []
59
+ );
60
+
61
+ const unpinConversation = useCallback(
62
+ async (conversation?: ConversationItem) => {
63
+ if (conversation == null) return;
64
+
65
+ try {
66
+ await OpenIMSDK.pinConversation({
67
+ conversationID: conversation.conversationID,
68
+ isPinned: false,
69
+ });
70
+
71
+ UIUtils.toast.open({
72
+ title: trans('chat:unpin_thread_success'),
73
+ theme: 'light',
74
+ });
75
+ } catch (error) {
76
+ console.error('unpinConversation failed', error);
77
+ UIUtils.toast.open({
78
+ title: trans('chat:generic_error'),
79
+ theme: 'error',
80
+ });
81
+ }
82
+ },
83
+ []
84
+ );
85
+
86
+ return { pinConversation, unpinConversation };
87
+ }
@@ -36,6 +36,7 @@ import type { MessageItem } from '@droppii/openim-rn-client-sdk';
36
36
  import { useMessages } from '../../hooks/message/useMessages';
37
37
  import { getBotId } from '../../utils/conversation';
38
38
  import { ChatEvent } from '../../types/events';
39
+ import { useSetIsShowFLashMessage } from '../../context/global';
39
40
 
40
41
  const ChatDetail = memo(
41
42
  ({
@@ -107,6 +108,8 @@ const ChatDetail = memo(
107
108
  hasMoreNew,
108
109
  } = useMessages({ conversationId });
109
110
 
111
+ const setShowFLashMessage = useSetIsShowFLashMessage();
112
+
110
113
  const { pinnedMessages, pinMessage, unpinMessage } =
111
114
  usePinMessage(conversationId);
112
115
 
@@ -114,12 +117,14 @@ const ChatDetail = memo(
114
117
  useConversationStore
115
118
  .getState()
116
119
  .setCurrentConversation(conversationId, targetUserId, targetGroupId);
120
+ setShowFLashMessage(false);
117
121
  return () => {
118
122
  useConversationStore
119
123
  .getState()
120
124
  .setCurrentConversation(undefined, undefined, undefined);
125
+ setShowFLashMessage(true);
121
126
  };
122
- }, [conversationId, targetUserId, targetGroupId]);
127
+ }, [conversationId, targetUserId, targetGroupId, setShowFLashMessage]);
123
128
 
124
129
  const resolvedShowAddMember =
125
130
  showAddMember ?? shouldShowAddMember(conversation);
@@ -16,6 +16,9 @@ export const ENDPOINTS = {
16
16
  get urlMetadata() {
17
17
  return getApiEndpoint('urlMetadata');
18
18
  },
19
+ get uploadFcmToken() {
20
+ return getApiEndpoint('uploadFcmToken');
21
+ },
19
22
  conversationFlow: (id: string) => `${getApiEndpoint('conversation')}/${id}`,
20
23
  resetConversationFlow: (id: string) =>
21
24
  `${getApiEndpoint('conversation')}/${id}/bot-flows/reset`,
package/src/store/user.ts CHANGED
@@ -5,6 +5,8 @@ import { ConnectStatus, SyncStatus } from '../types/chat';
5
5
  export interface UserStore {
6
6
  user?: SelfUserInfo;
7
7
  setUser: (user: SelfUserInfo) => void;
8
+ token?: string;
9
+ setToken: (token: string) => void;
8
10
  connectStatus: ConnectStatus;
9
11
  updateConnectStatus: (status: ConnectStatus) => void;
10
12
  syncStatus: SyncStatus;
@@ -17,6 +19,9 @@ export const useUserStore = create<UserStore>()((set) => ({
17
19
  setUser(user) {
18
20
  set({ user });
19
21
  },
22
+ setToken(token) {
23
+ set({ token });
24
+ },
20
25
  updateConnectStatus(connectStatus) {
21
26
  set({ connectStatus });
22
27
  },
@@ -51,6 +51,14 @@ const i18nKey: Record<string, string> = {
51
51
  'chat:pinned_messages_title': 'Tin nhắn đã ghim',
52
52
  'chat:pinned_messages_hint':
53
53
  'Nhấn vào tin nhắn để xem tin nhắn gốc, nhấn vào biểu tượng để bỏ ghim',
54
+ 'chat:pin_thread': 'Ghim',
55
+ 'chat:unpin_thread': 'Bỏ ghim',
56
+ 'chat:pin_thread_success': 'Đã ghim đoạn chat thành công',
57
+ 'chat:unpin_thread_success': 'Đã bỏ ghim đoạn chat thành công',
58
+ 'chat:pin_thread_limit_title': 'Không thể ghim đoạn chat',
59
+ 'chat:pin_thread_limit_desc':
60
+ 'Bạn đã ghim số đoạn chat tối đa. Để ghim đoạn chat này, trước tiên bạn phải bỏ ghim đoạn chat khác.',
61
+ 'chat:pin_thread_limit_button': 'OK',
54
62
  'chat:view_original_message': 'Xem tin nhắn gốc',
55
63
  'chat:scroll_to_message_todo':
56
64
  'Tính năng di chuyển đến tin nhắn gốc sẽ sớm được cập nhật',
package/src/types/chat.ts CHANGED
@@ -53,6 +53,17 @@ export enum DChatApplicationType {
53
53
  OBEFE = 'OBEFE',
54
54
  }
55
55
 
56
+ export enum DChatPlatform {
57
+ IOS = 1,
58
+ ANDROID = 2,
59
+ WEB = 5,
60
+ }
61
+
62
+ export enum DChatProject {
63
+ BIZ = 'BIZ',
64
+ CUS = 'CUS',
65
+ }
66
+
56
67
  export enum DChatCategory {
57
68
  BIZ_BIZ = 'BIZ_BIZ',
58
69
  BIZ_MALL = 'BIZ_MALL',