@messenger-box/platform-mobile 0.0.1-alpha.392 → 0.0.1-alpha.394

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.
@@ -12,7 +12,7 @@ import {
12
12
  ScrollView,
13
13
  Center,
14
14
  } from 'native-base';
15
- import { Platform, TouchableOpacity, TouchableHighlight } from 'react-native';
15
+ import { Platform, TouchableHighlight } from 'react-native';
16
16
  import { useNavigation, useFocusEffect, useIsFocused } from '@react-navigation/native';
17
17
  import { useSelector } from 'react-redux';
18
18
  import { orderBy, uniqBy, startCase } from 'lodash';
@@ -58,6 +58,7 @@ const createdAtText = (value: string) => {
58
58
 
59
59
  interface ISubscriptionHandlerProps {
60
60
  subscribeToNewMessages: () => any;
61
+ channelId: string;
61
62
  }
62
63
 
63
64
  interface IMessageProps extends IMessage {
@@ -100,19 +101,8 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
100
101
  const isFocused = useIsFocused();
101
102
  const { data: mongooseObjectId, refetch: refetchNewPostId } = useGetNewMongooseObjectIdQuery({
102
103
  fetchPolicy: 'network-only',
103
- //pollInterval: 5000,
104
104
  });
105
105
 
106
- // const {
107
- // data: newMessage,
108
- // loading: newMsgLoading,
109
- // error: newMsgError,
110
- // }: any = useOnChatMessageAddedSubscription({
111
- // variables: {
112
- // channelId: channelId?.toString(),
113
- // },
114
- // });
115
-
116
106
  const { startUpload } = useUploadFilesNative();
117
107
 
118
108
  const [sendMsg] = useSendMessagesMutation();
@@ -134,9 +124,8 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
134
124
  },
135
125
  skip: !channelId,
136
126
  fetchPolicy: 'cache-and-network',
127
+ nextFetchPolicy: 'cache-first',
137
128
  refetchWritePolicy: 'merge',
138
- // fetchPolicy: 'cache-and-network',
139
- // nextFetchPolicy: 'cache-first',
140
129
  });
141
130
 
142
131
  const {
@@ -150,15 +139,6 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
150
139
  });
151
140
  // const { data: users } = useGetAllUsersQuery();
152
141
 
153
- // const { data: checkForMessages }: any = useCheckForNewMessagesQuery({
154
- // variables: {
155
- // channelId: channelId?.toString(),
156
- // },
157
- // skip: !channelId,
158
- // fetchPolicy: 'network-only',
159
- // pollInterval: 5000,
160
- // });
161
-
162
142
  useFocusEffect(
163
143
  React.useCallback(() => {
164
144
  // Do something when the screen is focused
@@ -175,13 +155,14 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
175
155
  }
176
156
  const { data: messages, totalCount }: any = data.messages;
177
157
  setTotalCount(totalCount);
178
- setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, ...messages], ({ id }) => id));
158
+ setChannelMessages(messages);
179
159
  });
180
160
  return () => {
181
161
  // Do something when the screen is unfocused
182
162
  // Useful for cleanup functions
183
163
  setTotalCount(0);
184
164
  setChannelMessages([]);
165
+ setSkip(0);
185
166
  };
186
167
  }, [isFocused]),
187
168
  );
@@ -190,76 +171,6 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
190
171
  if (selectedImage) setImageLoading(false);
191
172
  }, [selectedImage]);
192
173
 
193
- // const currentUser = useMemo(
194
- // () => users?.getUsers?.find(({ alias }: any) => alias?.includes(auth?.auth0UserId)),
195
- // [users, auth],
196
- // );
197
-
198
- // useEffect(() => {
199
- // if (data?.messages?.data && (loadingOldMessages || channelMessages.length === 0)) {
200
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
201
- // if (messages && messages.length > 0) {
202
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
203
- // }
204
- // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
205
- // }
206
- // }, [data, loadingOldMessages, channelMessages]);
207
-
208
- // useEffect(() => {
209
- // if (data?.messages?.data) {
210
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
211
- // if (
212
- // messages &&
213
- // messages.length > 0 &&
214
- // totalCount !== messeageTotalCount &&
215
- // (loadingOldMessages || channelMessages.length === 0)
216
- // ) {
217
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
218
- // setLoadingOldMessages(false);
219
- // setTotalCount(messeageTotalCount);
220
- // }
221
- // // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
222
- // }
223
- // }, [data, loadingOldMessages, channelMessages]);///
224
- ////......... initiate messages ......................////
225
- // useEffect(() => {
226
- // if (data?.messages?.data && (loadingOldMessages || channelMessages.length === 0)) {
227
- // console.log('loading msg')
228
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
229
- // if (messages && messages.length > 0) {
230
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
231
- // setLoadingOldMessages(false);
232
- // }
233
- // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
234
- // }
235
- // }, [data, loadingOldMessages, channelMessages, totalCount]);
236
- ////.... initiate messages end................................////
237
-
238
- // useEffect(() => {
239
- // if (data?.messages?.data && (loadingOldMessages || channelMessages.length === 0)) {
240
- // console.log('initiate msg')
241
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
242
- // if (messages && messages.length > 0) {
243
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
244
- // setTotalCount(messeageTotalCount);
245
- // }
246
- // if(loadingOldMessages) setLoadingOldMessages(false);
247
- // }
248
-
249
- // }, [data, channelMessages,loadingOldMessages]);
250
-
251
- // useEffect(() => {
252
- // if ((data?.messages?.data && channelMessages.length === 0) || (data?.messages?.data && loadingOldMessages)) {
253
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
254
- // if (messages && messages.length > 0) {
255
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
256
- // setTotalCount(messeageTotalCount);
257
- // }
258
- // setLoadEarlierMsg(false);
259
- // if (loadingOldMessages) setLoadingOldMessages(false);
260
- // }
261
- // }, [data, loadingOldMessages, channelMessages]);
262
-
263
174
  useEffect(() => {
264
175
  if (data?.messages?.data) {
265
176
  const { data: messages, totalCount: messeageTotalCount } = data.messages;
@@ -269,140 +180,38 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
269
180
  ) {
270
181
  setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
271
182
  setTotalCount(messeageTotalCount);
272
- setLoadEarlierMsg(false);
273
183
  }
274
184
 
275
185
  if (loadingOldMessages && channelMessages) setLoadingOldMessages(false);
276
-
277
- if (
278
- channelMessages &&
279
- channelMessages?.length == MESSAGES_PER_PAGE &&
280
- totalCount > channelMessages?.length
281
- ) {
282
- onFetchOld();
283
- }
284
186
  }
285
187
  }, [data, loadingOldMessages, channelMessages, totalCount]);
286
188
 
287
- // React.useEffect(() => {
288
- // if (newMessage) {
289
- // const msg = newMessage?.chatMessageAdded;
290
- // setTotalCount((preCount: any) => preCount + 1);
291
- // setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, msg], ({ id }) => id));
292
- // }
293
- // }, [newMessage]);
294
-
295
- // useEffect(() => {
296
- // if (data?.messages?.data) {
297
- // const { data: messages, totalCount: messeageTotalCount } = data.messages;
298
- // console.log('messeageTotalCount',messeageTotalCount)
299
- // console.log('totalCount',totalCount)
300
- // if (messages && messages.length > 0) {
301
- // setChannelMessages((oldMessages: any) => uniqBy([...messages, ...oldMessages], ({ id }) => id));
302
- // }
303
- // if (totalCount !== messeageTotalCount) setTotalCount(messeageTotalCount);
304
- // }
305
- // }, [data]);
306
-
307
- // useEffect(() => {
308
- // if (checkForMessages?.messages?.totalCount > totalCount) {
309
- // const numberOfNewMessages = checkForMessages?.messages?.totalCount - totalCount;
310
- // refetch({
311
- // limit: numberOfNewMessages,
312
- // }).then(({ data }) => {
313
- // if (!data?.messages) {
314
- // return;
315
- // }
316
- // const { data: messages, totalCount }:any = data.messages;
317
- // setTotalCount(totalCount);
318
- // setChannelMessages((oldMessages:any) => uniqBy([...oldMessages, ...messages], ({ id }) => id));
319
- // });
320
- // }
321
- // }, [checkForMessages, totalCount]);
322
- ////////...............New msg check...........////
323
- // useEffect(() => {
324
- // if (
325
- // !messageLoading &&
326
- // checkForMessages?.messages?.totalCount &&
327
- // checkForMessages?.messages?.totalCount > totalCount
328
- // ) {
329
- // const numberOfNewMessages = checkForMessages?.messages?.totalCount - totalCount;
330
- // console.log('new msg check');
331
- // refetch({
332
- // channelId: channelId?.toString(),
333
- // parentId: null,
334
- // limit: numberOfNewMessages,
335
- // }).then(({ data }) => {
336
- // if (!data?.messages) {
337
- // return;
338
- // }
339
- // const { data: messages, totalCount }: any = data.messages;
340
- // setTotalCount(totalCount);
341
- // setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, ...messages], ({ id }) => id));
342
- // });
343
- // }
344
- // }, [checkForMessages, totalCount]);
345
- ////////////....new msg check end.........//
346
-
347
- // const onFetchOld = useCallback(() => {
348
- // // if (data?.messages?.totalCount > channelMessages.length) {
349
- // //if(channelMessages.length !== data?.messages?.totalCount){
350
- // if(totalCount > channelMessages.length){
351
- // setLoadingOldMessages(true);
352
- // refetch({ skip: channelMessages.length });
353
- // }
354
- // }, [data, channelMessages]);
355
-
356
- // const onFetchOld = () => {
357
- // // if (data?.messages?.totalCount > channelMessages.length) {
358
- // //if(channelMessages.length !== data?.messages?.totalCount){
359
- // if(totalCount > channelMessages.length){
360
- // setLoadingOldMessages(true);
361
- // refetch({ skip: channelMessages.length });
362
- // }
363
- // };
364
-
365
- // const onFetchOld = useCallback(() => {
366
- // if (data?.messages?.totalCount > channelMessages.length) {
367
- // console.log('fetchmore')
368
-
369
- // refetch({ channelId: channelId?.toString(), parentId: null, skip: channelMessages.length })?.then((res:any)=>{
370
- // setLoadingOldMessages(true);
371
- // });
372
-
373
- // }
374
- // }, [data, channelMessages]);
375
-
376
- const onFetchOld = useCallback(() => {
189
+ const onFetchOld = useCallback(async () => {
377
190
  if (totalCount > channelMessages.length && !loadingOldMessages) {
378
- setSkip(channelMessages.length);
379
191
  setLoadEarlierMsg(true);
380
- fetchMoreMessages({
381
- variables: {
382
- channelId: channelId?.toString(),
383
- parentId: null,
384
- skip: channelMessages.length,
385
- },
386
- })?.then((res: any) => {
387
- setLoadingOldMessages(true);
388
- });
389
- // refetch({ channelId: channelId?.toString(), parentId: null, skip: channelMessages.length })?.then(
390
- // (res: any) => setLoadingOldMessages(true),
391
- // );
192
+ try {
193
+ const response = await fetchMoreMessages({
194
+ variables: {
195
+ channelId: channelId?.toString(),
196
+ parentId: null,
197
+ skip: channelMessages.length,
198
+ },
199
+ });
200
+ if (response?.data) {
201
+ setSkip(channelMessages.length);
202
+ setLoadEarlierMsg(false);
203
+ setLoadingOldMessages(true);
204
+ }
205
+ } catch (error: any) {
206
+ setLoadEarlierMsg(false);
207
+ }
208
+
209
+ // ?.then((res: any) => {
210
+ // setLoadingOldMessages(true);
211
+ // });
392
212
  }
393
213
  }, [totalCount, channelMessages]);
394
214
 
395
- // const onFetchOld = () => {
396
- // if(totalCount > channelMessages.length){
397
- // console.log('totalCount',totalCount)
398
- // console.log('channelMessages.length',channelMessages.length)
399
- // setLoadingOldMessages(true);
400
- // refetch({
401
- // skip: channelMessages.length
402
- // });
403
- // }
404
- // };
405
-
406
215
  // const isCloseToTop = ({ layoutMeasurement, contentOffset, contentSize }) => {
407
216
  // return contentOffset.y <= 100; // 100px from top
408
217
  // };
@@ -443,130 +252,6 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
443
252
  if (imageSource.cancelled) setLoading(false);
444
253
  };
445
254
 
446
- // const sendPushNotification = async (title: String, body: String, data: any, to: any) => {
447
- // try {
448
- // const response = await fetch('https://exp.host/--/api/v2/push/send/', {
449
- // method: 'POST',
450
- // headers: {
451
- // Accept: 'application/json',
452
- // 'Accept-Encoding': 'gzip, deflate',
453
- // 'Content-Type': 'application/json',
454
- // },
455
- // body: JSON.stringify({
456
- // to: to,
457
- // data: data,
458
- // title: title,
459
- // body: body,
460
- // sound: Platform.OS === 'android' ? undefined || null : 'default',
461
- // }),
462
- // });
463
- // const result: any = await response.json();
464
- // console.log('expo api response', result);
465
- // } catch (error) {
466
- // console.error('Error:', error);
467
- // }
468
-
469
- // // fetch('https://exp.host/--/api/v2/push/send/', {
470
- // // method: 'POST',
471
- // // headers: {
472
- // // Accept: 'application/json',
473
- // // 'Accept-Encoding': 'gzip, deflate',
474
- // // 'Content-Type': 'application/json',
475
- // // },
476
- // // body: JSON.stringify({
477
- // // to: to,
478
- // // data: data,
479
- // // title: title,
480
- // // body: body,
481
- // // sound: Platform.OS === 'android' ? null : 'default',
482
- // // }),
483
- // // });
484
- // };
485
-
486
- // const handleSend = useCallback(
487
- // async (message: string) => {
488
- // // if (!(message && channelId)) {
489
- // // return;
490
- // // }
491
-
492
- // if (!channelId) return;
493
- // if (!message && message != ' ' && images.length == 0) return;
494
-
495
- // setLoading(true);
496
- // const { data } = await sendMsg({
497
- // variables: {
498
- // channelId,
499
- // content: message,
500
- // },
501
- // update: (cache, { data, errors }) => {
502
- // if (!data || errors) {
503
- // setLoading(false);
504
- // return;
505
- // }
506
- // setChannelMessages((messages) => [...messages, data?.sendMessage]);
507
- // setTotalCount((t) => t + 1);
508
- // setChannelToTop(channelToTop + 1);
509
- // setLoading(false);
510
- // const title: String = currentUser?.givenName+' '+currentUser?.familyName+' in Followup Chat';
511
- // const body: String = message;
512
- // const notificationData: any = {
513
- // url: config.INBOX_MESSEGE_PATH,
514
- // params: { channelId, hideTabBar: true },
515
- // screen: 'DialogMessages',
516
- // };
517
- // console.log('expo to',JSON.stringify(expoTokens));
518
- // if (expoTokens?.length > 0) {
519
- // const to: any = expoTokens?.length > 0 ? expoTokens : [];
520
-
521
- // sendPushNotification(title, body, notificationData, to);
522
- // }
523
-
524
- // setMsg('');
525
- // },
526
- // });
527
- // if (images && images.length > 0 && data?.sendMessage?.id) {
528
- // const { id: postId } = data.sendMessage;
529
- // setLoading(true);
530
- // const uploadResponse = await startUpload({
531
- // file: images,
532
- // saveUploadedFile: {
533
- // variables: {
534
- // postId,
535
- // },
536
- // },
537
- // createUploadLink: {
538
- // variables: {
539
- // postId,
540
- // },
541
- // },
542
- // });
543
- // if (uploadResponse?.error) setLoading(false);
544
- // const uploadedFiles = uploadResponse.data as unknown as IFileInfo[];
545
- // if (uploadResponse.data) {
546
- // setImage('');
547
- // setFiles([]);
548
- // setImages([]);
549
- // setLoading(false);
550
- // }
551
- // setChannelMessages((messages) =>
552
- // messages.map((message) => {
553
- // if (message.id === postId) {
554
- // return {
555
- // ...message,
556
- // files: {
557
- // totalCount: uploadedFiles.length,
558
- // data: uploadedFiles,
559
- // },
560
- // };
561
- // }
562
- // return message;
563
- // }),
564
- // );
565
- // }
566
- // },
567
- // [setChannelMessages, currentUser, channelId, images,expoTokens],
568
- // );
569
-
570
255
  const handleSend = useCallback(
571
256
  async (message: string) => {
572
257
  if (!channelId) return;
@@ -582,7 +267,7 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
582
267
  if (images && images.length > 0) {
583
268
  const newPostId = await refetchNewPostId();
584
269
  const postId: any = newPostId?.data?.getNewMongooseObjectId?.toString();
585
- // const postId: any = mongooseObjectId?.getNewMongooseObjectId;
270
+
586
271
  setLoading(true);
587
272
  const uploadResponse = await startUpload({
588
273
  file: images,
@@ -619,22 +304,10 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
619
304
  setLoading(false);
620
305
  return;
621
306
  }
622
- // setChannelMessages((messages: any) => [
623
- // ...messages,
624
- // {
625
- // ...data?.sendMessage,
626
- // files: {
627
- // totalCount: uploadedFiles.length,
628
- // data: uploadedFiles,
629
- // },
630
- // },
631
- // ]);
632
- // setTotalCount((t: any) => t + 1);
307
+
633
308
  setChannelToTop(channelToTop + 1);
634
309
  setLoading(false);
635
310
  setMsg('');
636
- const msg = message == '' ? 'Send a file' : message;
637
- //sendPushNotification(data?.sendMessage, channelId);
638
311
  },
639
312
  });
640
313
  }
@@ -651,12 +324,9 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
651
324
  setLoading(false);
652
325
  return;
653
326
  }
654
- // setChannelMessages((messages: any) => [...messages, data?.sendMessage]);
655
- // setTotalCount((t: any) => t + 1);
656
327
  setChannelToTop(channelToTop + 1);
657
328
  setLoading(false);
658
329
  setMsg('');
659
- // sendPushNotification(data?.sendMessage, channelId);
660
330
  },
661
331
  });
662
332
  }
@@ -664,153 +334,6 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
664
334
  [mongooseObjectId, setChannelMessages, channelId, images, channelToTop, expoTokens],
665
335
  );
666
336
 
667
- // const sendPushNotification = async (post: IPost, channelId: string) => {
668
- // const notificationData: IExpoNotificationData = {
669
- // url: config.INBOX_MESSEGE_PATH,
670
- // params: { channelId, hideTabBar: true },
671
- // screen: 'DialogMessages',
672
- // other: { sound: Platform.OS === 'android' ? undefined || null : 'default' },
673
- // };
674
-
675
- // await sendExpoNotificationOnPostMutation({
676
- // variables: {
677
- // postId: post?.id?.toString(),
678
- // notificationData,
679
- // },
680
- // });
681
- // };
682
-
683
- // const fetchTokenAndSendPushNotification = (message: any, channelId: any) => {
684
- // const givenName = auth?.profile?.given_name ?? '';
685
- // const familyName = auth?.profile?.family_name ?? '';
686
- // const fullName = givenName ? givenName + ' ' + familyName : '';
687
- // const title: String = fullName ? fullName : 'Message';
688
- // const body: String = message;
689
- // const notificationData: any = {
690
- // url: config.INBOX_MESSEGE_PATH,
691
- // params: { channelId, hideTabBar: true },
692
- // screen: 'DialogMessages',
693
- // };
694
- // refetchChannelDetail({ id: channelId?.toString() })?.then((res: any) => {
695
- // if (res?.data?.viewChannelDetail?.members?.length) {
696
- // const channelData: any =
697
- // res?.data?.viewChannelDetail?.members?.filter((mu: any) => mu?.user?.id != auth?.id) ?? [];
698
- // const tokens: any =
699
- // channelData
700
- // ?.map(
701
- // (u: any) =>
702
- // u?.user?.tokens
703
- // ?.filter((t: any) => t?.type == 'EXPO_NOTIFICATION_TOKEN')
704
- // ?.map((et: any) => et?.token) ?? [],
705
- // )
706
- // ?.flat(1)
707
- // ?.filter((t: any) => t)
708
- // ?.filter((value: any, index: any, array: any) => array.indexOf(value) === index) ?? [];
709
- // console.log('expo to', JSON.stringify(tokens));
710
- // if (tokens?.length > 0) {
711
- // const to: any = tokens?.length > 0 ? tokens : [];
712
- // sendPushNotification(title, body, notificationData, to);
713
- // }
714
- // }
715
- // });
716
- // };
717
-
718
- // const handleSend1 = async (message: string) => {
719
- // if (!channelId) return;
720
- // if (!message && message != ' ' && images.length == 0) return;
721
-
722
- // setLoading(true);
723
- // const { data } = await sendMsg({
724
- // variables: {
725
- // channelId,
726
- // content: message,
727
- // },
728
- // update: (cache, { data, errors }: any) => {
729
- // if (!data || errors) {
730
- // setLoading(false);
731
- // return;
732
- // }
733
- // setChannelMessages((messages: any) => [...messages, data?.sendMessage]);
734
- // setTotalCount((t: any) => t + 1);
735
- // setChannelToTop(channelToTop + 1);
736
- // setLoading(false);
737
- // setMsg('');
738
- // const givenName = auth?.profile?.given_name ?? '';
739
- // const familyName = auth?.profile?.family_name ?? '';
740
- // const fullName = givenName ? givenName + ' ' + familyName : '';
741
- // const title: String = fullName ? fullName : 'Message';
742
- // const body: String = message;
743
- // const notificationData: any = {
744
- // url: config.INBOX_MESSEGE_PATH,
745
- // params: { channelId, hideTabBar: true },
746
- // screen: 'DialogMessages',
747
- // };
748
- // refetchChannelDetail({ id: channelId?.toString() })?.then((res: any) => {
749
- // if (res?.data?.viewChannelDetail?.members?.length) {
750
- // const channelData: any =
751
- // res?.data?.viewChannelDetail?.members?.filter((mu: any) => mu?.user?.id != auth?.id) ?? [];
752
- // const tokens: any =
753
- // channelData
754
- // ?.map(
755
- // (u: any) =>
756
- // u?.user?.tokens
757
- // ?.filter((t: any) => t?.type == 'EXPO_NOTIFICATION_TOKEN')
758
- // ?.map((et: any) => et?.token) ?? [],
759
- // )
760
- // ?.flat(1)
761
- // ?.filter((t: any) => t)
762
- // ?.filter((value: any, index: any, array: any) => array.indexOf(value) === index) ?? [];
763
- // console.log('expo to', JSON.stringify(tokens));
764
- // if (tokens?.length > 0) {
765
- // const to: any = tokens?.length > 0 ? tokens : [];
766
-
767
- // sendPushNotification(title, body, notificationData, to);
768
- // }
769
- // }
770
- // });
771
- // },
772
- // });
773
- // if (images && images.length > 0 && data?.sendMessage?.id) {
774
- // const { id: postId } = data.sendMessage;
775
- // setLoading(true);
776
- // const uploadResponse = await startUpload({
777
- // file: images,
778
- // saveUploadedFile: {
779
- // variables: {
780
- // postId,
781
- // },
782
- // },
783
- // createUploadLink: {
784
- // variables: {
785
- // postId,
786
- // },
787
- // },
788
- // });
789
- // if (uploadResponse?.error) setLoading(false);
790
- // const uploadedFiles = uploadResponse.data as unknown as IFileInfo[];
791
- // if (uploadResponse.data) {
792
- // setImage('');
793
- // setFiles([]);
794
- // setImages([]);
795
- // setLoading(false);
796
- // }
797
- // setChannelMessages((messages: any) =>
798
- // messages.map((message: any) => {
799
- // if (message.id === postId) {
800
- // return {
801
- // ...message,
802
- // files: {
803
- // totalCount: uploadedFiles.length,
804
- // data: uploadedFiles,
805
- // },
806
- // };
807
- // }
808
- // return message;
809
- // }),
810
- // );
811
- // }
812
- // };
813
-
814
337
  const messageList = useMemo(() => {
815
338
  let currentDate = '';
816
339
  let res: any = [];
@@ -1095,66 +618,58 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
1095
618
  );
1096
619
  }, [imageObject]);
1097
620
 
1098
- const renderMessage = (props: any) => {
1099
- // const {
1100
- // currentMessage: { text: currText },
1101
- // } = props;
621
+ const renderMessage = useCallback(
622
+ (props: any) => {
623
+ // const {
624
+ // currentMessage: { text: currText },
625
+ // } = props;
1102
626
 
1103
- //let messageTextStyle: any;
627
+ //let messageTextStyle: any;
1104
628
 
1105
- // Make "pure emoji" messages much bigger than plain text.
1106
- // if (currText && emojiUtils.isPureEmojiString(currText)) {
1107
- // messageTextStyle = {
1108
- // fontSize: 28,
1109
- // // Emoji get clipped if lineHeight isn't increased; make it consistent across platforms.
1110
- // lineHeight: Platform.OS === 'android' ? 34 : 30,
1111
- // }
1112
- // }
629
+ // Make "pure emoji" messages much bigger than plain text.
630
+ // if (currText && emojiUtils.isPureEmojiString(currText)) {
631
+ // messageTextStyle = {
632
+ // fontSize: 28,
633
+ // // Emoji get clipped if lineHeight isn't increased; make it consistent across platforms.
634
+ // lineHeight: Platform.OS === 'android' ? 34 : 30,
635
+ // }
636
+ // }
1113
637
 
1114
- // return <SlackMessage {...props} messageTextStyle={messageTextStyle} />;
1115
- return <SlackMessage {...props} isShowImageViewer={isShowImageViewer} setImageViewer={setImageViewerObject} />;
1116
- };
638
+ // return <SlackMessage {...props} messageTextStyle={messageTextStyle} />;
639
+ return (
640
+ <SlackMessage {...props} isShowImageViewer={isShowImageViewer} setImageViewer={setImageViewerObject} />
641
+ );
642
+ },
643
+ [isShowImageViewer],
644
+ );
1117
645
 
1118
- let onScroll = false;
646
+ // const renderMessage = (props: any) => {
647
+ // // const {
648
+ // // currentMessage: { text: currText },
649
+ // // } = props;
1119
650
 
1120
- // const onEndReached = () => {
1121
- // console.log('on end reached');
1122
- // if (!onScroll) return;
1123
- // // load messages, show ActivityIndicator
1124
- // onScroll = false;
1125
- // // setLoadingOldMessages(true);
1126
- // };
651
+ // //let messageTextStyle: any;
1127
652
 
1128
- // const onMomentumScrollBegin = useCallback(
1129
- // ({ nativeEvent }: any) => {
1130
- // onScroll = true;
1131
- // console.log('scroll top');
1132
- // if (!loadingOldMessages && channelMessages?.length <= 10 && channelMessages?.length != totalCount) {
1133
- // onFetchOld();
1134
- // } else if (!loadingOldMessages && isCloseToTop(nativeEvent) && channelMessages?.length != totalCount) {
1135
- // onFetchOld();
1136
- // }
1137
- // },
1138
- // [loadingOldMessages, channelMessages],
1139
- // );
653
+ // // Make "pure emoji" messages much bigger than plain text.
654
+ // // if (currText && emojiUtils.isPureEmojiString(currText)) {
655
+ // // messageTextStyle = {
656
+ // // fontSize: 28,
657
+ // // // Emoji get clipped if lineHeight isn't increased; make it consistent across platforms.
658
+ // // lineHeight: Platform.OS === 'android' ? 34 : 30,
659
+ // // }
660
+ // // }
1140
661
 
1141
- // const onMomentumScrollBegin = ({ nativeEvent }: any) => {
1142
- // onScroll = true;
1143
- // console.log('scroll top');
1144
- // if (
1145
- // !loadingOldMessages &&
1146
- // (channelMessages?.length <= 10 || isCloseToTop(nativeEvent)) &&
1147
- // channelMessages?.length != totalCount
1148
- // ) {
1149
- // onFetchOld();
1150
- // }
662
+ // // return <SlackMessage {...props} messageTextStyle={messageTextStyle} />;
663
+ // return <SlackMessage {...props} isShowImageViewer={isShowImageViewer} setImageViewer={setImageViewerObject} />;
1151
664
  // };
1152
665
 
1153
- const onMomentumScrollBegin = ({ nativeEvent }: any) => {
666
+ let onScroll = false;
667
+
668
+ const onMomentumScrollBegin = async ({ nativeEvent }: any) => {
1154
669
  onScroll = true;
1155
670
  console.log('scroll top');
1156
671
  if (!loadingOldMessages && isCloseToTop(nativeEvent) && totalCount > channelMessages?.length) {
1157
- onFetchOld();
672
+ await onFetchOld();
1158
673
  }
1159
674
  };
1160
675
 
@@ -1231,6 +746,7 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
1231
746
  modalContent={modalContent}
1232
747
  />
1233
748
  <SubscriptionHandler
749
+ channelId={channelId?.toString()}
1234
750
  subscribeToNewMessages={() =>
1235
751
  subscribeToMore({
1236
752
  document: CHAT_MESSAGE_ADDED,
@@ -1239,17 +755,12 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
1239
755
  },
1240
756
  updateQuery: (prev, { subscriptionData }: any) => {
1241
757
  if (!subscriptionData.data) return prev;
1242
-
758
+ setSkip(0);
1243
759
  const newMessage: any = subscriptionData?.data?.chatMessageAdded;
1244
760
  const previousData = prev?.messages?.data
1245
761
  ? [...prev.messages.data, newMessage]
1246
762
  : [];
1247
763
  const totalMsgCount = prev?.messages?.totalCount + 1;
1248
- // const merged = {
1249
- // ...prev,
1250
- // data: previousData,
1251
- // totalCount: totalMsgCount,
1252
- // };
1253
764
  const merged = {
1254
765
  ...prev,
1255
766
  messages: {
@@ -1281,8 +792,8 @@ const ConversationViewComponent = ({ channelId, role }: any) => {
1281
792
  );
1282
793
  };
1283
794
 
1284
- const SubscriptionHandler = ({ subscribeToNewMessages }: ISubscriptionHandlerProps) => {
1285
- useEffect(() => subscribeToNewMessages(), []);
795
+ const SubscriptionHandler = ({ subscribeToNewMessages, channelId }: ISubscriptionHandlerProps) => {
796
+ useEffect(() => subscribeToNewMessages(), [channelId]);
1286
797
  return <></>;
1287
798
  };
1288
799