fix donwload attachment and modal to edit message

This commit is contained in:
Peter Maquiran
2024-08-29 12:13:15 +01:00
parent 97ad62e2b6
commit d8d294b662
38 changed files with 627 additions and 198 deletions
@@ -45,12 +45,16 @@
<div
*ngFor="let message of messages1[roomId]; let messageIndex = index" class="messages-list-item-wrapper"
[ngClass]="{'my-message': message.sender.wxUserId === SessionStore.user.UserId, 'other-message': message.sender.wxUserId !== SessionStore.user.UserId}"
[ngClass]="{
'info-meeting': message.messageType == IMessageType.information,
'my-message': message.messageType != IMessageType.information && message?.sender?.wxUserId === SessionStore.user.UserId,
'other-message': message.messageType != IMessageType.information && message?.sender?.wxUserId !== SessionStore.user.UserId
}"
>
<div class="message-container rotate-div" *ngIf="message.isDeleted != true">
<div class="message-container rotate-div" *ngIf="message.isDeleted != true && message.messageType != IMessageType.information">
<div class="d-flex justify-content-between">
<div>
<div>
<div >
{{ message.message }}
</div>
@@ -146,8 +150,11 @@
<div class="message-container rotate-div" *ngIf="message.isDeleted == true">
Mensagem foi eliminada
</div>
<div *ngIf="message.messageType == IMessageType.information" class="text-center">
{{ message.message }}
</div>
<!-- current emoji -->
<div class="rotate-div" *ngIf="message.isDeleted != true">
<div class="rotate-div emoji-container" *ngIf="message.isDeleted != true && message.messageType != IMessageType.information">
<span *ngFor="let reaction of message.reactions" class="emoji-icon">
{{ reaction.reaction }}
</span>
@@ -504,3 +504,10 @@ ion-footer {
// -ms-transform: rotate(180deg);
// -o-transform: rotate(180deg);
// }
.emoji-container{
padding: 0px 20px;
/* margin-bottom: -10px; */
position: relative;
top: -10px;
margin-bottom: -15px;
}
@@ -1,4 +1,4 @@
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, TemplateRef, ViewChild } from '@angular/core';
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren } from '@angular/core';
import { AnimationController, GestureController, IonRange, ModalController, PopoverController } from '@ionic/angular';
import { ToastService } from 'src/app/services/toast.service';
import { ContactsPage } from '../contacts/contacts.page';
@@ -26,7 +26,7 @@ import { RoomLocalRepository } from 'src/app/module/chat/data/repository/room/ro
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service'
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service';
import { EditMessagePage } from 'src/app/modals/edit-message/edit-message.page';
import { MessageAttachmentFileType, MessageAttachmentSource, MessageEntity } from 'src/app/core/chat/entity/message';
import { IMessageType, MessageAttachmentFileType, MessageAttachmentSource, MessageEntity } from 'src/app/core/chat/entity/message';
import { JSFileToDataUrl } from 'src/app/utils/ToBase64';
import { CameraService } from 'src/app/infra/camera/camera.service'
import { FilePickerWebService } from 'src/app/infra/file-picker/web/file-picker-web.service'
@@ -48,6 +48,9 @@ import { MemberTable } from 'src/app/infra/database/dexie/instance/chat/schema/m
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
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 { MatMenuTrigger } from '@angular/material/menu';
@Component({
selector: 'app-messages',
@@ -144,11 +147,15 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
messages1: {[key: string]: MessageEntity[]} = {}
MessageAttachmentFileType = MessageAttachmentFileType
MessageAttachmentFileSource = MessageAttachmentSource
IMessageType = IMessageType
@ViewChild('imageModal') imageModal: TemplateRef<any>;
totalMembers = 0
members: MemberTable[] = []
private worker: SharedWorker;
private port: MessagePort;
constructor(
public popoverController: PopoverController,
private modalController: ModalController,
@@ -173,14 +180,55 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
private userTypingLocalRepository: UserTypingLocalRepository,
private UserTypingRemoteRepositoryService: UserTypingRemoteRepositoryService,
private messageLocalDataSourceService: MessageLocalDataSourceService,
private alertController: AlertController
private alertController: AlertController,
private http: HttpClient
) {
// update
this.checkAudioPermission()
//this.sendChunks()
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.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 }
];
const identifier = uuidv4(); // You can set a unique identifier for the file
const totalChunks = chunks.length;
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);
});
});
}
ngOnChanges(changes: SimpleChanges): void {
this.roomData$ = this.RoomLocalRepository.getRoomByIdLive(this.roomId)
this.roomData$.subscribe(e => {
@@ -1387,7 +1435,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
closeModal(a: any) {
}
}
@@ -173,7 +173,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.listenToIncomingMessage();
this.listenToDeleteMessage();
this.listenToUpdateMessage();
this.listenToSendMessage()
this.listenToSendMessage();
// this.roomMessage$ = this.messageRepositoryService.getItemsLive(this.roomId)
@@ -211,14 +211,19 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
async loadAttachment() {
for(const message of this.messages1[this.roomId]) {
if(message.hasAttachment) {
console.log('get attachment')
const result = await this.chatServiceService.getMessageAttachmentByMessageId(message)
console.log('result')
if(result.isOk()) {
console.log(result.value, message)
message.attachments[0].safeFile = result.value
} else {
console.log('error', result.error)
}
}
@@ -562,6 +567,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
const message = new MessageEntity();
message.roomId = this.roomId
message.sentAt = new Date().toISOString()
message.sender = {
userPhoto: '',
+24 -31
View File
@@ -1,52 +1,45 @@
import { SafeResourceUrl } from "@angular/platform-browser";
import { MessageAttachmentFileType, MessageAttachmentSource, MessageEntity } from "src/app/core/chat/entity/message";
import { IMessageType, MessageEntity, MessageEntitySchema } from "src/app/core/chat/entity/message";
import { SessionStore } from "src/app/store/session.service";
export class MessageViewModal {
$id!: number
id!: string
$id?: number
id?: string
roomId?: string
receiverId?: number
message!: string
message?: string
messageType: number = 0
canEdit: boolean = false
oneShot: boolean = false
sentAt!: string
sentAt?: string
requireUnlock: boolean = false
info: {
memberId?: number
readAt?: string,
deliverAt?: string
}[] = []
sender!: {
wxUserId: number,
wxFullName: string,
wxeMail: string,
userPhoto: string,
}
info: typeof MessageEntitySchema._type.info = []
sender!: typeof MessageEntitySchema._type.sender
sending: boolean = false
sendAttemp = 0
attachments: {
safeFile?: SafeResourceUrl;
fileType: MessageAttachmentFileType,
source: MessageAttachmentSource,
file?: string,
fileName: string,
applicationId?: number,
docId?: string,
mimeType?: string,
description?: string
id?: string
}[] = []
reactions = []
attachments: typeof MessageEntitySchema._type.attachments = []
reactions: typeof MessageEntitySchema._type.reactions = []
requestId!: string
status = ''
isDeleted: typeof MessageEntitySchema._type.isDeleted = false
status!: 'allViewed' | 'allReceived'| 'enviado'| 'enviar'
messageUiType!: 'info-meeting'| 'my-message'| 'other-message'
constructor(model: MessageEntity) {
Object.assign(this, model)
this.setMessageUIType()
}
setMessageUIType() {
if(this.messageType == IMessageType.information) {
this.messageUiType = 'info-meeting'
} else if (this.sender?.wxUserId === SessionStore.user.UserId) {
this.messageUiType = 'my-message'
} else {
this.messageUiType = 'other-message'
}
}
messageStatus(totalMembers: number) {
if(this.allViewed(totalMembers)) {