fix ballon

This commit is contained in:
Peter Maquiran
2024-09-04 10:58:26 +01:00
parent 100d64f799
commit 0f3096b25e
11 changed files with 123 additions and 34 deletions
@@ -101,6 +101,10 @@ export class DexieRepository<T, R> implements IDexieRepository<T, R> {
const updatedCount = await this.table.update(id, dataValidation.data);
return ok(updatedCount);
} catch (error) {
Logger.error(`dexie.js failed to update into ${this.table.name}, invalid data`, {
data: updatedDocument,
id,
});
return err(new Error('Failed to update document: ' + error.message));
}
} else {
@@ -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;
@@ -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)
@@ -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)
}
});
@@ -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
})
});
}
}
}
@@ -48,9 +48,9 @@
*ngFor="let message of messages1[roomId]; let messageIndex = index" class="messages-list-item-wrapper px-10-em"
[ngClass]="{
'info-meeting': message.messageType == IMessageType.information && !message.ballon,
'info-ballon': message.ballon,
'my-message': message.messageType == IMessageType.normal && message?.sender?.wxUserId === SessionStore.user.UserId,
'other-message': message.messageType == IMessageType.normal && message?.sender?.wxUserId !== SessionStore.user.UserId
'info-ballon': message.ballon == true,
'my-message': message.messageType == IMessageType.normal && message?.sender?.wxUserId === SessionStore.user.UserId && !message.ballon,
'other-message': message.messageType == IMessageType.normal && message?.sender?.wxUserId !== SessionStore.user.UserId && !message.ballon
}"
>
<div class="message-container rotate-div" *ngIf="message.showMessage">
@@ -148,7 +148,7 @@
<div class="message-container rotate-div" *ngIf="message.isDeleted == true">
Mensagem foi eliminada
</div>
<div *ngIf="message.messageType == IMessageType.information" class="text-center">
<div *ngIf="message.messageType == IMessageType.information && !message.ballon" class="text-center">
{{ message.message }}
</div>
<div *ngIf="message.ballon" class="text-center ballon">
@@ -351,7 +351,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
async loadAttachment() {
for(const message of this.messages1[this.roomId]) {
if(message.hasAttachment) {
if(message.hasAttachment && message.attachments[0].source != MessageAttachmentSource.Webtrix) {
if(message.$id) {
this.chatServiceService.getMessageAttachmentByMessageId(message).then((result)=> {
@@ -422,6 +422,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.messageReceiveSubject?.unsubscribe();
this.messageReceiveSubject = this.chatServiceService.listenToIncomingMessage(this.roomId).subscribe(async (message) => {
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.roomId].push(Ballon)
}
this.messages1[this.roomId].push(new MessageViewModal(message))
if(message.hasAttachment) {
@@ -754,8 +761,19 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
safeFile: this.sanitiser.bypassSecurityTrustResourceUrl(this.audioRecordedDataUrl)
}]
this.chatServiceService.sendMessage(message, this.roomType)
message.sentAt = new Date().toISOString()
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.roomId].push(Ballon)
}
this.messages1[this.roomId].push(message)
this.chatServiceService.sendMessage(message, this.roomType)
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)
@@ -811,6 +829,14 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
message.sentAt = new Date().toISOString()
this.textField = ''
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.roomId].push(Ballon)
}
this.messages1[this.roomId].push(message)
setTimeout(() => {
this.scrollToBottomClicked()
@@ -997,7 +1023,14 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
mimeType: 'image/'+picture.value.format
}]
this.messages1[this.roomId].push(new MessageViewModal(message))
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.roomId].push(Ballon)
}
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)
@@ -1053,6 +1086,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
docId: res.data.selected.Id,
}]
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.roomId].push(Ballon)
}
this.messages1[this.roomId].push(new MessageViewModal(message))
setTimeout(() => {
this.scrollToBottomClicked()
@@ -1143,6 +1183,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
description: ''
}]
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.roomId].push(Ballon)
}
this.messages1[this.roomId].push(message)
setTimeout(() => {
this.scrollToBottomClicked()
@@ -1199,6 +1246,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
mimeType: file.value.type
}]
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.roomId].push(Ballon)
}
this.messages1[this.roomId].push(message)
setTimeout(() => {
this.scrollToBottomClicked()
+1 -1
View File
@@ -27,7 +27,7 @@ export class MessageViewModal {
messageUiType!: 'info-meeting'| 'my-message'| 'other-message'
showReaction = false
showMessage = false
ballo = false
ballon = false
constructor(model?: IMessage) {
if(model) {
+3 -1
View File
@@ -1,6 +1,7 @@
import { SessionStore } from "src/app/store/session.service";
import { MessageViewModal } from "../store/model/message";
import { whatsappDate } from "../../shared/utils/whatappdate";
import { IMessageType } from "src/app/core/chat/entity/message";
export function XBallon(message: any) {
const MessageBallon = new MessageViewModal(message as any)
@@ -9,7 +10,8 @@ export function XBallon(message: any) {
MessageBallon.isDeleted = false
MessageBallon.sentAt = message.sentAt
MessageBallon.message = whatsappDate(message.sentAt, false)
MessageBallon.ballo = true
MessageBallon.messageType == IMessageType.information
MessageBallon.ballon = true
MessageBallon.sender = {
userPhoto: '',
wxeMail: SessionStore.user.Email,