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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user