mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
create offline direct message
This commit is contained in:
@@ -26,7 +26,7 @@ export function messageListDetermineChanges(serverList: MessageTable[], localLis
|
||||
item.$id = localItem.$id
|
||||
}
|
||||
|
||||
return localItem && (item.editedAt !== localItem.editedAt || item.sentAt != item.sentAt || item.reactions.some((r, index) => {
|
||||
return localItem && (item.editedAt !== localItem.editedAt || item.isDeleted !== localItem.isDeleted || item.sentAt != item.sentAt || item.reactions.some((r, index) => {
|
||||
const localReaction = localItem.reactions[index];
|
||||
return !localReaction || r.reactedAt !== localReaction.reactedAt;
|
||||
}));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { RoomType } from "src/app/core/chat/entity/group";
|
||||
import { RoomTable } from "src/app/infra/database/dexie/instance/chat/schema/room";
|
||||
import { RoomListItemOutPutDTO } from "src/app/module/chat/domain/use-case/room/room-get-list-use-case.service";
|
||||
import { SessionStore } from "src/app/store/session.service";
|
||||
|
||||
export function roomListDetermineChanges(serverRooms: RoomListItemOutPutDTO[], localRooms: RoomTable[]) {
|
||||
const serverRoomMap = new Map(serverRooms.map(room => [room.chatRoom.id, room]));
|
||||
@@ -8,7 +9,7 @@ export function roomListDetermineChanges(serverRooms: RoomListItemOutPutDTO[], l
|
||||
|
||||
const roomsToInsert = serverRooms.filter(room => !localRoomMap.has(room.chatRoom.id));
|
||||
const roomsToUpdate = serverRooms.filter(room => {
|
||||
const localRoom = localRoomMap.get(room.chatRoom.id);
|
||||
const localRoom = localRoomMap.get(room.chatRoom.id);
|
||||
|
||||
return localRoom && (
|
||||
room.chatRoom.roomName !== localRoom.roomName && room.chatRoom.roomType == RoomType.Group ||
|
||||
|
||||
@@ -5,10 +5,11 @@ import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository
|
||||
import { Observable as DexieObservable, PromiseExtended } from 'Dexie';
|
||||
import { DexieMessageTable, MessageTable, MessageTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
import { chatDatabase } from 'src/app/infra/database/dexie/service';
|
||||
import { IMessageLocalRepository } from 'src/app/core/chat/repository/message/message-local-repository';
|
||||
import { IDirectMessages, IMessageLocalRepository } from 'src/app/core/chat/repository/message/message-local-repository';
|
||||
import { BehaviorSubject, combineLatest, from, Observable } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { err, ok } from 'neverthrow';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -79,9 +80,6 @@ export class MessageLocalDataSourceService extends DexieRepository<MessageTable,
|
||||
return chatDatabase.message.where('roomId').equals(roomId).sortBy('sentAt') as any
|
||||
}
|
||||
|
||||
getItemsLive(roomId: string): DexieObservable<MessageEntity[]> {
|
||||
return liveQuery(() => chatDatabase.message.where('roomId').equals(roomId).sortBy('sentAt') as any)
|
||||
}
|
||||
|
||||
async getOfflineMessages () {
|
||||
try {
|
||||
@@ -96,7 +94,6 @@ export class MessageLocalDataSourceService extends DexieRepository<MessageTable,
|
||||
}
|
||||
|
||||
|
||||
|
||||
getLastMessageForRooms(roomIds: string[]): Observable<any[]> {
|
||||
const observables = roomIds.map(roomId =>
|
||||
from (liveQuery(async() =>{
|
||||
@@ -114,5 +111,20 @@ export class MessageLocalDataSourceService extends DexieRepository<MessageTable,
|
||||
|
||||
return combineLatest(observables); // Combine all observables into one array of results
|
||||
}
|
||||
|
||||
async getDirectMessages(input: IDirectMessages) {
|
||||
try {
|
||||
const result = await chatDatabase.message
|
||||
.where('receiverId')
|
||||
.equals(input.receiverId)
|
||||
.or('roomId')
|
||||
.equals(input.roomId)
|
||||
.toArray()
|
||||
|
||||
return ok(result as MessageEntity[])
|
||||
} catch (e) {
|
||||
return err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,38 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { liveQuery, Observable } from 'Dexie';
|
||||
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
|
||||
import { from } from 'rxjs';
|
||||
import { BehaviorSubject, from } from 'rxjs';
|
||||
import { RoomTable, RoomTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/room';
|
||||
import { chatDatabase } from 'src/app/infra/database/dexie/service';
|
||||
import { IRoomLocalRepository } from 'src/app/core/chat/repository/room/room-local-repository';
|
||||
import { IDBoolean } from 'src/app/infra/database/dexie/type';
|
||||
import { RoomType } from 'src/app/core/chat/entity/group';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomLocalRepository extends DexieRepository<RoomTable, RoomTable> implements IRoomLocalRepository {
|
||||
|
||||
private listenCreateSyncSubject : BehaviorSubject<RoomTable> = new BehaviorSubject<RoomTable>(null);
|
||||
|
||||
constructor() {
|
||||
super(chatDatabase.room, RoomTableSchema)
|
||||
|
||||
chatDatabase.room.hook('creating', (primaryKey, obj, transaction) => {
|
||||
|
||||
if(obj.id && !obj.$id && obj.roomType == RoomType.Group) {
|
||||
obj.$id = obj.id
|
||||
}
|
||||
|
||||
if(obj.id) {
|
||||
obj.local = IDBoolean.false
|
||||
} else {
|
||||
obj.local = IDBoolean.true
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
chatDatabase.room.hook('updating', (modifications, primKey, oldValue, transaction) => {
|
||||
|
||||
// if((modifications as Partial<RoomTable>).messages?.[0].requestId == oldValue.messages?.[0].requestId) {
|
||||
@@ -22,6 +41,12 @@ export class RoomLocalRepository extends DexieRepository<RoomTable, RoomTable> i
|
||||
// (modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt
|
||||
// }
|
||||
|
||||
if((modifications as Partial<RoomTable>).id || oldValue.id) {
|
||||
(modifications as Partial<RoomTable>).local = IDBoolean.false
|
||||
} else {
|
||||
(modifications as Partial<RoomTable>).local = IDBoolean.true
|
||||
}
|
||||
|
||||
return modifications
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user