fix open pdf and member list

This commit is contained in:
Peter Maquiran
2024-09-19 23:36:59 +01:00
parent 1f08eb5514
commit 9da65a1e7b
18 changed files with 215 additions and 53 deletions
+12 -2
View File
@@ -7,7 +7,7 @@ import { ModalController } from '@ionic/angular';
import { GroupMessagesPage } from './modal/group-messages/group-messages.page';
import { ContactsPage } from './modal/./messages/contacts/contacts.page';
import { MessagesPage } from './modal/./messages/messages.page';
import { NewGroupPage } from './modal/./new-group/new-group.page';
import { INewGroupModalOutPut, NewGroupPage } from './modal/./new-group/new-group.page';
import { Observable, Subject } from "rxjs/Rx";
import { Router, NavigationEnd } from '@angular/router';
import { TimeService } from 'src/app/services/functions/time.service';
@@ -476,7 +476,17 @@ export class ChatPage implements OnInit {
cssClass: 'modal modal-desktop',
});
await modal.present();
modal.onDidDismiss();
modal.onDidDismiss<INewGroupModalOutPut>().then((event) => {
if(event.data?.roomId) {
const room = this.rooms.find(e => e.id == (event.data.roomId))
if(room) {
this.openMessagesPage(room.$id)
} else {
Logger.error('Cant find room after creating chat.page.ts/newGroup')
}
}
})
}
async editGroup(roomId) {
@@ -23,7 +23,7 @@
<ion-list class="header-bottom-contacts" *ngIf="roomMembers$ | async as memberList" >
<ng-container *ngFor="let user of memberList; let i = index">
<span > {{ user.wxFullName }}<ng-container *ngIf="i < memberList.length - 1">, </ng-container> </span>
<span *ngIf="roomType == RoomTypeEnum.Group"> {{ user.wxFullName }}<ng-container *ngIf="i < memberList.length - 1">, </ng-container> </span>
</ng-container>
</ion-list>
@@ -230,6 +230,18 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
stop() {
this.messageReceiveSubject?.unsubscribe();
this.messageDeleteSubject?.unsubscribe();
this.messageUpdateSubject?.unsubscribe();
this.messageSendSubject?.unsubscribe();
this.messageTypingSubject?.unsubscribe();
this.messageOnReconnectSubject?.unsubscribe();
this.messageOnSetRoomId?.unsubscribe();
this.newMessagesStream?.unsubscribe();
}
subscribeToChanges() {
this.listenToIncomingMessage();
this.listenToDeleteMessage();
@@ -479,6 +491,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
}
//this.sendReadMessage()
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)
@@ -695,6 +709,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
// window.addEventListener('scroll', this.scrollChangeCallback, true);
}
ngOnDestroy() {
// this.stop()
window.removeEventListener('scroll', this.scrollChangeCallback, true);
this.handleClickActive = false; // Disable the listener before component destruction
}
@@ -17,8 +17,9 @@
.buttons{
display: flex;
flex-wrap: wrap;
justify-content: space-around;
flex-direction: column;
align-items: center;
justify-content: center;
}
.solid {
display: block;
@@ -16,6 +16,7 @@
</div>
</div>
</ion-toolbar>
<ion-progress-bar type="indeterminate" *ngIf="showLoader"></ion-progress-bar>
</ion-header>
<ion-content>
@@ -38,7 +39,7 @@
</div>
</div>
</div>
</div>
</div>
</ion-content>
@@ -1,7 +1,11 @@
import { HttpErrorResponse } from '@angular/common/http';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams, PickerController } from '@ionic/angular';
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { ThemeService } from 'src/app/services/theme.service'
import { ToastService } from 'src/app/services/toast.service';
import { ZodError } from 'zod';
@Component({
selector: 'app-edit-group',
@@ -21,7 +25,10 @@ export class EditGroupPage implements OnInit {
private modalController: ModalController,
private pickerController: PickerController,
private navParams: NavParams,
public ThemeService: ThemeService
public ThemeService: ThemeService,
private httpErrorHandle: HttpErrorHandle,
private toastService: ToastService,
private chatServiceService: ChatServiceService,
) {
this.roomId = this.navParams.get('roomId');
}
@@ -39,17 +46,27 @@ export class EditGroupPage implements OnInit {
this.modalController.dismiss();
}
changeGroupName(){
if(this.groupName.trim().length > 1){
let name = this.groupName.split(' ').join('-');
let body = {
"roomId": this.room._id,
"name": name,
}
}
else{
async changeGroupName() {
this.showLoader = true
const result = await this.chatServiceService.updateRoomById({
roomId: this.roomId,
roomName: this.groupName,
roomType: 0
})
if(result.isOk()) {
this.modalController.dismiss();
} else if (result.error instanceof HttpResponse) {
this.httpErrorHandle.httpStatusHandle(result.error)
} else if (result.error instanceof ZodError) {
this.toastService._badRequest("Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico.")
console.log(result.error.errors)
} else {
this.toastService._badRequest("Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico.")
console.log(result.error)
}
this.showLoader = false
}
_ionChange(event){
this.showDuration = event.detail.checked;
@@ -2,8 +2,6 @@ import { HttpClient, HttpErrorResponse, HttpHeaders, HttpRequest, HttpResponse }
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';
import * as _ from 'lodash';
import { AuthService } from 'src/app/services/auth.service';
import { GroupMessagesPage } from '../group-messages.page';
import { ThemeService } from 'src/app/services/theme.service'
import { SessionStore } from 'src/app/store/session.service';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
@@ -12,7 +10,12 @@ import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/m
import { UserContacts } from 'src/app/services/Repositorys/contacts/data-source/contacts-data-source.service';
import { ToastService } from 'src/app/services/toast.service';
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service';
import { ZodError } from 'zod';
import { z, ZodError } from 'zod';
const GroupContactsPageOutPutSchema = z.object({
roomId: z.string().optional()
})
export type IGroupContactsPageOutPutSchema = z.infer<typeof GroupContactsPageOutPutSchema>
@Component({
@@ -11,7 +11,7 @@
</div>
<div class="div-title">
<!-- MOBILE -->
<ion-label class="title">Nova Conversa ..</ion-label>
<ion-label class="title">Nova Conversa</ion-label>
</div>
</div>
</div>
@@ -21,7 +21,7 @@
<fa-icon (click)="deleteMessage(selectedMsgId)" icon="trash" class="middle-container-options-icons"></fa-icon>
<!-- <ion-icon name="trash"></ion-icon> -->
</div>
<div class="right" *ngIf="roomType == RoomTypeEnum.Group">
<div class="right" *ngIf="RoomStore.room.roomType == RoomTypeEnum.Group">
<button class="btn-no-color" (click)="openMessagesOptions()">
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " src="assets/images/theme/blue/icons-menu.svg"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " src="assets/images/theme/gov/icons-menu.svg">
@@ -29,8 +29,8 @@
</button>
</div>
</div>
<div class="header-bottom">
<div class="header-bottom-icon" *ngIf="roomType == RoomTypeEnum.Group">
<div class="header-bottom d-flex">
<div class="header-bottom-icon" *ngIf="RoomStore.room.roomType == RoomTypeEnum.Group">
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " src="assets/icon/icons-user.svg"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " src="assets/icon/theme/gov/icons-user.svg"></ion-icon>
</div>
@@ -44,6 +44,8 @@ import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { FileSystemMobileService } from 'src/app/infra/file-system/mobile/file-system-mobile.service';
import { RoomViewModel } from '../../store/model/room';
import { RoomStore } from '../../store/roomStore'
import { GroupContactsPage, IGroupContactsPageOutPutSchema } from '../group-messages/group-contacts/group-contacts.page';
import { EditGroupPage } from '../edit-group/edit-group.page';
const IMAGE_DIR = 'stored-images';
@@ -101,7 +103,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
selectedMessage: any = null;
emojis: string[] = ['😊', '😂', '❤️', '👍', '😢']; // Add more emojis as needed
textField = ''
roomType!: RoomType
MessageAttachmentFileType = MessageAttachmentFileType
MessageAttachmentFileSource = MessageAttachmentSource
@@ -140,6 +141,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.RoomStore.start(this.room)
}
@HostListener('document:click', ['$event'])
handleClickOutside(event: Event) {
if (!this.handleClickActive) return;
@@ -360,6 +362,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
ngOnDestroy() {
this.RoomStore.stop()
window.removeEventListener('scroll', this.scrollChangeCallback, true);
this.handleClickActive = false; // Disable the listener before component destruction
}
@@ -512,29 +515,73 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
roomId: this.room.id,
members: [],
isAdmin: this.RoomStore.isAdmin,
roomType: this.roomType
roomType: this.RoomStore.room.roomType
},
cssClass: 'messages-options',
event: ev,
translucent: true,
});
return await popover.present();
await popover.present();
popover.onDidDismiss().then(res => {
if (res.data == 'leave') {
this.modalController.dismiss()
}
else if (res.data == 'delete') {
this.modalController.dismiss()
}
else if (res.data == 'cancel') {
this.modalController.dismiss()
}
else if (res.data == 'edit') {
//this.closeAllDesktopComponents.emit();
this.editGroup()
} else if (res.data == 'addUser') {
this.addContacts();
}
else {}
});
}
async addContacts() {
const modal = await this.modalController.create({
component: ContactsPage,
componentProps: {},
component: GroupContactsPage,
componentProps: {
roomId: this.RoomStore.room.id,
},
cssClass: 'contacts',
backdropDismiss: false
});
modal.onDidDismiss<IGroupContactsPageOutPutSchema>().then(result => {
modal.onDidDismiss();
// this.modalController.dismiss({roomId})
});
await modal.present();
}
async editGroup() {
const modal = await this.modalController.create({
component: EditGroupPage,
cssClass: 'modal modal-desktop',
componentProps: {
roomId: this.RoomStore.room.id,
},
});
await modal.present();
modal.onDidDismiss().then((res) => {
this.RoomStore.updateRoomDetails()
// this.getRoomInfo();
//this.modalController.dismiss(res.data);
});
}
async onImageError() {}
async onImageLoad(message: MessageViewModal, index:number) {
@@ -717,7 +764,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
const fileName = file.value.name
const validation = await allowedDocExtension(fileName)
const validation = await allowedDocExtension(file.value.type)
if (validation.isOk()) {
@@ -730,12 +777,14 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
fileName: file.value.name,
source: MessageAttachmentSource.Device,
fileType: MessageAttachmentFileType.Doc,
mimeType: file.value.type
mimeType: file.value.type,
description: file.value.name
}])
}
} else {
console.log({fileName})
this.toastService._badRequest("Ficheiro inválido")
}
}
@@ -904,7 +953,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
modal.present();
} else {
this.openFile(msg.attachments[0].safeFile, msg.attachments[0].description, msg.attachments[0].mimeType);
this.openFile(msg.attachments[0].safeFile, msg.attachments[0].fileName || msg.attachments[0].description, msg.attachments[0].mimeType);
}
}
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams, PickerController, PopoverController } from '@ionic/angular';
import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page';
import { GroupContactsPage } from '../group-messages/group-contacts/group-contacts.page';
import { GroupContactsPage, IGroupContactsPageOutPutSchema } from '../group-messages/group-contacts/group-contacts.page';
import { ThemeService } from 'src/app/services/theme.service';
import { SessionStore } from 'src/app/store/session.service';
import { ToastService } from 'src/app/services/toast.service';
@@ -9,8 +9,14 @@ import { catchError } from 'rxjs/operators';
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
import { UDate } from 'src/app/utils/date';
import { HttpErrorResponse } from '@angular/common/http';
import { z } from 'zod';
const NewGroupModalOutPutSchema = z.object({
roomId: z.string().optional()
})
export type INewGroupModalOutPut = z.infer<typeof NewGroupModalOutPutSchema>
@Component({
selector: 'app-new-group',
templateUrl: './new-group.page.html',
@@ -82,12 +88,10 @@ export class NewGroupPage implements OnInit {
async addContacts(roomId) {
this.close();
async addContacts(roomId:string) {
let name = this.groupName.split(' ').join('-');
const modal = await this.modalController.create({
component: GroupContactsPage,
componentProps: {
@@ -98,7 +102,11 @@ export class NewGroupPage implements OnInit {
});
modal.onDidDismiss();
modal.onDidDismiss<IGroupContactsPageOutPutSchema>().then(result => {
this.modalController.dismiss({roomId})
});
await modal.present();
}
@@ -1,7 +1,18 @@
<ion-header>
<ion-toolbar>
<ion-title class="title" *ngIf="roomData$ | async as roomData"> {{ roomData.roomName }}</ion-title>
</ion-toolbar>
<div class="d-flex justify-content-between">
<ion-toolbar>
<ion-title class="title" *ngIf="roomData$ | async as roomData"> {{ roomData.roomName }}</ion-title>
</ion-toolbar>
<div class="btn-close d-flex cursor-pointer pr-20" >
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " class="icon"
src="assets/images/icons-search-close.svg"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " class="icon"
src="assets/images/theme/gov/icons-search-close.svg"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'doneIt' " class="icon"
src="assets/images/theme/{{ThemeService.currentTheme}}/icons-search-close.svg"></ion-icon>
</div>
</div>
</ion-header>
<ion-content class="px-20">
@@ -7,6 +7,8 @@ import { RoomTable } from 'src/app/infra/database/dexie/instance/chat/schema/roo
import { map, tap } from 'rxjs/operators';
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
import { MemberEntity } from 'src/app/core/chat/entity/member';
import { ThemeService } from 'src/app/services/theme.service'
@Component({
selector: 'app-room-info',
templateUrl: './room-info.page.html',
@@ -23,7 +25,8 @@ export class RoomInfoPage implements OnInit {
private navParams: NavParams,
private MemberListLocalRepository: MemberListLocalRepository,
private RoomLocalRepository: RoomLocalRepository,
private ChatServiceService: ChatServiceService
private ChatServiceService: ChatServiceService,
public ThemeService: ThemeService,
) {
this.roomId = this.navParams.get('roomId');
}
@@ -34,7 +34,7 @@
<div *virtualItem="let user" class="item-checkbox">
<div class="cursor-pointer d-flex width-100" (click)="setRoomOwner(user)" (ionChange)="setRoomOwner(user)">
<p class="flex-1">{{user.wxFullName}}</p>
<ion-icon slot="end" class="{{user.status}}" name="ellipse"></ion-icon>
<!-- <ion-icon slot="end" class="{{user.status}}" name="ellipse"></ion-icon> -->
</div>
</div>
+35 -2
View File
@@ -38,9 +38,9 @@ export class RoomStore {
messageTypingSubject: Subscription
messageOnReconnectSubject: Subscription
messageOnSetRoomId: Subscription
messageRoomData: Subscription
newMessagesStream!: Subscription
roomData$: Observable<RoomTable | undefined>
roomStatus$: DexieObservable<Boolean >
roomMessage$: DexieObservable<MessageTable[]>
roomMembers$: Observable<MemberTable[] | undefined>
@@ -71,10 +71,41 @@ export class RoomStore {
} else {
await this.getMessages()
}
this.messageRoomData?.unsubscribe();
this.messageRoomData = this.RoomLocalRepository.getRoomByIdLive(this.room.$id).subscribe(e => {
if(e) {
this.room = new RoomViewModel(e)
}
})
this.messageOnSetRoomId?.unsubscribe()
if(this.room.local == IDBoolean.true) {
this.messageOnSetRoomId = this.chatServiceService.roomDirectOnSetId({$roomId: this.room.$id}).subscribe((data) => {
this.messageOnSetRoomId?.unsubscribe()
this.room = new RoomViewModel(data)
const hasMyMessage = this.messages1[this.room.$id].find(e => e.sender.wxUserId == SessionStore.user.UserId)
if(!hasMyMessage) {
setTimeout(() => {
this.getMessages()
}, 500)
}
setTimeout(() => {
this.subscribeToChanges()
}, 500)
})
}
}
stop() {
this.messageReceiveSubject?.unsubscribe();
this.messageReceiveSubject?.unsubscribe();
this.messageDeleteSubject?.unsubscribe();
this.messageUpdateSubject?.unsubscribe();
@@ -194,6 +225,8 @@ export class RoomStore {
}
}
this.sendReadMessage()
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)