mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
realtime
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageRemoteDataSourceService } from '../data-source/message/message-remote-data-source.service';
|
||||
import { MessageLiveDataSourceService } from '../data-source/message/message-live-data-source.service';
|
||||
import { MessageLocalDataSourceService } from '../data-source/message/message-local-data-source.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { SignalRService } from '../../infra/socket/signal-r.service';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
@@ -14,7 +12,10 @@ import { InstanceId } from '../../domain/chat-service.service';
|
||||
import { MessageMapper } from '../../domain/mapper/messageMapper';
|
||||
import { MessageOutPutDataDTO } from '../dto/message/messageOutputDTO';
|
||||
import { MessageTable } from 'src/app/module/chat/infra/database/dexie/schema/message';
|
||||
|
||||
import { MessageLocalDataSourceService } from '../data-source/message/message-local-data-source.service';
|
||||
import { MessageLiveDataSourceService } from '../data-source/message/message-live-signalr-data-source.service';
|
||||
import { AttachmentLocalDataSourceService } from 'src/app/module/chat/data/data-source/attachment/message-local-data-source.service'
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -25,7 +26,8 @@ export class MessageRepositoryService {
|
||||
private messageRemoteDataSourceService: MessageRemoteDataSourceService,
|
||||
private messageLiveDataSourceService: MessageLiveDataSourceService,
|
||||
private messageLiveSignalRDataSourceService: SignalRService,
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService,
|
||||
private AttachmentLocalDataSourceService: AttachmentLocalDataSourceService
|
||||
) {}
|
||||
|
||||
|
||||
@@ -37,17 +39,30 @@ export class MessageRepositoryService {
|
||||
|
||||
}
|
||||
|
||||
async sendMessage(entity: MessageEntity) {
|
||||
|
||||
const requestId = InstanceId +'@'+ uuidv4();
|
||||
async createMessage(entity: MessageEntity) {
|
||||
//const requestId = InstanceId +'@'+ uuidv4();
|
||||
|
||||
const localActionResult = await this.messageLocalDataSourceService.sendMessage(entity)
|
||||
|
||||
return localActionResult.map(e => {
|
||||
entity.$id = e
|
||||
return entity
|
||||
})
|
||||
}
|
||||
|
||||
async sendMessage(entity: MessageEntity) {
|
||||
const messageSubject = new Subject<MessageTable | string>();
|
||||
|
||||
const roomId = entity.roomId
|
||||
|
||||
entity.sending = true
|
||||
const localActionResult = await this.messageLocalDataSourceService.sendMessage(entity)
|
||||
|
||||
if(localActionResult.isOk()) {
|
||||
const DTO = MessageMapper.fromDomain(entity, requestId)
|
||||
const DTO = MessageMapper.fromDomain(entity, entity.requestId)
|
||||
const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage<MessageOutPutDataDTO>(DTO)
|
||||
// return this sendMessageResult
|
||||
|
||||
if(sendMessageResult.isOk()) {
|
||||
|
||||
@@ -62,6 +77,8 @@ export class MessageRepositoryService {
|
||||
$id : localActionResult.value
|
||||
}
|
||||
|
||||
// console.log('sendMessageResult.value', sendMessageResult.value)
|
||||
// this.attachment(sendMessageResult.value.attachments[0].id)
|
||||
return this.messageLocalDataSourceService.update(localActionResult.value, {...clone, sending: false, roomId: entity.roomId})
|
||||
} else {
|
||||
await this.messageLocalDataSourceService.update(localActionResult.value, {sending: false, $id: localActionResult.value})
|
||||
@@ -113,12 +130,14 @@ export class MessageRepositoryService {
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
const { addedItems, changedItems } = messageListDetermineChanges(result.value.data, localResult)
|
||||
const { addedItems, changedItems, deletedItems } = messageListDetermineChanges(result.value.data, localResult)
|
||||
|
||||
console.log({addedItems, changedItems});
|
||||
|
||||
for(const message of changedItems) {
|
||||
let clone: MessageTable = message
|
||||
clone.roomId = id
|
||||
await this.messageLocalDataSourceService.findOrUpdate(clone)
|
||||
this.messageLocalDataSourceService.findOrUpdate(clone)
|
||||
}
|
||||
|
||||
for(const message of addedItems) {
|
||||
@@ -126,7 +145,14 @@ export class MessageRepositoryService {
|
||||
clone.roomId = id
|
||||
|
||||
}
|
||||
await this.messageLocalDataSourceService.createManyMessage(addedItems.reverse())
|
||||
this.messageLocalDataSourceService.createManyMessage(addedItems.reverse())
|
||||
|
||||
|
||||
for(const message of deletedItems) {
|
||||
this.messageLocalDataSourceService.deleteByMessageId(message.id)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -135,6 +161,10 @@ export class MessageRepositoryService {
|
||||
return this.messageLocalDataSourceService.getItemsLive(roomId)
|
||||
}
|
||||
|
||||
getItems (roomId: string) {
|
||||
return this.messageLocalDataSourceService.getItems(roomId)
|
||||
}
|
||||
|
||||
subscribeToNewMessages(roomId: any) {
|
||||
return this.messageLocalDataSourceService.subscribeToNewMessage(roomId)
|
||||
}
|
||||
@@ -147,4 +177,9 @@ export class MessageRepositoryService {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
attachment(roomId: string) {
|
||||
console.log('attachment')
|
||||
return this.messageRemoteDataSourceService.getAttachment(roomId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import { MessageLiveDataSourceService } from '../data-source/message/message-liv
|
||||
import { MemberListUPdateStatusInputDTO } from '../../domain/use-case/socket/member-list-update-status-use-case.service';
|
||||
import { MemberSetAdminDTO } from '../../domain/use-case/member-admin-use-case.service';
|
||||
import { MemberListMapper } from '../../domain/mapper/memberLIstMapper';
|
||||
import { SignalRService } from '../../infra/socket/signal-r.service';
|
||||
|
||||
|
||||
function date(isoDateString) {
|
||||
@@ -43,8 +44,7 @@ export class RoomRepositoryService {
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService,
|
||||
// private roomMemoryDataSourceService: Store<RoomRemoteDataSourceState>,
|
||||
private roomLocalDataSourceService: RoomLocalDataSourceService,
|
||||
private roomLiveDataSourceService: RoomLiveDataSourceService,
|
||||
private messageLiveDataSourceService: MessageLiveDataSourceService,
|
||||
private roomLiveSignalRDataSourceService: RoomLiveDataSourceService,
|
||||
) {}
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/list')
|
||||
@@ -80,13 +80,13 @@ export class RoomRepositoryService {
|
||||
this.list()
|
||||
}, timeRemaining)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -223,9 +223,12 @@ export class RoomRepositoryService {
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/addMemberToRoom')
|
||||
async addMemberToRoom(data: AddMemberToRoomInputDTO) {
|
||||
const result = await this.roomRemoteDataSourceService.addMemberToRoom(data)
|
||||
|
||||
return result
|
||||
return this.roomLiveSignalRDataSourceService.addMemberToRoom(data)
|
||||
|
||||
// const result = await this.roomRemoteDataSourceService.addMemberToRoom(data)
|
||||
|
||||
// return result
|
||||
}
|
||||
|
||||
async updateMemberStatus(data: MemberListUPdateStatusInputDTO) {
|
||||
|
||||
Reference in New Issue
Block a user