mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix ballon
This commit is contained in:
@@ -21,6 +21,11 @@ export function messageListDetermineChanges(serverList: MessageTable[], localLis
|
||||
// Identify changed items
|
||||
const changedItems = serverList.filter(item => {
|
||||
const localItem = localDict[item.id];
|
||||
|
||||
if(localItem?.$id) {
|
||||
item.$id = localItem.$id
|
||||
}
|
||||
|
||||
return localItem && (item.editedAt !== localItem.editedAt || item.reactions.some((r, index) => {
|
||||
const localReaction = localItem.reactions[index];
|
||||
return !localReaction || r.reactedAt !== localReaction.reactedAt;
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ export class MessageAttachmentByMessageIdUseCase {
|
||||
private AttachmentLocalDataSource: AttachmentLocalDataSource
|
||||
) { }
|
||||
|
||||
@XTracerAsync({name:'Message-Attachment-By-MessageIdUseCase', module:'chat', bugPrint: true, waitNThrow: 15000})
|
||||
@XTracerAsync({name:'Message-Attachment-By-MessageIdUseCase', module:'chat', bugPrint: true, waitNThrow: 5000})
|
||||
async execute(input: MessageAttachmentByMessageIdInput, tracing?: TracingType): Promise<Result<string, any>> {
|
||||
|
||||
tracing.setAttribute('messageId', input.id)
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ export class MessageDeleteLiveUseCaseService {
|
||||
public repository: MessageSocketRepositoryService
|
||||
) { }
|
||||
|
||||
@XTracerAsync({name:'MessageDeleteLiveUseCaseService', module:'chat', bugPrint: true})
|
||||
@XTracerAsync({name:'MessageDeleteLiveUseCaseService', module:'chat', bugPrint: true, waitNThrow: 2000})
|
||||
async execute(data: MessageDeleteInputDTO, tracing?: TracingType) {
|
||||
tracing.log('MessageDeleteLiveUseCaseService payload', {
|
||||
data: data
|
||||
|
||||
@@ -49,21 +49,22 @@ export class SyncAllRoomMessagesService {
|
||||
const { addedItems, changedItems, deletedItems } = messageListDetermineChanges(result.value.data, localResult);
|
||||
|
||||
for (const message of changedItems) {
|
||||
delete message.sentAt
|
||||
let clone: MessageTable = { ...message, roomId: room.id };
|
||||
await this.messageLocalDataSourceService.update(clone.$id, clone);
|
||||
|
||||
const me = message.info.find(e => e.memberId === SessionStore.user.UserId && typeof e.deliverAt === 'string');
|
||||
// const me = message.info.find(e => e.memberId === SessionStore.user.UserId && typeof e.deliverAt === 'string');
|
||||
|
||||
if (!me) {
|
||||
this.MessageSocketRepositoryService.sendDeliverAt({
|
||||
memberId: SessionStore.user.UserId,
|
||||
messageId: message.id,
|
||||
roomId: message.roomId,
|
||||
requestId: uuidv4()
|
||||
});
|
||||
// if (!me) {
|
||||
// this.MessageSocketRepositoryService.sendDeliverAt({
|
||||
// memberId: SessionStore.user.UserId,
|
||||
// messageId: message.id,
|
||||
// roomId: message.roomId,
|
||||
// requestId: uuidv4()
|
||||
// });
|
||||
|
||||
tracing.addEvent('send deliver roomId ' + room.id);
|
||||
}
|
||||
// tracing.addEvent('send deliver roomId ' + room.id);
|
||||
// }
|
||||
}
|
||||
|
||||
for (const message of addedItems) {
|
||||
|
||||
@@ -69,8 +69,6 @@ export class RoomBoldSyncUseCaseService {
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
console.log(message.info.filter(e => typeof e.readAt == 'string' && e.memberId == SessionStore.user.UserId).length == 1, '', message)
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
+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