Viktoriia 1 tydzień temu
rodzic
commit
562fbe1a72

+ 6 - 2
src/watermelondb/features/chat/data/chat.repo.ts

@@ -1,6 +1,10 @@
 import { Q } from '@nozbe/watermelondb';
 import { database } from 'src/watermelondb';
 import Chat from 'src/watermelondb/models/Chat';
+import dayjs from 'dayjs';
+import utc from 'dayjs/plugin/utc';
+
+dayjs.extend(utc);
 
 type ServerChat = {
   uid: number | null;
@@ -58,7 +62,7 @@ export async function upsertChats(chats: ServerChat[]) {
             rec.avatar = c.avatar ?? null;
             rec.short = c.short;
             rec.sentBy = c.sent_by;
-            rec.updated = new Date(c.updated).getTime();
+            rec.updated = dayjs.utc(c.updated, 'YYYY-MM-DD HH:mm:ss', true).valueOf();
             rec.status = c.status;
             rec.unreadCount = c.unread_count;
             rec.lastMessageId = c.last_message_id;
@@ -87,7 +91,7 @@ export async function upsertChats(chats: ServerChat[]) {
             rec.avatar = c.avatar ?? null;
             rec.short = c.short;
             rec.sentBy = c.sent_by;
-            rec.updated = new Date(c.updated).getTime();
+            rec.updated = dayjs.utc(c.updated, 'YYYY-MM-DD HH:mm:ss', true).valueOf();
             rec.status = c.status;
             rec.unreadCount = c.unread_count;
             rec.lastMessageId = c.last_message_id;

+ 6 - 2
src/watermelondb/features/chat/data/chat.sync.ts

@@ -5,6 +5,10 @@ import BlockedUser from 'src/watermelondb/models/BlockedUser';
 import { chatApi } from '@api/chat';
 import NetInfo from '@react-native-community/netinfo';
 import { testConnectionSpeed } from 'src/database/speedService';
+import dayjs from 'dayjs';
+import utc from 'dayjs/plugin/utc';
+
+dayjs.extend(utc);
 
 export type DirtyAction = {
   type: 'pin' | 'archive' | 'mute' | 'block' | 'unblock' | 'delete' | 'leave_group';
@@ -380,7 +384,7 @@ async function pullUpdates(token: string) {
             typeof s.updated === 'number'
               ? s.updated
               : s.updated
-                ? new Date(s.updated).getTime()
+                ? dayjs.utc(s.updated, 'YYYY-MM-DD HH:mm:ss', true).valueOf()
                 : Date.now();
 
           r.status = s.status ?? 0;
@@ -437,7 +441,7 @@ async function pullUpdates(token: string) {
           typeof server.updated === 'number'
             ? server.updated
             : server.updated
-              ? new Date(server.updated).getTime()
+              ? dayjs.utc(server.updated, 'YYYY-MM-DD HH:mm:ss', true).valueOf()
               : r.updated;
         r.status = server.status ?? r.status;
         r.unreadCount = server.unread_count ?? r.unreadCount;