mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add readAt and delete message
This commit is contained in:
@@ -6,6 +6,7 @@ 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';
|
||||
|
||||
const { App } = Plugins;
|
||||
|
||||
@@ -19,6 +20,8 @@ export class SignalRService {
|
||||
private messageSubject: BehaviorSubject<MessageOutPutDataDTO> = new BehaviorSubject<MessageOutPutDataDTO>(null);
|
||||
private typingSubject: BehaviorSubject<UserTypingDTO> = new BehaviorSubject<UserTypingDTO>(null);
|
||||
private connectingSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);
|
||||
private messageDelete: BehaviorSubject<MessageOutPutDataDTO> = new BehaviorSubject<MessageOutPutDataDTO>(null);
|
||||
private messageUpdateSubject: BehaviorSubject<MessageOutPutDataDTO> = new BehaviorSubject<MessageOutPutDataDTO>(null);
|
||||
|
||||
constructor(
|
||||
private platform: Platform) {
|
||||
@@ -48,7 +51,8 @@ export class SignalRService {
|
||||
|
||||
private async establishConnection() {
|
||||
|
||||
const connection = new SignalRConnection({url:'https://41e3-41-63-166-54.ngrok-free.app/api/v2/chathub'})
|
||||
// const connection = new SignalRConnection({url:'https://41e3-41-63-166-54.ngrok-free.app/api/v2/chathub'})
|
||||
const connection = new SignalRConnection({url:'https://gdapi-dev.dyndns.info/stage/api/v2/chathub'})
|
||||
const attempConnection = await connection.establishConnection()
|
||||
|
||||
if(attempConnection.isOk()) {
|
||||
@@ -66,6 +70,14 @@ export class SignalRService {
|
||||
this.connection.getTyping().subscribe((data) => {
|
||||
this.typingSubject.next(data)
|
||||
})
|
||||
|
||||
this.connection.getMessageDelete().subscribe((data) => {
|
||||
this.messageDelete.next(data)
|
||||
})
|
||||
|
||||
this.connection.getMessageUpdateSubject().subscribe((data) => {
|
||||
this.messageUpdateSubject.next(data)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,6 +92,14 @@ export class SignalRService {
|
||||
return this.typingSubject.asObservable().pipe()
|
||||
}
|
||||
|
||||
getMessageDelete() {
|
||||
return this.messageDelete.asObservable()
|
||||
}
|
||||
|
||||
getMessageUpdate() {
|
||||
return this.messageUpdateSubject.asObservable()
|
||||
}
|
||||
|
||||
async sendMessage(data: Object) {
|
||||
return await this.connection.sendMessage(data as any)
|
||||
}
|
||||
@@ -95,4 +115,10 @@ export class SignalRService {
|
||||
async sendReadAt({ roomId, memberId, chatMessageId}) {
|
||||
return await this.connection.sendReadAt({ roomId, memberId, chatMessageId})
|
||||
}
|
||||
|
||||
|
||||
async sendMessageDelete(data: MessageDeleteInputDTO) {
|
||||
return await this.connection.deleteMessage(data)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,41 +6,14 @@ import { filter, first } from 'rxjs/operators';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { UserTypingDTO } from '../../data/dto/typing/typingInputDTO';
|
||||
import { MessageOutPutDataDTO } from '../../data/dto/message/messageOutputDTO';
|
||||
|
||||
|
||||
var msgObj = {
|
||||
roomId: "53bc6471-c28e-42d0-aa72-f4e52221f16f",
|
||||
senderId:312,
|
||||
message:"message enviada",
|
||||
messageType:312,
|
||||
canEdit:true,
|
||||
oneShot:false,
|
||||
requestId:"testing"
|
||||
};
|
||||
// var deletObj = {
|
||||
// roomId: "53bc6471-c28e-42d0-aa72-f4e52221f16f",
|
||||
// senderId:312,
|
||||
// messageId:"message enviada",
|
||||
// requestId:"testing"
|
||||
// };
|
||||
// var reactObj = {
|
||||
// roomId: "53bc6471-c28e-42d0-aa72-f4e52221f16f",
|
||||
// memberId:2,
|
||||
// messageId:"e7074c10-4f92-458c-adb2-774ec2d42992",
|
||||
// reaction:"reacted",
|
||||
// requestId:"testingReaction"
|
||||
// };
|
||||
const typingObj = {
|
||||
roomId: "53bc6471-c28e-42d0-aa72-f4e52221f16f",
|
||||
userId: 312,
|
||||
userName:"usertyping",
|
||||
requestId:"testing"
|
||||
};
|
||||
import { MessageDeleteInputDTO } from '../../data/dto/message/messageDeleteInputDTO';
|
||||
|
||||
export class SignalRConnection {
|
||||
|
||||
private hubConnection: signalR.HubConnection;
|
||||
private messageSubject: BehaviorSubject<MessageOutPutDataDTO> = new BehaviorSubject<MessageOutPutDataDTO>(null);
|
||||
private messageDelete: BehaviorSubject<MessageOutPutDataDTO> = new BehaviorSubject<MessageOutPutDataDTO>(null);
|
||||
private messageUPdateSubject: BehaviorSubject<MessageOutPutDataDTO> = new BehaviorSubject<MessageOutPutDataDTO>(null);
|
||||
private typingSubject: BehaviorSubject<UserTypingDTO> = new BehaviorSubject<UserTypingDTO>(null);
|
||||
private readAtSubject: BehaviorSubject<string> = new BehaviorSubject<any>(null);
|
||||
private connectionStateSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
@@ -57,7 +30,6 @@ export class SignalRConnection {
|
||||
establishConnection(): Promise<Result<signalR.HubConnection, false>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
console.log('try to connect');
|
||||
const hubConnection = new signalR.HubConnectionBuilder()
|
||||
.withUrl(this.url)
|
||||
.build();
|
||||
@@ -106,7 +78,7 @@ export class SignalRConnection {
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
|
||||
console.log('join=================')
|
||||
this.hubConnection.invoke("Join", 312, SessionStore.user.FullName);
|
||||
this.hubConnection.invoke("Join", SessionStore.user.UserId, SessionStore.user.FullName);
|
||||
//this.hubConnection.invoke("Join", 105, "UserFirefox");
|
||||
} else {
|
||||
this.sendLaterSubject.next({method: 'SendMessage', args:["Join", 312, "Daniel"]})
|
||||
@@ -119,7 +91,7 @@ export class SignalRConnection {
|
||||
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
console.log('sendMessage', data)
|
||||
this.hubConnection.invoke("SendMessage", msgObj)
|
||||
this.hubConnection.invoke("SendMessage", data)
|
||||
|
||||
this.messageSubject.pipe(
|
||||
filter((message: any) => data.requestId == message?.requestId),
|
||||
@@ -138,6 +110,23 @@ export class SignalRConnection {
|
||||
})
|
||||
}
|
||||
|
||||
public async deleteMessage(data: MessageDeleteInputDTO) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
console.log('delete message', data)
|
||||
this.hubConnection.invoke("DeleteMessage", data)
|
||||
|
||||
this.messageSubject.pipe(
|
||||
filter((message: any) => data.requestId == message?.requestId),
|
||||
first()
|
||||
).subscribe((value) => {
|
||||
resolve(ok(value))
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
public async typing(data: Object & { roomId, UserName, userId }):Promise<Result<any, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -146,7 +135,7 @@ export class SignalRConnection {
|
||||
console.log('send typing', data)
|
||||
|
||||
try {
|
||||
this.hubConnection.invoke("Typing", typingObj)
|
||||
this.hubConnection.invoke("Typing", data)
|
||||
|
||||
} catch (error) {}
|
||||
|
||||
@@ -176,7 +165,7 @@ export class SignalRConnection {
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
|
||||
try {
|
||||
this.hubConnection.invoke("ReadAt", { roomId: data.roomId, memberId: data.memberId, requestId } as any)
|
||||
this.hubConnection.invoke("ReadAt", { roomId: data.roomId, memberId: data.memberId, requestId, messageId: data.chatMessageId} as any)
|
||||
|
||||
} catch (error) {}
|
||||
|
||||
@@ -215,6 +204,20 @@ export class SignalRConnection {
|
||||
this.readAtSubject.next(_message);
|
||||
});
|
||||
|
||||
this.hubConnection.on('DeleteMessage', (_message) => {
|
||||
console.log('DeleteMessage', _message)
|
||||
this.messageDelete.next(_message);
|
||||
});
|
||||
|
||||
this.hubConnection.on('UpdateMessage', (_message) => {
|
||||
console.log('UpdateMessage', _message)
|
||||
this.messageUPdateSubject.next(_message);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
public getMessageUpdateSubject() {
|
||||
return this.messageUPdateSubject.asObservable()
|
||||
}
|
||||
|
||||
public getMessages() {
|
||||
@@ -237,6 +240,10 @@ export class SignalRConnection {
|
||||
return this.sendLaterSubject.asObservable();
|
||||
}
|
||||
|
||||
public getMessageDelete() {
|
||||
return this.messageDelete.asObservable()
|
||||
}
|
||||
|
||||
public closeConnection(): void {
|
||||
this.reconnect = false
|
||||
if (this.hubConnection) {
|
||||
|
||||
Reference in New Issue
Block a user