mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix delete message on ui layer
This commit is contained in:
@@ -49,8 +49,10 @@ import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/
|
||||
import { RoomTable } from 'src/app/infra/database/dexie/instance/chat/schema/room';
|
||||
import { TypingTable } from 'src/app/infra/database/dexie/instance/chat/schema/typing';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { RoomViewModel } from '../../store/model/room';
|
||||
import { MessageViewModal } from '../../store/model/message';
|
||||
import { XBallon } from '../../utils/messageBallon';
|
||||
import { whatsappDate } from 'src/app/ui/shared/utils/whatappdate';
|
||||
@Component({
|
||||
selector: 'app-messages',
|
||||
templateUrl: './messages.page.html',
|
||||
@@ -91,7 +93,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
scrollToBottomBtn = false;
|
||||
longPressActive = false;
|
||||
downloadFile: string;
|
||||
|
||||
showAvatar = true;
|
||||
|
||||
recording = false;
|
||||
@@ -125,7 +126,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
roomStatus$: DexieObservable<Boolean >
|
||||
roomMessage$: DexieObservable<MessageTable[]>
|
||||
roomMembers$: Observable<MemberTable[] | undefined>
|
||||
//userTyping$: DexieObservable<TypingTable[] | undefined>
|
||||
userTyping$: TypingTable[] | undefined
|
||||
newMessagesStream!: Subscription
|
||||
|
||||
@@ -143,7 +143,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
messageTypingSubject: Subscription
|
||||
messageOnReconnectSubject: Subscription
|
||||
|
||||
messages1: {[key: string]: MessageEntity[]} = {}
|
||||
messages1: {[key: string]: MessageViewModal[]} = {}
|
||||
MessageAttachmentFileType = MessageAttachmentFileType
|
||||
MessageAttachmentFileSource = MessageAttachmentSource
|
||||
IMessageType = IMessageType
|
||||
@@ -155,6 +155,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
private worker: SharedWorker;
|
||||
private port: MessagePort;
|
||||
|
||||
date: {[key: string]: Object} = {}
|
||||
|
||||
constructor(
|
||||
public popoverController: PopoverController,
|
||||
private modalController: ModalController,
|
||||
@@ -186,56 +188,53 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.checkAudioPermission()
|
||||
//this.sendChunks()
|
||||
|
||||
this.worker = new SharedWorker('shared-worker.js');
|
||||
this.port = this.worker.port;
|
||||
// this.worker = new SharedWorker('shared-worker.js');
|
||||
// this.port = this.worker.port;
|
||||
|
||||
this.port.onmessage = (event) => {
|
||||
console.log('Received from worker:', event.data);
|
||||
}
|
||||
// this.port.onmessage = (event) => {
|
||||
// console.log('Received from worker:', event.data);
|
||||
// }
|
||||
|
||||
this.port.postMessage('hello');
|
||||
// this.port.postMessage('hello');
|
||||
}
|
||||
|
||||
sendChunks() {
|
||||
const base64String = 'data:video/mp4;base64,AAAAHGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb21tcDQyaXNvbXJtZGEAAAAHZnJlZS1ybWRhAAAAGXZmY2MtbGF2ZjU4LmEyLTkyLm12NTZjAGZyZWUtcm1kYQAAAAVyZWZsYXYAAABWZGF0YTqBgIAAAAs9AAABM/f/+6mpg6z+d0+j5adJHVD+lk75p0ntRFEyTlHT/GRYbDg4ODhISEhAQK/jMCAxCBAIEwMmJgAABNmY2MtbGF2ZjU4LmEyLTkyLm12NTZjAGZyZWUtcm1kYQAAAAVyZWZsYXY=';
|
||||
const chunkSize = Math.ceil(base64String.length / 2);
|
||||
const chunks = [
|
||||
{ chunk: base64String.slice(0, chunkSize), index: 0 },
|
||||
{ chunk: base64String.slice(chunkSize), index: 1 }
|
||||
];
|
||||
// sendChunks() {
|
||||
// const base64String = 'data:video/mp4;base64,AAAAHGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb21tcDQyaXNvbXJtZGEAAAAHZnJlZS1ybWRhAAAAGXZmY2MtbGF2ZjU4LmEyLTkyLm12NTZjAGZyZWUtcm1kYQAAAAVyZWZsYXYAAABWZGF0YTqBgIAAAAs9AAABM/f/+6mpg6z+d0+j5adJHVD+lk75p0ntRFEyTlHT/GRYbDg4ODhISEhAQK/jMCAxCBAIEwMmJgAABNmY2MtbGF2ZjU4LmEyLTkyLm12NTZjAGZyZWUtcm1kYQAAAAVyZWZsYXY=';
|
||||
// const chunkSize = Math.ceil(base64String.length / 2);
|
||||
// const chunks = [
|
||||
// { chunk: base64String.slice(0, chunkSize), index: 0 },
|
||||
// { chunk: base64String.slice(chunkSize), index: 1 }
|
||||
// ];
|
||||
|
||||
const identifier = uuidv4(); // You can set a unique identifier for the file
|
||||
// const identifier = uuidv4(); // You can set a unique identifier for the file
|
||||
|
||||
const totalChunks = chunks.length;
|
||||
// const totalChunks = chunks.length;
|
||||
|
||||
chunks.forEach((chunkData) => {
|
||||
const payload = {
|
||||
chunk: chunkData.chunk,
|
||||
identifier,
|
||||
index: chunkData.index,
|
||||
totalChunks
|
||||
};
|
||||
// chunks.forEach((chunkData) => {
|
||||
// const payload = {
|
||||
// chunk: chunkData.chunk,
|
||||
// identifier,
|
||||
// index: chunkData.index,
|
||||
// totalChunks
|
||||
// };
|
||||
|
||||
this.http.post('https://gdapi-dev.dyndns.info/stage/api/v2/File/UploadBase64Chunks', payload)
|
||||
.subscribe(response => {
|
||||
console.log('Chunk sent successfully:', response);
|
||||
}, error => {
|
||||
console.error('Error sending chunk:', error);
|
||||
});
|
||||
});
|
||||
}
|
||||
// this.http.post('https://gdapi-dev.dyndns.info/stage/api/v2/File/UploadBase64Chunks', payload)
|
||||
// .subscribe(response => {
|
||||
// console.log('Chunk sent successfully:', response);
|
||||
// }, error => {
|
||||
// console.error('Error sending chunk:', error);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
|
||||
|
||||
this.roomData$ = this.RoomLocalRepository.getRoomByIdLive(this.roomId)
|
||||
|
||||
this.roomData$.subscribe(e => {
|
||||
// console.log(e)
|
||||
if(e) {
|
||||
this.roomType = e.roomType
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
this.getMessages();
|
||||
@@ -244,7 +243,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.listenToUpdateMessage();
|
||||
this.listenToSendMessage();
|
||||
|
||||
// this.roomMessage$ = this.messageRepositoryService.getItemsLive(this.roomId)
|
||||
this.roomMembers$ = this.MemberListLocalRepository.getRoomMemberByIdLive(this.roomId).pipe(
|
||||
tap((members) => {
|
||||
this.totalMembers = members.length
|
||||
@@ -258,7 +256,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
)
|
||||
|
||||
this.roomStatus$ = this.MemberListLocalRepository.allMemberOnline(this.roomId)
|
||||
// this.chatServiceService.getRoomById(this.roomId)
|
||||
|
||||
this.messageTypingSubject?.unsubscribe()
|
||||
this.messageTypingSubject = this.userTypingLocalRepository.getUserTypingLiveByRoomId(this.roomId).subscribe((e) => {
|
||||
@@ -307,7 +304,25 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
let messages = await this.messageLocalDataSourceService.getItems(this.roomId)
|
||||
|
||||
this.messages1[this.roomId] = []
|
||||
this.messages1[this.roomId] = messages
|
||||
this.date = {}
|
||||
const allMessage = [];
|
||||
|
||||
for(const message of messages) {
|
||||
const date = whatsappDate(message.sentAt, false)
|
||||
if(!this.date[date]) {
|
||||
this.date[date] = true
|
||||
const Ballon = XBallon(message)
|
||||
allMessage.push(Ballon)
|
||||
}
|
||||
|
||||
allMessage.push(new MessageViewModal(message))
|
||||
}
|
||||
|
||||
console.time("mappingTime");
|
||||
|
||||
this.messages1[this.roomId] = allMessage
|
||||
|
||||
console.timeEnd("mappingTime");
|
||||
|
||||
// if(messages.length >= 1) {
|
||||
// this.messages1[this.roomId].push(LastMessage)
|
||||
@@ -321,13 +336,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.messageOnReconnectSubject?.unsubscribe()
|
||||
this.messageOnReconnectSubject = this.chatServiceService.listenToMessageLoadHistory({roomId: this.roomId}).subscribe((messages) => {
|
||||
|
||||
console.log('message', messages);
|
||||
|
||||
for(const message of messages.data) {
|
||||
const found = this.messages1[this.roomId].find((e) => e.id == message.id)
|
||||
|
||||
if(!found) {
|
||||
const msg = new MessageEntity()
|
||||
const msg = new MessageViewModal(message as any)
|
||||
Object.assign(msg, message)
|
||||
this.messages1[this.roomId].push(msg)
|
||||
}
|
||||
@@ -387,17 +400,19 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
for(const message of this.messages1[this.roomId]) {
|
||||
|
||||
const me = message.info.find(e => e.memberId == SessionStore.user.UserId && typeof e.readAt == 'string')
|
||||
if(!message.meSender()) {
|
||||
const me = message.haveSeen(message.info)
|
||||
|
||||
if(!me) {
|
||||
Logger.info('send read at')
|
||||
if(!me) {
|
||||
Logger.info('send read at, sender '+ message.sender.wxFullName+ ' '+ message.message +'message id'+ message.id)
|
||||
|
||||
this.chatServiceService.sendReadAt({
|
||||
memberId: SessionStore.user.UserId,
|
||||
messageId: message.id,
|
||||
requestId: '',
|
||||
roomId: this.roomId
|
||||
})
|
||||
this.chatServiceService.sendReadAt({
|
||||
memberId: SessionStore.user.UserId,
|
||||
messageId: message.id,
|
||||
requestId: '',
|
||||
roomId: this.roomId
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,7 +422,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.messageReceiveSubject?.unsubscribe();
|
||||
this.messageReceiveSubject = this.chatServiceService.listenToIncomingMessage(this.roomId).subscribe(async (message) => {
|
||||
|
||||
this.messages1[this.roomId].push(message as MessageEntity)
|
||||
this.messages1[this.roomId].push(new MessageViewModal(message))
|
||||
|
||||
if(message.hasAttachment) {
|
||||
|
||||
@@ -440,7 +455,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
console.log('delete class', deleteMessage);
|
||||
|
||||
const index = this.messages1[this.roomId].findIndex(e => e?.id === deleteMessage.id); // Use triple equals for comparison
|
||||
this.messages1[this.roomId][index].isDeleted = true
|
||||
this.messages1[this.roomId][index].delete()
|
||||
// if (index !== -1) { // Check if the item was found
|
||||
// console.log('delete ==')
|
||||
// this.messages1[this.roomId].splice(index, 1);
|
||||
@@ -474,6 +489,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
this.messageSendSubject = this.chatServiceService.listenToSendMessage(this.roomId).subscribe((updateMessage) => {
|
||||
|
||||
console.log({updateMessage})
|
||||
|
||||
const index = this.messages1[this.roomId].findIndex(e => e?.requestId === updateMessage.requestId); // Use triple equals for comparison
|
||||
|
||||
@@ -717,7 +733,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
//Converting base64 to blob
|
||||
const encodedData = this.audioRecordedDataUrl;
|
||||
|
||||
const message = new MessageEntity();
|
||||
const message = new MessageViewModal();
|
||||
message.roomId = this.roomId
|
||||
|
||||
message.sentAt = new Date().toISOString()
|
||||
@@ -782,7 +798,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
async sendMessage() {
|
||||
|
||||
const message = new MessageEntity();
|
||||
const message = new MessageViewModal();
|
||||
message.message = this.textField
|
||||
message.roomId = this.roomId
|
||||
|
||||
@@ -960,7 +976,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
if(compressedImage.isOk()) {
|
||||
|
||||
const message = new MessageEntity();
|
||||
const message = new MessageViewModal();
|
||||
message.roomId = this.roomId
|
||||
message.oneShot = oneShot
|
||||
|
||||
@@ -981,7 +997,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
mimeType: 'image/'+picture.value.format
|
||||
}]
|
||||
|
||||
this.messages1[this.roomId].push(message)
|
||||
this.messages1[this.roomId].push(new MessageViewModal(message))
|
||||
setTimeout(() => {
|
||||
this.scrollToBottomClicked()
|
||||
}, 100)
|
||||
@@ -1017,7 +1033,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
// "title": res.data.selected.Assunto,
|
||||
// "description": res.data.selected.DocTypeDesc,
|
||||
|
||||
const message = new MessageEntity();
|
||||
const message = new MessageViewModal();
|
||||
message.message = this.textField
|
||||
message.roomId = this.roomId
|
||||
|
||||
@@ -1037,7 +1053,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
docId: res.data.selected.Id,
|
||||
}]
|
||||
|
||||
this.messages1[this.roomId].push(message)
|
||||
this.messages1[this.roomId].push(new MessageViewModal(message))
|
||||
setTimeout(() => {
|
||||
this.scrollToBottomClicked()
|
||||
}, 100)
|
||||
@@ -1105,7 +1121,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
if(compressedImage.isOk()) {
|
||||
|
||||
const message = new MessageEntity();
|
||||
const message = new MessageViewModal();
|
||||
message.roomId = this.roomId
|
||||
|
||||
message.sentAt = new Date().toISOString()
|
||||
@@ -1163,7 +1179,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
if(fileBase64.isOk()) {
|
||||
|
||||
const message = new MessageEntity();
|
||||
const message = new MessageViewModal();
|
||||
message.roomId = this.roomId
|
||||
|
||||
message.sentAt = new Date().toISOString()
|
||||
|
||||
Reference in New Issue
Block a user