2024-08-19 16:01:58 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { err, ok } from 'neverthrow';
|
|
|
|
|
import { SignalRService } from '../../../infra/socket/signal-r.service';
|
|
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
|
|
|
import { MessageDeleteInputDTO } from '../../dto/message/messageDeleteInputDTO';
|
|
|
|
|
import { v4 as uuidv4 } from 'uuid'
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
interface msgObj {
|
|
|
|
|
roomId: string;
|
|
|
|
|
senderId: string;
|
|
|
|
|
message:string;
|
|
|
|
|
messageType:1;
|
|
|
|
|
canEdit:Boolean;
|
|
|
|
|
oneShot:Boolean;
|
|
|
|
|
requestId: string;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 16:34:47 +01:00
|
|
|
interface sendDeliverAt {
|
|
|
|
|
memberId: number,
|
|
|
|
|
messageId:string,
|
|
|
|
|
roomId: string,
|
|
|
|
|
requestId: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface sendReadAt {
|
|
|
|
|
memberId: number,
|
|
|
|
|
messageId:string,
|
|
|
|
|
roomId: string,
|
|
|
|
|
requestId: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-08-19 16:01:58 +01:00
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class MessageSocketRepositoryService {
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private socket: SignalRService
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
async sendMessage(data: msgObj) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const result = await this.socket.sendMessage(data)
|
|
|
|
|
return ok(result)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return err(e)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async sendDirectMessage(data: MessageInputDTO) {
|
|
|
|
|
const result = await this.socket.sendData<MessageOutPutDataDTO>({
|
|
|
|
|
method: 'SendDirectMessage',
|
|
|
|
|
data: data as any,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 16:34:47 +01:00
|
|
|
async sendDeliverAt(data: sendDeliverAt) {
|
|
|
|
|
const result = await this.socket.sendData<any>({
|
|
|
|
|
method: 'DeliverAt',
|
|
|
|
|
data: data as any,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async sendReadAt(data: sendReadAt) {
|
|
|
|
|
const result = await this.socket.sendData<any>({
|
|
|
|
|
method: 'ReadAt',
|
|
|
|
|
data: data as any,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-19 16:01:58 +01:00
|
|
|
listenToMessages() {
|
|
|
|
|
return this.socket.getMessage()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listenToDeleteMessages() {
|
|
|
|
|
return this.socket.getMessageDelete()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listenToUpdateMessages() {
|
|
|
|
|
return this.socket.getMessageUpdate()
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 16:34:47 +01:00
|
|
|
|
2024-08-19 16:01:58 +01:00
|
|
|
reactToMessageSocket(data) {
|
|
|
|
|
this.socket.sendData({
|
|
|
|
|
method: 'ReactMessage',
|
|
|
|
|
data
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateMessage(input: MessageUpdateInput) {
|
|
|
|
|
this.socket.sendData({
|
|
|
|
|
method: 'EditMessage',
|
|
|
|
|
data: input,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-08-20 16:34:47 +01:00
|
|
|
|
2024-08-19 16:01:58 +01:00
|
|
|
|
|
|
|
|
}
|