@cometchat/chat-uikit-react-native 4.3.21 → 4.3.22-t1

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 (37) hide show
  1. package/package.json +1 -1
  2. package/src/AI/AIConversationSummary/AIConversationSummaryView.tsx +171 -167
  3. package/src/AI/CardView.tsx +55 -53
  4. package/src/CometChatCreateGroup/CometChatCreateGroup.tsx +8 -13
  5. package/src/CometChatGroups/CometChatGroups.tsx +545 -514
  6. package/src/CometChatJoinProtectedGroup/CometChatJoinProtectedGroup.tsx +5 -8
  7. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +544 -378
  8. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +103 -78
  9. package/src/CometChatThreadedMessages/CometChatThreadedMessages.tsx +3 -8
  10. package/src/CometChatTransferOwnership/CometChatTransferOwnership.tsx +11 -13
  11. package/src/CometChatUsers/CometChatUsers.tsx +24 -23
  12. package/src/extensions/CollaborativeBubble/CometChatCollaborativeBubble.tsx +24 -25
  13. package/src/extensions/Polls/Polls.tsx +8 -16
  14. package/src/extensions/Polls/PollsBubble.tsx +5 -10
  15. package/src/extensions/SmartReplies/SmartRepliesView.tsx +16 -22
  16. package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +51 -51
  17. package/src/shared/libs/datePickerModal/DateTimePickerModal.android.js +1 -7
  18. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.js +38 -46
  19. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +19 -19
  20. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +8 -20
  21. package/src/shared/views/CometChatBadge/CometChatBadge.tsx +8 -14
  22. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +141 -140
  23. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +47 -51
  24. package/src/shared/views/CometChatDate/CometChatDate.tsx +18 -17
  25. package/src/shared/views/CometChatDateTimePicker/CometChatDateTimePicker.tsx +65 -51
  26. package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +76 -72
  27. package/src/shared/views/CometChatFormBubble/CometChatFormBubble.tsx +3 -8
  28. package/src/shared/views/CometChatList/CometChatList.tsx +133 -134
  29. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +65 -64
  30. package/src/shared/views/CometChatMediaRecorder/CometChatMediaRecorder.tsx +2 -6
  31. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +3 -8
  32. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +24 -23
  33. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +107 -53
  34. package/src/shared/views/CometChatReceipt/CometChatReceipt.tsx +22 -14
  35. package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +15 -8
  36. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +2 -6
  37. package/src/shared/views/SwipeRow/SwipeRow.tsx +6 -14
@@ -1,199 +1,209 @@
1
1
  //@ts-ignore
2
- import React, { useState, useRef } from "react";
2
+ import React, { useState, useRef } from 'react';
3
3
  //@ts-ignore
4
- import { Text, TextStyle, View, ViewProps } from "react-native";
4
+ import { Text, TextStyle, View, ViewProps } from 'react-native';
5
5
  import {
6
- backIcon,
7
- passwordGroupIcon, privateGroupIcon,
8
- checkIcon,
9
- } from "./resources";
6
+ backIcon,
7
+ passwordGroupIcon as passwordGroupIconDefault,
8
+ privateGroupIcon as privateGroupIconDefault,
9
+ checkIcon,
10
+ } from './resources';
10
11
  //@ts-ignore
11
- import { CometChat } from "@cometchat/chat-sdk-react-native";
12
- import { GroupsStyle, GroupsStyleInterface } from "./GroupsStyle";
13
- import { Style } from "./style";
14
- import { CometChatContext, CometChatListActionsInterface, ListItemStyleInterface, localize } from "../shared";
15
- import { BorderStyle, ImageType } from "../shared";
16
- import { GroupTypeConstants, PASSWORD_GROUP_COLOR, PRIVATE_GROUP_COLOR } from "../shared/constants/UIKitConstants";
17
- import { CometChatListItem, ListItemStyle } from "../shared";
18
- import { AvatarStyle, StatusIndicatorStyle } from "../shared";
19
- import { CometChatList } from "../shared";
20
- import { CometChatContextType, SelectionMode } from "../shared/base/Types";
21
- import { CometChatOptions } from "../shared/modals/CometChatOptions";
22
- import { AvatarStyleInterface } from "../shared/views/CometChatAvatar/AvatarStyle";
23
- import { StatusIndicatorStyleInterface } from "../shared/views/CometChatStatusIndicator/StatusIndicatorStyle";
24
- import { CometChatUIEventHandler } from "../shared/events/CometChatUIEventHandler/CometChatUIEventHandler";
25
-
26
- const uiEventListener = "uiEvents_" + new Date().getTime();
12
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
13
+ import { GroupsStyle, GroupsStyleInterface } from './GroupsStyle';
14
+ import { Style } from './style';
15
+ import {
16
+ CometChatContext,
17
+ CometChatListActionsInterface,
18
+ ListItemStyleInterface,
19
+ localize,
20
+ } from '../shared';
21
+ import { BorderStyle, ImageType } from '../shared';
22
+ import {
23
+ GroupTypeConstants,
24
+ PASSWORD_GROUP_COLOR,
25
+ PRIVATE_GROUP_COLOR,
26
+ } from '../shared/constants/UIKitConstants';
27
+ import { CometChatListItem, ListItemStyle } from '../shared';
28
+ import { AvatarStyle, StatusIndicatorStyle } from '../shared';
29
+ import { CometChatList } from '../shared';
30
+ import { CometChatContextType, SelectionMode } from '../shared/base/Types';
31
+ import { CometChatOptions } from '../shared/modals/CometChatOptions';
32
+ import { AvatarStyleInterface } from '../shared/views/CometChatAvatar/AvatarStyle';
33
+ import { StatusIndicatorStyleInterface } from '../shared/views/CometChatStatusIndicator/StatusIndicatorStyle';
34
+ import { CometChatUIEventHandler } from '../shared/events/CometChatUIEventHandler/CometChatUIEventHandler';
35
+
36
+ const uiEventListener = 'uiEvents_' + new Date().getTime();
27
37
 
28
38
  export interface CometChatGroupsInterface {
29
- /**
30
- * Custom subtitle view
31
- */
32
- SubtitleView?: (item: CometChat.Group) => JSX.Element,
33
- /**
34
- * Custom list item view
35
- */
36
- ListItemView?: (item: CometChat.Group) => JSX.Element,
37
- /**
38
- * pass compoent for menu, will be shown at top right side
39
- */
40
- AppBarOption?: () => JSX.Element,
41
- /**
42
- * Pass array of CometChatOptions type
43
- * Tobe shown on swipe of list item
44
- */
45
- options?: (item: CometChat.Group) => CometChatOptions[],
46
- /**
47
- * toggle the seperator
48
- */
49
- hideSeperator?: boolean,
50
- /**
51
- * hide selection icon
52
- */
53
- hideSubmitIcon?: boolean,
54
- /**
55
- * styles for groups
56
- */
57
- groupsStyle?: GroupsStyleInterface,
58
- /**
59
- * styles for list item
60
- */
61
- listItemStyle?: ListItemStyleInterface,
62
- /**
63
- * styles for avatar
64
- */
65
- avatarStyle?: AvatarStyleInterface,
66
- /**
67
- * styles for status indicator
68
- */
69
- statusIndicatorStyle?: StatusIndicatorStyleInterface,
70
- /**
71
- * search placeholder text
72
- */
73
- searchPlaceHolderText?: string,
74
- /**
75
- * back button icon
76
- */
77
- backButtonIcon?: ImageType,
78
- /**
79
- * toggle back button
80
- */
81
- showBackButton?: boolean,
82
- /**
83
- * select items pass "none" | "single" | "multitple"
84
- */
85
- selectionMode?: SelectionMode,
86
- /**
87
- * call back on seleciton is done
88
- */
89
- onSelection?: (items: Array<CometChat.Group>) => void,
90
- /**
91
- * icon for search box
92
- */
93
- searchBoxIcon?: ImageType,
94
- /**
95
- * toggle seearch box
96
- */
97
- hideSearch?: boolean,
98
- /**
99
- * title to be shown default "Groups"
100
- */
101
- title?: string,
102
- /**
103
- * Custom Functional component for empty state
104
- */
105
- EmptyStateView?: () => JSX.Element,
106
- /**
107
- * text to be shown in case no groups found.
108
- */
109
- emptyStateText?: string,
110
- /**
111
- * Custom functional component for error state.
112
- */
113
- ErrorStateView?: () => JSX.Element,
114
- /**
115
- * text to be shown in case error occured while fetching gounps for first time
116
- */
117
- errorStateText?: string,
118
- /**
119
- * Custom image for loading state.
120
- */
121
- LoadingStateView?: () => JSX.Element,
122
- /**
123
- * Request builder to fetch groups.
124
- */
125
- groupsRequestBuilder?: CometChat.GroupsRequestBuilder,
126
- /**
127
- * request builder for search
128
- */
129
- searchRequestBuilder?: CometChat.GroupsRequestBuilder,
130
- /**
131
- * pass icon for private group
132
- */
133
- privateGroupIcon?: ImageType,
134
- /**
135
- * pass icon for password group
136
- */
137
- passwordGroupIcon?: ImageType,
138
- /**
139
- * toogle error visibility
140
- */
141
- hideError?: boolean,
142
- /**
143
- * function tobe called on group pressed.
144
- */
145
- onItemPress?: (item: CometChat.Group) => void,
146
- /**
147
- * function tobe called on group long pressed.
148
- */
149
- onItemLongPress?: (item: CometChat.Group) => void,
150
- /**
151
- * function will be called when error occured.
152
- */
153
- onError?: (e: CometChat.CometChatException) => void,
154
- /**
155
- * function will be called when back button pressed.
156
- */
157
- onBack?: () => void,
39
+ /**
40
+ * Custom subtitle view
41
+ */
42
+ SubtitleView?: (item: CometChat.Group) => JSX.Element;
43
+ /**
44
+ * Custom list item view
45
+ */
46
+ ListItemView?: (item: CometChat.Group) => JSX.Element;
47
+ /**
48
+ * pass compoent for menu, will be shown at top right side
49
+ */
50
+ AppBarOption?: () => JSX.Element;
51
+ /**
52
+ * Pass array of CometChatOptions type
53
+ * Tobe shown on swipe of list item
54
+ */
55
+ options?: (item: CometChat.Group) => CometChatOptions[];
56
+ /**
57
+ * toggle the seperator
58
+ */
59
+ hideSeperator?: boolean;
60
+ /**
61
+ * hide selection icon
62
+ */
63
+ hideSubmitIcon?: boolean;
64
+ /**
65
+ * styles for groups
66
+ */
67
+ groupsStyle?: GroupsStyleInterface;
68
+ /**
69
+ * styles for list item
70
+ */
71
+ listItemStyle?: ListItemStyleInterface;
72
+ /**
73
+ * styles for avatar
74
+ */
75
+ avatarStyle?: AvatarStyleInterface;
76
+ /**
77
+ * styles for status indicator
78
+ */
79
+ statusIndicatorStyle?: StatusIndicatorStyleInterface;
80
+ /**
81
+ * search placeholder text
82
+ */
83
+ searchPlaceHolderText?: string;
84
+ /**
85
+ * back button icon
86
+ */
87
+ backButtonIcon?: ImageType;
88
+ /**
89
+ * toggle back button
90
+ */
91
+ showBackButton?: boolean;
92
+ /**
93
+ * select items pass "none" | "single" | "multitple"
94
+ */
95
+ selectionMode?: SelectionMode;
96
+ /**
97
+ * call back on seleciton is done
98
+ */
99
+ onSelection?: (items: Array<CometChat.Group>) => void;
100
+ /**
101
+ * icon for search box
102
+ */
103
+ searchBoxIcon?: ImageType;
104
+ /**
105
+ * toggle seearch box
106
+ */
107
+ hideSearch?: boolean;
108
+ /**
109
+ * title to be shown default "Groups"
110
+ */
111
+ title?: string;
112
+ /**
113
+ * Custom Functional component for empty state
114
+ */
115
+ EmptyStateView?: () => JSX.Element;
116
+ /**
117
+ * text to be shown in case no groups found.
118
+ */
119
+ emptyStateText?: string;
120
+ /**
121
+ * Custom functional component for error state.
122
+ */
123
+ ErrorStateView?: () => JSX.Element;
124
+ /**
125
+ * text to be shown in case error occured while fetching gounps for first time
126
+ */
127
+ errorStateText?: string;
128
+ /**
129
+ * Custom image for loading state.
130
+ */
131
+ LoadingStateView?: () => JSX.Element;
132
+ /**
133
+ * Request builder to fetch groups.
134
+ */
135
+ groupsRequestBuilder?: CometChat.GroupsRequestBuilder;
136
+ /**
137
+ * request builder for search
138
+ */
139
+ searchRequestBuilder?: CometChat.GroupsRequestBuilder;
140
+ /**
141
+ * pass icon for private group
142
+ */
143
+ privateGroupIcon?: ImageType;
144
+ /**
145
+ * pass icon for password group
146
+ */
147
+ passwordGroupIcon?: ImageType;
148
+ /**
149
+ * toogle error visibility
150
+ */
151
+ hideError?: boolean;
152
+ /**
153
+ * function tobe called on group pressed.
154
+ */
155
+ onItemPress?: (item: CometChat.Group) => void;
156
+ /**
157
+ * function tobe called on group long pressed.
158
+ */
159
+ onItemLongPress?: (item: CometChat.Group) => void;
160
+ /**
161
+ * function will be called when error occured.
162
+ */
163
+ onError?: (e: CometChat.CometChatException) => void;
164
+ /**
165
+ * function will be called when back button pressed.
166
+ */
167
+ onBack?: () => void;
158
168
  }
159
169
 
160
- const groupListenerId = "grouplist_" + new Date().getTime();
161
-
162
- export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface, ref: any) => {
170
+ const groupListenerId = 'grouplist_' + new Date().getTime();
163
171
 
172
+ export const CometChatGroups = React.forwardRef(
173
+ (props: CometChatGroupsInterface, ref: any) => {
164
174
  const {
165
- SubtitleView,
166
- ListItemView,
167
- AppBarOption,
168
- options,
169
- hideSeperator,
170
- hideSubmitIcon,
171
- groupsStyle,
172
- listItemStyle,
173
- avatarStyle,
174
- statusIndicatorStyle,
175
- searchPlaceHolderText,
176
- backButtonIcon,
177
- showBackButton,
178
- selectionMode,
179
- onSelection,
180
- searchBoxIcon,
181
- hideSearch,
182
- title,
183
- EmptyStateView,
184
- emptyStateText,
185
- ErrorStateView,
186
- errorStateText,
187
- LoadingStateView,
188
- groupsRequestBuilder,
189
- searchRequestBuilder,
190
- privateGroupIcon,
191
- passwordGroupIcon,
192
- hideError,
193
- onItemPress,
194
- onItemLongPress,
195
- onError,
196
- onBack,
175
+ SubtitleView,
176
+ ListItemView,
177
+ AppBarOption,
178
+ options,
179
+ hideSubmitIcon,
180
+ groupsStyle,
181
+ listItemStyle,
182
+ avatarStyle,
183
+ statusIndicatorStyle,
184
+ onSelection,
185
+ searchBoxIcon,
186
+ EmptyStateView,
187
+ emptyStateText,
188
+ ErrorStateView,
189
+ errorStateText,
190
+ LoadingStateView,
191
+ groupsRequestBuilder,
192
+ searchRequestBuilder,
193
+ onItemPress,
194
+ onItemLongPress,
195
+ onError,
196
+ onBack,
197
+ title = localize('GROUPS'),
198
+ searchPlaceHolderText = localize('SEARCH'),
199
+ showBackButton = false,
200
+ hideSearch = false,
201
+ hideSeperator = false,
202
+ backButtonIcon = backIcon,
203
+ selectionMode = 'none',
204
+ privateGroupIcon = privateGroupIconDefault,
205
+ passwordGroupIcon = passwordGroupIconDefault,
206
+ hideError = false,
197
207
  } = props;
198
208
 
199
209
  //context values
@@ -202,45 +212,49 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
202
212
  const groupListRef = useRef<CometChatListActionsInterface | null>(null);
203
213
  const activeSwipeRows = React.useRef<any>({});
204
214
 
205
- const [selecting, setSelecting] = useState(selectionMode != 'none' ? true : false);
215
+ const [selecting, setSelecting] = useState(
216
+ selectionMode != 'none' ? true : false
217
+ );
206
218
  const [selectedGroups, setSelectedGroups] = useState<any[]>([]);
207
219
 
208
220
  const _groupsStyle = new GroupsStyle({
209
- backgroundColor: theme?.palette.getBackgroundColor(),
210
- backIconTint: theme?.palette.getPrimary(),
211
- emptyTextColor: theme?.palette.getAccent400(),
212
- emptyTextFont: theme?.typography.caption2,
213
- errorTextColor: theme?.palette.getError(),
214
- errorTextFont: theme?.typography.subtitle1,
215
- searchBackgroundColor: theme?.palette.getAccent600(),
216
- searchBorder: new BorderStyle({
217
- borderColor: theme?.palette.getAccent700(),
218
- ...groupsStyle?.border,
219
- }),
220
- separatorColor: theme?.palette.getAccent100(),
221
- subtitleTextColor: theme?.palette.getAccent600(),
222
- subtitleTextFont: theme?.typography.text1,
223
- titleColor: theme?.palette.getAccent(),
224
- titleFont: theme?.typography.title1,
225
- loadingIconTint: theme?.palette.getPrimary(),
226
- ...groupsStyle
221
+ backgroundColor: theme?.palette.getBackgroundColor(),
222
+ backIconTint: theme?.palette.getPrimary(),
223
+ emptyTextColor: theme?.palette.getAccent400(),
224
+ emptyTextFont: theme?.typography.caption2,
225
+ errorTextColor: theme?.palette.getError(),
226
+ errorTextFont: theme?.typography.subtitle1,
227
+ searchBackgroundColor: theme?.palette.getAccent600(),
228
+ searchBorder: new BorderStyle({
229
+ borderColor: theme?.palette.getAccent700(),
230
+ ...groupsStyle?.border,
231
+ }),
232
+ separatorColor: theme?.palette.getAccent100(),
233
+ subtitleTextColor: theme?.palette.getAccent600(),
234
+ subtitleTextFont: theme?.typography.text1,
235
+ titleColor: theme?.palette.getAccent(),
236
+ titleFont: theme?.typography.title1,
237
+ loadingIconTint: theme?.palette.getPrimary(),
238
+ ...groupsStyle,
227
239
  });
228
240
  const _avatarStyle = new AvatarStyle({
229
- backgroundColor: theme?.palette.getAccent600(),
230
- nameTextColor: theme?.palette.getSecondary(),
231
- nameTextFont: theme?.typography.title1,
232
- ...avatarStyle
241
+ backgroundColor: theme?.palette.getAccent600(),
242
+ nameTextColor: theme?.palette.getSecondary(),
243
+ nameTextFont: theme?.typography.title1,
244
+ ...avatarStyle,
233
245
  });
234
- const _statusIndicatorStyle = new StatusIndicatorStyle(statusIndicatorStyle || {
246
+ const _statusIndicatorStyle = new StatusIndicatorStyle(
247
+ statusIndicatorStyle || {
235
248
  borderRadius: 10,
236
249
  height: 15,
237
250
  width: 15,
238
- });
251
+ }
252
+ );
239
253
  const _listItemStyle = new ListItemStyle({
240
- backgroundColor: theme?.palette?.getBackgroundColor(),
241
- titleColor: theme?.palette.getAccent(),
242
- titleFont: theme?.typography.name,
243
- ...listItemStyle
254
+ backgroundColor: theme?.palette?.getBackgroundColor(),
255
+ titleColor: theme?.palette.getAccent(),
256
+ titleFont: theme?.typography.name,
257
+ ...listItemStyle,
244
258
  });
245
259
 
246
260
  // const listStyle = new CometChatListStyles({
@@ -250,51 +264,63 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
250
264
  // })
251
265
 
252
266
  React.useImperativeHandle(ref, () => ({
253
- addGroup: addGroup,
254
- updateGroup: updateGroup,
255
- removeGroup: removeGroup,
256
- getSelectedItems
267
+ addGroup: addGroup,
268
+ updateGroup: updateGroup,
269
+ removeGroup: removeGroup,
270
+ getSelectedItems,
257
271
  }));
258
272
 
259
273
  const getSelectedItems = () => {
260
- return selectedGroups;
261
- }
274
+ return selectedGroups;
275
+ };
262
276
 
263
277
  const ErrorView = () => {
264
- if (hideError) return null;
265
-
266
- if (ErrorStateView)
267
- return <ErrorStateView />;
268
- else
269
- return (
270
- <View style={Style.listContainer}>
271
- <Text style={{ ..._groupsStyle.errorTextFont, color: _groupsStyle.errorTextColor } as TextStyle}>
272
- {errorStateText || localize("SOMETHING_WRONG")}
273
- </Text>
274
- </View>
275
- );
276
- }
278
+ if (hideError) return null;
279
+
280
+ if (ErrorStateView) return <ErrorStateView />;
281
+ else
282
+ return (
283
+ <View style={Style.listContainer}>
284
+ <Text
285
+ style={
286
+ {
287
+ ..._groupsStyle.errorTextFont,
288
+ color: _groupsStyle.errorTextColor,
289
+ } as TextStyle
290
+ }
291
+ >
292
+ {errorStateText || localize('SOMETHING_WRONG')}
293
+ </Text>
294
+ </View>
295
+ );
296
+ };
277
297
 
278
298
  const EmptyView = () => {
279
- if (EmptyStateView)
280
- return <EmptyStateView />;
281
- else
282
- return (
283
- <View style={Style.listContainer}>
284
- <Text style={{ ..._groupsStyle.emptyTextFont, color: _groupsStyle.emptyTextColor } as TextStyle}>
285
- {emptyStateText || localize("NO_GROUPS_FOUND")}
286
- </Text>
287
- </View>
288
- )
289
- }
299
+ if (EmptyStateView) return <EmptyStateView />;
300
+ else
301
+ return (
302
+ <View style={Style.listContainer}>
303
+ <Text
304
+ style={
305
+ {
306
+ ..._groupsStyle.emptyTextFont,
307
+ color: _groupsStyle.emptyTextColor,
308
+ } as TextStyle
309
+ }
310
+ >
311
+ {emptyStateText || localize('NO_GROUPS_FOUND')}
312
+ </Text>
313
+ </View>
314
+ );
315
+ };
290
316
 
291
317
  /**
292
318
  *
293
319
  * Listener callback when a member is kicked from / has left the group
294
320
  */
295
321
  const handleGroupMemberRemoval = (...options: any[]) => {
296
- const group = options[3];
297
- groupListRef.current?.updateList(group);
322
+ const group = options[3];
323
+ groupListRef.current?.updateList(group);
298
324
  };
299
325
 
300
326
  /**
@@ -302,8 +328,8 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
302
328
  * Listener callback when a member is banned from the group
303
329
  */
304
330
  const handleGroupMemberBan = (...options: any[]) => {
305
- const group = options[3];
306
- groupListRef.current?.updateList(group);
331
+ const group = options[3];
332
+ groupListRef.current?.updateList(group);
307
333
  };
308
334
 
309
335
  /**
@@ -311,8 +337,8 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
311
337
  * Listener callback when a user joins/added to the group
312
338
  */
313
339
  const handleGroupMemberAddition = (...options: any[]) => {
314
- const group = options[3];
315
- groupListRef.current?.updateList(group);
340
+ const group = options[3];
341
+ groupListRef.current?.updateList(group);
316
342
  };
317
343
 
318
344
  /**
@@ -320,303 +346,308 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
320
346
  * Listener callback when a group member scope is updated
321
347
  */
322
348
  const handleGroupMemberScopeChange = (...options: any[]) => {
323
- const group = options[4];
324
- groupListRef.current?.updateList(group);
349
+ const group = options[4];
350
+ groupListRef.current?.updateList(group);
325
351
  };
326
352
 
327
353
  /**
328
- * This will update group in the list if not found then
354
+ * This will update group in the list if not found then
329
355
  * @param {object} group Group object
330
356
  */
331
357
  const updateGroup = (group: any) => {
332
- groupListRef.current?.updateList((grp: any) => grp["guid"] == group["guid"]);
333
- }
358
+ groupListRef.current?.updateList(
359
+ (grp: any) => grp['guid'] == group['guid']
360
+ );
361
+ };
334
362
 
335
363
  /**
336
364
  * Add the group to the group list at first position.
337
365
  * @param {object} group group object
338
366
  */
339
367
  const addGroup = (group: any) => {
340
- groupListRef.current?.addItemToList((grp: any) => grp["guid"] == group["guid"], 0);
341
- }
368
+ groupListRef.current?.addItemToList(
369
+ (grp: any) => grp['guid'] == group['guid'],
370
+ 0
371
+ );
372
+ };
342
373
 
343
374
  /**
344
375
  * removes the group from the list.
345
376
  * @param {object} group Group object
346
377
  */
347
378
  const removeGroup = (group: any) => {
348
- groupListRef.current?.removeItemFromList(group["guid"])
349
- //remove from selected items if present
350
- if (selecting) {
351
- let index: any = selectedGroups.find(grp => grp['guid'] == group['guid'])
352
- if (index > -1) {
353
- let selectedItems = [...selectedGroups];
354
- selectedItems.splice(index, 1);
355
- setSelectedGroups(selectedItems);
356
- }
379
+ groupListRef.current?.removeItemFromList(group['guid']);
380
+ //remove from selected items if present
381
+ if (selecting) {
382
+ let index: any = selectedGroups.find(
383
+ (grp) => grp['guid'] == group['guid']
384
+ );
385
+ if (index > -1) {
386
+ let selectedItems = [...selectedGroups];
387
+ selectedItems.splice(index, 1);
388
+ setSelectedGroups(selectedItems);
357
389
  }
358
- }
390
+ }
391
+ };
359
392
 
360
393
  const groupClicked = (group: any) => {
361
- if (selecting) {
362
- if (selectionMode == "single") {
363
- if (selectedGroups.length > 0 && selectedGroups[0].guid == group.guid)
364
- setSelectedGroups([]);
365
- else
366
- setSelectedGroups([group]);
367
- return;
368
- }
369
- const index: number = selectedGroups.findIndex((value) => value.guid == group.guid)
370
- if (index >= 0) {
371
- let tmp = [...selectedGroups]
372
- tmp.splice(index, 1);
373
- setSelectedGroups([...tmp]);
374
- } else {
375
- setSelectedGroups([...selectedGroups, group]);
376
- }
377
- return;
394
+ if (selecting) {
395
+ if (selectionMode == 'single') {
396
+ if (selectedGroups.length > 0 && selectedGroups[0].guid == group.guid)
397
+ setSelectedGroups([]);
398
+ else setSelectedGroups([group]);
399
+ return;
378
400
  }
379
- onItemPress && onItemPress(group)
380
- }
401
+ const index: number = selectedGroups.findIndex(
402
+ (value) => value.guid == group.guid
403
+ );
404
+ if (index >= 0) {
405
+ let tmp = [...selectedGroups];
406
+ tmp.splice(index, 1);
407
+ setSelectedGroups([...tmp]);
408
+ } else {
409
+ setSelectedGroups([...selectedGroups, group]);
410
+ }
411
+ return;
412
+ }
413
+ onItemPress && onItemPress(group);
414
+ };
381
415
 
382
416
  const groupLongPressed = (group: any) => {
383
- if (selectionMode != "none") {
384
- setSelecting(true);
385
- if (selectionMode === "multiple")
386
- setSelectedGroups([...selectedGroups, group]);
387
- else
388
- setSelectedGroups([group]);
389
- }
390
- onItemLongPress && onItemLongPress(group);
391
- }
417
+ if (selectionMode != 'none') {
418
+ setSelecting(true);
419
+ if (selectionMode === 'multiple')
420
+ setSelectedGroups([...selectedGroups, group]);
421
+ else setSelectedGroups([group]);
422
+ }
423
+ onItemLongPress && onItemLongPress(group);
424
+ };
392
425
 
393
426
  React.useEffect(() => {
394
- CometChat.addGroupListener(
395
- groupListenerId,
396
- new CometChat.GroupListener({
397
- onGroupMemberScopeChanged: (
398
- message: any,
399
- changedUser: any,
400
- newScope: any,
401
- oldScope: any,
402
- changedGroup: any
403
- ) => {
404
- handleGroupMemberScopeChange(
405
- message,
406
- changedUser,
407
- newScope,
408
- oldScope,
409
- changedGroup
410
- );
411
- },
412
- onGroupMemberKicked: (message: any, kickedUser: any, kickedBy: any, kickedFrom: any) => {
413
- handleGroupMemberRemoval(
414
- message,
415
- kickedUser,
416
- kickedBy,
417
- kickedFrom
418
- );
419
- },
420
- onGroupMemberLeft: (message: any, leavingUser: any, group: any) => {
421
- handleGroupMemberRemoval(message, leavingUser, null, group);
422
- },
423
- onGroupMemberBanned: (message: any, bannedUser: any, bannedBy: any, bannedFrom: any) => {
424
- handleGroupMemberBan(
425
- message,
426
- bannedUser,
427
- bannedBy,
428
- bannedFrom
429
- );
430
- },
431
- onMemberAddedToGroup: (
432
- message: any,
433
- userAdded: any,
434
- userAddedBy: any,
435
- userAddedIn: any
436
- ) => {
437
- handleGroupMemberAddition(
438
- message,
439
- userAdded,
440
- userAddedBy,
441
- userAddedIn
442
- );
443
- },
444
- onGroupMemberJoined: (message: any, joinedUser: any, joinedGroup: any) => {
445
- handleGroupMemberAddition(
446
- message,
447
- joinedUser,
448
- null,
449
- joinedGroup
450
- );
451
- },
452
- })
453
- );
454
- CometChatUIEventHandler.addGroupListener(
455
- uiEventListener,
456
- {
457
- ccGroupCreated: ({ group }: any) => {
458
- groupListRef.current?.addItemToList(group, 0);
459
- },
460
- ccGroupDeleted: ({ group }: any) => {
461
- groupListRef.current?.removeItemFromList(group.guid);
462
- },
463
- ccGroupLeft: ({ leftGroup }: any) => {
464
- leftGroup['hasJoined'] = false;
465
- leftGroup['membersCount'] = leftGroup['membersCount'] - 1;
466
- console.log(leftGroup);
467
- if (leftGroup['type'] == CometChat.GROUP_TYPE.PRIVATE) {
468
- groupListRef.current?.removeItemFromList(leftGroup.getGuid());
469
- } else {
470
- groupListRef.current?.updateList(leftGroup);
471
- }
472
- },
473
- ccGroupMemberKicked: ({ group }: any) => {
474
- if (group['type'] == CometChat.GROUP_TYPE.PRIVATE) {
475
- groupListRef.current?.removeItemFromList(group.getGuid());
476
- } else {
477
- group.setHasJoined(false);
478
- groupListRef.current?.updateList(group);
479
- }
480
- },
481
- ccOwnershipChanged: ({ group }: any) => {
482
- groupListRef.current?.updateList(group);
483
- },
484
- ccGroupMemberAdded: ({ userAddedIn }: { userAddedIn: CometChat.Group }) => {
485
- groupListRef.current?.updateList(userAddedIn);
486
- },
487
- ccGroupMemberJoined: ({ joinedGroup }: { joinedGroup: CometChat.Group }) => {
488
- joinedGroup['membersCount'] = joinedGroup['membersCount'] + 1;
489
- joinedGroup['scope'] = "participant";
490
- joinedGroup['hasJoined'] = true;
491
- groupListRef.current?.updateList(joinedGroup);
492
- }
493
- }
494
- )
495
- return () => {
496
- CometChat.removeGroupListener(groupListenerId);
497
- CometChatUIEventHandler.removeGroupListener(uiEventListener);
498
- }
427
+ CometChat.addGroupListener(
428
+ groupListenerId,
429
+ new CometChat.GroupListener({
430
+ onGroupMemberScopeChanged: (
431
+ message: any,
432
+ changedUser: any,
433
+ newScope: any,
434
+ oldScope: any,
435
+ changedGroup: any
436
+ ) => {
437
+ handleGroupMemberScopeChange(
438
+ message,
439
+ changedUser,
440
+ newScope,
441
+ oldScope,
442
+ changedGroup
443
+ );
444
+ },
445
+ onGroupMemberKicked: (
446
+ message: any,
447
+ kickedUser: any,
448
+ kickedBy: any,
449
+ kickedFrom: any
450
+ ) => {
451
+ handleGroupMemberRemoval(message, kickedUser, kickedBy, kickedFrom);
452
+ },
453
+ onGroupMemberLeft: (message: any, leavingUser: any, group: any) => {
454
+ handleGroupMemberRemoval(message, leavingUser, null, group);
455
+ },
456
+ onGroupMemberBanned: (
457
+ message: any,
458
+ bannedUser: any,
459
+ bannedBy: any,
460
+ bannedFrom: any
461
+ ) => {
462
+ handleGroupMemberBan(message, bannedUser, bannedBy, bannedFrom);
463
+ },
464
+ onMemberAddedToGroup: (
465
+ message: any,
466
+ userAdded: any,
467
+ userAddedBy: any,
468
+ userAddedIn: any
469
+ ) => {
470
+ handleGroupMemberAddition(
471
+ message,
472
+ userAdded,
473
+ userAddedBy,
474
+ userAddedIn
475
+ );
476
+ },
477
+ onGroupMemberJoined: (
478
+ message: any,
479
+ joinedUser: any,
480
+ joinedGroup: any
481
+ ) => {
482
+ handleGroupMemberAddition(message, joinedUser, null, joinedGroup);
483
+ },
484
+ })
485
+ );
486
+ CometChatUIEventHandler.addGroupListener(uiEventListener, {
487
+ ccGroupCreated: ({ group }: any) => {
488
+ groupListRef.current?.addItemToList(group, 0);
489
+ },
490
+ ccGroupDeleted: ({ group }: any) => {
491
+ groupListRef.current?.removeItemFromList(group.guid);
492
+ },
493
+ ccGroupLeft: ({ leftGroup }: any) => {
494
+ leftGroup['hasJoined'] = false;
495
+ leftGroup['membersCount'] = leftGroup['membersCount'] - 1;
496
+ console.log(leftGroup);
497
+ if (leftGroup['type'] == CometChat.GROUP_TYPE.PRIVATE) {
498
+ groupListRef.current?.removeItemFromList(leftGroup.getGuid());
499
+ } else {
500
+ groupListRef.current?.updateList(leftGroup);
501
+ }
502
+ },
503
+ ccGroupMemberKicked: ({ group }: any) => {
504
+ if (group['type'] == CometChat.GROUP_TYPE.PRIVATE) {
505
+ groupListRef.current?.removeItemFromList(group.getGuid());
506
+ } else {
507
+ group.setHasJoined(false);
508
+ groupListRef.current?.updateList(group);
509
+ }
510
+ },
511
+ ccOwnershipChanged: ({ group }: any) => {
512
+ groupListRef.current?.updateList(group);
513
+ },
514
+ ccGroupMemberAdded: ({
515
+ userAddedIn,
516
+ }: {
517
+ userAddedIn: CometChat.Group;
518
+ }) => {
519
+ groupListRef.current?.updateList(userAddedIn);
520
+ },
521
+ ccGroupMemberJoined: ({
522
+ joinedGroup,
523
+ }: {
524
+ joinedGroup: CometChat.Group;
525
+ }) => {
526
+ joinedGroup['membersCount'] = joinedGroup['membersCount'] + 1;
527
+ joinedGroup['scope'] = 'participant';
528
+ joinedGroup['hasJoined'] = true;
529
+ groupListRef.current?.updateList(joinedGroup);
530
+ },
531
+ });
532
+ return () => {
533
+ CometChat.removeGroupListener(groupListenerId);
534
+ CometChatUIEventHandler.removeGroupListener(uiEventListener);
535
+ };
499
536
  }, []);
500
537
 
501
538
  const GroupItemView = ({ item }: any) => {
502
- //custom view check
503
- if (ListItemView)
504
- return ListItemView(item);
505
-
506
- const { type, name, icon, membersCount } = item;
507
- let image: ImageType | undefined, backgroundColor: string = "transparent";
508
- if (type == GroupTypeConstants.password) {
509
- image = passwordGroupIcon || passwordGroupIcon;
510
- backgroundColor = PASSWORD_GROUP_COLOR;
511
- }
512
- if (type == GroupTypeConstants.private) {
513
- image = privateGroupIcon || privateGroupIcon;
514
- backgroundColor = PRIVATE_GROUP_COLOR;
515
- }
516
- if (selecting) {
517
- let index: number = selectedGroups.findIndex((value) => value.guid == item.guid);
518
- if (index >= 0) {
519
- image = checkIcon;
520
- backgroundColor = theme?.palette?.getBackgroundColor();
521
- }
539
+ //custom view check
540
+ if (ListItemView) return ListItemView(item);
541
+
542
+ const { type, name, icon, membersCount } = item;
543
+ let image: ImageType | undefined,
544
+ backgroundColor: string = 'transparent';
545
+ if (type == GroupTypeConstants.password) {
546
+ image = passwordGroupIcon || passwordGroupIcon;
547
+ backgroundColor = PASSWORD_GROUP_COLOR;
548
+ }
549
+ if (type == GroupTypeConstants.private) {
550
+ image = privateGroupIcon || privateGroupIcon;
551
+ backgroundColor = PRIVATE_GROUP_COLOR;
552
+ }
553
+ if (selecting) {
554
+ let index: number = selectedGroups.findIndex(
555
+ (value) => value.guid == item.guid
556
+ );
557
+ if (index >= 0) {
558
+ image = checkIcon;
559
+ backgroundColor = theme?.palette?.getBackgroundColor();
522
560
  }
523
-
524
- return <CometChatListItem
525
- id={item.guid}
526
- avatarName={name}
527
- avatarURL={icon}
528
- hideSeparator={hideSeperator}
529
- SubtitleView={() => SubtitleView && SubtitleView(item) || <Text style={{ color: theme.palette.getAccent600() }}>{membersCount} <Text>{localize("MEMBERS")}</Text></Text>}
530
- title={name}
531
- statusIndicatorIcon={image}
532
- statusIndicatorColor={backgroundColor}
533
- listItemStyle={_listItemStyle}
534
- avatarStyle={_avatarStyle}
535
- statusIndicatorStyle={_statusIndicatorStyle as ViewProps}
536
- onPress={groupClicked.bind(this, item)}
537
- onLongPress={groupLongPressed.bind(this, item)}
538
- options={() => options && options(item) || []}
539
- activeSwipeRows={activeSwipeRows.current}
540
- rowOpens={(id) => {
541
- Object.keys(activeSwipeRows.current).forEach(key => {
542
- if (id !== key && activeSwipeRows.current[key]) {
543
- activeSwipeRows.current[key]?.current?.closeRow?.()
544
- delete activeSwipeRows.current[key]
545
- }
546
- })
547
- }}
561
+ }
562
+
563
+ return (
564
+ <CometChatListItem
565
+ id={item.guid}
566
+ avatarName={name}
567
+ avatarURL={icon}
568
+ hideSeparator={hideSeperator}
569
+ SubtitleView={() =>
570
+ (SubtitleView && SubtitleView(item)) || (
571
+ <Text style={{ color: theme.palette.getAccent600() }}>
572
+ {membersCount} <Text>{localize('MEMBERS')}</Text>
573
+ </Text>
574
+ )
575
+ }
576
+ title={name}
577
+ statusIndicatorIcon={image}
578
+ statusIndicatorColor={backgroundColor}
579
+ listItemStyle={_listItemStyle}
580
+ avatarStyle={_avatarStyle}
581
+ statusIndicatorStyle={_statusIndicatorStyle as ViewProps}
582
+ onPress={groupClicked.bind(this, item)}
583
+ onLongPress={groupLongPressed.bind(this, item)}
584
+ options={() => (options && options(item)) || []}
585
+ activeSwipeRows={activeSwipeRows.current}
586
+ rowOpens={(id) => {
587
+ Object.keys(activeSwipeRows.current).forEach((key) => {
588
+ if (id !== key && activeSwipeRows.current[key]) {
589
+ activeSwipeRows.current[key]?.current?.closeRow?.();
590
+ delete activeSwipeRows.current[key];
591
+ }
592
+ });
593
+ }}
548
594
  />
595
+ );
549
596
  };
550
597
 
551
598
  const onSelectionClicked = () => {
552
- if(!selectedGroups.length) return
553
- onSelection && onSelection(selectedGroups);
599
+ if (!selectedGroups.length) return;
600
+ onSelection && onSelection(selectedGroups);
554
601
 
555
- setSelecting(false);
556
- setSelectedGroups([]);
557
- }
602
+ setSelecting(false);
603
+ setSelectedGroups([]);
604
+ };
558
605
 
559
606
  return (
560
- <View style={[Style.container, { backgroundColor: _groupsStyle.backgroundColor }]}>
561
- <CometChatList
562
- title={title}
563
- LoadingStateView={LoadingStateView}
564
- searchPlaceholderText={searchPlaceHolderText}
565
- ref={groupListRef}
566
- listItemKey="guid"
567
- ListItemView={GroupItemView}
568
- EmptyStateView={EmptyView}
569
- ErrorStateView={ErrorView}
570
- requestBuilder={groupsRequestBuilder || new CometChat.GroupsRequestBuilder()
571
- .setLimit(30)
572
- .setSearchKeyword("")}
573
- searchRequestBuilder={searchRequestBuilder}
574
- AppBarOptions={AppBarOption}
575
- hideSeparator={hideSeperator}
576
- backButtonIcon={backButtonIcon}
577
- showBackButton={showBackButton}
578
- selectionMode={selectedGroups.length > 0 || selecting ? selectionMode : "none"}
579
- onSelection={onSelectionClicked}
580
- searchBoxIcon={searchBoxIcon}
581
- hideSearch={hideSearch}
582
- hideSubmitIcon={hideSubmitIcon}
583
- onError={onError}
584
- onBack={onBack}
585
- listStyle={{ ..._groupsStyle, background: _groupsStyle.backgroundColor }}
586
- statusIndicatorStyle={_statusIndicatorStyle}
587
- avatarStyle={_avatarStyle}
588
- listItemStyle={_listItemStyle}
589
- />
590
- </View>
591
- )
592
- });
593
-
594
- CometChatGroups.defaultProps = {
595
- title: localize("GROUPS"),
596
- searchPlaceHolderText: localize("SEARCH"),
597
- showBackButton: false,
598
- searchBoxIcon: undefined,
599
- hideSearch: false,
600
- listItemStyle: undefined,
601
- avatarStyle: undefined,
602
- statusIndicatorStyle: undefined,
603
- SubtitleView: undefined,
604
- ListItemView: undefined,
605
- AppBarOption: undefined,
606
- options: undefined,
607
- hideSeperator: false,
608
- backButtonIcon: backIcon,
609
- selectionMode: "none",
610
- onSelection: undefined,
611
- EmptyStateView: undefined,
612
- emptyStateText: undefined,
613
- LoadingStateView: undefined,
614
- groupsRequestBuilder: undefined,
615
- privateGroupIcon: privateGroupIcon,
616
- passwordGroupIcon: passwordGroupIcon,
617
- hideError: false,
618
- onItemPress: undefined,
619
- onItemLongPress: undefined,
620
- onError: undefined,
621
- onBack: undefined,
622
- }
607
+ <View
608
+ style={[
609
+ Style.container,
610
+ { backgroundColor: _groupsStyle.backgroundColor },
611
+ ]}
612
+ >
613
+ <CometChatList
614
+ title={title}
615
+ LoadingStateView={LoadingStateView}
616
+ searchPlaceholderText={searchPlaceHolderText}
617
+ ref={groupListRef}
618
+ listItemKey="guid"
619
+ ListItemView={GroupItemView}
620
+ EmptyStateView={EmptyView}
621
+ ErrorStateView={ErrorView}
622
+ requestBuilder={
623
+ groupsRequestBuilder ||
624
+ new CometChat.GroupsRequestBuilder()
625
+ .setLimit(30)
626
+ .setSearchKeyword('')
627
+ }
628
+ searchRequestBuilder={searchRequestBuilder}
629
+ AppBarOptions={AppBarOption}
630
+ hideSeparator={hideSeperator}
631
+ backButtonIcon={backButtonIcon}
632
+ showBackButton={showBackButton}
633
+ selectionMode={
634
+ selectedGroups.length > 0 || selecting ? selectionMode : 'none'
635
+ }
636
+ onSelection={onSelectionClicked}
637
+ searchBoxIcon={searchBoxIcon}
638
+ hideSearch={hideSearch}
639
+ hideSubmitIcon={hideSubmitIcon}
640
+ onError={onError}
641
+ onBack={onBack}
642
+ listStyle={{
643
+ ..._groupsStyle,
644
+ background: _groupsStyle.backgroundColor,
645
+ }}
646
+ statusIndicatorStyle={_statusIndicatorStyle}
647
+ avatarStyle={_avatarStyle}
648
+ listItemStyle={_listItemStyle}
649
+ />
650
+ </View>
651
+ );
652
+ }
653
+ );