@droppii-org/chat-mobile 0.2.75 → 0.2.76

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 (55) hide show
  1. package/lib/module/components/GroupPermissionGate/GroupPermissionGate.js +33 -0
  2. package/lib/module/components/GroupPermissionGate/GroupPermissionGate.js.map +1 -0
  3. package/lib/module/components/GroupPermissionGate/index.js +4 -0
  4. package/lib/module/components/GroupPermissionGate/index.js.map +1 -0
  5. package/lib/module/context/ChatDetailContext.js +15 -11
  6. package/lib/module/context/ChatDetailContext.js.map +1 -1
  7. package/lib/module/core/useChatListener.js +13 -7
  8. package/lib/module/core/useChatListener.js.map +1 -1
  9. package/lib/module/hooks/groups/useDismissGroup.js +79 -0
  10. package/lib/module/hooks/groups/useDismissGroup.js.map +1 -0
  11. package/lib/module/hooks/groups/useJoinGroup.js +1 -3
  12. package/lib/module/hooks/groups/useJoinGroup.js.map +1 -1
  13. package/lib/module/hooks/useGroupPermission.js +4 -3
  14. package/lib/module/hooks/useGroupPermission.js.map +1 -1
  15. package/lib/module/screens/ChatInfo/ChatInfo.js +6 -3
  16. package/lib/module/screens/ChatInfo/ChatInfo.js.map +1 -1
  17. package/lib/module/screens/ChatInfo/ChatInfoActions.js +48 -6
  18. package/lib/module/screens/ChatInfo/ChatInfoActions.js.map +1 -1
  19. package/lib/module/translation/resources/i18n.js +7 -1
  20. package/lib/module/translation/resources/i18n.js.map +1 -1
  21. package/lib/typescript/src/components/GroupPermissionGate/GroupPermissionGate.d.ts +19 -0
  22. package/lib/typescript/src/components/GroupPermissionGate/GroupPermissionGate.d.ts.map +1 -0
  23. package/lib/typescript/src/components/GroupPermissionGate/index.d.ts +3 -0
  24. package/lib/typescript/src/components/GroupPermissionGate/index.d.ts.map +1 -0
  25. package/lib/typescript/src/context/ChatDetailContext.d.ts.map +1 -1
  26. package/lib/typescript/src/core/useChatListener.d.ts.map +1 -1
  27. package/lib/typescript/src/hooks/groups/useDismissGroup.d.ts +8 -0
  28. package/lib/typescript/src/hooks/groups/useDismissGroup.d.ts.map +1 -0
  29. package/lib/typescript/src/hooks/groups/useJoinGroup.d.ts.map +1 -1
  30. package/lib/typescript/src/hooks/useGroupPermission.d.ts.map +1 -1
  31. package/lib/typescript/src/screens/ChatInfo/ChatInfo.d.ts +2 -2
  32. package/lib/typescript/src/screens/ChatInfo/ChatInfo.d.ts.map +1 -1
  33. package/lib/typescript/src/screens/ChatInfo/ChatInfoActions.d.ts +3 -2
  34. package/lib/typescript/src/screens/ChatInfo/ChatInfoActions.d.ts.map +1 -1
  35. package/lib/typescript/src/screens/ChatInfo/types.d.ts +1 -0
  36. package/lib/typescript/src/screens/ChatInfo/types.d.ts.map +1 -1
  37. package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -1
  38. package/lib/typescript/src/types/chat.d.ts +2 -2
  39. package/lib/typescript/src/types/chat.d.ts.map +1 -1
  40. package/lib/typescript/src/types/events.d.ts +2 -4
  41. package/lib/typescript/src/types/events.d.ts.map +1 -1
  42. package/package.json +1 -1
  43. package/src/components/GroupPermissionGate/GroupPermissionGate.tsx +51 -0
  44. package/src/components/GroupPermissionGate/index.ts +5 -0
  45. package/src/context/ChatDetailContext.tsx +17 -11
  46. package/src/core/useChatListener.ts +13 -7
  47. package/src/hooks/groups/useDismissGroup.tsx +80 -0
  48. package/src/hooks/groups/useJoinGroup.ts +1 -3
  49. package/src/hooks/useGroupPermission.ts +5 -4
  50. package/src/screens/ChatInfo/ChatInfo.tsx +4 -1
  51. package/src/screens/ChatInfo/ChatInfoActions.tsx +79 -32
  52. package/src/screens/ChatInfo/types.ts +1 -0
  53. package/src/translation/resources/i18n.ts +7 -0
  54. package/src/types/chat.ts +2 -2
  55. package/src/types/events.ts +2 -4
@@ -6,9 +6,14 @@ import {
6
6
  type KListItemBaseItemProps,
7
7
  KLabel,
8
8
  } from '@droppii/libs';
9
- import type { ConversationItem } from '@droppii/openim-rn-client-sdk';
9
+ import {
10
+ GroupMemberRole,
11
+ type ConversationItem,
12
+ } from '@droppii/openim-rn-client-sdk';
10
13
  import { usePinConversation } from '../../hooks/usePinConversation';
11
14
  import { trans } from '../../translation';
15
+ import { useChatDetailContext } from '../../context';
16
+ import { useDismissGroup } from '../../hooks/groups/useDismissGroup';
12
17
 
13
18
  interface ChatInfoActionsProps {
14
19
  conversation?: ConversationItem;
@@ -18,6 +23,7 @@ interface ChatInfoActionsProps {
18
23
  onPressCreateGroup?: () => void;
19
24
  onPressAddToGroup?: () => void;
20
25
  onPressLeaveGroup?: () => void;
26
+ onDismissGroup?: () => void;
21
27
  }
22
28
 
23
29
  const ChatInfoActions = memo(
@@ -29,10 +35,17 @@ const ChatInfoActions = memo(
29
35
  onPressCreateGroup,
30
36
  onPressAddToGroup,
31
37
  onPressLeaveGroup,
38
+ onDismissGroup,
32
39
  }: ChatInfoActionsProps) => {
33
40
  const { pinConversation, unpinConversation } = usePinConversation();
34
41
  const isPinned = Boolean(conversation?.isPinned);
35
42
  const showName = conversation?.showName || '';
43
+ const { userInfo } = useChatDetailContext();
44
+ const { dismissGroup } = useDismissGroup({ onSuccess: onDismissGroup });
45
+
46
+ const isOwner = useMemo(() => {
47
+ return userInfo?.roleLevel === GroupMemberRole.Owner;
48
+ }, [userInfo?.roleLevel]);
36
49
 
37
50
  const handlePinPress = useCallback(() => {
38
51
  if (isPinned) {
@@ -44,6 +57,11 @@ const ChatInfoActions = memo(
44
57
 
45
58
  const handleDeleteHistory = useCallback(() => {}, []);
46
59
 
60
+ const handleDismissGroup = useCallback(() => {
61
+ if (!conversation?.groupID) return;
62
+ dismissGroup(conversation?.groupID);
63
+ }, [dismissGroup, conversation?.groupID]);
64
+
47
65
  const primaryData = useMemo(() => {
48
66
  const items: KListItemBaseItemProps[] = [];
49
67
 
@@ -118,17 +136,40 @@ const ChatInfoActions = memo(
118
136
  ]);
119
137
 
120
138
  const dangerData: KListItemBaseItemProps[] = useMemo(() => {
139
+ const items: KListItemBaseItemProps[] = [];
121
140
  if (isGroup) {
122
- return [
123
- {
141
+ items.push({
142
+ leftNode: {
143
+ icon: {
144
+ vectorName: 'logout-o',
145
+ tintColor: KColors.danger.normal,
146
+ },
147
+ },
148
+ tintColor: KColors.danger.normal,
149
+ onPress: onPressLeaveGroup,
150
+ showChevron: false,
151
+ paddingH: '0.75rem',
152
+ paddingV: '0.75rem',
153
+ customLabel: (
154
+ <KLabel.Text
155
+ typo="TextMdMedium"
156
+ color={KColors.danger.normal}
157
+ numberOfLines={1}
158
+ >
159
+ {trans('chat:info_leave_group')}
160
+ </KLabel.Text>
161
+ ),
162
+ });
163
+ if (isOwner) {
164
+ items.push({
124
165
  leftNode: {
125
166
  icon: {
126
- vectorName: 'logout-o',
167
+ vectorName: 'minus-circle-o',
127
168
  tintColor: KColors.danger.normal,
128
169
  },
129
170
  },
130
171
  tintColor: KColors.danger.normal,
131
- onPress: onPressLeaveGroup,
172
+ onPress: handleDismissGroup,
132
173
  showChevron: false,
133
174
  paddingH: '0.75rem',
134
175
  paddingV: '0.75rem',
@@ -138,39 +179,45 @@ const ChatInfoActions = memo(
138
179
  color={KColors.danger.normal}
139
180
  numberOfLines={1}
140
181
  >
141
- {trans('chat:info_leave_group')}
182
+ {trans('chat:dismiss_group')}
142
183
  </KLabel.Text>
143
184
  ),
144
- },
145
- ];
185
+ });
186
+ }
146
187
  }
147
188
 
148
- return [
149
- {
150
- label: trans('chat:info_delete_history'),
151
- leftNode: {
152
- icon: {
153
- vectorName: 'trash-alt-o-1',
154
- tintColor: KColors.danger.normal,
155
- },
189
+ items.push({
190
+ label: trans('chat:info_delete_history'),
191
+ leftNode: {
192
+ icon: {
193
+ vectorName: 'trash-alt-o-1',
194
+ tintColor: KColors.danger.normal,
156
195
  },
157
- tintColor: KColors.danger.normal,
158
- onPress: handleDeleteHistory,
159
- showChevron: false,
160
- paddingH: '0.75rem',
161
- paddingV: '0.75rem',
162
- customLabel: (
163
- <KLabel.Text
164
- typo="TextMdMedium"
165
- color={KColors.danger.normal}
166
- numberOfLines={1}
167
- >
168
- {trans('chat:info_delete_history')}
169
- </KLabel.Text>
170
- ),
171
196
  },
172
- ];
173
- }, [isGroup, onPressLeaveGroup, handleDeleteHistory]);
197
+ tintColor: KColors.danger.normal,
198
+ onPress: handleDeleteHistory,
199
+ showChevron: false,
200
+ paddingH: '0.75rem',
201
+ paddingV: '0.75rem',
202
+ customLabel: (
203
+ <KLabel.Text
204
+ typo="TextMdMedium"
205
+ color={KColors.danger.normal}
206
+ numberOfLines={1}
207
+ >
208
+ {trans('chat:info_delete_history')}
209
+ </KLabel.Text>
210
+ ),
211
+ });
212
+
213
+ return items;
214
+ }, [
215
+ isGroup,
216
+ onPressLeaveGroup,
217
+ handleDeleteHistory,
218
+ isOwner,
219
+ handleDismissGroup,
220
+ ]);
174
221
 
175
222
  return (
176
223
  <>
@@ -9,4 +9,5 @@ export interface ChatInfoProps {
9
9
  onPressCreateGroup?: () => void;
10
10
  onPressAddToGroup?: () => void;
11
11
  onPressLeaveGroup?: () => void;
12
+ onDismissGroup?: () => void;
12
13
  }
@@ -124,6 +124,7 @@ const i18nKey: Record<string, string> = {
124
124
  'chat:info_unpin_message': 'Bỏ ghim trò chuyện',
125
125
  'chat:info_delete_history': 'Xoá lịch sử trò chuyện',
126
126
  'chat:info_leave_group': 'Rời nhóm',
127
+ 'chat:dismiss_group': 'Giải tán nhóm',
127
128
  'chat:info_view_more': 'Xem thêm',
128
129
  'chat:group_description_title': 'Mô tả nhóm',
129
130
  'start': 'Bắt đầu',
@@ -174,6 +175,12 @@ const i18nKey: Record<string, string> = {
174
175
  'group:joined_group': 'Đã tham gia nhóm {{groupName}}',
175
176
  'group:public_group': 'Nhóm công khai',
176
177
  'group:private_group': 'Nhóm riêng tư',
178
+ 'group:dismiss_confirm_title': 'Giải tán nhóm?',
179
+ 'group:dismiss_confirm_desc':
180
+ 'Tất cả thành viên và tin nhắn sẽ bị xoá. Bạn có chắc chắn muốn giải tán nhóm?',
181
+ 'group:dismiss_confirm_primary': 'Giải tán',
182
+ 'group:dismiss_confirm_secondary': 'Quay lại',
183
+ 'group:dismiss_toast_success': 'Đã giải tán nhóm',
177
184
  };
178
185
 
179
186
  export default {
package/src/types/chat.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
- GroupPermission,
3
2
  MessageType,
4
3
  type ConversationItem,
5
4
  type MessageItem,
5
+ type SelfUserInfo,
6
6
  } from '@droppii/openim-rn-client-sdk';
7
7
  import type { PropsWithChildren } from 'react';
8
8
  import type { IUrlMetadata } from './common';
@@ -217,7 +217,7 @@ export interface ChatDetailContextType {
217
217
  quotedMessage?: MessageItem;
218
218
  setQuotedMessage: (item?: MessageItem) => void;
219
219
  conversationFlowMainMenu?: InputButtonItem[];
220
- groupPermissions: GroupPermission[];
220
+ userInfo?: SelfUserInfo;
221
221
  }
222
222
 
223
223
  export interface ChatDetailProviderProps extends PropsWithChildren {}
@@ -1,4 +1,4 @@
1
- import type { GroupPermission } from '@droppii/openim-rn-client-sdk';
1
+ import type { SelfUserInfo } from '@droppii/openim-rn-client-sdk';
2
2
 
3
3
  export enum ChatEvent {
4
4
  ScrollToMessage = 'chat:scroll_to_message',
@@ -16,9 +16,7 @@ export interface MessageRevokedPayload {
16
16
  clientMsgID: string;
17
17
  }
18
18
 
19
- export interface GroupPermissionUpdatedPayload {
20
- permissions: GroupPermission[];
21
- }
19
+ export type GroupPermissionUpdatedPayload = Partial<SelfUserInfo>;
22
20
 
23
21
  export interface GroupRemovedPayload {
24
22
  groupID: string;