|
@@ -86,6 +86,7 @@ import { database } from 'src/watermelondb';
|
|
|
import { Q } from '@nozbe/watermelondb';
|
|
import { Q } from '@nozbe/watermelondb';
|
|
|
import { createOptimisticMessage } from 'src/watermelondb/features/chat/data/createOptimisticMessage';
|
|
import { createOptimisticMessage } from 'src/watermelondb/features/chat/data/createOptimisticMessage';
|
|
|
import _ from 'lodash';
|
|
import _ from 'lodash';
|
|
|
|
|
+import { Galeria } from '@nandorojo/galeria';
|
|
|
|
|
|
|
|
const options = {
|
|
const options = {
|
|
|
enableVibrateFallback: true,
|
|
enableVibrateFallback: true,
|
|
@@ -1041,20 +1042,20 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
|
|
|
|
|
if (!unreadMessageId) return;
|
|
if (!unreadMessageId) return;
|
|
|
|
|
|
|
|
- const giftedIndex = giftedMessages.findIndex((m) => m._id === unreadMessageId);
|
|
|
|
|
-
|
|
|
|
|
- if (giftedIndex === -1) return;
|
|
|
|
|
-
|
|
|
|
|
didInitUnreadRef.current = true;
|
|
didInitUnreadRef.current = true;
|
|
|
- setUnreadMessageIndex(giftedIndex);
|
|
|
|
|
|
|
+ setUnreadMessageIndex(unreadMessageId);
|
|
|
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- flatList.current?.scrollToIndex({
|
|
|
|
|
- index: giftedIndex,
|
|
|
|
|
- animated: true,
|
|
|
|
|
- viewPosition: 0.5
|
|
|
|
|
- });
|
|
|
|
|
- }, 400);
|
|
|
|
|
|
|
+ const giftedIndex = giftedMessages.findIndex((m) => m._id === unreadMessageId);
|
|
|
|
|
+
|
|
|
|
|
+ if (giftedIndex !== -1) {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ flatList.current?.scrollToIndex({
|
|
|
|
|
+ index: giftedIndex,
|
|
|
|
|
+ animated: true,
|
|
|
|
|
+ viewPosition: 0.5
|
|
|
|
|
+ });
|
|
|
|
|
+ }, 400);
|
|
|
|
|
+ }
|
|
|
}, [giftedMessages, chatData]);
|
|
}, [giftedMessages, chatData]);
|
|
|
|
|
|
|
|
const giftedMessagesWithUnread = useMemo(() => {
|
|
const giftedMessagesWithUnread = useMemo(() => {
|
|
@@ -1062,6 +1063,10 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
return giftedMessages;
|
|
return giftedMessages;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const index = giftedMessages.findIndex((m) => m._id === unreadMessageIndex);
|
|
|
|
|
+
|
|
|
|
|
+ if (index === -1) return giftedMessages;
|
|
|
|
|
+
|
|
|
const unreadMarker = {
|
|
const unreadMarker = {
|
|
|
_id: 'unreadMarker',
|
|
_id: 'unreadMarker',
|
|
|
text: 'Unread messages',
|
|
text: 'Unread messages',
|
|
@@ -1069,7 +1074,7 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const copy = [...giftedMessages];
|
|
const copy = [...giftedMessages];
|
|
|
- copy.splice(unreadMessageIndex + 1, 0, unreadMarker as any);
|
|
|
|
|
|
|
+ copy.splice(index + 1, 0, unreadMarker as any);
|
|
|
|
|
|
|
|
return copy;
|
|
return copy;
|
|
|
}, [giftedMessages, unreadMessageIndex]);
|
|
}, [giftedMessages, unreadMessageIndex]);
|