2024-09-10 16:01:51 +01:00
|
|
|
import { AfterViewInit, Component, ElementRef, EventEmitter, HostListener, Input, OnChanges, OnDestroy, OnInit, Output, QueryList, SimpleChanges, TemplateRef, ViewChild, ViewChildren } 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-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';
|
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-20 16:34:47 +01:00
|
|
|
import { Observable, Subscription } from 'rxjs';
|
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-07-31 17:23:44 +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-10 16:01:51 +01:00
|
|
|
import { IMessageType, MessageAttachmentFileType, MessageAttachmentSource } from 'src/app/core/chat/entity/message';
|
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-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-20 16:34:47 +01:00
|
|
|
import { Logger } from 'src/app/services/logger/main/service';
|
2024-09-01 14:27:32 +01:00
|
|
|
import { tap } from 'rxjs/operators';
|
2024-08-22 12:27:57 +01:00
|
|
|
import { AlertController } from '@ionic/angular';
|
|
|
|
|
import { ViewOncesImagePage, ViewOncesImagePageInput } from '../../modal/view-onces/view-onces.page';
|
2024-08-27 10:15:00 +01:00
|
|
|
import { MemberTable } from 'src/app/infra/database/dexie/instance/chat/schema/members';
|
|
|
|
|
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
|
|
|
|
import { RoomTable } from 'src/app/infra/database/dexie/instance/chat/schema/room';
|
|
|
|
|
import { TypingTable } from 'src/app/infra/database/dexie/instance/chat/schema/typing';
|
2024-08-29 12:13:15 +01:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
2024-09-02 12:33:43 +01:00
|
|
|
import { RoomViewModel } from '../../store/model/room';
|
2024-09-03 16:26:54 +01:00
|
|
|
import { MessageViewModal } from '../../store/model/message';
|
|
|
|
|
import { XBallon } from '../../utils/messageBallon';
|
|
|
|
|
import { whatsappDate } from 'src/app/ui/shared/utils/whatappdate';
|
2024-09-17 16:02:12 +01:00
|
|
|
import { IDBoolean } from 'src/app/infra/database/dexie/type';
|
|
|
|
|
import { Result } from 'neverthrow';
|
|
|
|
|
import { MessageOutPutDataDTO } from 'src/app/core/chat/repository/dto/messageOutputDTO';
|
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
|
2024-08-23 11:10:52 +01:00
|
|
|
RoomTypeEnum = RoomType
|
2024-08-26 09:59:30 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
@Input() _room!: RoomViewModel
|
|
|
|
|
room!: RoomViewModel
|
|
|
|
|
|
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;
|
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
|
2024-08-22 12:27:57 +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;
|
|
|
|
|
|
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-09-01 12:57:33 +01:00
|
|
|
roomData$: Observable<RoomTable | undefined>
|
2024-08-06 11:24:00 +01:00
|
|
|
roomStatus$: DexieObservable<Boolean >
|
2024-08-07 19:30:20 +01:00
|
|
|
roomMessage$: DexieObservable<MessageTable[]>
|
2024-08-20 16:34:47 +01:00
|
|
|
roomMembers$: Observable<MemberTable[] | undefined>
|
2024-08-07 20:23:33 +01:00
|
|
|
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-09-10 16:01:51 +01:00
|
|
|
messages: MessageViewModal[] = []
|
2024-08-13 10:52:35 +01:00
|
|
|
|
|
|
|
|
messageReceiveSubject: Subscription
|
|
|
|
|
messageDeleteSubject: Subscription
|
|
|
|
|
messageUpdateSubject: Subscription
|
|
|
|
|
messageSendSubject: Subscription
|
2024-08-23 11:10:52 +01:00
|
|
|
messageTypingSubject: Subscription
|
2024-08-27 15:42:11 +01:00
|
|
|
messageOnReconnectSubject: Subscription
|
2024-08-13 10:52:35 +01:00
|
|
|
|
2024-09-03 16:26:54 +01:00
|
|
|
messages1: {[key: string]: MessageViewModal[]} = {}
|
2024-08-15 14:29:11 +01:00
|
|
|
MessageAttachmentFileType = MessageAttachmentFileType
|
|
|
|
|
MessageAttachmentFileSource = MessageAttachmentSource
|
2024-08-29 12:13:15 +01:00
|
|
|
IMessageType = IMessageType
|
2024-08-13 10:52:35 +01:00
|
|
|
|
2024-08-20 16:34:47 +01:00
|
|
|
@ViewChild('imageModal') imageModal: TemplateRef<any>;
|
|
|
|
|
totalMembers = 0
|
2024-08-26 09:59:30 +01:00
|
|
|
members: MemberTable[] = []
|
2024-08-20 16:34:47 +01:00
|
|
|
|
2024-09-03 16:26:54 +01:00
|
|
|
date: {[key: string]: Object} = {}
|
2024-09-10 16:01:51 +01:00
|
|
|
handleClickActive = true
|
2024-09-03 16:26:54 +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-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,
|
2024-08-29 12:13:15 +01:00
|
|
|
private alertController: AlertController,
|
2024-09-01 14:27:32 +01:00
|
|
|
private http: HttpClient
|
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()
|
2024-08-29 12:13:15 +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-09-17 16:02:12 +01:00
|
|
|
this.room = {...this._room} as any
|
|
|
|
|
console.log('message', this.room)
|
|
|
|
|
if(this.room.local == IDBoolean.false) {
|
|
|
|
|
this.getMessages()
|
|
|
|
|
this.subscribeToChanges()
|
|
|
|
|
} else {
|
|
|
|
|
this.getMessages()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.roomData$ = this.RoomLocalRepository.getRoomByIdLive(this.room.$id)
|
2024-09-01 14:27:32 +01:00
|
|
|
|
|
|
|
|
this.roomData$.subscribe(e => {
|
|
|
|
|
if(e) {
|
2024-09-17 16:02:12 +01:00
|
|
|
this.room = new RoomViewModel(e)
|
|
|
|
|
this.roomType = e.roomType;
|
2024-09-01 14:27:32 +01:00
|
|
|
}
|
|
|
|
|
})
|
2024-09-17 16:02:12 +01:00
|
|
|
}
|
2024-09-01 14:27:32 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
subscribeToChanges() {
|
2024-08-14 15:29:16 +01:00
|
|
|
this.listenToIncomingMessage();
|
|
|
|
|
this.listenToDeleteMessage();
|
2024-08-13 10:52:35 +01:00
|
|
|
this.listenToUpdateMessage();
|
2024-08-20 16:34:47 +01:00
|
|
|
this.listenToSendMessage();
|
2024-08-06 16:53:13 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.roomMembers$ = this.MemberListLocalRepository.getRoomMemberByIdLive(this.room.id).pipe(
|
2024-08-20 16:34:47 +01:00
|
|
|
tap((members) => {
|
|
|
|
|
this.totalMembers = members.length
|
2024-08-26 09:59:30 +01:00
|
|
|
this.members = members
|
2024-08-23 11:10:52 +01:00
|
|
|
for(const member of members) {
|
|
|
|
|
if(member.wxUserId == SessionStore.user.UserId) {
|
|
|
|
|
this.isAdmin = member.isAdmin
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-20 16:34:47 +01:00
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.roomStatus$ = this.MemberListLocalRepository.allMemberOnline(this.room.id)
|
2024-08-26 09:59:30 +01:00
|
|
|
|
2024-08-23 11:10:52 +01:00
|
|
|
this.messageTypingSubject?.unsubscribe()
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messageTypingSubject = this.userTypingLocalRepository.getUserTypingLiveByRoomId(this.room.id).subscribe((e) => {
|
2024-08-23 11:10:52 +01:00
|
|
|
const arrayNames = e.filter((b)=> b.userId != SessionStore.user.UserId).map(e => e.userName)
|
2024-07-17 16:39:18 +01:00
|
|
|
this.userTyping$ = e as any
|
|
|
|
|
|
|
|
|
|
const uniqueArray = [...new Set(arrayNames)];
|
|
|
|
|
|
2024-08-23 11:10:52 +01:00
|
|
|
if(uniqueArray.length >= 1) {
|
|
|
|
|
(this.myInputRef.nativeElement as HTMLDivElement).innerHTML = uniqueArray + '...'
|
|
|
|
|
} else {
|
|
|
|
|
(this.myInputRef.nativeElement as HTMLDivElement).innerHTML = ''
|
|
|
|
|
}
|
2024-08-26 09:59:30 +01:00
|
|
|
|
2024-08-23 11:10:52 +01:00
|
|
|
}) as any
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.updateRoomDetails()
|
|
|
|
|
}
|
2024-08-27 15:42:11 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
|
|
|
|
|
updateRoomDetails() {
|
|
|
|
|
if(!this.room?.local) {
|
|
|
|
|
this.chatServiceService.getRoomById(this.room.id)
|
|
|
|
|
}
|
2024-08-13 10:52:35 +01:00
|
|
|
}
|
2024-06-13 12:11:17 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
removeBold() {
|
|
|
|
|
if(!this.room?.local) {
|
|
|
|
|
this.chatServiceService.removeBoldFromRoom({roomId: this.room.$id})
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-10 16:01:51 +01:00
|
|
|
|
|
|
|
|
@HostListener('document:click', ['$event'])
|
|
|
|
|
handleClickOutside(event: Event) {
|
|
|
|
|
if (!this.handleClickActive) return;
|
|
|
|
|
|
|
|
|
|
const clickedInside = (event.target as HTMLElement).closest('.mat-menu-content');
|
|
|
|
|
if (!clickedInside) {
|
|
|
|
|
this.selectedMessage = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
messageStatus(message: MessageViewModal) {
|
2024-08-20 16:34:47 +01:00
|
|
|
if(this.allViewed(message)) {
|
|
|
|
|
return 'allViewed'
|
|
|
|
|
} else if(this.allReceived(message)) {
|
|
|
|
|
return 'allReceived'
|
|
|
|
|
} else if (message.messageStatus == 'send') {
|
|
|
|
|
return 'enviado'
|
|
|
|
|
} else {
|
|
|
|
|
return 'enviar'
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-10 16:01:51 +01:00
|
|
|
allReceived(message: MessageViewModal) {
|
2024-08-20 16:34:47 +01:00
|
|
|
return message.info.filter(e => typeof e.deliverAt == 'string').length == this.totalMembers
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-10 16:01:51 +01:00
|
|
|
allViewed(message: MessageViewModal) {
|
2024-08-26 09:59:30 +01:00
|
|
|
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-20 16:34:47 +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
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id] = []
|
|
|
|
|
let messages = await this.chatServiceService.messageLocalGetById({
|
|
|
|
|
roomId: this.room.id,
|
|
|
|
|
receiverId: this.room?.receiverId?.toString()
|
|
|
|
|
})
|
2024-09-03 16:26:54 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
if(messages.isOk()) {
|
|
|
|
|
this.messages1[this.room.$id] = []
|
|
|
|
|
this.date = {}
|
|
|
|
|
const allMessage = [];
|
2024-09-03 16:26:54 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
console.time("mappingTime");
|
|
|
|
|
const sortMessages = messages.value.sort((a, b) => new Date(a.sentAt).getTime() - new Date(b.sentAt).getTime())
|
2024-09-03 16:26:54 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
for(const message of sortMessages) {
|
|
|
|
|
const date = whatsappDate(message.sentAt, false)
|
|
|
|
|
if(!this.date[date]) {
|
|
|
|
|
this.date[date] = true
|
|
|
|
|
const Ballon = XBallon(message)
|
|
|
|
|
allMessage.push(Ballon)
|
|
|
|
|
}
|
2024-09-03 16:26:54 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
allMessage.push(new MessageViewModal(message))
|
|
|
|
|
}
|
|
|
|
|
console.timeEnd("mappingTime");
|
|
|
|
|
this.messages1[this.room.$id]
|
|
|
|
|
this.messages1[this.room.$id] = allMessage
|
2024-09-05 11:45:54 +01:00
|
|
|
|
2024-08-18 13:27:57 +01:00
|
|
|
|
2024-08-13 17:05:46 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
// if(messages.length >= 1) {
|
|
|
|
|
// this.messages1[this.room.$id].push(LastMessage)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
this.loadAttachment()
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.sendReadMessage()
|
|
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
|
|
if(this.room.$id) {
|
|
|
|
|
this.onReconnectGetMessages()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-14 15:29:16 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
onReconnectGetMessages() {
|
2024-08-27 15:42:11 +01:00
|
|
|
this.messageOnReconnectSubject?.unsubscribe()
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messageOnReconnectSubject = this.chatServiceService.listenToMessageLoadHistory({roomId: this.room.id}).subscribe((messages) => {
|
2024-09-01 12:57:33 +01:00
|
|
|
|
2024-08-27 15:42:11 +01:00
|
|
|
for(const message of messages.data) {
|
2024-09-17 16:02:12 +01:00
|
|
|
const found = this.messages1[this.room.$id].find((e) => e.id == message.id)
|
2024-08-27 15:42:11 +01:00
|
|
|
|
|
|
|
|
if(!found) {
|
2024-09-03 16:26:54 +01:00
|
|
|
const msg = new MessageViewModal(message as any)
|
2024-08-27 15:42:11 +01:00
|
|
|
Object.assign(msg, message)
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(msg)
|
2024-08-27 15:42:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-12 14:50:10 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].sort((a, b) => {
|
2024-09-12 14:50:10 +01:00
|
|
|
return new Date(a.sentAt).getTime() - new Date(b.sentAt).getTime()
|
|
|
|
|
})
|
2024-08-27 15:42:11 +01:00
|
|
|
})
|
2024-08-13 17:05:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async loadAttachment() {
|
2024-09-17 16:02:12 +01:00
|
|
|
for(const message of this.messages1[this.room.$id]) {
|
2024-09-04 10:58:26 +01:00
|
|
|
if(message.hasAttachment && message.attachments[0].source != MessageAttachmentSource.Webtrix) {
|
2024-08-14 15:29:16 +01:00
|
|
|
|
2024-09-05 11:45:54 +01:00
|
|
|
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-08-17 22:05:57 +01:00
|
|
|
}
|
2024-09-05 11:45:54 +01:00
|
|
|
}
|
|
|
|
|
})
|
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-09-10 16:01:51 +01:00
|
|
|
async onImageLoad(message: MessageViewModal, index:number) {
|
2024-08-17 22:05:57 +01:00
|
|
|
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)
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].splice(index, 1);
|
2024-08-17 22:05:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
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-09-10 16:01:51 +01:00
|
|
|
async viewOnce(event: Event, message: MessageViewModal, index:number) {
|
2024-08-22 12:27:57 +01:00
|
|
|
const params: ViewOncesImagePageInput = {
|
|
|
|
|
imageDataUrl: message.attachments[index].safeFile as any,
|
|
|
|
|
}
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: ViewOncesImagePage,
|
|
|
|
|
cssClass: '',
|
|
|
|
|
componentProps: params
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modal.present()
|
|
|
|
|
|
|
|
|
|
return modal.onDidDismiss().then((res) => {
|
|
|
|
|
this.messageDelete(message)
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-08-14 15:29:16 +01:00
|
|
|
|
2024-08-20 16:34:47 +01:00
|
|
|
sendReadMessage() {
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
if(this.room.local == IDBoolean.false) {
|
|
|
|
|
for(const message of this.messages1[this.room.$id]) {
|
2024-08-20 16:34:47 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
if(!message.meSender()) {
|
|
|
|
|
const me = message.haveSeen(message.info)
|
2024-08-20 16:34:47 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
if(!me) {
|
|
|
|
|
Logger.info('send read at, sender '+ message.sender.wxFullName+ ' '+ message.message +'message id'+ message.id)
|
2024-08-22 12:28:25 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.chatServiceService.sendReadAt({
|
|
|
|
|
memberId: SessionStore.user.UserId,
|
|
|
|
|
messageId: message.id,
|
|
|
|
|
requestId: '',
|
|
|
|
|
roomId: this.room.$id
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-09-03 16:26:54 +01:00
|
|
|
}
|
2024-08-20 16:34:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
listenToIncomingMessage() {
|
|
|
|
|
this.messageReceiveSubject?.unsubscribe();
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messageReceiveSubject = this.chatServiceService.listenToIncomingMessage(this.room.id).subscribe(async (_message) => {
|
2024-08-27 09:14:59 +01:00
|
|
|
|
2024-09-05 11:45:54 +01:00
|
|
|
const date = whatsappDate(_message.sentAt, false)
|
2024-09-04 10:58:26 +01:00
|
|
|
if(!this.date[date]) {
|
|
|
|
|
this.date[date] = true
|
2024-09-05 11:45:54 +01:00
|
|
|
const Ballon = XBallon(_message)
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(Ballon)
|
2024-09-04 10:58:26 +01:00
|
|
|
}
|
|
|
|
|
|
2024-09-05 11:45:54 +01:00
|
|
|
const message = new MessageViewModal(_message)
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(new MessageViewModal(message))
|
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-09-05 11:45:54 +01:00
|
|
|
$messageId: message.id,
|
2024-08-14 15:29:16 +01:00
|
|
|
id: message.attachments[0].id
|
|
|
|
|
})
|
|
|
|
|
|
2024-09-05 11:45:54 +01:00
|
|
|
if(result.isOk()) {
|
2024-08-14 15:29:16 +01:00
|
|
|
message.attachments[0].safeFile = result.value
|
2024-09-05 11:45:54 +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-08-30 12:41:50 +01:00
|
|
|
|
2024-09-02 12:33:43 +01:00
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2024-09-17 16:02:12 +01:00
|
|
|
this.removeBold()
|
2024-09-02 12:33:43 +01:00
|
|
|
}, 1000)
|
2024-08-13 10:52:35 +01:00
|
|
|
});
|
2024-09-01 12:57:33 +01:00
|
|
|
|
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();
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messageDeleteSubject = this.chatServiceService.listenToDeleteMessage(this.room.id).subscribe((deleteMessage) => {
|
2024-08-13 10:52:35 +01:00
|
|
|
console.log('delete class', deleteMessage);
|
2024-06-13 12:11:17 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
const index = this.messages1[this.room.$id].findIndex(e =>
|
2024-09-10 16:01:51 +01:00
|
|
|
typeof e?.id == 'string' && e?.id === deleteMessage.id ||
|
|
|
|
|
typeof e?.requestId == 'string' && e?.requestId == deleteMessage.requestId);
|
|
|
|
|
|
|
|
|
|
try {
|
2024-09-17 16:02:12 +01:00
|
|
|
console.log(this.messages1[this.room.$id][index])
|
|
|
|
|
this.messages1[this.room.$id][index].delete()
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('delete', e)
|
|
|
|
|
}
|
2024-09-10 16:01:51 +01:00
|
|
|
|
2024-08-27 09:14:59 +01:00
|
|
|
// if (index !== -1) { // Check if the item was found
|
|
|
|
|
// console.log('delete ==')
|
2024-09-17 16:02:12 +01:00
|
|
|
// this.messages1[this.room.$id].splice(index, 1);
|
2024-08-27 09:14:59 +01:00
|
|
|
// // console.log('removed index', index);
|
|
|
|
|
// } else {
|
|
|
|
|
// // console.log('message not found');
|
|
|
|
|
// }
|
2024-08-13 10:52:35 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listenToUpdateMessage() {
|
|
|
|
|
this.messageUpdateSubject?.unsubscribe();
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
console.log('liste to update')
|
|
|
|
|
this.messageUpdateSubject = this.chatServiceService.listenToUpdateMessage(this.room.id).subscribe((updateMessage) => {
|
2024-08-13 10:52:35 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
const index = this.messages1[this.room.$id].findIndex(e => e?.id === updateMessage.id); // Use triple equals for comparison
|
|
|
|
|
|
|
|
|
|
console.log('updateMessage', updateMessage)
|
2024-08-13 10:52:35 +01:00
|
|
|
|
|
|
|
|
if (index !== -1) { // Check if the item was found
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id][index].info = updateMessage.info
|
|
|
|
|
this.messages1[this.room.$id][index].message = updateMessage.message
|
|
|
|
|
this.messages1[this.room.$id][index].reactions = updateMessage.reactions
|
2024-08-13 10:52:35 +01:00
|
|
|
} else {
|
|
|
|
|
// console.log('message not found');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listenToSendMessage() {
|
|
|
|
|
this.messageSendSubject?.unsubscribe();
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messageSendSubject = this.chatServiceService.listenToSendMessage(this.room.id).subscribe((updateMessage) => {
|
2024-08-13 10:52:35 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
const index = this.messages1[this.room.$id].findIndex(e => e?.requestId === updateMessage.requestId); // Use triple equals for comparison
|
2024-08-13 10:52:35 +01:00
|
|
|
|
|
|
|
|
if (index !== -1) { // Check if the item was found
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id][index].id = updateMessage.id
|
|
|
|
|
this.messages1[this.room.$id][index].info = updateMessage.info
|
2024-08-13 10:52:35 +01:00
|
|
|
|
2024-08-13 17:05:46 +01:00
|
|
|
let attachmentIndex = 0;
|
|
|
|
|
|
|
|
|
|
for(const message of updateMessage.attachments) {
|
2024-08-20 16:34:47 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id][index].attachments[attachmentIndex].id = message.id
|
2024-08-13 17:05:46 +01:00
|
|
|
attachmentIndex++;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
} else {
|
2024-08-27 09:14:59 +01:00
|
|
|
console.log('not found message to update ui');
|
2024-08-13 10:52:35 +01:00
|
|
|
}
|
|
|
|
|
});
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-27 15:42:11 +01:00
|
|
|
onDisConnect() {}
|
2024-08-02 11:34:57 +01:00
|
|
|
|
2024-09-10 16:01:51 +01:00
|
|
|
toggleEmojiPicker(message: MessageViewModal) {
|
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-09-10 16:01:51 +01:00
|
|
|
addReaction(message: MessageViewModal, 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-09-17 16:02:12 +01:00
|
|
|
roomId: this.room.id,
|
2024-08-02 11:34:57 +01:00
|
|
|
reaction: emoji,
|
|
|
|
|
requestId: ''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 12:40:34 +01:00
|
|
|
|
2024-07-31 17:23:44 +01:00
|
|
|
sendReadAt() {
|
2024-09-17 16:02:12 +01:00
|
|
|
// this.chatServiceService.messageMarkAsRead({roomId: this.room.$id}).then((e) => {
|
2024-08-20 16:34:47 +01:00
|
|
|
// console.log(e)
|
|
|
|
|
// })
|
2024-07-31 17:23:44 +01:00
|
|
|
}
|
2024-08-02 11:34:57 +01:00
|
|
|
|
2024-07-17 16:39:18 +01:00
|
|
|
sendTyping() {
|
2024-09-17 16:02:12 +01:00
|
|
|
if(this.room.local == IDBoolean.false) {
|
|
|
|
|
this.UserTypingRemoteRepositoryService.sendTyping(this.room.id)
|
|
|
|
|
}
|
2024-07-17 16:39:18 +01:00
|
|
|
}
|
2024-03-07 12:02:59 +01:00
|
|
|
|
2024-09-10 16:01:51 +01:00
|
|
|
async editMessage(message: MessageViewModal) {
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-09-10 16:01:51 +01:00
|
|
|
const modal = await this.popoverController.create({
|
2024-08-02 12:40:34 +01:00
|
|
|
component: EditMessagePage,
|
2024-09-10 16:01:51 +01:00
|
|
|
cssClass: 'edit-message',
|
2022-09-29 12:17:00 +01:00
|
|
|
componentProps: {
|
2024-08-02 12:40:34 +01:00
|
|
|
message: message.message,
|
2024-09-17 16:02:12 +01:00
|
|
|
roomId: this.room.$id,
|
2022-09-29 12:17:00 +01:00
|
|
|
}
|
|
|
|
|
});
|
2024-08-02 12:40:34 +01:00
|
|
|
|
|
|
|
|
modal.present()
|
|
|
|
|
|
|
|
|
|
return modal.onDidDismiss().then((res) => {
|
|
|
|
|
|
2024-09-10 21:45:46 +01:00
|
|
|
if(res.data) {
|
|
|
|
|
this.chatServiceService.updateMessage({
|
|
|
|
|
memberId: SessionStore.user.UserId,
|
|
|
|
|
message: res.data.message,
|
|
|
|
|
messageId: message.id,
|
|
|
|
|
requestId: '',
|
2024-09-17 16:02:12 +01:00
|
|
|
roomId: this.room.id
|
2024-09-10 21:45:46 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 12:40:34 +01:00
|
|
|
});
|
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-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-03-12 11:56:54 +01:00
|
|
|
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
doRefresh(ev: any) {
|
2024-09-17 16:02:12 +01:00
|
|
|
// ev.target.complete();
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
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);
|
2024-09-10 16:01:51 +01:00
|
|
|
this.handleClickActive = false; // Disable the listener before component destruction
|
2024-08-09 14:56:36 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
createMessage() {
|
2024-09-03 16:26:54 +01:00
|
|
|
const message = new MessageViewModal();
|
2024-09-17 16:02:12 +01:00
|
|
|
|
|
|
|
|
if(this.room.id) {
|
|
|
|
|
message.roomId = this.room.id
|
|
|
|
|
} else {
|
|
|
|
|
message.roomId = this.room.$id
|
|
|
|
|
}
|
2024-08-09 14:56:36 +01:00
|
|
|
|
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-09-17 16:02:12 +01:00
|
|
|
message.sentAt = new Date().toISOString()
|
|
|
|
|
if(this.room.receiverId) {
|
|
|
|
|
message.receiverId = this.room.receiverId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return message
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async messageResult(result: Promise<Result<MessageOutPutDataDTO, any>> ) {
|
|
|
|
|
let message = await result
|
|
|
|
|
|
|
|
|
|
console.log('result', message)
|
|
|
|
|
|
|
|
|
|
if(message.isOk() && this.room.local == IDBoolean.true) {
|
|
|
|
|
this.room.local = IDBoolean.false;
|
|
|
|
|
|
|
|
|
|
// console.log('enter')
|
|
|
|
|
// await this.chatServiceService.roomSetLocalToFalseById({
|
|
|
|
|
// $roomId: this.room.$id,
|
|
|
|
|
// roomId: message.value.roomId
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
this.room.id = message.value.roomId
|
|
|
|
|
this.subscribeToChanges()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async sendAudio(fileName) {
|
|
|
|
|
const roomId = this.room.$id
|
|
|
|
|
//Converting base64 to blob
|
|
|
|
|
const encodedData = this.audioRecordedDataUrl;
|
|
|
|
|
|
|
|
|
|
const message = this.createMessage();
|
|
|
|
|
|
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-09-04 10:58:26 +01:00
|
|
|
|
|
|
|
|
const date = whatsappDate(message.sentAt, false)
|
|
|
|
|
if(!this.date[date]) {
|
|
|
|
|
this.date[date] = true
|
|
|
|
|
const Ballon = XBallon(message)
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(Ballon)
|
2024-09-04 10:58:26 +01:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(message)
|
|
|
|
|
let sendMessage = this.chatServiceService.sendMessage(message, this.roomType)
|
|
|
|
|
this.messageResult(sendMessage)
|
2024-09-04 10:58:26 +01:00
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
async sendMessage() {
|
2024-06-05 10:28:38 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
const message = this.createMessage();
|
2024-08-07 11:18:41 +01:00
|
|
|
message.message = this.textField
|
2024-06-05 10:28:38 +01:00
|
|
|
|
2024-06-13 12:11:17 +01:00
|
|
|
this.textField = ''
|
2024-09-04 10:58:26 +01:00
|
|
|
|
|
|
|
|
const date = whatsappDate(message.sentAt, false)
|
|
|
|
|
if(!this.date[date]) {
|
|
|
|
|
this.date[date] = true
|
|
|
|
|
const Ballon = XBallon(message)
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(Ballon)
|
2024-09-04 10:58:26 +01:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(message)
|
2024-08-13 10:52:35 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-09-17 16:02:12 +01:00
|
|
|
let sendMessage = this.chatServiceService.sendMessage(message, this.roomType)
|
|
|
|
|
this.messageResult(sendMessage)
|
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
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
async openViewDocumentModal(msg: MessageViewModal) {
|
|
|
|
|
|
|
|
|
|
console.log('passing', msg)
|
2021-10-09 20:24:34 +01:00
|
|
|
let task = {
|
|
|
|
|
serialNumber: '',
|
|
|
|
|
taskStartDate: '',
|
|
|
|
|
isEvent: true,
|
|
|
|
|
workflowInstanceDataFields: {
|
|
|
|
|
FolderID: '',
|
2024-09-11 12:16:05 +01:00
|
|
|
Subject: msg.attachments[0].description,
|
|
|
|
|
SourceSecFsID: msg.attachments[0].applicationId,
|
2021-10-09 20:24:34 +01:00
|
|
|
SourceType: 'DOC',
|
2024-09-11 12:16:05 +01:00
|
|
|
SourceID: msg.attachments[0].docId,
|
2021-10-09 20:24:34 +01:00
|
|
|
DispatchNumber: ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let doc = {
|
2021-12-16 16:36:39 +01:00
|
|
|
"Id": "",
|
|
|
|
|
"ParentId": "",
|
|
|
|
|
"Source": 1,
|
2024-09-11 12:16:05 +01:00
|
|
|
"ApplicationId": msg.attachments[0].applicationId,
|
2021-12-16 16:36:39 +01:00
|
|
|
"CreateDate": "",
|
|
|
|
|
"Data": null,
|
|
|
|
|
"Description": "",
|
|
|
|
|
"Link": null,
|
2024-09-11 12:16:05 +01:00
|
|
|
"SourceId": msg.attachments[0].docId,
|
|
|
|
|
"SourceName": msg.attachments[0].description,
|
2021-12-16 16:36:39 +01:00
|
|
|
"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: {
|
2024-09-11 12:16:05 +01:00
|
|
|
title: msg.attachments[0].description,
|
2021-10-09 20:24:34 +01:00
|
|
|
url: '',
|
|
|
|
|
title_link: '',
|
|
|
|
|
},
|
|
|
|
|
Document: doc,
|
2024-09-11 12:16:05 +01:00
|
|
|
applicationId: msg.attachments[0].applicationId,
|
|
|
|
|
docId: msg.attachments[0].docId,
|
2021-10-09 20:24:34 +01:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
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: {
|
2024-09-17 16:02:12 +01:00
|
|
|
roomId: this.room.id,
|
2024-06-10 16:34:43 +01:00
|
|
|
members: [],
|
2024-09-17 16:02:12 +01:00
|
|
|
isAdmin: true,
|
2024-09-01 14:27:32 +01:00
|
|
|
roomType: this.roomType
|
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-09-17 16:02:12 +01:00
|
|
|
// this.ChatSystemService.hidingRoom(this.room.$id).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();
|
2024-09-17 16:02:12 +01:00
|
|
|
this.openEditGroupPage.emit(this.room.$id);
|
2024-06-10 16:34:43 +01:00
|
|
|
} else if (res.data == 'addUser') {
|
|
|
|
|
|
|
|
|
|
this.openGroupContactsPage();
|
|
|
|
|
}
|
|
|
|
|
else {}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openGroupContactsPage() {
|
2024-09-17 17:28:50 +01:00
|
|
|
this.openGroupContacts.emit(this.room.id);
|
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-22 12:27:57 +01:00
|
|
|
const oneShot = await this.askIfOneShot()
|
|
|
|
|
|
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-09-17 16:02:12 +01:00
|
|
|
const message = this.createMessage();
|
2022-02-11 15:08:27 +01:00
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
message.oneShot = oneShot
|
2024-08-14 15:29:16 +01:00
|
|
|
|
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-09-04 10:58:26 +01:00
|
|
|
|
|
|
|
|
const date = whatsappDate(message.sentAt, false)
|
|
|
|
|
if(!this.date[date]) {
|
|
|
|
|
this.date[date] = true
|
|
|
|
|
const Ballon = XBallon(message)
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(Ballon)
|
2024-09-04 10:58:26 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-09-17 16:02:12 +01:00
|
|
|
let sendMessage = this.chatServiceService.sendMessage(message, this.roomType)
|
|
|
|
|
this.messageResult(sendMessage)
|
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;
|
|
|
|
|
|
2024-09-04 12:15:44 +01:00
|
|
|
console.log(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-09-17 16:02:12 +01:00
|
|
|
const message = this.createMessage();
|
2024-08-09 12:36:51 +01:00
|
|
|
message.message = this.textField
|
2024-08-14 15:29:16 +01:00
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
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,
|
2024-09-11 12:16:05 +01:00
|
|
|
docId: parseInt(res.data.selected.Id) ,
|
2024-09-04 12:15:44 +01:00
|
|
|
description: res.data.selected.Assunto
|
2024-08-09 12:36:51 +01:00
|
|
|
}]
|
|
|
|
|
|
2024-09-04 10:58:26 +01:00
|
|
|
const date = whatsappDate(message.sentAt, false)
|
|
|
|
|
if(!this.date[date]) {
|
|
|
|
|
this.date[date] = true
|
|
|
|
|
const Ballon = XBallon(message)
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(Ballon)
|
2024-09-04 10:58:26 +01:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(message)
|
2024-08-13 10:52:35 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-09-17 16:02:12 +01:00
|
|
|
let sendMessage = this.chatServiceService.sendMessage(message, this.roomType)
|
|
|
|
|
this.messageResult(sendMessage)
|
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-22 12:27:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
askIfOneShot(): Promise<boolean> {
|
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
|
const alert = await this.alertController.create({
|
|
|
|
|
header: 'Confirm',
|
|
|
|
|
message: 'Visualização unica?',
|
|
|
|
|
buttons: [
|
|
|
|
|
{
|
|
|
|
|
text: 'não',
|
|
|
|
|
role: 'cancel',
|
|
|
|
|
handler: () => {
|
|
|
|
|
resolve(false)
|
|
|
|
|
console.log('User clicked No');
|
|
|
|
|
// Handle No action here
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: 'Sim',
|
|
|
|
|
handler: () => {
|
|
|
|
|
console.log('User clicked Yes');
|
|
|
|
|
resolve(true)
|
|
|
|
|
// Handle Yes action here
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-26 09:59:30 +01:00
|
|
|
|
2024-08-22 12:27:57 +01:00
|
|
|
await alert.present();
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 12:36:51 +01:00
|
|
|
async pickPicture() {
|
2022-02-09 13:59:41 +01:00
|
|
|
|
2024-08-22 12:27:57 +01:00
|
|
|
const oneShot = await this.askIfOneShot()
|
|
|
|
|
|
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-09-17 16:02:12 +01:00
|
|
|
const message = this.createMessage();
|
2024-08-22 12:27:57 +01:00
|
|
|
message.oneShot = oneShot
|
2024-08-14 15:29:16 +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-09-04 10:58:26 +01:00
|
|
|
const date = whatsappDate(message.sentAt, false)
|
|
|
|
|
if(!this.date[date]) {
|
|
|
|
|
this.date[date] = true
|
|
|
|
|
const Ballon = XBallon(message)
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(Ballon)
|
2024-09-04 10:58:26 +01:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(message)
|
2024-08-13 10:52:35 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-09-17 16:02:12 +01:00
|
|
|
let sendMessage = this.chatServiceService.sendMessage(message, this.roomType)
|
|
|
|
|
this.messageResult(sendMessage)
|
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-09-10 16:01:51 +01:00
|
|
|
messageDelete(message: MessageViewModal) {
|
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-09-17 16:02:12 +01:00
|
|
|
roomId: this.room.id,
|
2024-07-31 17:23:44 +01:00
|
|
|
})
|
|
|
|
|
}
|
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-09-17 16:02:12 +01:00
|
|
|
const message = this.createMessage();
|
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,
|
2024-09-10 16:01:51 +01:00
|
|
|
mimeType: file.value.type,
|
|
|
|
|
description: file.value.name
|
2024-08-09 10:50:32 +01:00
|
|
|
}]
|
2023-09-06 21:23:21 +01:00
|
|
|
|
2024-09-04 10:58:26 +01:00
|
|
|
const date = whatsappDate(message.sentAt, false)
|
|
|
|
|
if(!this.date[date]) {
|
|
|
|
|
this.date[date] = true
|
|
|
|
|
const Ballon = XBallon(message)
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(Ballon)
|
2024-09-04 10:58:26 +01:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 16:02:12 +01:00
|
|
|
this.messages1[this.room.$id].push(message)
|
2024-08-13 10:52:35 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottomClicked()
|
|
|
|
|
}, 100)
|
2024-09-17 16:02:12 +01:00
|
|
|
let sendMessage = this.chatServiceService.sendMessage(message, this.roomType)
|
|
|
|
|
this.messageResult(sendMessage)
|
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() {
|
2024-09-17 16:02:12 +01:00
|
|
|
const roomId = this.room.$id;
|
2022-02-03 21:01:53 +01:00
|
|
|
|
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: {
|
2024-09-17 16:02:12 +01:00
|
|
|
roomId: this.room.$id,
|
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 = {
|
2024-09-17 16:02:12 +01:00
|
|
|
roomId: this.room.$id,
|
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
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
downloadFileFromBrowser(fileName: string, msg: MessageViewModal): void {
|
2024-03-18 12:59:41 +01:00
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
if(msg.attachments[0]?.blobURl) {
|
|
|
|
|
// Create a temporary URL for the Blob
|
|
|
|
|
const url = msg.attachments[0].safeFile;
|
2024-03-18 12:59:41 +01:00
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
// Create an <a> element with the download attribute
|
|
|
|
|
const a = document.createElement('a');
|
|
|
|
|
a.href = url;
|
|
|
|
|
a.download = fileName; // Set the desired file name
|
2022-03-31 11:56:49 +01:00
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
a.click();
|
|
|
|
|
} else {
|
|
|
|
|
const link = document.createElement("a")
|
|
|
|
|
link.href = `data:${msg.attachments[0].mimeType}';base64,${msg.attachments[0].safeFile}`;
|
|
|
|
|
link.download = fileName
|
|
|
|
|
link.click()
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
link.remove()
|
2022-04-06 16:25:47 +01:00
|
|
|
}
|
2024-09-11 12:16:05 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
viewDocument(msg: MessageViewModal) {
|
|
|
|
|
this.openViewDocumentModal(msg);
|
2022-04-06 16:25:47 +01:00
|
|
|
}
|
2022-02-25 15:10:10 +01:00
|
|
|
|
2024-09-11 12:38:25 +01:00
|
|
|
openFile(blob: Blob, filename, type) {
|
2022-04-06 17:35:44 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
async openPreview(msg: MessageViewModal) {
|
2022-03-31 11:56:49 +01:00
|
|
|
|
2022-07-06 09:59:22 +01:00
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
console.log(msg)
|
|
|
|
|
if (msg.attachments[0].source === MessageAttachmentSource.Webtrix) {
|
|
|
|
|
this.viewDocument(msg)
|
2022-04-06 16:25:47 +01:00
|
|
|
} else {
|
|
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
if (!msg.attachments[0].safeFile || msg.attachments[0].safeFile === null || msg.attachments[0].safeFile === '') {
|
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
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
var str = msg.attachments[0].safeFile
|
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
|
|
|
|
2024-09-11 12:16:05 +01:00
|
|
|
if (msg.attachments[0].mimeType.includes('image')) {
|
2022-07-06 09:59:22 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: ViewMediaPage,
|
|
|
|
|
cssClass: 'modal modal-desktop',
|
|
|
|
|
componentProps: {
|
2024-09-11 12:16:05 +01:00
|
|
|
image: msg.attachments[0].safeFile,
|
|
|
|
|
type: msg.attachments[0].mimeType,
|
|
|
|
|
username: msg.attachments[0].description,
|
|
|
|
|
_updatedAt: msg.sentAt
|
2022-07-06 09:59:22 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
modal.present();
|
|
|
|
|
} else {
|
2024-09-11 12:16:05 +01:00
|
|
|
this.downloadFileFromBrowser(msg.attachments[0].description, msg)
|
2022-07-06 09:59:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-08-20 16:34:47 +01:00
|
|
|
|
|
|
|
|
closeModal(a: any) {
|
|
|
|
|
|
|
|
|
|
}
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
2021-03-12 11:56:54 +01:00
|
|
|
|
2021-11-22 13:53:37 +01:00
|
|
|
|
|
|
|
|
|