Files
doneit-web/src/app/ui/chat/modal/messages/messages.page.ts
T

1447 lines
41 KiB
TypeScript
Raw Normal View History

2023-07-06 12:18:15 +01:00
import { AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { GestureController, ModalController, NavParams, PopoverController, Platform } from '@ionic/angular';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
2021-10-09 16:41:18 +01:00
import { ExpedientTaskModalPageNavParamsTask } from 'src/app/models/ExpedientTaskModalPage';
2024-08-16 14:21:01 +01:00
import { ContactsPage } from 'src/app/ui/chat/modal/messages/contacts/contacts.page';
2021-04-13 14:14:55 +01:00
import { AlertService } from 'src/app/services/alert.service';
2021-09-21 14:05:59 +01:00
import { FileService } from 'src/app/services/functions/file.service';
2021-07-12 11:13:29 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-10-23 09:53:21 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2022-02-25 15:10:10 +01:00
import { VoiceRecorder, GenericResponse } from 'capacitor-voice-recorder';
2021-11-05 18:19:27 +01:00
import { Haptics, ImpactStyle } from '@capacitor/haptics';
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
2022-02-03 21:01:53 +01:00
import { SearchPage } from 'src/app/pages/search/search.page';
import { Storage } from '@ionic/storage';
2024-08-17 22:05:57 +01:00
import { CameraResultType } from '@capacitor/camera';
2022-03-14 08:09:33 +01:00
import { DomSanitizer } from '@angular/platform-browser';
2022-04-18 15:12:27 +01:00
import { SessionStore } from 'src/app/store/session.service';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
2024-08-17 22:05:57 +01:00
2024-08-08 11:44:41 +01:00
//======
import { Observable as DexieObservable } from 'Dexie';
2024-09-01 12:57:33 +01:00
import { Observable, Subscription } from 'rxjs';
2024-08-27 10:15:00 +01:00
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
2024-08-08 11:44:41 +01:00
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service';
2024-08-29 15:23:11 +01:00
import { EditMessagePage } from 'src/app/ui/chat/modal/edit-message/edit-message.page';
2024-09-06 14:38:30 +01:00
import { IMessageType, MessageAttachmentFileType, MessageAttachmentSource } from 'src/app/core/chat/entity/message';
2024-08-27 10:15:00 +01:00
import { MemberTable } from 'src/app/infra/database/dexie/instance/chat/schema/members';
import { TypingTable } from 'src/app/infra/database/dexie/instance/chat/schema/typing';
2024-08-13 10:52:35 +01:00
import { compressImageBase64 } from 'src/app/utils/imageCompressore';
import { FilePickerService } from 'src/app/infra/file-picker/file-picker.service'
import { RecordingData } from 'capacitor-voice-recorder';
2024-08-16 12:24:26 +01:00
import { Logger } from 'src/app/services/logger/main/service';
2024-08-16 17:45:45 +01:00
import { MessagesOptionsPage } from '../messages-options/messages-options.page';
import { ChatOptionsPopoverPage } from '../chat-options-popover/chat-options-popover.page';
2024-08-17 22:05:57 +01:00
import { CameraService } from 'src/app/infra/camera/camera.service'
import { FilePickerMobileService } from 'src/app/infra/file-picker/mobile/file-picker-mobile.service'
import { FilePickerWebService } from 'src/app/infra/file-picker/web/file-picker-web.service'
import { allowedDocExtension } from 'src/app/utils/allowedDocExtension';
import { JSFileToDataUrl } from 'src/app/utils/ToBase64';
2024-08-21 20:14:48 +01:00
import { RoomLocalRepository } from 'src/app/module/chat/data/repository/room/room-local-repository.service'
2024-08-27 09:14:59 +01:00
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service'
2024-08-23 11:10:52 +01:00
import { UserTypingLocalRepository } from 'src/app/module/chat/data/repository/typing/user-typing-local-data-source.service';
import { UserTypingRemoteRepositoryService } from 'src/app/module/chat/data/repository/typing/user-typing-live-data-source.service';
2024-08-19 16:01:58 +01:00
import { MessageLocalDataSourceService } from 'src/app/module/chat/data/repository/message/message-local-data-source.service';
2024-08-26 14:47:03 +01:00
import { RoomType } from "src/app/core/chat/entity/group";
2024-08-27 10:15:00 +01:00
import { RoomTable } from 'src/app/infra/database/dexie/instance/chat/schema/room';
2024-09-06 14:38:30 +01:00
import { whatsappDate } from 'src/app/ui/shared/utils/whatappdate';
import { MessageViewModal } from '../../store/model/message';
import { XBallon } from '../../utils/messageBallon';
import { tap } from 'rxjs/operators';
import { ChatPopoverPage } from '../chat-popover/chat-popover.page';
2024-08-19 16:45:29 +01:00
2024-08-18 15:40:43 +01:00
2021-11-21 19:49:59 +01:00
const IMAGE_DIR = 'stored-images';
2020-12-30 11:13:50 +01:00
@Component({
selector: 'app-messages',
templateUrl: './messages.page.html',
styleUrls: ['./messages.page.scss'],
})
2021-08-23 16:31:06 +01:00
export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
2021-01-27 16:01:49 +01:00
showLoader: boolean;
2021-01-13 10:02:30 +01:00
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
@ViewChild('rectangle') private rectangle: ElementRef;
2021-01-13 10:02:30 +01:00
2021-11-23 10:57:07 +01:00
canvas: any
ctx: any
2021-01-13 10:02:30 +01:00
loggedUser: any;
userPresence = '';
dmUsers: any;
roomId: string;
el: any;
members: any;
scrollingOnce: boolean = true;
2021-07-23 14:43:51 +01:00
2021-08-23 16:31:06 +01:00
private scrollChangeCallback: () => void;
currentPosition: any;
startPosition: number;
2021-09-24 15:39:25 +01:00
scrollToBottomBtn = false;
2021-09-30 10:41:40 +01:00
showMessageOptions = false;
selectedMsgId: string;
2021-01-13 10:02:30 +01:00
2021-10-09 16:41:18 +01:00
dicIndex = 0;
task: ExpedientTaskModalPageNavParamsTask;
LoadedDocument: any = null;
2021-10-09 16:41:18 +01:00
2021-11-05 18:19:27 +01:00
recording = false;
2022-03-04 18:46:56 +01:00
allowTyping = true;
2021-11-05 18:19:27 +01:00
storedFileNames = [];
2022-03-04 11:52:43 +01:00
lastAudioRecorded = '';
2022-04-04 00:37:00 +01:00
audioRecorded: any = "";
audioDownloaded: any = "";
2021-11-05 18:19:27 +01:00
durationDisplay = '';
duration = 0;
@ViewChild('recordbtn', { read: ElementRef }) recordBtn: ElementRef;
myAudio: any;
2021-12-16 16:36:39 +01:00
downloadfile: any;
2021-12-17 17:20:43 +01:00
downloadFile: any;
2022-03-27 18:54:08 +01:00
files: any[] = [];
@ViewChild('filechooser') fileChooserElementRef: ElementRef;
2024-08-15 10:26:20 +01:00
@ViewChild('array') myInputRef!: ElementRef;
2022-03-27 18:54:08 +01:00
//items: File[] = [];
fileSelected?: Blob;
2022-04-04 00:37:00 +01:00
pdfUrl?: string;
2022-03-27 18:54:08 +01:00
base64File: string;
2022-03-09 09:23:27 +01:00
downloadProgess: number;
downloadLoader: boolean;
2021-11-05 18:19:27 +01:00
2022-07-06 17:02:42 +01:00
audioPermissionStatus: 'granted' | 'denied' | 'prompt' | null = null
2022-04-18 15:12:27 +01:00
sessionStore = SessionStore
2024-09-06 14:38:30 +01:00
SessionStore = SessionStore
2022-04-02 09:40:09 +01:00
2024-09-01 12:57:33 +01:00
roomData$: Observable<RoomTable | undefined>
2024-08-08 11:44:41 +01:00
roomStatus$: DexieObservable<Boolean >
roomMessage$: DexieObservable<MessageTable[]>
2024-09-06 14:38:30 +01:00
roomMembers$: Observable<MemberTable[]>
2024-08-08 11:44:41 +01:00
//userTyping$: DexieObservable<TypingTable[] | undefined>
userTyping$: TypingTable[] | undefined
newMessagesStream!: Subscription
selectedMessage: any = null;
emojis: string[] = ['😊', '😂', '❤️', '👍', '😢']; // Add more emojis as needed
textField = ''
2024-08-19 16:45:29 +01:00
roomType!: RoomType
2024-08-14 15:29:16 +01:00
messageReceiveSubject: Subscription
messageDeleteSubject: Subscription
messageUpdateSubject: Subscription
messageSendSubject: Subscription
2024-09-06 14:38:30 +01:00
messages1: {[key: string]: MessageViewModal[]} = {}
2024-08-14 15:29:16 +01:00
MessageAttachmentFileType = MessageAttachmentFileType
MessageAttachmentFileSource = MessageAttachmentSource
2024-09-06 14:38:30 +01:00
messageOnReconnectSubject: Subscription
date: {[key: string]: Object} = {}
totalMembers = 0
isAdmin = true
RoomTypeEnum = RoomType
IMessageType = IMessageType
2020-12-30 11:13:50 +01:00
constructor(
public popoverController: PopoverController,
private modalController: ModalController,
2021-03-12 11:56:54 +01:00
private navParams: NavParams,
2021-04-13 14:14:55 +01:00
private alertService: AlertService,
2021-07-12 11:13:29 +01:00
private toastService: ToastService,
2021-09-21 14:05:59 +01:00
private fileService: FileService,
private gestureController: GestureController,
2021-11-17 15:34:15 +01:00
public ThemeService: ThemeService,
2021-12-08 19:36:41 +01:00
private platform: Platform,
2022-02-03 21:01:53 +01:00
private storage: Storage,
2022-03-14 08:09:33 +01:00
private sanitiser: DomSanitizer,
2024-08-13 10:52:35 +01:00
private chatServiceService: ChatServiceService,
private FilePickerService: FilePickerService,
2024-08-17 22:05:57 +01:00
private CameraService: CameraService,
private FilePickerMobileService: FilePickerMobileService,
2024-08-18 13:27:57 +01:00
private FilePickerWebService: FilePickerWebService,
private RoomLocalRepository: RoomLocalRepository,
private MemberListLocalRepository: MemberListLocalRepository,
2024-08-18 15:40:43 +01:00
private userTypingLocalRepository: UserTypingLocalRepository,
private UserTypingRemoteRepositoryService: UserTypingRemoteRepositoryService,
private messageLocalDataSourceService: MessageLocalDataSourceService,
2021-07-23 14:43:51 +01:00
) {
2022-07-06 17:02:42 +01:00
2023-10-19 15:03:12 +01:00
2024-08-08 11:44:41 +01:00
this.roomId = this.navParams.get('roomId');
2021-09-03 17:02:42 +01:00
2023-10-19 15:03:12 +01:00
2024-08-18 13:27:57 +01:00
this.roomData$ = this.RoomLocalRepository.getRoomByIdLive(this.roomId)
2024-08-20 16:34:47 +01:00
2024-08-19 16:45:29 +01:00
this.roomData$.subscribe(e => {
2024-08-20 16:34:47 +01:00
// console.log(e)
2024-08-19 16:45:29 +01:00
if(e) {
this.roomType = e.roomType
}
2024-08-20 16:34:47 +01:00
2024-08-19 16:45:29 +01:00
})
2024-08-08 11:44:41 +01:00
2024-08-15 10:26:20 +01:00
this.getMessages();
2024-08-14 15:29:16 +01:00
this.listenToIncomingMessage();
this.listenToDeleteMessage();
this.listenToUpdateMessage();
this.listenToSendMessage();
2022-01-11 15:43:09 +01:00
2024-08-14 15:29:16 +01:00
2024-08-17 22:05:57 +01:00
// this.roomMessage$ = this.messageRepositoryService.getItemsLive(this.roomId)
2024-09-06 14:38:30 +01:00
this.roomMembers$ = this.MemberListLocalRepository.getRoomMemberByIdLive(this.roomId).pipe(
tap((members) => {
this.totalMembers = members.length
this.members = members
for(const member of members) {
if(member.wxUserId == SessionStore.user.UserId) {
this.isAdmin = member.isAdmin
}
}
})
)
2024-08-18 13:27:57 +01:00
this.roomStatus$ = this.MemberListLocalRepository.allMemberOnline(this.roomId)
2024-08-17 22:05:57 +01:00
// this.roomRepositoryService.getRoomById(this.roomId)
2024-08-08 11:44:41 +01:00
2024-08-18 15:40:43 +01:00
this.userTypingLocalRepository.getUserTypingLive().subscribe((e) => {
2024-08-15 10:26:20 +01:00
const arrayNames = e.map(e => e.userName)
this.userTyping$ = e as any
const uniqueArray = [...new Set(arrayNames)];
(this.myInputRef.nativeElement as HTMLDivElement).innerHTML = '::'+ uniqueArray
})
2024-09-06 14:38:30 +01:00
this.chatServiceService.removeBoldFromRoom({roomId: this.roomId})
this.chatServiceService.getRoomById(this.roomId)
2024-08-15 10:26:20 +01:00
}
2024-08-08 11:44:41 +01:00
2024-08-15 10:26:20 +01:00
async getMessages() {
2024-09-06 14:38:30 +01:00
2024-08-15 10:26:20 +01:00
// dont remove this line
this.messages1[this.roomId] = []
2024-08-18 15:40:43 +01:00
let messages = await this.messageLocalDataSourceService.getItems(this.roomId)
2024-08-15 10:26:20 +01:00
this.messages1[this.roomId] = []
2024-09-06 14:38:30 +01:00
this.date = {}
const allMessage = [];
// let ids = {}
// messages = messages.filter((message: any) => {
// if (message.$createAt) {
// if (!ids[message.$createAt]) {
// ids[message.$createAt] = true;
// return true; // Keep this message
// } else {
// console.log('delete');
// return false; // Remove this message
// }
// }
// return true; // Keep messages without an id
// });
console.time("mappingTime");
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.timeEnd("mappingTime");
2024-08-15 10:26:20 +01:00
2024-09-06 14:38:30 +01:00
this.messages1[this.roomId] = allMessage
this.loadAttachment()
2024-08-15 10:26:20 +01:00
setTimeout(() => {
2024-09-06 14:38:30 +01:00
this.sendReadMessage()
}, 1000)
2024-08-08 11:44:41 +01:00
2024-09-06 14:38:30 +01:00
this.messageOnReconnectSubject?.unsubscribe()
this.messageOnReconnectSubject = this.chatServiceService.listenToMessageLoadHistory({roomId: this.roomId}).subscribe((messages) => {
2022-01-11 15:43:09 +01:00
2024-09-06 14:38:30 +01:00
for(const message of messages.data) {
const found = this.messages1[this.roomId].find((e) => e.id == message.id)
if(!found) {
const msg = new MessageViewModal(message as any)
Object.assign(msg, message)
this.messages1[this.roomId].push(msg)
}
}
})
2024-08-15 10:26:20 +01:00
2024-09-06 14:38:30 +01:00
}
2024-08-17 22:05:57 +01:00
2024-09-06 14:38:30 +01:00
sendReadMessage() {
2024-08-15 10:26:20 +01:00
2024-09-06 14:38:30 +01:00
for(const message of this.messages1[this.roomId]) {
2024-08-15 10:26:20 +01:00
2024-09-06 14:38:30 +01:00
if(!message.meSender()) {
const me = message.haveSeen(message.info)
2024-08-15 10:26:20 +01:00
2024-09-06 14:38:30 +01:00
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
})
2024-08-15 10:26:20 +01:00
}
}
2024-09-06 14:38:30 +01:00
}
}
async loadAttachment() {
for(const message of this.messages1[this.roomId]) {
if(message.hasAttachment && message.attachments[0].source != MessageAttachmentSource.Webtrix) {
this.chatServiceService.getMessageAttachmentByMessageId(message).then((result)=> {
if(result.isOk()) {
message.attachments[0].safeFile = result.value
if(result.value.startsWith('blob:http')) {
message.attachments[0].blobURl = true
}
}
})
2024-03-26 12:03:30 +01:00
2024-09-06 14:38:30 +01:00
}
2024-08-15 10:26:20 +01:00
}
2024-09-06 14:38:30 +01:00
}
2024-08-15 10:26:20 +01:00
2024-09-06 14:38:30 +01:00
messageStatus(message: MessageViewModal) {
if(this.allViewed(message)) {
return 'allViewed'
} else if(this.allReceived(message)) {
return 'allReceived'
} else if (message.messageStatus == 'send') {
return 'enviado'
} else {
return 'enviar'
}
}
allReceived(message: MessageViewModal) {
return message.info.filter(e => typeof e.deliverAt == 'string').length == this.totalMembers
2024-08-15 10:26:20 +01:00
}
2020-12-30 11:13:50 +01:00
2024-09-06 14:38:30 +01:00
allViewed(message: MessageViewModal) {
const totalMembers = this.members.filter((e) => message.sender.wxUserId != e.wxUserId ).length
return message.info.filter(e => typeof e.readAt == 'string' && message.sender.wxUserId != e.memberId ).length == totalMembers
}
2024-08-16 17:17:32 +01:00
ngOnInit() {}
2023-09-29 16:40:50 +01:00
2021-07-23 14:43:51 +01:00
2021-11-05 18:19:27 +01:00
ngAfterViewInit() {
this.scrollChangeCallback = () => this.onContentScrolled(event);
window.addEventListener('scroll', this.scrollChangeCallback, true);
2021-11-05 18:19:27 +01:00
const longpress = this.gestureController.create({
el: this.recordBtn.nativeElement,
threshold: 0,
gestureName: 'long-press',
onStart: ev => {
Haptics.impact({ style: ImpactStyle.Light })
this.startRecording();
2022-03-04 18:46:56 +01:00
//this.calculateDuration();
2021-11-05 18:19:27 +01:00
},
onEnd: ev => {
2021-11-05 18:19:27 +01:00
Haptics.impact({ style: ImpactStyle.Light })
this.stopRecording();
}
}, true);
longpress.enable();
}
2023-10-19 15:03:12 +01:00
onDragOver(e?) { }
onDragLeave(e?) { }
2023-04-28 12:56:45 +01:00
calculateDuration() {
if (!this.recording) {
2021-11-05 18:19:27 +01:00
this.duration = 0;
this.durationDisplay = '';
return;
}
this.duration += 1;
const minutes = Math.floor(this.duration / 60);
const seconds = (this.duration % 60).toString().padStart(2, '0');
2021-11-05 18:19:27 +01:00
this.durationDisplay = `${minutes}:${seconds}`;
setTimeout(() => {
2021-11-05 18:19:27 +01:00
this.calculateDuration();
}, 1000)
}
2024-08-14 15:29:16 +01:00
listenToIncomingMessage() {
this.messageReceiveSubject?.unsubscribe();
2024-09-06 14:38:30 +01:00
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)
}
const message = new MessageViewModal(_message)
this.messages1[this.roomId].push(new MessageViewModal(message))
2024-08-14 15:29:16 +01:00
if(message.hasAttachment) {
2024-09-06 14:38:30 +01:00
const result = await this.chatServiceService.downloadMessageAttachmentByMessageId({
$messageId: message.id,
id: message.attachments[0].id
})
2024-08-14 15:29:16 +01:00
if(result.isOk()) {
message.attachments[0].safeFile = result.value
2024-09-06 14:38:30 +01:00
if((result.value as unknown as string).startsWith('blob:http')) {
message.attachments[0].blobURl = true
} else {
message.attachments[0].blobURl = false
}
2024-08-14 15:29:16 +01:00
}
}
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)
2024-09-06 14:38:30 +01:00
setTimeout(() => {
this.chatServiceService.removeBoldFromRoom({roomId: this.roomId})
}, 1000)
2024-08-14 15:29:16 +01:00
});
2024-09-06 14:38:30 +01:00
2024-08-14 15:29:16 +01:00
}
listenToDeleteMessage() {
this.messageDeleteSubject?.unsubscribe();
this.messageDeleteSubject = this.chatServiceService.listenToDeleteMessage(this.roomId).subscribe((deleteMessage) => {
2024-09-06 14:38:30 +01:00
console.log('delete class', deleteMessage);
2024-08-14 15:29:16 +01:00
2024-09-06 14:38:30 +01:00
const index = this.messages1[this.roomId].findIndex(e => e?.id === deleteMessage.id); // Use triple equals for comparison
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);
// // console.log('removed index', index);
// } else {
// // console.log('message not found');
// }
2024-08-14 15:29:16 +01:00
});
}
listenToUpdateMessage() {
this.messageUpdateSubject?.unsubscribe();
this.messageUpdateSubject = this.chatServiceService.listenToUpdateMessage(this.roomId).subscribe((updateMessage) => {
const index = this.messages1[this.roomId].findIndex(e => e?.id === updateMessage.id); // Use triple equals for comparison
if (index !== -1) { // Check if the item was found
this.messages1[this.roomId][index].message = updateMessage.message
this.messages1[this.roomId][index].reactions = updateMessage.reactions
2024-09-06 14:38:30 +01:00
this.messages1[this.roomId][index].reactions = updateMessage.reactions
2024-08-14 15:29:16 +01:00
} else {
// console.log('message not found');
}
});
}
listenToSendMessage() {
this.messageSendSubject?.unsubscribe();
this.messageSendSubject = this.chatServiceService.listenToSendMessage(this.roomId).subscribe((updateMessage) => {
const index = this.messages1[this.roomId].findIndex(e => e?.requestId === updateMessage.requestId); // Use triple equals for comparison
if (index !== -1) { // Check if the item was found
this.messages1[this.roomId][index].id = updateMessage.id
2024-08-20 16:34:47 +01:00
this.messages1[this.roomId][index].info = updateMessage.info
2024-08-14 15:29:16 +01:00
let attachmentIndex = 0;
2024-08-20 16:34:47 +01:00
for(const attachment of updateMessage.attachments) {
2024-08-16 18:09:40 +01:00
2024-08-20 16:34:47 +01:00
this.messages1[this.roomId][index].attachments[attachmentIndex].id = attachment.id
2024-08-14 15:29:16 +01:00
attachmentIndex++;
}
} else {
// console.log('message not found');
}
});
}
async loadFiles() {
2022-03-18 11:45:38 +01:00
this.storage.get('fileName').then((fileName) => {
this.lastAudioRecorded = fileName;
2021-11-05 18:19:27 +01:00
})
2022-03-18 11:45:38 +01:00
2022-03-22 14:23:38 +01:00
try {
this.storage.get('recordData').then((recordData) => {
2022-07-06 17:02:42 +01:00
2022-04-04 00:37:00 +01:00
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
2022-03-24 17:40:14 +01:00
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
2022-03-22 14:23:38 +01:00
}
2022-07-06 17:02:42 +01:00
else if (recordData?.value?.mimeType && recordData?.value?.recordDataBase64) {
2022-03-24 17:40:14 +01:00
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
2022-03-22 14:23:38 +01:00
}
});
2022-04-04 00:37:00 +01:00
} catch (error) { }
2022-03-22 14:23:38 +01:00
}
2022-04-07 15:22:25 +01:00
async startRecording() {
VoiceRecorder.requestAudioRecordingPermission();
2022-07-06 17:02:42 +01:00
if (await VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) => { return result.value })) {
if (await VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => { return result.value })) {
2022-04-07 15:22:25 +01:00
//if(await this.hasAudioRecordingPermission()){
2022-07-06 17:02:42 +01:00
if (this.recording) {
return;
}
this.recording = true;
VoiceRecorder.startRecording();
this.calculateDuration();
2022-04-07 15:22:25 +01:00
//}
}
2022-07-06 17:02:42 +01:00
else {
2022-04-07 15:22:25 +01:00
this.toastService._badRequest('Para gravar uma mensagem de voz, permita o acesso do Gabinete Digital ao seu microfone.');
}
}
2022-07-06 17:02:42 +01:00
else {
2022-04-07 15:22:25 +01:00
this.toastService._badRequest('Este dispositivo não tem capacidade para gravação de áudio!');
2021-11-05 18:19:27 +01:00
}
}
stopRecording() {
2022-03-18 11:45:38 +01:00
this.deleteRecording();
2022-03-04 18:46:56 +01:00
this.allowTyping = false;
2022-07-06 17:02:42 +01:00
if (!this.recording) {
2021-11-05 18:19:27 +01:00
return;
}
this.recording = false;
VoiceRecorder.stopRecording().then(async (result: RecordingData) => {
2022-07-06 17:02:42 +01:00
2021-11-05 18:19:27 +01:00
this.recording = false;
if (result.value && result.value.recordDataBase64) {
2021-11-05 18:19:27 +01:00
const recordData = result.value.recordDataBase64;
2022-04-18 15:27:16 +01:00
//
2022-03-18 16:42:59 +01:00
const fileName = new Date().getTime() + ".mp3";
2022-03-18 11:45:38 +01:00
//Save file
2022-04-04 00:37:00 +01:00
this.storage.set('fileName', fileName);
this.storage.set('recordData', result).then(() => {
2022-07-06 17:02:42 +01:00
2021-11-05 18:19:27 +01:00
})
}
})
2022-03-10 16:26:43 +01:00
setTimeout(async () => {
2022-03-04 18:46:56 +01:00
this.loadFiles();
2022-03-18 11:45:38 +01:00
}, 1000);
2021-11-05 18:19:27 +01:00
}
2022-04-04 00:37:00 +01:00
async deleteRecording() {
2022-03-18 11:45:38 +01:00
this.storage.remove('fileName');
this.storage.remove('recordData');
2021-10-08 15:37:24 +01:00
2022-03-04 18:46:56 +01:00
this.allowTyping = true;
2022-03-04 11:52:43 +01:00
this.lastAudioRecorded = '';
this.loadFiles();
}
2022-03-14 08:09:33 +01:00
handlePress(id?: string) {
2021-09-30 10:41:40 +01:00
this.selectedMsgId = id;
this.showMessageOptions = true;
}
handleClick() {
this.showMessageOptions = false;
2021-09-30 10:41:40 +01:00
this.selectedMsgId = "";
}
2024-08-16 17:17:32 +01:00
deleteMessage(msgId: string) {}
2021-08-23 16:31:06 +01:00
2021-04-13 14:14:55 +01:00
notImplemented() {
2021-04-13 14:14:55 +01:00
this.alertService.presentAlert('Funcionalidade em desenvolvimento');
}
close() {
2021-03-12 11:56:54 +01:00
this.modalController.dismiss();
2022-03-18 11:45:38 +01:00
this.deleteRecording();
2021-03-12 11:56:54 +01:00
}
2021-07-26 09:55:57 +01:00
load() {
2021-01-27 16:01:49 +01:00
this.getChatMembers();
2021-01-13 10:02:30 +01:00
}
2021-07-26 09:55:57 +01:00
doRefresh(ev: any) {
2021-01-27 16:01:49 +01:00
this.load();
ev.target.complete();
}
2021-07-23 14:43:51 +01:00
scrollToBottom(): void {
2021-01-13 10:02:30 +01:00
try {
if (this.scrollingOnce) {
2021-08-23 16:31:06 +01:00
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
//this.scrollingOnce = false;
}
} catch (err) { }
2021-01-13 10:02:30 +01:00
}
2022-01-14 14:50:47 +01:00
scrollToBottomClicked = () => {
2021-09-24 15:39:25 +01:00
try {
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
} catch (err) { }
2021-09-24 15:39:25 +01:00
}
2022-08-03 16:31:03 +01:00
async goToEvent(event: any) {
2023-09-29 16:40:50 +01:00
let classs;
if (window.innerWidth < 701) {
classs = 'modal modal-desktop'
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: ViewEventPage,
componentProps: {
2022-08-03 16:31:03 +01:00
eventId: event.id,
CalendarId: event.calendarId
},
cssClass: classs,
});
await modal.present();
modal.onDidDismiss().then((res) => {
2022-07-06 17:02:42 +01:00
});
}
2021-08-23 16:31:06 +01:00
2021-09-24 15:39:25 +01:00
onContentScrolled(e) {
2021-08-23 16:31:06 +01:00
this.startPosition = e.srcElement.scrollTop;
let scroll = e.srcElement.scrollTop;
2021-09-24 15:39:25 +01:00
let windowHeight = e.srcElement.scrollHeight;
let containerHeight = windowHeight - e.srcElement.clientHeight;
2021-09-24 15:39:25 +01:00
2021-08-23 16:31:06 +01:00
if (scroll > this.currentPosition) {
} else {
this.scrollingOnce = false;
}
if ((containerHeight - 100) > scroll) {
2021-09-24 15:39:25 +01:00
this.scrollToBottomBtn = true;
}
else {
2021-09-24 15:39:25 +01:00
this.scrollToBottomBtn = false;
}
2021-08-23 16:31:06 +01:00
this.currentPosition = scroll;
2021-09-24 15:39:25 +01:00
2021-08-23 16:31:06 +01:00
}
ngOnDestroy() {
window.removeEventListener('scroll', this.scrollChangeCallback, true);
}
2024-09-06 14:38:30 +01:00
async sendMessage() {
const message = new MessageViewModal();
2024-08-13 10:52:35 +01:00
message.message = this.textField
message.roomId = this.roomId
message.sender = {
userPhoto: '',
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
}
2024-09-06 14:38:30 +01:00
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)
}
2024-08-13 10:52:35 +01:00
this.messages1[this.roomId].push(message)
2024-09-06 14:38:30 +01:00
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)
const data = await this.chatServiceService.sendMessage(message, this.roomType)
2024-08-13 10:52:35 +01:00
2023-02-02 18:24:26 +01:00
}
2022-03-04 14:51:08 +01:00
async sendAudio(fileName) {
const roomId = this.roomId
2022-03-21 21:09:05 +01:00
let audioFile;
this.storage.get('recordData').then(async (recordData:RecordingData) => {
2022-03-29 00:03:54 +01:00
2022-03-21 21:09:05 +01:00
audioFile = recordData;
2022-04-04 00:37:00 +01:00
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
2022-03-24 17:40:14 +01:00
this.audioRecorded = recordData?.value?.recordDataBase64;
2022-03-18 11:45:38 +01:00
}
2022-07-06 17:02:42 +01:00
else if (recordData?.value?.mimeType && recordData?.value?.recordDataBase64) {
2022-03-24 17:40:14 +01:00
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`;
2022-03-18 11:45:38 +01:00
}
2022-03-04 14:51:08 +01:00
const audioMimeType: string = recordData.value.mimeType
2022-04-04 00:37:00 +01:00
const encodedData = btoa(this.audioRecorded);
2022-07-06 17:02:42 +01:00
2024-09-06 14:38:30 +01:00
const message = new MessageViewModal();
2024-08-13 10:52:35 +01:00
message.roomId = this.roomId
2024-09-06 14:38:30 +01:00
message.sentAt = new Date().toISOString()
2024-08-13 10:52:35 +01:00
message.sender = {
userPhoto: '',
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
}
message.attachments = [{
2024-08-21 20:14:48 +01:00
file: this.audioRecorded.split(',')[1],
2024-08-13 10:52:35 +01:00
fileName: "audio",
source: MessageAttachmentSource.Device,
fileType: MessageAttachmentFileType.Audio,
2024-09-06 14:38:30 +01:00
mimeType: audioMimeType, // 'audio/webm',
2024-08-16 17:17:32 +01:00
safeFile: this.sanitiser.bypassSecurityTrustResourceUrl(this.audioRecorded)
2024-08-13 10:52:35 +01:00
}]
2024-09-06 14:38:30 +01:00
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)
2024-08-19 16:45:29 +01:00
this.chatServiceService.sendMessage(message, this.roomType)
2024-09-06 14:38:30 +01:00
2024-08-16 17:17:32 +01:00
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)
2022-03-04 14:51:08 +01:00
2024-09-06 14:38:30 +01:00
this.deleteRecording();
2022-04-04 00:37:00 +01:00
});
2022-03-21 21:09:05 +01:00
this.deleteRecording();
2022-03-04 14:51:08 +01:00
}
viewDocument(file: any, url?: string) {
2022-07-06 17:02:42 +01:00
if (file.type == "application/webtrix") {
this.openViewDocumentModal(file);
2022-02-25 15:10:10 +01:00
}
else {
let fullUrl = "https://www.tabularium.pt" + url;
this.fileService.viewDocumentByUrl(fullUrl);
}
}
2022-03-14 08:09:33 +01:00
docIndex(index: number) {
2021-10-09 16:41:18 +01:00
this.dicIndex = index
}
async openViewDocumentModal(file: any) {
2021-10-09 20:24:34 +01:00
let task = {
serialNumber: '',
taskStartDate: '',
isEvent: true,
workflowInstanceDataFields: {
FolderID: '',
Subject: file.Assunto,
SourceSecFsID: file.ApplicationId,
2022-02-25 15:10:10 +01:00
SourceType: 'PDF',
2021-10-09 20:24:34 +01:00
SourceID: file.DocId,
DispatchNumber: ''
2021-10-09 16:41:18 +01:00
}
2021-10-09 20:24:34 +01:00
}
2021-10-09 16:41:18 +01:00
2021-10-09 20:24:34 +01:00
let doc = {
"Id": "",
"ParentId": "",
"Source": 1,
"ApplicationId": file.ApplicationId,
"CreateDate": "",
"Data": null,
"Description": "",
"Link": null,
"SourceId": file.DocId,
"SourceName": file.Assunto,
"Stakeholders": "",
2021-10-09 20:24:34 +01:00
}
2021-10-09 16:41:18 +01:00
2021-10-09 20:24:34 +01:00
const modal = await this.modalController.create({
component: ViewDocumentPage,
componentProps: {
trustedUrl: '',
file: {
title: file.Assunto,
url: '',
title_link: '',
2021-10-09 16:41:18 +01:00
},
2021-10-09 20:24:34 +01:00
Document: doc,
applicationId: file.ApplicationId,
docId: file.DocId,
folderId: '',
task: task
},
cssClass: 'modal modal-desktop'
});
2021-10-09 20:24:34 +01:00
await modal.present();
2021-09-21 14:05:59 +01:00
}
2024-08-16 17:17:32 +01:00
getChatMembers() {}
2020-12-30 11:13:50 +01:00
showDateDuration(start: any) {
2021-08-20 17:00:48 +01:00
let end;
end = new Date();
start = new Date(start);
let customizedDate;
const totalSeconds = Math.floor((end - (start)) / 1000);;
const totalMinutes = Math.floor(totalSeconds / 60);
const totalHours = Math.floor(totalMinutes / 60);
const totalDays = Math.floor(totalHours / 24);
2021-08-20 17:00:48 +01:00
const hours = totalHours - (totalDays * 24);
const minutes = totalMinutes - (totalDays * 24 * 60) - (hours * 60);
const seconds = totalSeconds - (totalDays * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60);
2021-08-20 17:00:48 +01:00
if (totalDays == 0) {
if (start.getDate() == new Date().getDate()) {
2021-08-20 17:00:48 +01:00
let time = start.getHours() + ":" + this.addZero(start.getUTCMinutes());
return time;
}
else {
2021-08-20 17:00:48 +01:00
return 'Ontem';
}
}
else {
let date = start.getDate() + "/" + (start.getMonth() + 1) + "/" + start.getFullYear();
2021-08-20 17:00:48 +01:00
return date;
}
}
addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
2021-06-03 17:07:29 +01:00
async openMessagesOptions(ev?: any) {
2020-12-30 11:13:50 +01:00
const popover = await this.popoverController.create({
2024-09-06 14:38:30 +01:00
component: ChatPopoverPage,
2021-01-13 10:02:30 +01:00
componentProps: {
2021-03-12 11:56:54 +01:00
roomId: this.roomId,
2024-09-06 14:38:30 +01:00
members: [],
isAdmin: this.isAdmin,
roomType: this.roomType
2021-01-13 10:02:30 +01:00
},
2020-12-30 11:13:50 +01:00
cssClass: 'messages-options',
event: ev,
2021-01-13 10:02:30 +01:00
translucent: true,
2020-12-30 11:13:50 +01:00
});
return await popover.present();
}
async addContacts() {
2020-12-30 11:13:50 +01:00
const modal = await this.modalController.create({
component: ContactsPage,
2021-07-23 14:43:51 +01:00
componentProps: {},
2020-12-30 11:13:50 +01:00
cssClass: 'contacts',
backdropDismiss: false
});
2023-07-15 11:01:09 +01:00
2020-12-30 11:13:50 +01:00
modal.onDidDismiss();
2023-07-15 11:01:09 +01:00
await modal.present();
2020-12-30 11:13:50 +01:00
}
2021-09-21 14:05:59 +01:00
2022-02-03 21:01:53 +01:00
2024-08-13 10:52:35 +01:00
async takePictureMobile() {
2022-09-28 21:05:28 +01:00
2024-08-17 22:05:57 +01:00
const picture = await this.CameraService.takePicture({
cameraResultType: CameraResultType.DataUrl,
quality: 90
})
2023-09-29 16:40:50 +01:00
2024-08-17 22:05:57 +01:00
if(picture.isOk()) {
const file = picture.value
2022-02-04 00:22:35 +01:00
2024-08-17 22:05:57 +01:00
const compressedImage = await compressImageBase64(
file.dataUrl,
800, // maxWidth
800, // maxHeight
0.9 // quality
)
if(compressedImage.isOk()) {
2024-09-06 14:38:30 +01:00
const message = new MessageViewModal();
2024-08-17 22:05:57 +01:00
message.roomId = this.roomId
2023-03-14 09:50:40 +01:00
2024-08-17 22:05:57 +01:00
message.sender = {
userPhoto: '',
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
}
2023-09-29 16:40:50 +01:00
2024-08-17 22:05:57 +01:00
message.attachments = [{
file: compressedImage.value.split(',')[1],
fileName: "foto",
source: MessageAttachmentSource.Device,
fileType: MessageAttachmentFileType.Image,
mimeType: 'image/'+picture.value.format
}]
2023-09-29 16:40:50 +01:00
2024-09-06 14:38:30 +01:00
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.roomId].push(Ballon)
}
2024-08-17 22:05:57 +01:00
this.messages1[this.roomId].push(message)
2024-08-19 16:45:29 +01:00
this.chatServiceService.sendMessage(message, this.roomType)
2023-09-29 16:40:50 +01:00
2024-08-17 22:05:57 +01:00
}
2023-09-29 16:40:50 +01:00
2023-03-14 09:50:40 +01:00
}
2023-09-29 16:40:50 +01:00
2022-02-03 21:01:53 +01:00
}
2022-02-08 15:45:09 +01:00
2022-02-11 15:08:27 +01:00
2022-02-03 21:01:53 +01:00
async addFile() {
this.addFileToChat(['.doc', '.docx', '.pdf'])
}
async addFileWebtrix() {
const modal = await this.modalController.create({
component: SearchPage,
cssClass: 'group-messages modal-desktop search-modal search-modal-to-desktop',
componentProps: {
type: 'AccoesPresidenciais & ArquivoDespachoElect',
select: true,
showSearchInput: true,
}
});
await modal.present();
2022-03-03 08:21:22 +01:00
modal.onDidDismiss().then(async res => {
2022-02-03 21:01:53 +01:00
const data = res.data;
2022-02-04 08:11:49 +01:00
const roomId = this.roomId
2022-02-03 21:01:53 +01:00
2022-03-03 08:21:22 +01:00
if (data.selected) {
2022-02-03 21:01:53 +01:00
2024-09-06 14:38:30 +01:00
const message = new MessageViewModal();
2024-08-13 10:52:35 +01:00
message.message = this.textField
message.roomId = this.roomId
2024-09-06 14:38:30 +01:00
message.sentAt = new Date().toISOString()
2024-08-13 10:52:35 +01:00
message.sender = {
userPhoto: '',
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
}
message.attachments = [{
fileName: res.data.selected.Assunto,
source: MessageAttachmentSource.Webtrix,
fileType: MessageAttachmentFileType.Doc,
applicationId: res.data.selected.ApplicationType,
docId: res.data.selected.Id,
2024-09-06 14:38:30 +01:00
description: res.data.selected.Assunto
2024-08-13 10:52:35 +01:00
}]
2024-09-06 14:38:30 +01:00
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)
2024-09-06 14:38:30 +01:00
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)
2024-08-19 16:45:29 +01:00
this.chatServiceService.sendMessage(message, this.roomType)
2024-08-13 10:52:35 +01:00
this.textField = ''
2022-02-04 00:22:35 +01:00
2022-02-03 21:01:53 +01:00
}
});
}
2024-08-13 10:52:35 +01:00
async pickPicture() {
2022-02-08 15:45:09 +01:00
2024-08-13 10:52:35 +01:00
const file = await this.FilePickerService.getPicture({
cameraResultType: CameraResultType.Base64
})
2022-07-06 17:02:42 +01:00
2024-08-13 10:52:35 +01:00
if(file.isOk()) {
2022-02-08 15:45:09 +01:00
2024-08-13 10:52:35 +01:00
var base64 = 'data:image/jpeg;base64,' + file.value.base64String
if (file.value.format == "jpeg" || file.value.format == "png" || file.value.format == "gif") {
2023-09-29 16:40:50 +01:00
2024-08-13 10:52:35 +01:00
const compressedImage = await compressImageBase64(
base64,
800, // maxWidth
800, // maxHeight
0.9 // quality
)
2024-08-13 10:52:35 +01:00
if(compressedImage.isOk()) {
2022-02-08 15:45:09 +01:00
2024-09-06 14:38:30 +01:00
const message = new MessageViewModal();
2024-08-13 10:52:35 +01:00
message.roomId = this.roomId
2024-09-06 14:38:30 +01:00
message.sentAt = new Date().toISOString()
// message.oneShot = oneShot
2024-08-13 10:52:35 +01:00
message.sender = {
userPhoto: '',
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
}
message.attachments = [{
file: compressedImage.value,
fileName: "foto",
source: MessageAttachmentSource.Device,
fileType: MessageAttachmentFileType.Image,
mimeType: 'image/'+file.value.format
2024-08-13 10:52:35 +01:00
}]
2024-09-06 14:38:30 +01:00
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)
2024-08-19 16:45:29 +01:00
this.chatServiceService.sendMessage(message, this.roomType)
2024-08-13 10:52:35 +01:00
}
}
} else {
2024-08-17 22:05:57 +01:00
if(file.error.type == 'PERMISSION_DENIED') {
this.toastService._badRequest("Sem acesso a camera")
}
2024-08-16 12:24:26 +01:00
Logger.error('failed to pick picture from the device', {
error: file.error
})
2024-08-13 10:52:35 +01:00
}
2022-02-08 15:45:09 +01:00
}
2023-08-16 08:01:45 +01:00
2024-08-13 10:52:35 +01:00
async addFileToChat(types) {
2024-03-11 11:18:32 +01:00
console.log('add file ')
2022-02-04 08:11:49 +01:00
const roomId = this.roomId
2022-03-27 18:54:08 +01:00
2024-03-12 16:45:08 +01:00
if (this.platform.is('ios')) {
2024-03-11 11:18:32 +01:00
console.log('ios add file ')
2024-08-17 22:05:57 +01:00
const result = await this.FilePickerMobileService.getFile({
2024-03-18 11:13:34 +01:00
types: ['application/pdf', 'application/doc', 'application/docx','application/xls', 'application/xlsx', 'application/ppt',
'application/pptx', 'application/txt'],
2024-03-11 11:18:32 +01:00
multiple: false,
readData: true,
2024-08-17 22:05:57 +01:00
})
2024-03-11 11:18:32 +01:00
2024-08-17 22:05:57 +01:00
if(result.isOk()) {
console.log('RESULT', result.value.files[0].data)
2024-03-11 11:18:32 +01:00
2024-09-06 14:38:30 +01:00
const message = new MessageViewModal();
2024-08-17 22:05:57 +01:00
message.roomId = this.roomId
2024-09-06 14:38:30 +01:00
message.sentAt = new Date().toISOString()
2024-08-13 10:52:35 +01:00
2024-08-17 22:05:57 +01:00
message.sender = {
userPhoto: '',
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
}
2024-08-13 10:52:35 +01:00
2024-08-17 22:05:57 +01:00
message.attachments = [{
file: result.value.files[0].data,
fileName: result.value.files[0].name,
source: MessageAttachmentSource.Device,
fileType: MessageAttachmentFileType.Doc
}]
2024-08-13 10:52:35 +01:00
2024-08-17 22:05:57 +01:00
this.messages1[this.roomId].push(message)
2024-08-19 16:45:29 +01:00
this.chatServiceService.sendMessage(message, this.roomType)
2024-08-17 22:05:57 +01:00
return
}
2024-08-13 10:52:35 +01:00
2024-03-12 16:45:08 +01:00
2024-03-11 11:18:32 +01:00
}
2024-08-17 22:05:57 +01:00
const file = await this.FilePickerWebService.getFileFromDevice(types)
2022-04-04 00:37:00 +01:00
2024-08-17 22:05:57 +01:00
if(file.isOk()) {
2022-07-06 17:02:42 +01:00
2024-08-17 22:05:57 +01:00
console.log(file)
2023-08-31 13:07:52 +01:00
2022-03-27 18:54:08 +01:00
2024-08-17 22:05:57 +01:00
const fileName = file.value.name
2022-02-04 00:22:35 +01:00
2024-08-17 22:05:57 +01:00
const validation = await allowedDocExtension(fileName)
2022-03-25 09:25:05 +01:00
2024-08-17 22:05:57 +01:00
if (validation.isOk()) {
2024-08-13 10:52:35 +01:00
2024-08-17 22:05:57 +01:00
let fileBase64 = await JSFileToDataUrl(file.value);
2024-08-13 10:52:35 +01:00
2024-08-17 22:05:57 +01:00
if(fileBase64.isOk()) {
2024-08-13 10:52:35 +01:00
2024-09-06 14:38:30 +01:00
const message = new MessageViewModal();
2024-08-17 22:05:57 +01:00
message.roomId = this.roomId
2024-09-06 14:38:30 +01:00
message.sentAt = new Date().toISOString()
2024-08-13 10:52:35 +01:00
2024-08-17 22:05:57 +01:00
message.sender = {
userPhoto: '',
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
}
2024-08-13 10:52:35 +01:00
2024-08-17 22:05:57 +01:00
message.attachments = [{
file: fileBase64.value.split(',')[1],
fileName: file.value.name,
source: MessageAttachmentSource.Device,
fileType: MessageAttachmentFileType.Doc,
mimeType: file.value.type
}]
2024-08-13 10:52:35 +01:00
2024-09-06 14:38:30 +01:00
const date = whatsappDate(message.sentAt, false)
if(!this.date[date]) {
this.date[date] = true
const Ballon = XBallon(message)
this.messages1[this.roomId].push(Ballon)
}
2024-08-17 22:05:57 +01:00
this.messages1[this.roomId].push(message)
2024-09-06 14:38:30 +01:00
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)
2024-08-19 16:45:29 +01:00
this.chatServiceService.sendMessage(message, this.roomType)
2022-03-25 09:25:05 +01:00
2024-08-17 22:05:57 +01:00
}
2022-02-04 00:22:35 +01:00
2022-07-06 17:02:42 +01:00
2024-08-17 22:05:57 +01:00
} else {
this.toastService._badRequest("Ficheiro inválido")
}
}
2022-04-04 00:37:00 +01:00
}
2022-03-27 18:54:08 +01:00
2021-08-18 18:58:02 +01:00
async openChatOptions(ev?: any) {
2021-10-07 15:30:36 +01:00
const roomId = this.roomId
2022-07-06 17:02:42 +01:00
2021-08-18 18:58:02 +01:00
2020-12-30 11:13:50 +01:00
const popover = await this.popoverController.create({
component: ChatOptionsPopoverPage,
cssClass: 'chat-options-popover',
event: ev,
2021-08-18 18:58:02 +01:00
componentProps: {
room: this.roomId,
members: this.members,
eventSelectedDate: new Date(),
},
2020-12-30 11:13:50 +01:00
translucent: true
});
2021-09-21 14:05:59 +01:00
await popover.present();
2022-03-03 08:21:22 +01:00
popover.onDidDismiss().then(async (res) => {
2022-07-06 17:02:42 +01:00
if (res['data'] == 'take-picture') {
2024-08-13 10:52:35 +01:00
this.takePictureMobile()
2021-09-21 14:05:59 +01:00
}
else if (res['data'] == 'add-picture') {
console.log('add-picture')
2024-08-13 10:52:35 +01:00
this.pickPicture()
2021-09-21 14:05:59 +01:00
}
else if (res['data'] == 'add-document') {
2022-02-03 21:01:53 +01:00
this.addFile()
2021-09-21 14:05:59 +01:00
}
else if (res['data'] == 'documentoGestaoDocumental') {
2021-09-21 14:05:59 +01:00
2022-02-03 21:01:53 +01:00
this.addFileWebtrix()
2021-09-21 14:05:59 +01:00
}
2022-01-29 20:39:35 +01:00
2021-09-21 14:05:59 +01:00
});
2020-12-30 11:13:50 +01:00
}
2021-12-08 19:36:41 +01:00
isJson(str) {
try {
JSON.parse(str);
2021-12-08 19:36:41 +01:00
} catch (e) {
return "";
2021-12-08 19:36:41 +01:00
}
return JSON.parse(str);
}
2021-12-08 19:36:41 +01:00
2023-08-20 22:05:46 +01:00
async openFile(pdfString, filename, type) {
2024-03-12 16:45:08 +01:00
2024-03-14 09:10:17 +01:00
console.log('url while open ',pdfString)
2024-03-18 11:13:34 +01:00
/* const modal = await this.modalController.create({
2024-03-14 09:10:17 +01:00
component: ViewDocumentSecondOptionsPage,
componentProps: {
fileUrl: pdfString,
filename: filename
},
cssClass: 'modal modal-desktop'
});
await modal.present();
2024-03-26 12:03:30 +01:00
/*
2024-03-18 11:13:34 +01:00
await modal.present(); */
2024-08-17 22:05:57 +01:00
// var blob = new Blob([pdfString], { type: 'application/pdf' });
2024-03-12 16:45:08 +01:00
2024-08-17 22:05:57 +01:00
// console.log('blob blob', blob)
2024-03-12 16:45:08 +01:00
2024-08-17 22:05:57 +01:00
// this.blobToBase64(blob).then((value) => {
// console.log(value)
// }).catch((error) => {
// console.log(error)
// })
2023-09-29 16:40:50 +01:00
2024-08-17 22:05:57 +01:00
// let pathFile = ''
// const fileName = filename
// if (this.platform.is('ios')) {
// pathFile = this.file.documentsDirectory
// } else {
// pathFile = this.file.externalRootDirectory
// }
// console.log('file data', pdfString)
// console.log(pathFile)
// let removePre = this.removeTextBeforeSlash(pdfString,',')
// console.log('file data remove ', removePre)
// await Filesystem.writeFile({
// path: fileName,
// data: removePre,
// directory: Directory.Cache,
// }).then((dir) => {
// console.log('DIR ', dir)
// this.fileOpener
// .open(dir.uri, type)
// .then(() => console.log())
// .catch(e => console.error(e))
// }).catch((error) => {
// console.log('error writing the file', error)
// });
2022-03-09 09:23:27 +01:00
}
2024-03-12 16:45:08 +01:00
removeTextBeforeSlash(inputString, controlString) {
if (inputString.includes(controlString)) {
const parts = inputString.split(controlString);
return parts.length > 1 ? parts[1] : inputString;
} else {
return inputString;
}
}
downloadFileFromBrowser(fileName: string, data: any): void {
const linkSource = data;
const downloadLink = document.createElement("a");
downloadLink.href = linkSource;
downloadLink.download = fileName;
downloadLink.click();
}
2022-04-04 00:37:00 +01:00
2021-11-17 15:34:15 +01:00
async openPreview(msg) {
2022-01-21 16:55:05 +01:00
2022-07-06 17:02:42 +01:00
if (msg.file.type === "application/webtrix") {
this.viewDocument(msg.file, msg.attachments.image_url)
2022-01-21 16:55:05 +01:00
} else {
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
2024-08-16 18:06:27 +01:00
// this.downloadFileMsg(msg)
// this.testDownlod(msg)
2022-04-07 15:22:25 +01:00
} else {
var str = msg.attachments[0].image_url;
str = str.substring(1, ((str.length) - 1));
2022-04-07 15:22:25 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2022-04-07 15:22:25 +01:00
console.log(msg)
2022-09-23 11:23:24 +01:00
if (msg.file.type == "application/img") {
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
image: msg.attachments[0].image_url,
type: msg.file.type,
username: msg.u.name,
_updatedAt: msg._updatedAt
}
});
modal.present();
} else {
2022-09-23 11:23:24 +01:00
this.downloadFileFromBrowser("file", str)
2023-03-28 16:11:59 +01:00
this.downloadFileFromBrowser(msg.attachments[0].title, str)
2022-09-23 11:23:24 +01:00
2023-03-28 16:11:59 +01:00
this.downloadFileFromBrowser(msg.attachments[0].title, str)
2022-09-23 11:34:38 +01:00
}
2022-04-07 15:22:25 +01:00
} else {
2022-07-06 17:02:42 +01:00
if (msg.file.type == "application/img") {
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
image: msg.attachments[0].image_url,
type: msg.file.type,
username: msg.u.name,
_updatedAt: msg._updatedAt
}
});
modal.present();
} else {
2024-03-14 09:10:17 +01:00
this.openFile(msg.attachments[0].image_url, msg.attachments[0].title, msg.file.type);
2022-07-06 17:02:42 +01:00
}
}
2022-04-07 15:22:25 +01:00
}
2021-12-17 17:20:43 +01:00
}
2022-01-21 16:55:05 +01:00
2021-11-17 15:34:15 +01:00
}
2021-11-22 13:53:37 +01:00
imageSize(img) {
2021-11-22 13:53:37 +01:00
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.width = 300
canvas.height = 234
2021-11-22 13:53:37 +01:00
ctx.drawImage(img.attachments[0].image_url, 0, 0, 300, 234);
document.body.appendChild(canvas);
}
2021-11-23 10:57:07 +01:00
getPicture(img) {
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.width = 300
canvas.height = 234
ctx.drawImage(img.attachments[0].image_url, 0, 0, 300, 234);
document.body.appendChild(canvas);
2021-11-23 10:57:07 +01:00
}
2021-11-30 12:30:58 +01:00
2024-08-17 22:05:57 +01:00
// dataURItoBlobIso(dataURI: any) {
// const byteString = window.atob(dataURI);
// const arrayBuffer = new ArrayBuffer(byteString.length);
// const int8Array = new Uint8Array(arrayBuffer);
// for (let i = 0; i < byteString.length; i++) {
// int8Array[i] = byteString.charCodeAt(i);
// }
// const blob = new Blob([int8Array], { type: 'application/pdf' });
// return blob;
// }
2024-03-11 11:18:32 +01:00
2024-08-08 11:44:41 +01:00
2024-09-06 14:38:30 +01:00
messageDelete(message: MessageViewModal) {
2024-08-08 11:44:41 +01:00
this.chatServiceService.messageDelete({
2024-08-09 10:50:32 +01:00
messageId: message.id,
2024-08-08 11:44:41 +01:00
roomId: this.roomId,
})
}
async editMessage(message: any) {
const modal = await this.modalController.create({
component: EditMessagePage,
cssClass: '',
componentProps: {
message: message.message,
roomId: this.roomId,
}
});
modal.present()
return modal.onDidDismiss().then((res) => {
this.chatServiceService.updateMessage({
memberId: SessionStore.user.UserId,
message: res.data.message,
messageId: message.id,
requestId: '',
roomId: this.roomId
})
});
}
toggleEmojiPicker(message: any) {
if (this.selectedMessage === message) {
this.selectedMessage = null; // Close the picker if it's already open
} else {
this.selectedMessage = message; // Open the picker for the selected message
}
}
addReaction(message: any, emoji: string) {
// Logic to add reaction to the message
console.log(`Reacting to message ${message.id} with emoji ${emoji.codePointAt(0).toString(16)}`);
this.selectedMessage = null; // Close the picker after adding reaction
this.chatServiceService.reactToMessage({
memberId: SessionStore.user.UserId,
messageId: message.id,
roomId: this.roomId,
reaction: emoji,
requestId: ''
})
}
sendTyping() {
2024-08-18 15:40:43 +01:00
this.UserTypingRemoteRepositoryService.sendTyping(this.roomId)
2024-08-08 11:44:41 +01:00
}
2021-07-23 14:43:51 +01:00
}