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:
@@ -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