2024-08-13 10:52:35 +01:00
|
|
|
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
|
2022-06-29 11:42:31 +01:00
|
|
|
import { AnimationController, GestureController, IonRange, ModalController, PopoverController } from '@ionic/angular';
|
2021-07-12 11:13:29 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2024-08-19 16:01:58 +01:00
|
|
|
import { ContactsPage } from '../contacts/contacts.page';
|
2021-08-18 18:58:02 +01:00
|
|
|
import { ChatOptionsFeaturesPage } from 'src/app/modals/chat-options-features/chat-options-features.page';
|
2021-09-06 16:53:58 +01:00
|
|
|
import { TimeService } from 'src/app/services/functions/time.service';
|
2021-09-21 14:05:59 +01:00
|
|
|
import { FileService } from 'src/app/services/functions/file.service';
|
2021-10-05 16:29:33 +01:00
|
|
|
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
|
2024-02-22 11:40:06 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service';
|
2021-12-22 10:31:10 +01:00
|
|
|
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
|
2022-02-03 21:01:53 +01:00
|
|
|
import { FileType } from 'src/app/models/fileType';
|
|
|
|
|
import { SearchPage } from 'src/app/pages/search/search.page';
|
2024-08-13 10:52:35 +01:00
|
|
|
import { CameraResultType } from '@capacitor/camera';
|
|
|
|
|
import { RecordingData } from 'capacitor-voice-recorder';
|
2022-03-18 11:45:38 +01:00
|
|
|
import { DomSanitizer } from '@angular/platform-browser';
|
2022-08-02 14:03:52 +01:00
|
|
|
import { Platform } from '@ionic/angular';
|
2022-04-06 16:25:47 +01:00
|
|
|
import { File } from '@awesome-cordova-plugins/file/ngx';
|
2022-04-06 17:35:44 +01:00
|
|
|
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
|
2022-04-18 15:12:27 +01:00
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
2022-06-29 11:42:31 +01:00
|
|
|
import { Howl } from 'howler';
|
2022-07-06 09:59:22 +01:00
|
|
|
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
|
2023-01-24 15:56:47 +01:00
|
|
|
import { PermissionService } from 'src/app/services/permission.service';
|
2024-06-10 16:34:43 +01:00
|
|
|
import { Observable as DexieObservable } from 'Dexie';
|
2024-08-13 10:52:35 +01:00
|
|
|
import { Subscription } from 'rxjs';
|
2024-08-18 13:27:57 +01:00
|
|
|
import { RoomLocalRepository } from 'src/app/module/chat/data/repository/room-local-repository.service'
|
|
|
|
|
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member-list-local-repository.service'
|
2024-08-07 19:30:20 +01:00
|
|
|
import { MessageTable } from 'src/app/module/chat/infra/database/dexie/schema/message';
|
2024-07-11 10:28:21 +01:00
|
|
|
import { RoomListItemOutPutDTO } from 'src/app/module/chat/data/dto/room/roomListOutputDTO';
|
2024-07-31 17:23:44 +01:00
|
|
|
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service';
|
2024-08-02 12:40:34 +01:00
|
|
|
import { EditMessagePage } from 'src/app/modals/edit-message/edit-message.page';
|
2024-08-07 11:18:41 +01:00
|
|
|
import { MessageEntity } from 'src/app/module/chat/domain/entity/message';
|
2024-08-07 19:30:20 +01:00
|
|
|
import { MemberTable } from 'src/app/module/chat/infra/database/dexie/schema/members';
|
2024-08-07 20:23:33 +01:00
|
|
|
import { TypingTable } from 'src/app/module/chat/infra/database/dexie/schema/typing';
|
2024-08-09 10:50:32 +01:00
|
|
|
import { MessageAttachmentFileType, MessageAttachmentSource } from 'src/app/module/chat/data/dto/message/messageOutputDTO';
|
2024-08-13 17:05:46 +01:00
|
|
|
import { JSFileToDataUrl } from 'src/app/utils/ToBase64';
|
2024-08-09 12:36:51 +01:00
|
|
|
import { CameraService } from 'src/app/infra/camera/camera.service'
|
|
|
|
|
import { FilePickerWebService } from 'src/app/infra/file-picker/web/file-picker-web.service'
|
2024-08-13 10:52:35 +01:00
|
|
|
import { FilePickerService } from 'src/app/infra/file-picker/file-picker.service'
|
2024-08-09 12:36:51 +01:00
|
|
|
import { allowedDocExtension } from 'src/app/utils/allowedDocExtension';
|
2024-08-09 14:56:36 +01:00
|
|
|
import { SpeakerService, StartRecordingResultError, StopRecordingResultError } from 'src/app/infra/speaker/speaker.service'
|
2024-08-16 14:21:01 +01:00
|
|
|
import { compressImageBase64 } from 'src/app/utils/imageCompressore';
|
2024-08-16 17:45:45 +01:00
|
|
|
import { ChatPopoverPage } from '../../modal/chat-popover/chat-popover.page';
|
2024-08-17 22:05:57 +01:00
|
|
|
import { LastMessage } from '../../utils/lastMessage';
|
2024-08-18 15:40:43 +01:00
|
|
|
import { UserTypingLocalRepository } from 'src/app/module/chat/data/repository/user-typing-local-data-source.service';
|
|
|
|
|
import { UserTypingRemoteRepositoryService } from 'src/app/module/chat/data/repository/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';
|
|
|
|
|
import { MessageRemoteDataSourceService } from 'src/app/module/chat/data/repository/message/message-remote-data-source.service';
|
|
|
|
|
import { MessageEnum } from 'src/app/module/chat/domain/use-case/message-create-use-case.service';
|
2024-08-19 16:45:29 +01:00
|
|
|
import { RoomType } from "src/app/module/chat/domain/entity/group";
|
|
|
|
|
import { RoomTable } from 'src/app/module/chat/infra/database/dexie/schema/room';
|
2024-08-18 15:40:43 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
|
2021-03-04 18:49: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, OnChanges, AfterViewInit, OnDestroy {
|
2021-03-04 18:49:50 +01:00
|
|
|
showLoader: boolean;
|
|
|
|
|
|
|
|
|
|
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
|
2021-09-30 08:43:49 +01:00
|
|
|
@ViewChild('message-item') messageContainer: ElementRef;
|
2021-03-04 18:49:50 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
dm: any;
|
|
|
|
|
userPresence = '';
|
|
|
|
|
dmUsers: any;
|
|
|
|
|
downloadProgess = 0;
|
2021-03-04 18:49:50 +01:00
|
|
|
|
2024-08-19 16:45:29 +01:00
|
|
|
roomType!: RoomType
|
2021-12-16 16:36:39 +01:00
|
|
|
@Input() roomId: string;
|
|
|
|
|
@Input() showMessages: string;
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
@Output() openNewEventPage: EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
@Output() getDirectMessages: EventEmitter<any> = new EventEmitter<any>();
|
2024-06-10 16:34:43 +01:00
|
|
|
@Output() closeAllDesktopComponents: EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
@Output() showEmptyContainer: EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
@Output() openGroupContacts: EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
@Output() openEditGroupPage: EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
@Output() getGroups: EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
|
2021-08-20 11:58:28 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
scrollingOnce: boolean = true;
|
2021-08-23 16:31:06 +01:00
|
|
|
private scrollChangeCallback: () => void;
|
|
|
|
|
currentPosition: any;
|
|
|
|
|
startPosition: number;
|
2021-09-24 15:38:50 +01:00
|
|
|
mesageItemDropdownOptions: boolean = false;
|
|
|
|
|
scrollToBottomBtn = false;
|
2021-09-30 08:43:49 +01:00
|
|
|
longPressActive = false;
|
2022-03-27 18:54:08 +01:00
|
|
|
downloadFile: string;
|
2021-08-20 11:24:42 +01:00
|
|
|
|
2022-03-14 17:11:00 +01:00
|
|
|
showAvatar = true;
|
|
|
|
|
|
|
|
|
|
recording = false;
|
|
|
|
|
allowTyping = true;
|
|
|
|
|
lastAudioRecorded = '';
|
2024-08-09 14:56:36 +01:00
|
|
|
audioRecordedSafe: any = "";
|
|
|
|
|
audioRecordedDataUrl: any = "";
|
2022-03-31 11:56:49 +01:00
|
|
|
audioDownloaded: any = "";
|
2022-03-14 17:11:00 +01:00
|
|
|
durationDisplay = '';
|
|
|
|
|
duration = 0;
|
2022-02-24 14:59:47 +01:00
|
|
|
|
2022-07-06 09:59:22 +01:00
|
|
|
audioPermissionStatus: 'granted' | 'denied' | 'prompt' | null = null
|
2022-04-18 15:12:27 +01:00
|
|
|
sessionStore = SessionStore
|
2022-06-29 11:42:31 +01:00
|
|
|
audioPlay: Howl = null;
|
|
|
|
|
isPlaying = false;
|
|
|
|
|
audioProgress = 0;
|
|
|
|
|
audioDuration = 0;
|
2022-07-06 09:59:22 +01:00
|
|
|
audioTimer: any;
|
|
|
|
|
@ViewChild('range', { static: false }) range: IonRange;
|
2024-07-17 16:39:18 +01:00
|
|
|
@ViewChild('array') myInputRef!: ElementRef;
|
|
|
|
|
|
2022-07-06 09:59:22 +01:00
|
|
|
userName = "";
|
2022-07-06 17:50:42 +01:00
|
|
|
room: any = new Array();
|
|
|
|
|
roomName: any;
|
2024-06-14 12:00:03 +01:00
|
|
|
isAdmin = true;
|
2022-07-06 17:50:42 +01:00
|
|
|
roomCountDownDate: string;
|
2024-08-13 10:52:35 +01:00
|
|
|
audioMimeType = ''
|
2023-11-09 11:45:04 +01:00
|
|
|
|
2024-06-05 10:28:38 +01:00
|
|
|
textField = ''
|
|
|
|
|
|
2024-08-19 16:45:29 +01:00
|
|
|
roomData$: DexieObservable<RoomTable | undefined>
|
2024-08-06 11:24:00 +01:00
|
|
|
roomStatus$: DexieObservable<Boolean >
|
2024-08-07 19:30:20 +01:00
|
|
|
roomMessage$: DexieObservable<MessageTable[]>
|
|
|
|
|
roomMembers$: DexieObservable<MemberTable[] | undefined>
|
2024-08-07 20:23:33 +01:00
|
|
|
//userTyping$: DexieObservable<TypingTable[] | undefined>
|
|
|
|
|
userTyping$: TypingTable[] | undefined
|
2024-06-14 12:00:03 +01:00
|
|
|
newMessagesStream!: Subscription
|
2024-06-13 12:11:17 +01:00
|
|
|
|
2024-08-02 11:34:57 +01:00
|
|
|
selectedMessage: any = null;
|
|
|
|
|
emojis: string[] = ['😊', '😂', '❤️', '👍', '😢']; // Add more emojis as needed
|
2024-08-06 16:53:13 +01:00
|
|
|
totalMessage = 0
|
2024-08-09 14:56:36 +01:00
|
|
|
recordData:RecordingData
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
messages: MessageEntity[] = []
|
|
|
|
|
|
|
|
|
|
messageReceiveSubject: Subscription
|
|
|
|
|
messageDeleteSubject: Subscription
|
|
|
|
|
messageUpdateSubject: Subscription
|
|
|
|
|
messageSendSubject: Subscription
|
|
|
|
|
|
|
|
|
|
messages1: {[key: string]: MessageEntity[]} = {}
|
2024-08-15 14:29:11 +01:00
|
|
|
MessageAttachmentFileType = MessageAttachmentFileType
|
|
|
|
|
MessageAttachmentFileSource = MessageAttachmentSource
|
2024-08-13 10:52:35 +01:00
|
|
|
|
2021-03-04 18:49:50 +01:00
|
|
|
constructor(
|
|
|
|
|
public popoverController: PopoverController,
|
|
|
|
|
private modalController: ModalController,
|
2021-03-18 09:25:59 +01:00
|
|
|
private animationController: AnimationController,
|
2021-07-12 11:13:29 +01:00
|
|
|
private toastService: ToastService,
|
2021-09-06 16:53:58 +01:00
|
|
|
private timeService: TimeService,
|
2021-09-21 14:05:59 +01:00
|
|
|
private fileService: FileService,
|
2021-09-30 08:43:49 +01:00
|
|
|
private gestureController: GestureController,
|
2021-11-22 13:53:37 +01:00
|
|
|
public ThemeService: ThemeService,
|
2022-03-18 11:45:38 +01:00
|
|
|
private sanitiser: DomSanitizer,
|
2022-04-06 16:25:47 +01:00
|
|
|
private file: File,
|
|
|
|
|
private platform: Platform,
|
2022-04-06 17:35:44 +01:00
|
|
|
private fileOpener: FileOpener,
|
2023-01-24 15:56:47 +01:00
|
|
|
public p: PermissionService,
|
2024-08-18 13:27:57 +01:00
|
|
|
private MemberListLocalRepository: MemberListLocalRepository,
|
2024-08-09 10:50:32 +01:00
|
|
|
private chatServiceService: ChatServiceService,
|
2024-08-09 12:36:51 +01:00
|
|
|
private CameraService: CameraService,
|
2024-08-09 14:56:36 +01:00
|
|
|
private FilePickerWebService: FilePickerWebService,
|
2024-08-13 10:52:35 +01:00
|
|
|
private FilePickerService: FilePickerService,
|
2024-08-15 16:34:07 +01:00
|
|
|
private SpeakerService: SpeakerService,
|
2024-08-18 15:40:43 +01:00
|
|
|
private RoomLocalRepository: RoomLocalRepository,
|
|
|
|
|
private userTypingLocalRepository: UserTypingLocalRepository,
|
|
|
|
|
private UserTypingRemoteRepositoryService: UserTypingRemoteRepositoryService,
|
|
|
|
|
private messageLocalDataSourceService: MessageLocalDataSourceService,
|
|
|
|
|
private MessageRemoteDataSourceService: MessageRemoteDataSourceService
|
2021-07-23 14:43:51 +01:00
|
|
|
) {
|
2022-09-30 10:16:08 +01:00
|
|
|
// update
|
2022-04-02 09:40:09 +01:00
|
|
|
this.checkAudioPermission()
|
2021-03-12 11:56:54 +01:00
|
|
|
}
|
2022-03-21 15:08:43 +01:00
|
|
|
|
2021-03-12 11:56:54 +01:00
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
2024-08-15 10:26:20 +01:00
|
|
|
|
2024-08-15 10:40:39 +01:00
|
|
|
|
2024-08-18 13:27:57 +01:00
|
|
|
this.roomData$ = this.RoomLocalRepository.getRoomByIdLive(this.roomId)
|
2024-08-19 16:45:29 +01:00
|
|
|
|
|
|
|
|
this.roomData$.subscribe(e => {
|
|
|
|
|
console.log(e)
|
|
|
|
|
if(e) {
|
|
|
|
|
this.roomType = e.roomType
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
2024-08-14 15:29:16 +01:00
|
|
|
this.getMessages();
|
|
|
|
|
this.listenToIncomingMessage();
|
|
|
|
|
this.listenToDeleteMessage();
|
2024-08-13 10:52:35 +01:00
|
|
|
this.listenToUpdateMessage();
|
2024-08-15 10:26:20 +01:00
|
|
|
this.listenToSendMessage()
|
2024-08-06 16:53:13 +01:00
|
|
|
|
2024-08-17 22:05:57 +01:00
|
|
|
// this.roomMessage$ = this.messageRepositoryService.getItemsLive(this.roomId)
|
2024-08-18 13:27:57 +01:00
|
|
|
this.roomMembers$ = this.MemberListLocalRepository.getRoomMemberByIdLive(this.roomId) as any
|
|
|
|
|
this.roomStatus$ = this.MemberListLocalRepository.allMemberOnline(this.roomId)
|
|
|
|
|
this.chatServiceService.getRoomById(this.roomId)
|
2024-06-13 12:11:17 +01:00
|
|
|
|
2024-08-18 15:40:43 +01:00
|
|
|
this.userTypingLocalRepository.getUserTypingLive().subscribe((e) => {
|
2024-07-17 16:39:18 +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-08-13 10:52:35 +01:00
|
|
|
}
|
2024-06-13 12:11:17 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
async getMessages() {
|
2024-06-14 12:00:03 +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:40:39 +01:00
|
|
|
|
2024-08-15 10:26:20 +01:00
|
|
|
this.messages1[this.roomId] = []
|
2024-08-14 15:29:16 +01:00
|
|
|
this.messages1[this.roomId] = messages
|
2024-08-18 13:27:57 +01:00
|
|
|
|
2024-08-17 22:05:57 +01:00
|
|
|
this.messages1[this.roomId].push(LastMessage)
|
2024-08-13 17:05:46 +01:00
|
|
|
|
2024-08-17 22:05:57 +01:00
|
|
|
this.loadAttachment()
|
2024-08-14 15:29:16 +01:00
|
|
|
|
2024-08-13 17:05:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async loadAttachment() {
|
|
|
|
|
for(const message of this.messages1[this.roomId]) {
|
|
|
|
|
if(message.hasAttachment) {
|
2024-08-14 15:29:16 +01:00
|
|
|
|
2024-08-17 22:05:57 +01:00
|
|
|
if(message.$id) {
|
|
|
|
|
console.log('message.$id', message.$id)
|
|
|
|
|
this.chatServiceService.getMessageAttachmentByMessageId(message).then((result)=> {
|
|
|
|
|
if(result.isOk()) {
|
|
|
|
|
message.attachments[0].safeFile = result.value
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-08-18 13:27:57 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-13 17:05:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-08-13 10:52:35 +01:00
|
|
|
}
|
2024-06-14 12:00:03 +01:00
|
|
|
|
2024-08-17 22:05:57 +01:00
|
|
|
async onImageLoad(message: MessageEntity, index:number) {
|
|
|
|
|
if(message.attachments[0].fileName == LastMessage.attachments[0].fileName) {
|
2024-08-14 15:29:16 +01:00
|
|
|
|
2024-08-17 22:05:57 +01:00
|
|
|
this.scrollToBottom()
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottom();
|
|
|
|
|
}, 100)
|
|
|
|
|
|
|
|
|
|
this.messages1[this.roomId].splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-18 13:27:57 +01:00
|
|
|
|
2024-08-17 22:05:57 +01:00
|
|
|
async onImageError() {}
|
2024-08-14 15:29:16 +01:00
|
|
|
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
listenToIncomingMessage() {
|
|
|
|
|
this.messageReceiveSubject?.unsubscribe();
|
2024-08-14 15:29:16 +01:00
|
|
|
this.messageReceiveSubject = this.chatServiceService.listenToIncomingMessage(this.roomId).subscribe(async (message) => {
|
2024-08-13 10:52:35 +01:00
|
|
|
this.messages1[this.roomId].push(message as MessageEntity)
|
2024-08-15 10:40:39 +01:00
|
|
|
|
2024-08-14 15:29:16 +01:00
|
|
|
if(message.hasAttachment) {
|
|
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
const result = await this.chatServiceService.downloadMessageAttachmentByMessageId({
|
2024-08-14 15:29:16 +01:00
|
|
|
$messageId: message.$id,
|
|
|
|
|
id: message.attachments[0].id
|
|
|
|
|
})
|
|
|
|
|
|
2024-08-16 11:26:31 +01:00
|
|
|
if(result.isOk()){
|
2024-08-14 15:29:16 +01:00
|
|
|
message.attachments[0].safeFile = result.value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-08-13 10:52:35 +01:00
|
|
|
});
|
|
|
|
|
}
|
2024-07-18 16:19:30 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
listenToDeleteMessage() {
|
|
|
|
|
this.messageDeleteSubject?.unsubscribe();
|
|
|
|
|
|
|
|
|
|
this.messageDeleteSubject = this.chatServiceService.listenToDeleteMessage(this.roomId).subscribe((deleteMessage) => {
|
|
|
|
|
console.log('delete class', deleteMessage);
|
2024-06-13 12:11:17 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
const index = this.messages1[this.roomId].findIndex(e => e?.id === deleteMessage.id); // Use triple equals for comparison
|
2024-07-17 16:39:18 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
console.log('update ==')
|
|
|
|
|
this.messages1[this.roomId][index].message = updateMessage.message
|
|
|
|
|
this.messages1[this.roomId][index].reactions = updateMessage.reactions
|
|
|
|
|
} else {
|
|
|
|
|
// console.log('message not found');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listenToSendMessage() {
|
|
|
|
|
this.messageSendSubject?.unsubscribe();
|
|
|
|
|
|
|
|
|
|
this.messageSendSubject = this.chatServiceService.listenToSendMessage(this.roomId).subscribe((updateMessage) => {
|
|
|
|
|
console.log('update message', 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
|
|
|
|
|
console.log('update ==')
|
|
|
|
|
|
|
|
|
|
this.messages1[this.roomId][index].id = updateMessage.id
|
|
|
|
|
|
2024-08-13 17:05:46 +01:00
|
|
|
let attachmentIndex = 0;
|
|
|
|
|
|
|
|
|
|
for(const message of updateMessage.attachments) {
|
|
|
|
|
console.log('set attachmen id', message)
|
|
|
|
|
this.messages1[this.roomId][index].attachments[attachmentIndex].id = message.id
|
|
|
|
|
attachmentIndex++;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
} else {
|
|
|
|
|
// console.log('message not found');
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-02 11:34:57 +01:00
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
toggleEmojiPicker(message: MessageEntity) {
|
2024-08-02 11:34:57 +01:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
addReaction(message: MessageEntity, emoji: string) {
|
2024-08-02 11:34:57 +01:00
|
|
|
// 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,
|
2024-08-06 11:24:00 +01:00
|
|
|
messageId: message.id,
|
2024-08-02 11:34:57 +01:00
|
|
|
roomId: this.roomId,
|
|
|
|
|
reaction: emoji,
|
|
|
|
|
requestId: ''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 12:40:34 +01:00
|
|
|
|
2024-07-31 17:23:44 +01:00
|
|
|
sendReadAt() {
|
2024-08-18 15:40:43 +01:00
|
|
|
this.chatServiceService.messageMarkAsRead({roomId: this.roomId}).then((e) => {
|
2024-07-31 17:23:44 +01:00
|
|
|
console.log(e)
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-08-02 11:34:57 +01:00
|
|
|
|
2024-07-17 16:39:18 +01:00
|
|
|
sendTyping() {
|
2024-08-18 15:40:43 +01:00
|
|
|
this.UserTypingRemoteRepositoryService.sendTyping(this.roomId)
|
2024-07-17 16:39:18 +01:00
|
|
|
}
|
2024-03-07 12:02:59 +01:00
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
async editMessage(message: MessageEntity) {
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2022-09-29 12:17:00 +01:00
|
|
|
const modal = await this.modalController.create({
|
2024-08-02 12:40:34 +01:00
|
|
|
component: EditMessagePage,
|
|
|
|
|
cssClass: '',
|
2022-09-29 12:17:00 +01:00
|
|
|
componentProps: {
|
2024-08-02 12:40:34 +01:00
|
|
|
message: message.message,
|
2022-09-29 12:17:00 +01:00
|
|
|
roomId: this.roomId,
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-08-02 12:40:34 +01:00
|
|
|
|
|
|
|
|
modal.present()
|
|
|
|
|
|
|
|
|
|
return modal.onDidDismiss().then((res) => {
|
|
|
|
|
|
|
|
|
|
this.chatServiceService.updateMessage({
|
|
|
|
|
memberId: SessionStore.user.UserId,
|
|
|
|
|
message: res.data.message,
|
2024-08-06 11:24:00 +01:00
|
|
|
messageId: message.id,
|
2024-08-02 12:40:34 +01:00
|
|
|
requestId: '',
|
|
|
|
|
roomId: this.roomId
|
|
|
|
|
})
|
|
|
|
|
});
|
2022-09-29 12:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-02 09:40:09 +01:00
|
|
|
async checkAudioPermission() {
|
|
|
|
|
const permissionStatus = await navigator.permissions.query({ name: 'microphone' } as any)
|
2022-04-07 15:44:31 +01:00
|
|
|
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2022-04-02 09:40:09 +01:00
|
|
|
|
|
|
|
|
this.audioPermissionStatus = permissionStatus.state
|
|
|
|
|
|
2022-07-06 09:59:22 +01:00
|
|
|
permissionStatus.onchange = (data: any) => {
|
2023-11-09 11:45:04 +01:00
|
|
|
//
|
|
|
|
|
//
|
2022-04-02 09:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 18:49:50 +01:00
|
|
|
ngOnInit() {
|
2021-07-26 09:44:11 +01:00
|
|
|
this.scrollToBottom();
|
2022-02-03 16:36:05 +01:00
|
|
|
this.getChatMembers();
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2022-03-18 11:45:38 +01:00
|
|
|
this.deleteRecording();
|
2021-07-26 19:31:19 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-20 14:31:49 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
onPressingMessage() {
|
2021-09-30 08:43:49 +01:00
|
|
|
const gesture = this.gestureController.create({
|
|
|
|
|
el: this.messageContainer.nativeElement,
|
|
|
|
|
gestureName: 'long-press',
|
2021-12-16 16:36:39 +01:00
|
|
|
onStart: ev => {
|
2021-09-30 08:43:49 +01:00
|
|
|
this.longPressActive = true;
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2021-09-30 08:43:49 +01:00
|
|
|
},
|
|
|
|
|
onEnd: ev => {
|
|
|
|
|
this.longPressActive = false;
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2021-09-30 08:43:49 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
load = () => {
|
2021-03-04 18:49:50 +01:00
|
|
|
this.getChatMembers();
|
|
|
|
|
}
|
2021-03-12 11:56:54 +01:00
|
|
|
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
doRefresh(ev: any) {
|
2021-03-04 18:49:50 +01:00
|
|
|
this.load();
|
|
|
|
|
ev.target.complete();
|
|
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2022-01-13 10:26:40 +01:00
|
|
|
scrollToBottom = () => {
|
2021-03-04 18:49:50 +01:00
|
|
|
try {
|
2021-12-16 16:36:39 +01:00
|
|
|
if (this.scrollingOnce) {
|
2021-08-23 16:31:06 +01:00
|
|
|
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
|
|
|
|
|
//this.scrollingOnce = false;
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
} catch (err) { }
|
2021-08-23 16:31:06 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-14 14:50:47 +01:00
|
|
|
scrollToBottomClicked = () => {
|
2021-09-24 15:38:50 +01:00
|
|
|
try {
|
|
|
|
|
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
|
|
|
|
|
//this.scrollingOnce = false;
|
2021-12-16 16:36:39 +01:00
|
|
|
} catch (err) { }
|
2021-09-24 15:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-06 16:53:13 +01:00
|
|
|
|
2021-08-23 16:31:06 +01:00
|
|
|
ngAfterViewInit() {
|
2024-08-06 16:53:13 +01:00
|
|
|
// this.scrollChangeCallback = () => this.onContentScrolled(event);
|
|
|
|
|
// window.addEventListener('scroll', this.scrollChangeCallback, true);
|
2021-08-23 16:31:06 +01:00
|
|
|
}
|
2024-08-09 14:56:36 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
|
window.removeEventListener('scroll', this.scrollChangeCallback, true);
|
|
|
|
|
}
|
2021-08-23 16:31:06 +01:00
|
|
|
|
2021-12-16 16:36:39 +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:38:50 +01:00
|
|
|
let windowHeight = e.srcElement.scrollHeight;
|
2021-09-24 16:10:24 +01:00
|
|
|
let containerHeight = windowHeight - e.srcElement.clientHeight;
|
2021-09-24 15:38:50 +01:00
|
|
|
|
2021-08-23 16:31:06 +01:00
|
|
|
if (scroll > this.currentPosition) {
|
|
|
|
|
} else {
|
|
|
|
|
this.scrollingOnce = false;
|
2021-07-12 11:13:29 +01:00
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
if ((containerHeight - 100) > scroll) {
|
2021-09-24 15:38:50 +01:00
|
|
|
this.scrollToBottomBtn = true;
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
else {
|
2021-09-24 15:38:50 +01:00
|
|
|
this.scrollToBottomBtn = false;
|
|
|
|
|
}
|
2021-08-23 16:31:06 +01:00
|
|
|
this.currentPosition = scroll;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 17:11:00 +01:00
|
|
|
calculateDuration() {
|
|
|
|
|
if (!this.recording) {
|
|
|
|
|
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');
|
|
|
|
|
this.durationDisplay = `${minutes}:${seconds}`;
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.calculateDuration();
|
|
|
|
|
}, 1000)
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
async startRecording() {
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
const start = await this.SpeakerService.startRecording()
|
2022-03-18 11:45:38 +01:00
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
if(start.isOk()) {
|
|
|
|
|
this.recording = true;
|
|
|
|
|
this.calculateDuration();
|
|
|
|
|
} else if(start.error == StartRecordingResultError.NoSpeaker) {
|
|
|
|
|
this.toastService._badRequest('Este dispositivo não tem capacidade para gravação de áudio!');
|
|
|
|
|
} else if (start.error == StartRecordingResultError.NeedPermission) {
|
|
|
|
|
this.toastService._badRequest('Para gravar uma mensagem de voz, permita o acesso do Gabinete Digital ao seu microfone.');
|
|
|
|
|
} else if(start.error == StartRecordingResultError.alreadyRecording) {
|
2022-03-18 11:45:38 +01:00
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
}
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2022-03-14 17:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
async stopRecording() {
|
|
|
|
|
this.deleteRecording();
|
|
|
|
|
this.allowTyping = false;
|
|
|
|
|
|
|
|
|
|
const stop = await this.SpeakerService.stopRecording()
|
|
|
|
|
|
|
|
|
|
if(stop.isOk()) {
|
|
|
|
|
this.lastAudioRecorded = 'audio'
|
|
|
|
|
this.recording = false;
|
|
|
|
|
const recordData = stop.value
|
|
|
|
|
this.recordData = recordData
|
2024-08-13 10:52:35 +01:00
|
|
|
this.audioMimeType = recordData.value.mimeType
|
2024-08-09 14:56:36 +01:00
|
|
|
if (recordData.value.recordDataBase64.includes('data:audio')) {
|
|
|
|
|
console.log({recordData})
|
|
|
|
|
this.audioRecordedDataUrl = recordData.value.recordDataBase64
|
|
|
|
|
this.audioRecordedSafe = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64);
|
2022-04-07 15:22:25 +01:00
|
|
|
}
|
2024-08-09 14:56:36 +01:00
|
|
|
else if (recordData.value.mimeType && recordData?.value?.recordDataBase64) {
|
|
|
|
|
console.log({recordData})
|
|
|
|
|
|
|
|
|
|
this.audioRecordedDataUrl = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`
|
|
|
|
|
this.audioRecordedSafe = this.sanitiser.bypassSecurityTrustResourceUrl(this.audioRecordedDataUrl);
|
|
|
|
|
|
2022-04-07 15:22:25 +01:00
|
|
|
}
|
2024-08-09 14:56:36 +01:00
|
|
|
|
|
|
|
|
} else if (stop.error == StopRecordingResultError.haventStartYet) {
|
|
|
|
|
return
|
2022-04-07 15:22:25 +01:00
|
|
|
}
|
2024-08-09 14:56:36 +01:00
|
|
|
|
2022-03-14 17:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
async sendAudio(fileName) {
|
|
|
|
|
const roomId = this.roomId
|
|
|
|
|
//Converting base64 to blob
|
|
|
|
|
const encodedData = this.audioRecordedDataUrl;
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
const message = new MessageEntity();
|
|
|
|
|
message.roomId = this.roomId
|
|
|
|
|
|
2024-08-14 15:29:16 +01:00
|
|
|
message.sentAt = new Date().toISOString()
|
|
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
message.sender = {
|
|
|
|
|
userPhoto: '',
|
|
|
|
|
wxeMail: SessionStore.user.Email,
|
|
|
|
|
wxFullName: SessionStore.user.FullName,
|
|
|
|
|
wxUserId: SessionStore.user.UserId
|
2022-03-14 17:11:00 +01:00
|
|
|
}
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
message.attachments = [{
|
2024-08-15 10:40:39 +01:00
|
|
|
file: encodedData.split(',')[1],
|
2024-08-09 14:56:36 +01:00
|
|
|
fileName: "audio",
|
|
|
|
|
source: MessageAttachmentSource.Device,
|
2024-08-13 10:52:35 +01:00
|
|
|
fileType: MessageAttachmentFileType.Audio,
|
2024-08-15 16:34:07 +01:00
|
|
|
mimeType: this.audioMimeType, // 'audio/webm',
|
|
|
|
|
safeFile: this.sanitiser.bypassSecurityTrustResourceUrl(this.audioRecordedDataUrl)
|
2024-08-09 14:56:36 +01:00
|
|
|
}]
|
2022-03-14 17:11:00 +01:00
|
|
|
|
2024-08-19 16:45:29 +01:00
|
|
|
this.chatServiceService.sendMessage(message, this.roomType)
|
2024-08-13 10:52:35 +01:00
|
|
|
this.messages1[this.roomId].push(message)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2022-03-14 17:11:00 +01:00
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
this.deleteRecording();
|
2021-07-26 09:44:11 +01:00
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
async deleteRecording() {
|
|
|
|
|
this.allowTyping = true;
|
|
|
|
|
this.lastAudioRecorded = '';
|
|
|
|
|
this.audioRecordedSafe = ''
|
|
|
|
|
this.audioRecordedDataUrl = ''
|
2021-08-20 11:58:28 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
showDateDuration(start: any) {
|
2021-09-06 16:53:58 +01:00
|
|
|
return this.timeService.showDateDuration(start);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-03 16:31:03 +01:00
|
|
|
async goToEvent(event: any) {
|
2021-12-22 10:31:10 +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
|
2021-12-22 10:31:10 +01:00
|
|
|
},
|
|
|
|
|
cssClass: classs,
|
|
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
|
2021-12-22 10:31:10 +01:00
|
|
|
modal.onDidDismiss().then((res) => {
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2021-12-22 10:31:10 +01:00
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
await modal.present();
|
2021-12-22 10:31:10 +01:00
|
|
|
}
|
2021-03-04 18:49:50 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
async sendMessage() {
|
2024-06-05 10:28:38 +01:00
|
|
|
|
2024-08-07 11:18:41 +01:00
|
|
|
const message = new MessageEntity();
|
|
|
|
|
message.message = this.textField
|
|
|
|
|
message.roomId = this.roomId
|
|
|
|
|
|
|
|
|
|
message.sender = {
|
|
|
|
|
userPhoto: '',
|
|
|
|
|
wxeMail: SessionStore.user.Email,
|
|
|
|
|
wxFullName: SessionStore.user.FullName,
|
|
|
|
|
wxUserId: SessionStore.user.UserId
|
2024-06-05 12:06:36 +01:00
|
|
|
}
|
2024-08-14 15:29:16 +01:00
|
|
|
message.sentAt = new Date().toISOString()
|
2024-06-05 10:28:38 +01:00
|
|
|
|
2024-06-13 12:11:17 +01:00
|
|
|
this.textField = ''
|
2024-08-13 10:52:35 +01:00
|
|
|
this.messages1[this.roomId].push(message)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-08-19 16:45:29 +01:00
|
|
|
const data = await this.chatServiceService.sendMessage(message, this.roomType)
|
2024-08-13 10:52:35 +01:00
|
|
|
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2022-03-18 16:29:10 +01:00
|
|
|
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2021-09-28 15:23:51 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
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,
|
|
|
|
|
SourceType: 'DOC',
|
|
|
|
|
SourceID: file.DocId,
|
|
|
|
|
DispatchNumber: ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let doc = {
|
2021-12-16 16:36:39 +01:00
|
|
|
"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-05 16:29:33 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: ViewDocumentPage,
|
|
|
|
|
componentProps: {
|
2021-10-09 20:24:34 +01:00
|
|
|
trustedUrl: '',
|
|
|
|
|
file: {
|
|
|
|
|
title: file.Assunto,
|
|
|
|
|
url: '',
|
|
|
|
|
title_link: '',
|
|
|
|
|
},
|
|
|
|
|
Document: doc,
|
|
|
|
|
applicationId: file.ApplicationId,
|
|
|
|
|
docId: file.DocId,
|
|
|
|
|
folderId: '',
|
|
|
|
|
task: task
|
2021-10-05 16:29:33 +01:00
|
|
|
},
|
2021-10-09 20:24:34 +01:00
|
|
|
cssClass: 'modal modal-desktop'
|
2021-10-05 16:29:33 +01:00
|
|
|
});
|
|
|
|
|
await modal.present();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 14:56:36 +01:00
|
|
|
getChatMembers() {}
|
2022-09-30 13:12:16 +01:00
|
|
|
|
2021-03-04 18:49:50 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
async addContacts() {
|
2021-03-04 18:49:50 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: ContactsPage,
|
2021-07-23 14:43:51 +01:00
|
|
|
componentProps: {},
|
2021-03-04 18:49:50 +01:00
|
|
|
cssClass: 'contacts',
|
|
|
|
|
backdropDismiss: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modal.onDidDismiss();
|
2023-07-15 11:01:09 +01:00
|
|
|
await modal.present();
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-18 09:25:59 +01:00
|
|
|
async _openMessagesOptions() {
|
|
|
|
|
const enterAnimation = (baseEl: any) => {
|
|
|
|
|
const backdropAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('ion-backdrop')!)
|
|
|
|
|
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
|
|
|
|
|
|
|
|
|
|
const wrapperAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('.modal-wrapper')!)
|
|
|
|
|
.keyframes([
|
|
|
|
|
{ offset: 0, opacity: '1', right: '-100%' },
|
|
|
|
|
{ offset: 1, opacity: '1', right: '0px' }
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return this.animationController.create()
|
|
|
|
|
.addElement(baseEl)
|
|
|
|
|
.easing('ease-out')
|
|
|
|
|
.duration(500)
|
|
|
|
|
.addAnimation([backdropAnimation, wrapperAnimation]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const leaveAnimation = (baseEl: any) => {
|
|
|
|
|
return enterAnimation(baseEl).direction('reverse');
|
|
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-03-18 09:25:59 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
enterAnimation,
|
|
|
|
|
leaveAnimation,
|
2024-06-10 16:34:43 +01:00
|
|
|
component: ChatPopoverPage,
|
|
|
|
|
cssClass: 'model search-submodal chat-option-aside',
|
2021-03-18 09:25:59 +01:00
|
|
|
componentProps: {
|
|
|
|
|
roomId: this.roomId,
|
2024-06-10 16:34:43 +01:00
|
|
|
members: [],
|
|
|
|
|
isAdmin: this.isAdmin
|
2021-03-18 09:25:59 +01:00
|
|
|
}
|
|
|
|
|
});
|
2024-06-10 16:34:43 +01:00
|
|
|
await modal.present();
|
|
|
|
|
modal.onDidDismiss().then(res => {
|
|
|
|
|
|
|
|
|
|
if (res.data == 'leave') {
|
2024-08-09 14:56:36 +01:00
|
|
|
// this.getRoomInfo();
|
2024-06-10 16:34:43 +01:00
|
|
|
this.closeAllDesktopComponents.emit();
|
|
|
|
|
this.showEmptyContainer.emit();
|
2024-06-10 17:04:04 +01:00
|
|
|
// this.ChatSystemService.hidingRoom(this.roomId).catch((error) => console.error(error));
|
2024-06-10 16:34:43 +01:00
|
|
|
}
|
|
|
|
|
else if (res.data == 'delete') {
|
|
|
|
|
this.closeAllDesktopComponents.emit();
|
|
|
|
|
this.showEmptyContainer.emit();
|
|
|
|
|
}
|
|
|
|
|
else if (res.data == 'cancel') {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (res.data == 'edit') {
|
|
|
|
|
|
|
|
|
|
//this.closeAllDesktopComponents.emit();
|
|
|
|
|
this.openEditGroupPage.emit(this.roomId);
|
|
|
|
|
} else if (res.data == 'addUser') {
|
|
|
|
|
|
|
|
|
|
this.openGroupContactsPage();
|
|
|
|
|
}
|
|
|
|
|
else {}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openGroupContactsPage() {
|
|
|
|
|
this.openGroupContacts.emit(this.roomId);
|
2021-03-18 09:25:59 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-09 13:59:41 +01:00
|
|
|
async takePictureMobile() {
|
2022-05-27 13:36:37 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
const picture = await this.CameraService.takePicture({
|
|
|
|
|
cameraResultType: CameraResultType.DataUrl,
|
|
|
|
|
quality: 90
|
|
|
|
|
})
|
2022-09-28 21:05:28 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
if(picture.isOk()) {
|
|
|
|
|
const file = picture.value
|
2022-02-09 13:59:41 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
const compressedImage = await compressImageBase64(
|
|
|
|
|
file.dataUrl,
|
|
|
|
|
800, // maxWidth
|
|
|
|
|
800, // maxHeight
|
|
|
|
|
0.9 // quality
|
|
|
|
|
)
|
2023-08-28 16:36:31 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
if(compressedImage.isOk()) {
|
2023-08-28 16:36:31 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
const message = new MessageEntity();
|
|
|
|
|
message.roomId = this.roomId
|
2022-02-09 13:59:41 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
message.sender = {
|
|
|
|
|
userPhoto: '',
|
|
|
|
|
wxeMail: SessionStore.user.Email,
|
|
|
|
|
wxFullName: SessionStore.user.FullName,
|
|
|
|
|
wxUserId: SessionStore.user.UserId
|
|
|
|
|
}
|
2022-02-11 15:08:27 +01:00
|
|
|
|
2024-08-14 15:29:16 +01:00
|
|
|
message.sentAt = new Date().toISOString()
|
|
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
message.attachments = [{
|
2024-08-15 10:26:20 +01:00
|
|
|
file: compressedImage.value.split(',')[1],
|
2024-08-09 12:36:51 +01:00
|
|
|
fileName: "foto",
|
|
|
|
|
source: MessageAttachmentSource.Device,
|
2024-08-13 10:52:35 +01:00
|
|
|
fileType: MessageAttachmentFileType.Image,
|
2024-08-15 10:26:20 +01:00
|
|
|
mimeType: 'image/'+picture.value.format
|
2024-08-09 12:36:51 +01:00
|
|
|
}]
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
this.messages1[this.roomId].push(message)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-08-19 16:45:29 +01:00
|
|
|
this.chatServiceService.sendMessage(message, this.roomType)
|
2024-08-09 12:36:51 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2022-02-09 13:59:41 +01:00
|
|
|
|
|
|
|
|
}
|
2021-03-18 16:30:03 +01:00
|
|
|
|
2022-02-03 21:01:53 +01:00
|
|
|
async addFile() {
|
2024-08-09 10:50:32 +01:00
|
|
|
this.addFileToChat(['.doc', '.docx', '.pdf'], MessageAttachmentFileType.Doc)
|
2021-10-06 17:27:49 +01:00
|
|
|
}
|
2022-02-03 21:01:53 +01:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
|
2022-03-03 08:21:22 +01:00
|
|
|
modal.onDidDismiss().then(async res => {
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2022-02-03 21:01:53 +01:00
|
|
|
const data = res.data;
|
|
|
|
|
|
2022-03-03 08:21:22 +01:00
|
|
|
if (data.selected) {
|
2022-02-03 21:01:53 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
// "title": res.data.selected.Assunto,
|
|
|
|
|
// "description": res.data.selected.DocTypeDesc,
|
2022-02-04 00:22:35 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
const message = new MessageEntity();
|
|
|
|
|
message.message = this.textField
|
|
|
|
|
message.roomId = this.roomId
|
|
|
|
|
|
2024-08-14 15:29:16 +01:00
|
|
|
message.sentAt = new Date().toISOString()
|
|
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
message.sender = {
|
|
|
|
|
userPhoto: '',
|
|
|
|
|
wxeMail: SessionStore.user.Email,
|
|
|
|
|
wxFullName: SessionStore.user.FullName,
|
|
|
|
|
wxUserId: SessionStore.user.UserId
|
|
|
|
|
}
|
|
|
|
|
message.attachments = [{
|
|
|
|
|
fileName: res.data.selected.Assunto,
|
2024-08-16 12:24:26 +01:00
|
|
|
source: MessageAttachmentSource.Webtrix,
|
2024-08-09 12:36:51 +01:00
|
|
|
fileType: MessageAttachmentFileType.Doc,
|
|
|
|
|
applicationId: res.data.selected.ApplicationType,
|
|
|
|
|
docId: res.data.selected.Id,
|
|
|
|
|
}]
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
this.messages1[this.roomId].push(message)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-08-19 16:45:29 +01:00
|
|
|
this.chatServiceService.sendMessage(message, this.roomType)
|
2024-08-09 12:36:51 +01:00
|
|
|
this.textField = ''
|
2022-02-03 21:01:53 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
|
|
|
|
|
await modal.present();
|
2021-10-06 17:27:49 +01:00
|
|
|
}
|
2022-02-03 21:01:53 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
async pickPicture() {
|
2022-02-09 13:59:41 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
const file = await this.FilePickerService.getPicture({
|
2024-08-09 12:36:51 +01:00
|
|
|
cameraResultType: CameraResultType.Base64
|
|
|
|
|
})
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
if(file.isOk()) {
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
var base64 = 'data:image/jpeg;base64,' + file.value.base64String
|
|
|
|
|
if (file.value.format == "jpeg" || file.value.format == "png" || file.value.format == "gif") {
|
2022-02-09 13:59:41 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
const compressedImage = await compressImageBase64(
|
|
|
|
|
base64,
|
|
|
|
|
800, // maxWidth
|
|
|
|
|
800, // maxHeight
|
|
|
|
|
0.9 // quality
|
|
|
|
|
)
|
2023-08-28 13:00:51 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
if(compressedImage.isOk()) {
|
2023-11-14 12:04:31 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
const message = new MessageEntity();
|
|
|
|
|
message.roomId = this.roomId
|
2023-11-14 12:04:31 +01:00
|
|
|
|
2024-08-14 15:29:16 +01:00
|
|
|
message.sentAt = new Date().toISOString()
|
|
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
message.sender = {
|
|
|
|
|
userPhoto: '',
|
|
|
|
|
wxeMail: SessionStore.user.Email,
|
|
|
|
|
wxFullName: SessionStore.user.FullName,
|
|
|
|
|
wxUserId: SessionStore.user.UserId
|
|
|
|
|
}
|
2023-11-14 12:04:31 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
message.attachments = [{
|
2024-08-15 16:34:07 +01:00
|
|
|
file: file.value.base64String,
|
2024-08-09 12:36:51 +01:00
|
|
|
fileName: "foto",
|
|
|
|
|
source: MessageAttachmentSource.Device,
|
2024-08-13 10:52:35 +01:00
|
|
|
fileType: MessageAttachmentFileType.Image,
|
|
|
|
|
mimeType: 'image/'+file.value.format,
|
|
|
|
|
description: ''
|
2024-08-09 12:36:51 +01:00
|
|
|
}]
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
this.messages1[this.roomId].push(message)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-08-19 16:45:29 +01:00
|
|
|
this.chatServiceService.sendMessage(message, this.roomType)
|
2024-08-09 12:36:51 +01:00
|
|
|
}
|
2023-11-14 12:04:31 +01:00
|
|
|
}
|
2022-02-11 15:08:27 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
}
|
2022-02-09 13:59:41 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-03 21:01:53 +01:00
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
messageDelete(message: MessageEntity) {
|
2024-07-31 17:23:44 +01:00
|
|
|
// this.messageRepositoryService.sendMessageDelete()
|
|
|
|
|
this.chatServiceService.messageDelete({
|
2024-08-09 10:50:32 +01:00
|
|
|
messageId: message.id,
|
2024-07-31 17:23:44 +01:00
|
|
|
roomId: this.roomId,
|
|
|
|
|
})
|
|
|
|
|
}
|
2022-02-04 00:22:35 +01:00
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
async addFileToChat(types: typeof FileType[], attachmentFileType:MessageAttachmentFileType) {
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
const file = await this.FilePickerWebService.getFileFromDevice(types);
|
|
|
|
|
if(file.isOk()) {
|
2022-04-06 16:25:47 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
const fileExtension = await allowedDocExtension(file.value.type)
|
2023-08-28 13:00:51 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
if(fileExtension.isOk()) {
|
2022-04-06 16:25:47 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
console.log('FILE rigth?', file)
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-08-13 17:05:46 +01:00
|
|
|
let fileBase64 = await JSFileToDataUrl(file.value);
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
if(fileBase64.isOk()) {
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
const message = new MessageEntity();
|
|
|
|
|
message.roomId = this.roomId
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-08-14 15:29:16 +01:00
|
|
|
message.sentAt = new Date().toISOString()
|
|
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
message.sender = {
|
|
|
|
|
userPhoto: '',
|
|
|
|
|
wxeMail: SessionStore.user.Email,
|
|
|
|
|
wxFullName: SessionStore.user.FullName,
|
|
|
|
|
wxUserId: SessionStore.user.UserId
|
|
|
|
|
}
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
message.attachments = [{
|
2024-08-15 14:29:11 +01:00
|
|
|
file: fileBase64.value.split(',')[1],
|
2024-08-09 12:36:51 +01:00
|
|
|
fileName: file.value.name,
|
2024-08-09 10:50:32 +01:00
|
|
|
source: MessageAttachmentSource.Device,
|
2024-08-13 10:52:35 +01:00
|
|
|
fileType: MessageAttachmentFileType.Doc,
|
|
|
|
|
mimeType: file.value.type
|
2024-08-09 10:50:32 +01:00
|
|
|
}]
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
this.messages1[this.roomId].push(message)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-08-19 16:45:29 +01:00
|
|
|
this.chatServiceService.sendMessage(message, this.roomType)
|
2023-11-14 12:04:31 +01:00
|
|
|
}
|
2023-08-28 13:00:51 +01:00
|
|
|
|
2023-11-14 12:04:31 +01:00
|
|
|
} else {
|
|
|
|
|
this.toastService._badRequest("Ficheiro inválido")
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-06 17:27:49 +01:00
|
|
|
}
|
2022-02-11 15:08:27 +01:00
|
|
|
|
2022-02-03 21:01:53 +01:00
|
|
|
|
2021-03-18 16:30:03 +01:00
|
|
|
async _openChatOptions() {
|
2022-02-03 21:01:53 +01:00
|
|
|
const roomId = this.roomId;
|
|
|
|
|
|
2021-03-18 16:30:03 +01:00
|
|
|
|
|
|
|
|
const enterAnimation = (baseEl: any) => {
|
|
|
|
|
const backdropAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('ion-backdrop')!)
|
|
|
|
|
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
|
|
|
|
|
|
|
|
|
|
const wrapperAnimation = this.animationController.create()
|
|
|
|
|
.addElement(baseEl.querySelector('.modal-wrapper')!)
|
|
|
|
|
.keyframes([
|
|
|
|
|
{ offset: 0, opacity: '1', right: '-100%' },
|
|
|
|
|
{ offset: 1, opacity: '1', right: '0px' }
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return this.animationController.create()
|
|
|
|
|
.addElement(baseEl)
|
|
|
|
|
.easing('ease-out')
|
|
|
|
|
.duration(500)
|
|
|
|
|
.addAnimation([backdropAnimation, wrapperAnimation]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const leaveAnimation = (baseEl: any) => {
|
|
|
|
|
return enterAnimation(baseEl).direction('reverse');
|
|
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-03-18 16:30:03 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
enterAnimation,
|
|
|
|
|
leaveAnimation,
|
2021-08-18 18:58:02 +01:00
|
|
|
component: ChatOptionsFeaturesPage,
|
2021-03-18 16:30:03 +01:00
|
|
|
cssClass: 'model profile-modal search-submodal',
|
|
|
|
|
componentProps: {
|
|
|
|
|
roomId: this.roomId,
|
2024-06-05 11:55:38 +01:00
|
|
|
members: [],
|
2021-03-18 16:30:03 +01:00
|
|
|
}
|
|
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
|
2022-03-03 08:21:22 +01:00
|
|
|
modal.onDidDismiss().then(async (res) => {
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2022-02-11 15:08:27 +01:00
|
|
|
|
2022-02-03 21:01:53 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
if (res['data'] == 'meeting') {
|
2021-08-20 11:58:28 +01:00
|
|
|
//this.closeAllDesktopComponents.emit();
|
|
|
|
|
let data = {
|
|
|
|
|
roomId: this.roomId,
|
2024-06-05 11:55:38 +01:00
|
|
|
members: []
|
2021-08-20 11:58:28 +01:00
|
|
|
}
|
|
|
|
|
this.openNewEventPage.emit(data);
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
else if (res['data'] == 'take-picture') {
|
2022-02-03 21:01:53 +01:00
|
|
|
|
2022-02-09 13:59:41 +01:00
|
|
|
this.takePictureMobile()
|
2022-02-03 21:01:53 +01:00
|
|
|
|
2021-09-23 12:13:20 +01:00
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
else if (res['data'] == 'add-picture') {
|
2022-02-03 21:01:53 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
this.pickPicture()
|
2022-02-03 21:01:53 +01:00
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
}
|
2021-12-16 16:36:39 +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
|
|
|
}
|
2021-12-16 16:36:39 +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()
|
2022-02-11 15:08:27 +01:00
|
|
|
|
2021-09-21 14:05:59 +01:00
|
|
|
this.showLoader = false;
|
|
|
|
|
}
|
2021-08-20 11:58:28 +01:00
|
|
|
|
|
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
await modal.present();
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2021-03-18 16:30:03 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-21 13:33:57 +01:00
|
|
|
async audioPreview(msg) {
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2022-03-21 13:33:57 +01:00
|
|
|
if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') {
|
2024-08-09 10:50:32 +01:00
|
|
|
// this.downloadFileMsg(msg)
|
2022-03-31 16:48:53 +01:00
|
|
|
} else { }
|
2022-03-21 13:33:57 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
b64toBlob(b64Data, contentType) {
|
|
|
|
|
contentType = contentType || '';
|
|
|
|
|
var sliceSize = 512;
|
|
|
|
|
b64Data = b64Data.replace(/^[^,]+,/, '');
|
|
|
|
|
b64Data = b64Data.replace(/\s/g, '');
|
|
|
|
|
var byteCharacters = window.atob(b64Data);
|
|
|
|
|
var byteArrays = [];
|
|
|
|
|
|
|
|
|
|
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
|
|
|
|
var slice = byteCharacters.slice(offset, offset + sliceSize);
|
|
|
|
|
|
|
|
|
|
var byteNumbers = new Array(slice.length);
|
|
|
|
|
for (var i = 0; i < slice.length; i++) {
|
|
|
|
|
byteNumbers[i] = slice.charCodeAt(i);
|
|
|
|
|
}
|
2022-01-20 15:33:55 +01:00
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
var byteArray = new Uint8Array(byteNumbers);
|
2022-01-20 14:31:49 +01:00
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
byteArrays.push(byteArray);
|
|
|
|
|
}
|
2022-03-31 11:56:49 +01:00
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
var blob = new Blob(byteArrays, { type: contentType });
|
|
|
|
|
return blob;
|
|
|
|
|
}
|
2022-03-31 11:56:49 +01:00
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
downloadFileFromBrowser(fileName: string, data: any): void {
|
2024-03-18 12:59:41 +01:00
|
|
|
|
|
|
|
|
const link = document.createElement("a")
|
|
|
|
|
link.href = `data:${data.type}';base64,${data.image_url}`;
|
|
|
|
|
link.download = fileName
|
|
|
|
|
link.click()
|
|
|
|
|
|
|
|
|
|
link.remove()
|
2022-04-06 16:25:47 +01:00
|
|
|
}
|
2022-03-31 11:56:49 +01:00
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
viewDocument(file: any, url?: string) {
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
if (file.type == "application/webtrix") {
|
|
|
|
|
this.openViewDocumentModal(file);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let fullUrl = "https://www.tabularium.pt" + url;
|
|
|
|
|
this.fileService.viewDocumentByUrl(fullUrl);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-25 15:10:10 +01:00
|
|
|
|
2022-04-06 17:35:44 +01:00
|
|
|
openFile(pdfString, filename, type) {
|
|
|
|
|
const blob = this.b64toBlob(pdfString, type)
|
|
|
|
|
let pathFile = ''
|
|
|
|
|
const fileName = filename
|
|
|
|
|
const contentFile = blob
|
|
|
|
|
if (this.platform.is('ios')) {
|
|
|
|
|
pathFile = this.file.documentsDirectory
|
|
|
|
|
} else {
|
|
|
|
|
pathFile = this.file.externalRootDirectory
|
|
|
|
|
}
|
2022-07-06 09:59:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-04-06 17:35:44 +01:00
|
|
|
this.file
|
|
|
|
|
.writeFile(pathFile, fileName, contentFile, { replace: true })
|
|
|
|
|
.then(success => {
|
|
|
|
|
this.fileOpener
|
|
|
|
|
.open(pathFile + fileName, type)
|
2022-07-06 09:59:22 +01:00
|
|
|
.then(() => { })
|
2022-04-28 09:32:27 +01:00
|
|
|
.catch(e => console.error(e))
|
2022-04-06 17:35:44 +01:00
|
|
|
})
|
2022-04-28 09:32:27 +01:00
|
|
|
.catch(e => console.error(e))
|
2022-04-06 17:35:44 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
async openPreview(msg) {
|
2022-03-31 11:56:49 +01:00
|
|
|
|
2022-07-06 09:59:22 +01:00
|
|
|
|
|
|
|
|
if (msg.file.type === "application/webtrix") {
|
2022-04-06 16:25:47 +01:00
|
|
|
this.viewDocument(msg.file, msg.attachments.image_url)
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
|
2024-08-09 10:50:32 +01:00
|
|
|
// this.downloadFileMsg(msg)
|
2022-04-07 15:22:25 +01:00
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
} else {
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2023-03-28 16:11:59 +01:00
|
|
|
var str = msg.attachments[0].image_url
|
2022-04-06 16:25:47 +01:00
|
|
|
str = str.substring(1, ((str.length) - 1));
|
2022-04-07 15:22:25 +01:00
|
|
|
|
2022-04-06 17:35:44 +01:00
|
|
|
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
2022-04-07 15:22:25 +01:00
|
|
|
|
2022-07-06 09:59:22 +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-18 12:59:41 +01:00
|
|
|
this.downloadFileFromBrowser(msg.attachments[0].title, msg.attachments[0],)
|
2022-07-06 09:59:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
2024-03-18 11:13:34 +01:00
|
|
|
this.openFile(msg.attachments[0].image_url, msg.attachments[0].title, msg.file.type);
|
2023-03-28 16:11:59 +01:00
|
|
|
// this.downloadFileFromBrowser("file", str)
|
2022-04-06 17:35:44 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-06 16:25:47 +01:00
|
|
|
}
|
2021-12-23 07:40:01 +01:00
|
|
|
}
|
2022-01-05 21:27:26 +01:00
|
|
|
|
2021-11-22 13:53:37 +01:00
|
|
|
}
|
2022-02-16 15:52:59 +01:00
|
|
|
|
2022-06-29 11:42:31 +01:00
|
|
|
start(track) {
|
2022-07-06 09:59:22 +01:00
|
|
|
if (this.audioPlay) {
|
2022-06-29 11:42:31 +01:00
|
|
|
this.audioPlay.stop();
|
|
|
|
|
}
|
|
|
|
|
this.audioPlay = new Howl({
|
|
|
|
|
src: [track.changingThisBreaksApplicationSecurity],
|
|
|
|
|
onplay: () => {
|
|
|
|
|
this.isPlaying = true;
|
|
|
|
|
this.updateProgress()
|
|
|
|
|
},
|
|
|
|
|
onend: () => {
|
|
|
|
|
this.isPlaying = false;
|
|
|
|
|
clearTimeout(this.audioTimer)
|
|
|
|
|
this.audioProgress = 0
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2022-06-29 11:42:31 +01:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
this.audioPlay.play();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
togglePlayer(pause) {
|
|
|
|
|
this.isPlaying = !pause;
|
2022-07-06 09:59:22 +01:00
|
|
|
if (pause) {
|
2022-06-29 11:42:31 +01:00
|
|
|
this.audioPlay.pause();
|
|
|
|
|
} else {
|
|
|
|
|
this.audioPlay.play();
|
|
|
|
|
}
|
2022-07-06 09:59:22 +01:00
|
|
|
}
|
2022-06-29 11:42:31 +01:00
|
|
|
|
|
|
|
|
seek() {
|
|
|
|
|
let newValue = +this.range.value;
|
|
|
|
|
let duration = this.audioPlay.duration();
|
|
|
|
|
this.audioPlay.seek(duration * (newValue / 100));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateProgress() {
|
|
|
|
|
let seek = this.audioPlay.seek();
|
|
|
|
|
this.audioProgress = (seek / this.audioPlay.duration()) * 100 || 0;
|
|
|
|
|
this.audioTimer = setTimeout(() => {
|
|
|
|
|
this.updateProgress()
|
2022-07-06 09:59:22 +01:00
|
|
|
}, 1000)
|
2022-06-29 11:42:31 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
2021-03-12 11:56:54 +01:00
|
|
|
|
2021-11-22 13:53:37 +01:00
|
|
|
|
|
|
|
|
|