mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
recei and clear the code
This commit is contained in:
@@ -5,7 +5,7 @@ import { skip, switchMap } from 'rxjs/operators';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { Subject, timer } from 'rxjs';
|
||||
import { UserTypingLocalRepository } from './data/repository/user-typing-local-data-source.service';
|
||||
|
||||
import { RoomService } from 'src/app/module/chat/domain/service/room.service'
|
||||
@NgModule({
|
||||
imports: [],
|
||||
providers: [],
|
||||
@@ -22,8 +22,10 @@ export class ChatModule {
|
||||
private ChatServiceService: ChatServiceService,
|
||||
private signalR: SignalRService,
|
||||
private localDataSource: UserTypingLocalRepository,
|
||||
private RoomService: RoomService
|
||||
) {
|
||||
|
||||
this.RoomService.init()
|
||||
this.syncMessage()
|
||||
this.listenToTyping()
|
||||
}
|
||||
|
||||
+27
-20
@@ -8,6 +8,7 @@ import { InstanceId } from '../../../domain/chat-service.service';
|
||||
import { MessageUpdateInput } from '../../../domain/use-case/message-update-by-id-use-case.service';
|
||||
import { MessageOutPutDataDTO } from '../../dto/message/messageOutputDTO';
|
||||
import { MessageInputDTO } from '../../dto/message/messageInputDtO';
|
||||
import { MessageReactionInput } from '../../../domain/use-case/message-reaction-by-id-use-case.service';
|
||||
|
||||
interface msgObj {
|
||||
roomId: string;
|
||||
@@ -48,15 +49,18 @@ export class MessageSocketRepositoryService {
|
||||
return this.socket.establishConnection();
|
||||
}
|
||||
|
||||
async sendMessage(data: msgObj) {
|
||||
async join() {
|
||||
return await this.socket.join()
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.socket.sendMessage(data)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(e)
|
||||
}
|
||||
|
||||
async sendGroupMessage(data: MessageInputDTO) {
|
||||
const result = await this.socket.sendData<MessageOutPutDataDTO>({
|
||||
method: 'sendMessage',
|
||||
data: data,
|
||||
})
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async sendDirectMessage(data: MessageInputDTO) {
|
||||
@@ -86,6 +90,15 @@ export class MessageSocketRepositoryService {
|
||||
return result;
|
||||
}
|
||||
|
||||
async sendDelete(data: MessageDeleteInputDTO) {
|
||||
const result = await this.socket.sendData<any>({
|
||||
method: 'ReadAt',
|
||||
data: data,
|
||||
})
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
listenToMessages() {
|
||||
return this.socket.getMessage()
|
||||
}
|
||||
@@ -101,7 +114,7 @@ export class MessageSocketRepositoryService {
|
||||
}
|
||||
|
||||
|
||||
reactToMessageSocket(data) {
|
||||
reactToMessageSocket(data: MessageReactionInput) {
|
||||
this.socket.sendData({
|
||||
method: 'ReactMessage',
|
||||
data
|
||||
@@ -115,23 +128,17 @@ export class MessageSocketRepositoryService {
|
||||
})
|
||||
}
|
||||
|
||||
sendTyping(roomId) {
|
||||
return this.socket.sendTyping({
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId: SessionStore.user.UserId
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
sendMessageDelete(data: MessageDeleteInputDTO) {
|
||||
|
||||
data['requestId'] = InstanceId +'@'+ uuidv4();
|
||||
|
||||
return this.socket.sendMessageDelete(data)
|
||||
const result = this.socket.sendData<any>({
|
||||
method: 'DeleteMessage',
|
||||
data: data,
|
||||
})
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from '../dto/room/roomListOutputDTO';
|
||||
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO';
|
||||
import { liveQuery, Observable } from 'Dexie';
|
||||
import { err, ok, Result } from 'neverthrow';
|
||||
import { z } from 'zod';
|
||||
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
||||
import { chatDatabase } from '../../infra/database/dexie/service';
|
||||
import { RoomTable, RoomTableSchema } from '../../infra/database/dexie/schema/room';
|
||||
import { chatDatabase } from '../../../infra/database/dexie/service';
|
||||
import { RoomTable, RoomTableSchema } from '../../../infra/database/dexie/schema/room';
|
||||
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
|
||||
import { from } from 'rxjs';
|
||||
|
||||
+11
-11
@@ -1,21 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Result } from 'neverthrow';
|
||||
import { HttpService } from 'src/app/services/http.service';
|
||||
import { RoomListOutPutDTO, RoomListOutPutDTOSchema } from '../dto/room/roomListOutputDTO';
|
||||
import { RoomInputDTO, RoomInputDTOSchema } from '../dto/room/roomInputDTO';
|
||||
import { RoomOutPutDTO, RoomOutPutDTOSchema } from '../dto/room/roomOutputDTO';
|
||||
import { AddMemberToRoomInputDTO, AddMemberToRoomInputDTOSchema } from '../dto/room/addMemberToRoomInputDto';
|
||||
import { RoomListOutPutDTO, RoomListOutPutDTOSchema } from '../../dto/room/roomListOutputDTO';
|
||||
import { RoomInputDTO, RoomInputDTOSchema } from '../../dto/room/roomInputDTO';
|
||||
import { RoomOutPutDTO, RoomOutPutDTOSchema } from '../../dto/room/roomOutputDTO';
|
||||
import { AddMemberToRoomInputDTO, AddMemberToRoomInputDTOSchema } from '../../dto/room/addMemberToRoomInputDto';
|
||||
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
||||
import { RoomByIdInputDTO, RoomByIdInputDTOSchema } from '../dto/room/roomByIdInputDTO';
|
||||
import { RoomByIdOutputDTO, RoomByIdOutputDTOSchema } from '../dto/room/roomByIdOutputDTO';
|
||||
import { RoomByIdInputDTO, RoomByIdInputDTOSchema } from '../../dto/room/roomByIdInputDTO';
|
||||
import { RoomByIdOutputDTO, RoomByIdOutputDTOSchema } from '../../dto/room/roomByIdOutputDTO';
|
||||
import { APIReturn } from 'src/app/services/decorators/api-validate-schema.decorator';
|
||||
import { UserRemoveListInputDTO, UserRemoveListInputDTOSchema } from '../dto/room/userRemoveListInputDTO';
|
||||
import { RoomUpdateInputDTO, RoomUpdateInputDTOSchema } from '../dto/room/roomUpdateInputDTO';
|
||||
import { RoomUpdateOutputDTO } from '../dto/room/roomUpdateOutputDTO';
|
||||
import { UserRemoveListInputDTO, UserRemoveListInputDTOSchema } from '../../dto/room/userRemoveListInputDTO';
|
||||
import { RoomUpdateInputDTO, RoomUpdateInputDTOSchema } from '../../dto/room/roomUpdateInputDTO';
|
||||
import { RoomUpdateOutputDTO } from '../../dto/room/roomUpdateOutputDTO';
|
||||
import { DataSourceReturn } from 'src/app/services/Repositorys/type';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { MemberSetAdminDTO } from '../../domain/use-case/member-admin-use-case.service';
|
||||
import { SignalRService } from '../../infra/socket/signal-r.service';
|
||||
import { MemberSetAdminDTO } from '../../../domain/use-case/member-admin-use-case.service';
|
||||
import { SignalRService } from '../../../infra/socket/signal-r.service';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
@Injectable({
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RoomSocketRepositoryService } from './room-socket-repository.service';
|
||||
|
||||
describe('RoomSocketRepositoryService', () => {
|
||||
let service: RoomSocketRepositoryService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RoomSocketRepositoryService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SignalRService } from '../../../infra/socket/signal-r.service';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { z } from 'zod';
|
||||
import { SocketMessage } from '../../../infra/socket/signalR';
|
||||
|
||||
const listenToDeleteRoomInputSchema = z.object({
|
||||
roomId: z.string()
|
||||
})
|
||||
|
||||
export type ListenToDeleteRoomInput = z.infer<typeof listenToDeleteRoomInputSchema>
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomSocketRepositoryService {
|
||||
|
||||
constructor(
|
||||
private socket: SignalRService
|
||||
) { }
|
||||
|
||||
listenToCreateRoom() {
|
||||
return this.socket.getData().pipe(
|
||||
filter((data) => data.method == 'UserAddGroup')
|
||||
)
|
||||
}
|
||||
|
||||
listenToDeleteRoom() {
|
||||
return this.socket.getData<any>().pipe(
|
||||
filter((data): data is SocketMessage<ListenToDeleteRoomInput> =>
|
||||
data?.method === 'UserRemoveGroup'
|
||||
),
|
||||
map((e) => e.data)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,17 @@ import { SessionStore } from 'src/app/store/session.service';
|
||||
export class UserTypingRemoteRepositoryService {
|
||||
|
||||
constructor(
|
||||
private SignalRLiveDataSourceService: SignalRService
|
||||
private socket: SignalRService
|
||||
) { }
|
||||
|
||||
sendTyping(roomId, ) {
|
||||
return this.SignalRLiveDataSourceService.sendTyping({
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId:SessionStore.user.UserId
|
||||
sendTyping(roomId) {
|
||||
return this.socket.sendData({
|
||||
method: 'Typing',
|
||||
data: {
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId:SessionStore.user.UserId
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import { AddMemberUseCaseService } from './use-case/member-add-use-case.service'
|
||||
import { UpdateRoomByIdUseCaseService } from './use-case/room-update-by-id-use-case.service'
|
||||
import { SocketConnectUseCaseService } from './use-case/socket-connect-use-case.service'
|
||||
import { MessageMarkAsReadUseCaseService } from './use-case/message/message-mark-as-read-use-case.service'
|
||||
import { MessageMarkAllMessageAsReadByRoomIdInputSchema, MessageMarkAllMessageAsReadByRoomIdService } from './use-case/message/message-mark-all-message-as-read-by-room-id.service'
|
||||
import { GetMessageAttachmentLocallyUseCaseService } from 'src/app/module/chat/domain/use-case/message-get-attachment-localy-use-case.service';
|
||||
import { GetRoomListUseCaseService } from 'src/app/module/chat/domain/use-case/room-get-list-use-case.service';
|
||||
import { filter } from 'rxjs/operators';
|
||||
@@ -78,7 +79,8 @@ export class ChatServiceService {
|
||||
private MessageReadAtByIdUseCaseService: MessageReadAtByIdUseCaseService,
|
||||
private SendLocalMessagesUseCaseService: SendLocalMessagesUseCaseService,
|
||||
private MessageMarkAsReadUseCaseService: MessageMarkAsReadUseCaseService,
|
||||
private SocketConnectUseCaseService: SocketConnectUseCaseService
|
||||
private SocketConnectUseCaseService: SocketConnectUseCaseService,
|
||||
private MessageMarkAllMessageAsReadByRoomIdService: MessageMarkAllMessageAsReadByRoomIdService
|
||||
) {
|
||||
this.messageLiveSignalRDataSourceService.getMessageDelete()
|
||||
.pipe()
|
||||
@@ -182,6 +184,7 @@ export class ChatServiceService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
getRoomList() {
|
||||
return this.GetRoomListUseCaseService.execute()
|
||||
}
|
||||
@@ -226,6 +229,10 @@ export class ChatServiceService {
|
||||
return this.MessageMarkAsReadUseCaseService.execute(sendReadAt)
|
||||
}
|
||||
|
||||
markAllMessagesAsRead(input: MessageMarkAllMessageAsReadByRoomIdInputSchema) {
|
||||
return this.MessageMarkAllMessageAsReadByRoomIdService.execute(input)
|
||||
}
|
||||
|
||||
listenToIncomingMessage(roomId:string) {
|
||||
return this.ListenMessageByRoomIdNewUseCase.execute({roomId})
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomExpirationService {
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RoomService } from './room.service';
|
||||
|
||||
describe('RoomService', () => {
|
||||
let service: RoomService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RoomService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RoomSocketRepositoryService } from 'src/app/module/chat/data/repository/room/room-socket-repository.service'
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomService {
|
||||
|
||||
constructor(
|
||||
private RoomSocketRepositoryService: RoomSocketRepositoryService
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
init() {
|
||||
this.OnReceiveCreateRoom()
|
||||
this.OnDeleteCreateRoom()
|
||||
}
|
||||
|
||||
|
||||
OnReceiveCreateRoom() {
|
||||
this.RoomSocketRepositoryService.listenToCreateRoom().subscribe((data)=> {
|
||||
console.log('OnReceiveCreateRoom', data)
|
||||
})
|
||||
}
|
||||
|
||||
OnDeleteCreateRoom() {
|
||||
this.RoomSocketRepositoryService.listenToCreateRoom().subscribe((data)=> {
|
||||
console.log('OnDeleteCreateRoom7', data)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { AddMemberToRoomInputDTO } from '../../data/dto/room/addMemberToRoomInputDto';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room-remote-repository.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room/room-remote-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { z } from "zod";
|
||||
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room-remote-repository.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room/room-remote-repository.service';
|
||||
|
||||
// Define the schema for the entire response
|
||||
const MemberSetAdminDTOSchema = z.object({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { UserRemoveListInputDTO } from '../../../data/dto/room/userRemoveListInputDTO';
|
||||
import { RoomRemoteDataSourceService } from '../../../data/repository/room-remote-repository.service';
|
||||
import { RoomRemoteDataSourceService } from '../../../data/repository/room/room-remote-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -18,6 +18,7 @@ import { RoomType } from "src/app/module/chat/domain/entity/group";
|
||||
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member-list-local-repository.service'
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
|
||||
const MessageInputUseCaseSchema = z.object({
|
||||
memberId: z.number(),
|
||||
roomId: z.string(),
|
||||
@@ -39,7 +40,7 @@ export class MessageCreateUseCaseService {
|
||||
constructor(
|
||||
private AttachmentLocalRepositoryService: AttachmentLocalDataSource,
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService,
|
||||
private messageLiveSignalRDataSourceService: SignalRService,
|
||||
private MessageSocketRepositoryService: MessageSocketRepositoryService,
|
||||
private messageSocketRepositoryService: MessageSocketRepositoryService,
|
||||
private MemberListLocalRepository: MemberListLocalRepository
|
||||
) { }
|
||||
@@ -99,7 +100,7 @@ export class MessageCreateUseCaseService {
|
||||
let sendMessageResult: Result<MessageOutPutDataDTO, any>
|
||||
if(messageEnum == RoomType.Group) {
|
||||
const DTO = MessageMapper.fromDomain(message, message.requestId)
|
||||
sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage<MessageOutPutDataDTO>(DTO)
|
||||
sendMessageResult = await this.MessageSocketRepositoryService.sendGroupMessage(DTO)
|
||||
} else {
|
||||
|
||||
if(message.receiverId) {
|
||||
@@ -113,7 +114,7 @@ export class MessageCreateUseCaseService {
|
||||
if(getRoomMembers.isOk()) {
|
||||
message.receiverId = getRoomMembers.value.wxUserId
|
||||
const DTO = MessageMapper.fromDomain(message, message.requestId)
|
||||
sendMessageResult = await this.messageSocketRepositoryService.sendDirectMessage(DTO)
|
||||
sendMessageResult = await this.messageSocketRepositoryService.sendGroupMessage(DTO)
|
||||
} else {
|
||||
console.log('not found direct users', getRoomMembers.error)
|
||||
}
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { z } from 'zod';
|
||||
import { MessageLocalDataSourceService } from 'src/app/module/chat/data/repository/message/message-local-data-source.service'
|
||||
import { MessageSocketRepositoryService } from 'src/app/module/chat/data/repository/message/message-live-signalr-data-source.service'
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
|
||||
const MessageMarkAllMessageAsReadByRoomIdInputSchema = z.object({
|
||||
roomId: z.string(),
|
||||
})
|
||||
|
||||
export type MessageMarkAllMessageAsReadByRoomIdInputSchema = z.infer<typeof MessageMarkAllMessageAsReadByRoomIdInputSchema>
|
||||
|
||||
|
||||
/**
|
||||
* @description avoid using it, avoid duplicate query. do it on the UI layer as the component load the message.
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageMarkAllMessageAsReadByRoomIdService {
|
||||
|
||||
constructor(
|
||||
private MessageLocalDataSourceService: MessageLocalDataSourceService,
|
||||
private MessageSocketRepositoryService: MessageSocketRepositoryService
|
||||
) { }
|
||||
|
||||
|
||||
async execute(input: MessageMarkAllMessageAsReadByRoomIdInputSchema) {
|
||||
const messages = await this.MessageLocalDataSourceService.find({roomId:input.roomId})
|
||||
|
||||
if(messages.isOk()) {
|
||||
for(const message of messages.value) {
|
||||
this.MessageSocketRepositoryService.sendReadAt({
|
||||
memberId: SessionStore.user.UserId,
|
||||
messageId: message.id,
|
||||
roomId: input.roomId,
|
||||
requestId: 'uuid'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageLocalDataSourceService } from '../../data/repository/message/message-local-data-source.service';
|
||||
import { MessageSocketRepositoryService } from '../../data/repository/message/message-live-signalr-data-source.service';
|
||||
import { MessageOutPutDataDTO } from '../../data/dto/message/messageOutputDTO';
|
||||
import { MessageTable } from '../../infra/database/dexie/schema/message';
|
||||
import { SignalRService } from '../../infra/socket/signal-r.service';
|
||||
@@ -14,7 +15,7 @@ import { AttachmentLocalDataSource } from '../../data/repository/attachment-loca
|
||||
export class SendLocalMessagesUseCaseService {
|
||||
|
||||
constructor(
|
||||
private messageLiveSignalRDataSourceService: SignalRService,
|
||||
private MessageSocketRepositoryService: MessageSocketRepositoryService,
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService,
|
||||
private AttachmentRepositoryService: AttachmentLocalDataSource,
|
||||
) { }
|
||||
@@ -47,7 +48,7 @@ export class SendLocalMessagesUseCaseService {
|
||||
const DTO = MessageMapper.fromDomain(message, requestId)
|
||||
|
||||
await this.messageLocalDataSourceService.update(message.$id, { sending: true })
|
||||
const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage<MessageOutPutDataDTO>(DTO)
|
||||
const sendMessageResult = await this.MessageSocketRepositoryService.sendGroupMessage(DTO)
|
||||
|
||||
if(sendMessageResult.isOk()) {
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { create } from 'domain';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room-remote-repository.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room/room-remote-repository.service';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { RoomInputDTO } from '../../data/dto/room/roomInputDTO';
|
||||
import { RoomLocalRepository } from '../../data/repository/room-local-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room/room-local-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -2,8 +2,8 @@ import { Injectable } from '@angular/core';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { isHttpResponse } from 'src/app/services/http.service';
|
||||
import { RoomByIdInputDTO } from '../../data/dto/room/roomByIdInputDTO';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room-local-repository.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room/room-local-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -3,8 +3,8 @@ import { id } from 'date-fns/locale';
|
||||
import { isHttpResponse } from 'src/app/services/http.service';
|
||||
import { roomListDetermineChanges } from '../../data/async/list/rooms/roomListChangeDetector';
|
||||
import { roomMemberListDetermineChanges } from '../../data/async/list/rooms/roomMembersChangeDetector';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room-local-repository.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room/room-local-repository.service';
|
||||
import { MemberListLocalRepository } from '../../data/repository/member-list-local-repository.service';
|
||||
import { MemberListMapper } from '../mapper/memberLIstMapper';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { roomListDetermineChanges } from '../../data/async/list/rooms/roomListChangeDetector';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room-local-repository.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room/room-local-repository.service';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { isHttpResponse } from 'src/app/services/http.service';
|
||||
import { CronJobService } from 'src/app/utils/task-scheduler'
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { UserRemoveListInputDTO } from '../../data/dto/room/userRemoveListInputDTO';
|
||||
import { isHttpResponse } from 'src/app/services/http.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room-local-repository.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room/room-local-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { RoomUpdateInputDTO } from '../../data/dto/room/roomUpdateInputDTO';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room-local-repository.service';
|
||||
import { RoomRemoteDataSourceService } from '../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room/room-local-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageSocketRepositoryService } from 'src/app/module/chat/data/repository/message/message-live-signalr-data-source.service';
|
||||
import { XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -10,8 +11,9 @@ export class SocketConnectUseCaseService {
|
||||
private MessageSocketRepositoryService: MessageSocketRepositoryService
|
||||
) { }
|
||||
|
||||
execute() {
|
||||
return this.MessageSocketRepositoryService.connect()
|
||||
@XTracerAsync({name:'SocketConnectUseCaseService', module:'chat', bugPrint: true})
|
||||
async execute() {
|
||||
return await this.MessageSocketRepositoryService.connect()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageSocketRepositoryService } from 'src/app/module/chat/data/repository/message/message-live-signalr-data-source.service';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SocketJoinUseCaseService {
|
||||
|
||||
constructor(
|
||||
private MessageSocketRepositoryService: MessageSocketRepositoryService
|
||||
) { }
|
||||
|
||||
|
||||
execute() {}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { MessageTable } from '../../infra/database/dexie/schema/message';
|
||||
import { MessageRemoteDataSourceService } from '../../data/repository/message/message-remote-data-source.service';
|
||||
import { MessageSocketRepositoryService } from '../../data/repository/message/message-live-signalr-data-source.service';
|
||||
import { ok } from 'neverthrow';
|
||||
import { RoomLocalRepository } from '../../data/repository/room-local-repository.service';
|
||||
import { RoomLocalRepository } from '../../data/repository/room/room-local-repository.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { XTracerAsync, TracingType } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SignalRService } from '../../infra/socket/signal-r.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { UserTypingRemoteRepositoryService } from '../../data/repository/user-typing-live-data-source.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -8,15 +9,11 @@ import { SessionStore } from 'src/app/store/session.service';
|
||||
export class SendTypingUseCaseService {
|
||||
|
||||
constructor(
|
||||
private messageLiveSignalRDataSourceService: SignalRService,
|
||||
private UserTypingRemoteRepositoryService: UserTypingRemoteRepositoryService,
|
||||
) { }
|
||||
|
||||
|
||||
execute(roomId) {
|
||||
return this.messageLiveSignalRDataSourceService.sendTyping({
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId: SessionStore.user.UserId
|
||||
})
|
||||
return this.UserTypingRemoteRepositoryService.sendTyping(roomId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { MessageDeleteInputDTO } from '../../data/dto/message/messageDeleteInput
|
||||
import { z } from 'zod';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { Result } from 'neverthrow';
|
||||
import { HubConnection } from '@microsoft/signalr';
|
||||
|
||||
const { App } = Plugins;
|
||||
|
||||
@@ -68,7 +69,7 @@ export class SignalRService {
|
||||
// this.establishConnection()
|
||||
}
|
||||
|
||||
async establishConnection() {
|
||||
async establishConnection(): Promise<Result<HubConnection, false>> {
|
||||
|
||||
// const connection = new SignalRConnection({url:'https://41e3-41-63-166-54.ngrok-free.app/api/v2/chathub'})
|
||||
const connection = new SignalRConnection({url:'https://gdapi-dev.dyndns.info/stage/api/v2/chathub'})
|
||||
@@ -106,11 +107,15 @@ export class SignalRService {
|
||||
this.connection.getConnectionState().subscribe((data) => {
|
||||
this.connectingSubject.next(data)
|
||||
})
|
||||
|
||||
return attempConnection
|
||||
} else {
|
||||
|
||||
setTimeout(() => {
|
||||
this.establishConnection()
|
||||
}, 2000)
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(this.establishConnection())
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -138,37 +143,25 @@ export class SignalRService {
|
||||
return this.connection.sendData<T>(input)
|
||||
}
|
||||
|
||||
getData() {
|
||||
return this.sendDataSubject.asObservable()
|
||||
join() {
|
||||
return this.connection.join()
|
||||
}
|
||||
|
||||
getData<T>() {
|
||||
return this.sendDataSubject.asObservable() as BehaviorSubject<{method: string, data: T}>
|
||||
}
|
||||
public getConnectionState(): Observable<boolean> {
|
||||
return this.connectingSubject.asObservable();
|
||||
}
|
||||
|
||||
async sendMessage<T>(data: Object): Promise<Result<T, any>> {
|
||||
return await this.connection.sendMessage(data as any)
|
||||
}
|
||||
|
||||
|
||||
newConnection() {
|
||||
this.establishConnection()
|
||||
}
|
||||
|
||||
async sendTyping({roomId, UserName, userId}) {
|
||||
return await this.connection.typing({ roomId, UserName, userId})
|
||||
}
|
||||
|
||||
async sendReadAt({ roomId, memberId, chatMessageId}) {
|
||||
return await this.connection.sendReadAt({ roomId, memberId, chatMessageId})
|
||||
}
|
||||
|
||||
|
||||
async sendMessageDelete(data: MessageDeleteInputDTO) {
|
||||
return await this.connection.deleteMessage(data)
|
||||
}
|
||||
|
||||
|
||||
async sendReactToMessage(data) {
|
||||
return await this.connection.sendReactMessage(data)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,12 @@ import { MessageDeleteInputDTO } from '../../data/dto/message/messageDeleteInput
|
||||
import { MessageReactionInput } from '../../domain/use-case/message-reaction-by-id-use-case.service';
|
||||
import { ISignalRInput } from './signal-r.service';
|
||||
|
||||
|
||||
export interface SocketMessage<T> {
|
||||
method: string,
|
||||
data: T
|
||||
}
|
||||
|
||||
export class SignalRConnection {
|
||||
|
||||
private hubConnection: signalR.HubConnection;
|
||||
@@ -96,8 +102,6 @@ export class SignalRConnection {
|
||||
|
||||
public join() {
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
|
||||
console.log('join=================')
|
||||
this.hubConnection.invoke("Join", SessionStore.user.UserId, SessionStore.user.FullName);
|
||||
//this.hubConnection.invoke("Join", 105, "UserFirefox");
|
||||
} else {
|
||||
@@ -106,81 +110,6 @@ export class SignalRConnection {
|
||||
|
||||
}
|
||||
|
||||
public async sendMessage(data: Object & { requestId}):Promise<Result<any, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
console.log('sendMessage', data)
|
||||
this.hubConnection.invoke("SendMessage", data)
|
||||
|
||||
//
|
||||
this.pendingRequests.set(data.requestId, { resolve, reject: (data) => resolve(data) });
|
||||
|
||||
this.messageSubject.pipe(
|
||||
filter((message: any) => data.requestId == message?.requestId),
|
||||
first()
|
||||
).subscribe(value => {
|
||||
resolve(ok(value))
|
||||
console.log('Received valid value:', value);
|
||||
//
|
||||
this.pendingRequests.delete(data.requestId);
|
||||
});
|
||||
|
||||
} else {
|
||||
this.sendLaterSubject.next({method: 'SendMessage', args: data})
|
||||
return reject(err(false))
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
public async deleteMessage(data: MessageDeleteInputDTO) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
console.log('delete message', data)
|
||||
this.hubConnection.invoke("DeleteMessage", data)
|
||||
|
||||
this.messageSubject.pipe(
|
||||
filter((message: any) => data.requestId == message?.requestId),
|
||||
first()
|
||||
).subscribe((value) => {
|
||||
resolve(ok(value))
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
public async typing(data: Object & { roomId, UserName, userId }):Promise<Result<any, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const requestId = uuidv4()
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
// console.log('send typing', data)
|
||||
|
||||
try {
|
||||
this.hubConnection.invoke("Typing", data)
|
||||
|
||||
} catch (error) {}
|
||||
|
||||
this.typingSubject.pipe(
|
||||
filter((message: any) => {
|
||||
return requestId == message?.requestId
|
||||
}),
|
||||
first()
|
||||
).subscribe(value => {
|
||||
resolve(ok(value));
|
||||
});
|
||||
|
||||
} else {
|
||||
this.sendLaterSubject.next({method: 'SendMessage', args: data})
|
||||
return reject(err(false))
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
public async sendReadAt(data: Object & { roomId, memberId, chatMessageId}):Promise<Result<any, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -212,57 +141,6 @@ export class SignalRConnection {
|
||||
}
|
||||
|
||||
|
||||
public async sendReactMessage(data: MessageReactionInput):Promise<Result<any, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const requestId = uuidv4()
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
|
||||
try {
|
||||
this.hubConnection.invoke("ReactMessage", { roomId: data.roomId, memberId: data.memberId, requestId, messageId: data.messageId} as any)
|
||||
|
||||
} catch (error) {}
|
||||
|
||||
this.messageUPdateSubject.pipe(
|
||||
filter((message: any) => {
|
||||
return requestId == message?.requestId
|
||||
}),
|
||||
first()
|
||||
).subscribe(value => {
|
||||
resolve(ok(value));
|
||||
});
|
||||
|
||||
// // Create an observable for the timeout (8 seconds)
|
||||
// const timeout$ = timer(8000);
|
||||
|
||||
// // Create an observable for the message
|
||||
// const message$ = this.messageUPdateSubject.pipe(
|
||||
// filter((message: MessageOutPutDataDTO) => requestId === message?.requestId),
|
||||
// first()
|
||||
// );
|
||||
|
||||
// // Use race to choose whichever completes first (either the message or the timeout)
|
||||
// race(message$, timeout$).subscribe({
|
||||
// next: (value) => {
|
||||
// if (typeof value === 'number') {
|
||||
// // If the value is a number, it means the timeout fired
|
||||
// reject(err('No response, timeout'));
|
||||
// } else {
|
||||
// resolve(ok(value));
|
||||
// }
|
||||
// },
|
||||
// error: (error) => reject(err('Error: ' + error))
|
||||
// });
|
||||
|
||||
} else {
|
||||
this.sendLaterSubject.next({method: 'SendMessage', args: data})
|
||||
return reject(err(false))
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
sendData<T>(input: ISignalRInput): Promise<Result<T, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user