mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add reaction to chat
This commit is contained in:
@@ -3,15 +3,23 @@ import { BehaviorSubject } from 'rxjs';
|
||||
import { Platform } from '@ionic/angular';
|
||||
import { SignalRConnection } from './signalR';
|
||||
import { Plugins } from '@capacitor/core';
|
||||
import { z } from 'zod';
|
||||
import { UserTypingDTO } from '../../data/dto/typing/typingInputDTO';
|
||||
import { MessageOutPutDataDTO } from '../../data/dto/message/messageOutputDTO';
|
||||
import { MessageDeleteInputDTO } from '../../data/dto/message/messageDeleteInputDTO';
|
||||
import { object, z } from 'zod';
|
||||
|
||||
const { App } = Plugins;
|
||||
|
||||
const SignalRInputSchema = z.object({
|
||||
method: z.string(),
|
||||
data: z.object({
|
||||
requestId: z.string()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
export type ISignalRInput = z.infer<typeof SignalRInputSchema>
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -22,6 +30,8 @@ export class SignalRService {
|
||||
private connectingSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);
|
||||
private messageDelete: BehaviorSubject<MessageOutPutDataDTO> = new BehaviorSubject<MessageOutPutDataDTO>(null);
|
||||
private messageUpdateSubject: BehaviorSubject<MessageOutPutDataDTO> = new BehaviorSubject<MessageOutPutDataDTO>(null);
|
||||
private sendDataSubject: BehaviorSubject<Object> = new BehaviorSubject<Object>(false);
|
||||
|
||||
|
||||
constructor(
|
||||
private platform: Platform) {
|
||||
@@ -78,6 +88,14 @@ export class SignalRService {
|
||||
this.connection.getMessageUpdateSubject().subscribe((data) => {
|
||||
this.messageUpdateSubject.next(data)
|
||||
})
|
||||
|
||||
this.connection.getMessageUpdateSubject().subscribe((data) => {
|
||||
this.messageUpdateSubject.next(data)
|
||||
})
|
||||
|
||||
this.connection.getData().subscribe((data) => {
|
||||
this.messageUpdateSubject.next(data)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,6 +118,14 @@ export class SignalRService {
|
||||
return this.messageUpdateSubject.asObservable()
|
||||
}
|
||||
|
||||
sendData(input: ISignalRInput) {
|
||||
return this.connection.sendData(input)
|
||||
}
|
||||
|
||||
getData() {
|
||||
return this.getData()
|
||||
}
|
||||
|
||||
async sendMessage(data: Object) {
|
||||
return await this.connection.sendMessage(data as any)
|
||||
}
|
||||
@@ -120,5 +146,10 @@ export class SignalRService {
|
||||
async sendMessageDelete(data: MessageDeleteInputDTO) {
|
||||
return await this.connection.deleteMessage(data)
|
||||
}
|
||||
|
||||
|
||||
|
||||
async sendReactToMessage(data) {
|
||||
return await this.connection.sendReactMessage(data)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import { v4 as uuidv4 } from 'uuid'
|
||||
import { UserTypingDTO } from '../../data/dto/typing/typingInputDTO';
|
||||
import { MessageOutPutDataDTO } from '../../data/dto/message/messageOutputDTO';
|
||||
import { MessageDeleteInputDTO } from '../../data/dto/message/messageDeleteInputDTO';
|
||||
import { MessageReactionInput } from '../../domain/use-case/message-reaction-use-case.service';
|
||||
import { ISignalRInput } from './signal-r.service';
|
||||
|
||||
export class SignalRConnection {
|
||||
|
||||
@@ -21,6 +23,9 @@ export class SignalRConnection {
|
||||
private reconnectSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
private sendLaterSubject: BehaviorSubject<Object> = new BehaviorSubject<Object>(false);
|
||||
private reconnect = true
|
||||
|
||||
private sendDataSubject: BehaviorSubject<Object> = new BehaviorSubject<Object>(false);
|
||||
|
||||
url: string
|
||||
|
||||
constructor({url}) {
|
||||
@@ -118,7 +123,7 @@ export class SignalRConnection {
|
||||
|
||||
this.messageSubject.pipe(
|
||||
filter((message: any) => data.requestId == message?.requestId),
|
||||
first()
|
||||
first()
|
||||
).subscribe((value) => {
|
||||
resolve(ok(value))
|
||||
})
|
||||
@@ -157,7 +162,6 @@ export class SignalRConnection {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
public async sendReadAt(data: Object & { roomId, memberId, chatMessageId}):Promise<Result<any, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -187,31 +191,104 @@ 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));
|
||||
});
|
||||
|
||||
} else {
|
||||
this.sendLaterSubject.next({method: 'SendMessage', args: data})
|
||||
return reject(err(false))
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
sendData(input: ISignalRInput) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
|
||||
this.hubConnection.invoke(input.method, input.data)
|
||||
|
||||
this.sendDataSubject.pipe(
|
||||
filter((message: any) => input.data.requestId == message?.requestId),
|
||||
first()
|
||||
).subscribe(value => {
|
||||
resolve(ok(value))
|
||||
console.log('Received valid value:', value);
|
||||
});
|
||||
|
||||
} else {
|
||||
this.sendLaterSubject.next({method: 'SendMessage', args: input})
|
||||
return reject(err(false))
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
private addMessageListener(): void {
|
||||
console.log('listening')
|
||||
this.hubConnection.on('ReceiveMessage', (message: MessageOutPutDataDTO) => {
|
||||
console.log('ReceiveMessage', message)
|
||||
this.messageSubject.next(message);
|
||||
this.sendDataSubject.next({
|
||||
method: 'ReceiveMessage',
|
||||
data: message
|
||||
})
|
||||
});
|
||||
|
||||
this.hubConnection.on('TypingMessage', (_typing: UserTypingDTO) => {
|
||||
console.log('Typing', _typing)
|
||||
this.typingSubject.next(_typing);
|
||||
this.sendDataSubject.next({
|
||||
method: 'ReceiveMessage',
|
||||
data: _typing
|
||||
})
|
||||
});
|
||||
|
||||
this.hubConnection.on('ReadAt', (_message) => {
|
||||
console.log('ReadAt', _message)
|
||||
this.readAtSubject.next(_message);
|
||||
this.sendDataSubject.next({
|
||||
method: 'ReceiveMessage',
|
||||
data: _message
|
||||
})
|
||||
});
|
||||
|
||||
this.hubConnection.on('DeleteMessage', (_message) => {
|
||||
console.log('DeleteMessage', _message)
|
||||
this.messageDelete.next(_message);
|
||||
this.sendDataSubject.next({
|
||||
method: 'ReceiveMessage',
|
||||
data: _message
|
||||
})
|
||||
});
|
||||
|
||||
this.hubConnection.on('UpdateMessage', (_message) => {
|
||||
console.log('UpdateMessage', _message)
|
||||
this.messageUPdateSubject.next(_message);
|
||||
this.sendDataSubject.next({
|
||||
method: 'ReceiveMessage',
|
||||
data: _message
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
@@ -244,6 +321,10 @@ export class SignalRConnection {
|
||||
return this.messageDelete.asObservable()
|
||||
}
|
||||
|
||||
public getData() {
|
||||
return this.sendDataSubject.asObservable()
|
||||
}
|
||||
|
||||
public closeConnection(): void {
|
||||
this.reconnect = false
|
||||
if (this.hubConnection) {
|
||||
|
||||
Reference in New Issue
Block a user