mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
realtime
This commit is contained in:
@@ -9,10 +9,13 @@ import { SignalRService } from '../infra/socket/signal-r.service';
|
||||
import { SocketMessageDeleteUseCaseService } from 'src/app/module/chat/domain/use-case/socket/socket-message-delete-use-case.service';
|
||||
import { SocketMessageUpdateUseCaseService } from 'src/app/module/chat/domain/use-case/socket/socket-message-update-use-case.service';
|
||||
import { SocketMessageCreateUseCaseService } from 'src/app/module/chat/domain/use-case/socket/socket-message-create-use-case.service';
|
||||
import { ListenMessageByRoomIdNewUseCase } from 'src/app/module/chat/domain/use-case/listen-message-by-roomId.service';
|
||||
import { MemberListUpdateStatusUseCaseService } from 'src/app/module/chat/domain/use-case/socket/member-list-update-status-use-case.service';
|
||||
import { ListenMessageDeleteByRoomIdService } from './use-case/listene-message-delete-by-roomId.service';
|
||||
import { ListenMessageUpdateByRoomIdUseCase } from './use-case/listen-message-update-by-roomId.service';
|
||||
import { ListenSendMessageUseCase } from './use-case/listen-send-message.service'
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { MessageInputDTO } from '../data/dto/message/messageInputDtO';
|
||||
import { MessageEntity } from './entity/message';
|
||||
|
||||
export const InstanceId = uuidv4();
|
||||
@@ -33,7 +36,11 @@ export class ChatServiceService {
|
||||
private SocketMessageCreateUseCaseService: SocketMessageCreateUseCaseService,
|
||||
private MemberListUpdateStatusUseCaseService: MemberListUpdateStatusUseCaseService,
|
||||
private MemberAdminUseCaseService: MemberAdminUseCaseService,
|
||||
private MessageCreateUseCaseService: MessageCreateUseCaseService
|
||||
private MessageCreateUseCaseService: MessageCreateUseCaseService,
|
||||
private ListenMessageByRoomIdNewUseCase: ListenMessageByRoomIdNewUseCase,
|
||||
private ListenMessageDeleteService: ListenMessageDeleteByRoomIdService,
|
||||
private ListenMessageUpdateByRoomIdUseCase: ListenMessageUpdateByRoomIdUseCase,
|
||||
private ListenSendMessageUseCase: ListenSendMessageUseCase
|
||||
) {
|
||||
this.messageLiveSignalRDataSourceService.getMessageDelete()
|
||||
.pipe()
|
||||
@@ -106,9 +113,26 @@ export class ChatServiceService {
|
||||
return this.MemberAdminUseCaseService.execute(input)
|
||||
}
|
||||
|
||||
|
||||
sendMessage(input: MessageEntity) {
|
||||
return this.MessageCreateUseCaseService.execute(input);
|
||||
}
|
||||
|
||||
listenToIncomingMessage(roomId:string) {
|
||||
return this.ListenMessageByRoomIdNewUseCase.execute({roomId})
|
||||
}
|
||||
|
||||
listenToDeleteMessage(roomId: string) {
|
||||
return this.ListenMessageDeleteService.execute({roomId})
|
||||
}
|
||||
|
||||
listenToUpdateMessage(roomId: string) {
|
||||
return this.ListenMessageUpdateByRoomIdUseCase.execute({roomId})
|
||||
}
|
||||
|
||||
|
||||
listenToSendMessage(roomId: string) {
|
||||
return this.ListenSendMessageUseCase.execute({roomId})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,15 @@ const MessageEntitySchema = z.object({
|
||||
attachments: z.array(z.object({
|
||||
fileType: z.nativeEnum(MessageAttachmentFileType),
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
file: z.string().optional(),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.string().optional(),
|
||||
docId: z.string().optional()
|
||||
})),
|
||||
attachmentsSource: z.array(z.object({
|
||||
file: z.string(),
|
||||
fileName: z.string(),
|
||||
applicationId: z.string(),
|
||||
docId: z.string()
|
||||
}))
|
||||
id: z.string(),
|
||||
})),
|
||||
})
|
||||
|
||||
type Message = z.infer<typeof MessageEntitySchema>;
|
||||
@@ -56,8 +60,19 @@ export class MessageEntity implements Message {
|
||||
file?: string,
|
||||
fileName: string,
|
||||
applicationId?: string,
|
||||
docId?: string
|
||||
}[]
|
||||
docId?: string,
|
||||
mimeType?: string,
|
||||
description?: string
|
||||
}[] = []
|
||||
|
||||
attachmentsSource: {
|
||||
id: string,
|
||||
file: string
|
||||
}[] = []
|
||||
|
||||
reactions = []
|
||||
|
||||
requestId: string
|
||||
|
||||
constructor() {}
|
||||
|
||||
@@ -67,4 +82,8 @@ export class MessageEntity implements Message {
|
||||
}
|
||||
}
|
||||
|
||||
get hasAttachment() {
|
||||
return this.attachments.length >= 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export class MessageMapper {
|
||||
roomId: entity.roomId,
|
||||
senderId: entity.sender.wxUserId,
|
||||
requestId: requestId,
|
||||
attachments: entity.attachments
|
||||
attachment: entity.attachments[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { InstanceId } from '../chat-service.service';
|
||||
import { MessageLiveDataSourceService } from 'src/app/module/chat/data/data-source/message/message-live-signalr-data-source.service'
|
||||
import { MessageEntity } from '../entity/message';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ListenMessageByRoomIdNewUseCase {
|
||||
|
||||
constructor(
|
||||
private MessageLiveDataSourceService: MessageLiveDataSourceService
|
||||
) { }
|
||||
|
||||
execute({roomId}: {roomId: string}) {
|
||||
|
||||
return this.MessageLiveDataSourceService.listenToMessages().pipe(
|
||||
filter((message) => !message?.requestId?.startsWith(InstanceId) && message?.roomId == roomId),
|
||||
map(message => Object.assign(new MessageEntity(), message))
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { MessageLiveDataSourceService } from '../../data/data-source/message/message-live-signalr-data-source.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ListenMessageUpdateByRoomIdUseCase {
|
||||
|
||||
constructor(
|
||||
private messageLiveSignalRDataSourceService: MessageLiveDataSourceService,
|
||||
) { }
|
||||
|
||||
execute({roomId}) {
|
||||
return this.messageLiveSignalRDataSourceService.listenToUpdateMessages().pipe(
|
||||
filter((message) => roomId == message?.roomId )
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageLiveDataSourceService } from 'src/app/module/chat/data/data-source/message/message-live-signalr-data-source.service'
|
||||
import { InstanceId } from '../chat-service.service';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ListenSendMessageUseCase {
|
||||
|
||||
constructor(
|
||||
private MessageLiveDataSourceService: MessageLiveDataSourceService
|
||||
) { }
|
||||
|
||||
execute({roomId}: {roomId: string}) {
|
||||
|
||||
return this.MessageLiveDataSourceService.listenToMessages().pipe(
|
||||
filter((message) => message?.requestId?.startsWith(InstanceId) && message?.roomId == roomId),
|
||||
map(message => message)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SignalRService } from '../../infra/socket/signal-r.service';
|
||||
import { filter } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ListenMessageDeleteByRoomIdService {
|
||||
|
||||
constructor(
|
||||
private messageLiveSignalRDataSourceService: SignalRService,
|
||||
) { }
|
||||
|
||||
execute({roomId}) {
|
||||
return this.messageLiveSignalRDataSourceService.getMessageDelete().pipe(
|
||||
filter((message) => {
|
||||
|
||||
console.log({message}, 'delete')
|
||||
return roomId == message?.roomId
|
||||
} )
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ import { MessageEntity } from '../entity/message';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { MessageRepositoryService } from "src/app/module/chat/data/repository/message-respository.service"
|
||||
import { z } from 'zod';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { InstanceId } from '../chat-service.service';
|
||||
|
||||
const MessageInputUseCaseSchema = z.object({
|
||||
memberId: z.number(),
|
||||
@@ -26,6 +28,8 @@ export class MessageCreateUseCaseService {
|
||||
|
||||
input.sendAttemp++;
|
||||
|
||||
input.requestId = InstanceId +'@'+ uuidv4();
|
||||
|
||||
const result = await this.MessageRepositoryService.sendMessage(input)
|
||||
|
||||
return result
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageEntity } from '../entity/message';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { MessageRepositoryService } from "src/app/module/chat/data/repository/message-respository.service"
|
||||
import { z } from 'zod';
|
||||
|
||||
const MessageInputUseCaseSchema = z.object({
|
||||
memberId: z.number(),
|
||||
roomId: z.string(),
|
||||
message: z.string()
|
||||
})
|
||||
|
||||
export type MessageInputUseCase = z.infer< typeof MessageInputUseCaseSchema>
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageCreateUseCaseService {
|
||||
|
||||
constructor(
|
||||
private MessageRepositoryService: MessageRepositoryService
|
||||
) { }
|
||||
|
||||
|
||||
async execute(input: MessageEntity) {
|
||||
|
||||
const result = await this.MessageRepositoryService.createMessage(input)
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SyncMessageRepositoryService } from 'src/app/module/chat/data/service/sync-repository/sync-message-repository.service'
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SyncLocalMessageService {
|
||||
|
||||
constructor(
|
||||
private SyncMessageRepositoryService: SyncMessageRepositoryService
|
||||
) { }
|
||||
|
||||
|
||||
async execute() {
|
||||
return this.SyncMessageRepositoryService.sendLocalMessages()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user