2024-06-04 13:12:38 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { HttpService } from 'src/app/services/http.service';
|
2024-08-19 16:01:58 +01:00
|
|
|
import { MessageInputDTO, MessageInputDTOSchema } from '../../dto/message/messageInputDtO';
|
2024-06-05 10:28:38 +01:00
|
|
|
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
2024-06-10 16:34:43 +01:00
|
|
|
import { APIReturn } from 'src/app/services/decorators/api-validate-schema.decorator';
|
2024-08-19 16:01:58 +01:00
|
|
|
import { MessageOutPutDataDTOSchema, MessageOutPutDTO, MessageOutPutDTOSchema } from '../../dto/message/messageOutputDTO';
|
2024-07-11 10:28:21 +01:00
|
|
|
import { DataSourceReturn } from 'src/app/services/Repositorys/type';
|
2024-08-19 16:01:58 +01:00
|
|
|
import { SignalRService } from '../../../infra/socket/signal-r.service';
|
|
|
|
|
import { MessageUpdateInput } from '../../../domain/use-case/message-update-by-id-use-case.service';
|
2024-08-18 15:40:43 +01:00
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
2024-08-19 16:01:58 +01:00
|
|
|
import { MessageDeleteInputDTO } from '../../dto/message/messageDeleteInputDTO';
|
|
|
|
|
import { InstanceId } from '../../../domain/chat-service.service';
|
2024-08-18 15:40:43 +01:00
|
|
|
import { v4 as uuidv4 } from 'uuid'
|
2024-06-04 13:12:38 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class MessageRemoteDataSourceService {
|
|
|
|
|
|
|
|
|
|
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2/Chat'; // Your base URL
|
|
|
|
|
|
2024-08-18 15:40:43 +01:00
|
|
|
constructor(
|
|
|
|
|
private httpService: HttpService,
|
|
|
|
|
private socket: SignalRService,
|
|
|
|
|
) {}
|
2024-06-04 13:12:38 +01:00
|
|
|
|
2024-08-08 11:44:41 +01:00
|
|
|
@APIReturn(MessageOutPutDTOSchema, 'post/Messages')
|
2024-06-05 10:28:38 +01:00
|
|
|
@ValidateSchema(MessageInputDTOSchema)
|
|
|
|
|
async sendMessage(data: MessageInputDTO) {
|
|
|
|
|
return await this.httpService.post<MessageOutPutDTO>(`${this.baseUrl}/Messages`, data);
|
2024-06-04 13:12:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async reactToMessage(id: string, reaction: any) {
|
|
|
|
|
return await this.httpService.post<any>(`${this.baseUrl}/Messages/${id}/React`, reaction);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 15:53:00 +01:00
|
|
|
|
2024-08-15 10:26:20 +01:00
|
|
|
// @APIReturn(MessageOutPutDTOSchema, 'get/Messages')
|
2024-08-08 09:58:44 +01:00
|
|
|
async getMessagesFromRoom(id: string): DataSourceReturn<MessageOutPutDTO> {
|
2024-06-04 16:21:11 +01:00
|
|
|
return await this.httpService.get(`${this.baseUrl}/Room/${id}/Messages`);
|
2024-06-04 13:12:38 +01:00
|
|
|
}
|
2024-06-05 14:31:26 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
|
|
|
|
|
@APIReturn(MessageOutPutDTOSchema, 'get/Messages/attachment')
|
|
|
|
|
async getAttachment(id: string): DataSourceReturn<MessageOutPutDTO> {
|
|
|
|
|
return await this.httpService.get(`${this.baseUrl}/attachment/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-18 15:40:43 +01:00
|
|
|
|
2024-06-04 13:12:38 +01:00
|
|
|
}
|