瀏覽代碼

fixed cycle import warning

Viktoriia 2 周之前
父節點
當前提交
00bd5c8b18

+ 2 - 10
src/screens/InAppScreens/MessagesScreen/ChatScreen/index.tsx

@@ -81,7 +81,8 @@ import {
   OutgoingWsEvent,
   reconcileChatRange,
   triggerMessagePush,
-  upsertMessagesIntoDB
+  upsertMessagesIntoDB,
+  findMsgRecord
 } from 'src/watermelondb/features/chat/data/message.sync';
 import { database } from 'src/watermelondb';
 import { Q } from '@nozbe/watermelondb';
@@ -95,15 +96,6 @@ const options = {
 
 const reactionEmojis = ['👍', '❤️', '😂', '😮', '😭'];
 
-export async function findMsgRecord(id: number, chatId: number): Promise<Message | null> {
-  const messagesCollection = database.get<Message>('messages');
-
-  const res = await messagesCollection
-    .query(Q.where('chat_key', 'u:' + chatId), Q.where('message_id', id))
-    .fetch();
-  return res[0] ?? null;
-}
-
 const ChatScreen = ({ route }: { route: any }) => {
   const token = storage.get('token', StoreType.STRING) as string;
   const [isConnected, setIsConnected] = useState<boolean>(true);

+ 3 - 3
src/screens/InAppScreens/MessagesScreen/Components/ReactionsListModal.tsx

@@ -4,15 +4,15 @@ import ActionSheet, { SheetManager } from 'react-native-actions-sheet';
 import { getFontSize } from 'src/utils';
 import { Colors } from 'src/theme';
 import { CustomMessage, Reaction } from '../types';
-import { findMsgRecord } from '../ChatScreen';
 import {
   addMessageDirtyAction,
-  triggerMessagePush
+  triggerMessagePush,
+  findMsgRecord,
+  findGroupMsgRecord
 } from 'src/watermelondb/features/chat/data/message.sync';
 import { database } from 'src/watermelondb';
 import { useNavigation } from '@react-navigation/native';
 import { NAVIGATION_PAGES } from 'src/types';
-import { findGroupMsgRecord } from '../GroupChatScreen';
 
 const ReactionsListModal = () => {
   const [reactionsData, setReactionsData] = useState<{

+ 2 - 10
src/screens/InAppScreens/MessagesScreen/GroupChatScreen/index.tsx

@@ -96,7 +96,8 @@ import {
   OutgoingWsEvent,
   reconcileChatRange,
   triggerMessagePush,
-  upsertMessagesIntoDB
+  upsertMessagesIntoDB,
+  findGroupMsgRecord
 } from 'src/watermelondb/features/chat/data/message.sync';
 import { database } from 'src/watermelondb';
 import { Q } from '@nozbe/watermelondb';
@@ -110,15 +111,6 @@ const options = {
 
 const reactionEmojis = ['👍', '❤️', '😂', '😮', '😭'];
 
-export async function findGroupMsgRecord(id: number, groupToken: string): Promise<Message | null> {
-  const messagesCollection = database.get<Message>('messages');
-
-  const res = await messagesCollection
-    .query(Q.where('chat_key', 'g:' + groupToken), Q.where('message_id', id))
-    .fetch();
-  return res[0] ?? null;
-}
-
 const GroupChatScreen = ({ route }: { route: any }) => {
   const token = storage.get('token', StoreType.STRING) as string;
   const [isConnected, setIsConnected] = useState<boolean>(true);

+ 18 - 0
src/watermelondb/features/chat/data/message.sync.ts

@@ -545,3 +545,21 @@ export async function syncMessagesIncremental(token: string) {
 
   await pushMessageChanges(token);
 }
+
+export async function findMsgRecord(id: number, chatId: number): Promise<Message | null> {
+  const messagesCollection = database.get<Message>('messages');
+
+  const res = await messagesCollection
+    .query(Q.where('chat_key', 'u:' + chatId), Q.where('message_id', id))
+    .fetch();
+  return res[0] ?? null;
+}
+
+export async function findGroupMsgRecord(id: number, groupToken: string): Promise<Message | null> {
+  const messagesCollection = database.get<Message>('messages');
+
+  const res = await messagesCollection
+    .query(Q.where('chat_key', 'g:' + groupToken), Q.where('message_id', id))
+    .fetch();
+  return res[0] ?? null;
+}