mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add message repository
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject, BehaviorSubject, Observable } from 'rxjs';
|
||||
import { filter } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageLiveDataSourceService {
|
||||
|
||||
private messageSubject: Subject<any> = new Subject<any>();
|
||||
private isPaused: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
private messageBuffer: any[] = []; // Buffer to store messages when paused
|
||||
private authentication!: string
|
||||
|
||||
constructor() { }
|
||||
|
||||
handleMessage(event: any) {
|
||||
const data: any = event.data || MessageEvent;
|
||||
|
||||
if (this.isPaused.getValue()) {
|
||||
this.messageBuffer.push({}); // Buffer the message if paused
|
||||
} else {
|
||||
this.messageSubject.next({} as any);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pauseBroadcast() {
|
||||
this.isPaused.next(true);
|
||||
}
|
||||
|
||||
resumeBroadcast() {
|
||||
this.isPaused.next(false);
|
||||
this.flushMessageBuffer(); // Emit all buffered messages
|
||||
}
|
||||
|
||||
private flushMessageBuffer() {
|
||||
while (this.messageBuffer.length > 0) {
|
||||
const bufferedMessage = this.messageBuffer.shift();
|
||||
this.messageSubject.next(bufferedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
subscribe(endpoint: any): Observable<any> {
|
||||
return this.messageSubject.pipe(
|
||||
filter(message =>
|
||||
message &&
|
||||
message.endpoint === endpoint &&
|
||||
message.authentication == this.authentication
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpService } from 'src/app/services/http.service';
|
||||
import { MessageOutPutDTO } from '../../dto/message/messageOutputDTO';
|
||||
import { MessageListInputDTO } from '../../dto/message/messageListInputDTO';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageRemoteDataSourceService {
|
||||
|
||||
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2/Chat'; // Your base URL
|
||||
|
||||
constructor(private httpService: HttpService) {}
|
||||
|
||||
|
||||
async sendMessage(message: any) {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Messages`, message);
|
||||
}
|
||||
|
||||
async reactToMessage(id: string, reaction: any) {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Messages/${id}/React`, reaction);
|
||||
}
|
||||
|
||||
async getMessagesFromRoom(id: MessageListInputDTO) {
|
||||
return await this.httpService.get<MessageOutPutDTO>(`${this.baseUrl}/Room/${id}/Messages`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user