mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix ballon
This commit is contained in:
+36
-11
@@ -31,13 +31,26 @@ export type ISocketMessageCreateOutput = z.infer<typeof SocketMessageCreateOutpu
|
||||
})
|
||||
export class SocketMessageCreateUseCaseService {
|
||||
|
||||
private broadcastChannel: BroadcastChannel;
|
||||
private processedMessages = new Set<string>();
|
||||
|
||||
constructor(
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService,
|
||||
) { }
|
||||
) {
|
||||
this.broadcastChannel = new BroadcastChannel('socket-message');
|
||||
this.broadcastChannel.onmessage = (event) => {
|
||||
console.log('hello', event.data)
|
||||
const messageId = event.data;
|
||||
this.processedMessages.add(messageId);
|
||||
};
|
||||
|
||||
// this.broadcastChannel.postMessage('incomingMessage.id');
|
||||
}
|
||||
|
||||
@XTracerAsync({name:'Socket-Message-Create-UseCase', module:'chat', bugPrint: true})
|
||||
async execute(input: ISocketMessageCreateOutput, tracing?: TracingType) {
|
||||
|
||||
this.broadcastChannel.postMessage(input.id);
|
||||
ParamsValidation(SocketMessageCreateOutputSchema, input, tracing)
|
||||
|
||||
const incomingMessage = {
|
||||
@@ -45,19 +58,31 @@ export class SocketMessageCreateUseCaseService {
|
||||
sending: false
|
||||
}
|
||||
|
||||
console.log('create message', {incomingMessage});
|
||||
|
||||
tracing?.addEvent("Message Create start")
|
||||
const result = await this.messageLocalDataSourceService.insert(incomingMessage)
|
||||
tracing?.addEvent("Message Create end")
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
// Check if the message ID already exists in the processedMessages set
|
||||
if (this.processedMessages.has(incomingMessage.id)) {
|
||||
console.warn(`Duplicate message detected: ${incomingMessage.id}`);
|
||||
return; // Exit early to prevent duplicate handling
|
||||
} else {
|
||||
tracing?.addEvent("error while creating message")
|
||||
console.log('no duplicate')
|
||||
}
|
||||
|
||||
// Add the message ID to the processedMessages set and broadcast it
|
||||
this.processedMessages.add(incomingMessage.id);
|
||||
|
||||
|
||||
console.log('create message', { incomingMessage });
|
||||
|
||||
tracing?.addEvent("Message Create start");
|
||||
const result = await this.messageLocalDataSourceService.insert(incomingMessage);
|
||||
tracing?.addEvent("Message Create end");
|
||||
|
||||
if (result.isOk()) {
|
||||
// Optionally, you can handle post-insertion logic here
|
||||
} else {
|
||||
tracing?.addEvent("error while creating message");
|
||||
tracing.log("error while creating message", {
|
||||
error: result.error
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user