mobile create grupo and contact

This commit is contained in:
Peter Maquiran
2024-09-19 09:16:14 +01:00
parent 9e7a8b6cb6
commit 1f08eb5514
6 changed files with 199 additions and 310 deletions
+24 -130
View File
@@ -6,6 +6,10 @@ import { ThemeService } from 'src/app/services/theme.service';
import { SessionStore } from 'src/app/store/session.service';
import { ToastService } from 'src/app/services/toast.service';
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';
@Component({
selector: 'app-new-group',
@@ -29,7 +33,7 @@ export class NewGroupPage implements OnInit {
private modalController: ModalController,
private navParams: NavParams,
public ThemeService: ThemeService,
// public ChatSystemService: ChatSystemService,
public chatSystemService: ChatServiceService,
private toastService: ToastService,
) {
this.loggedUserChat = SessionStore.user.ChatData['data'];
@@ -38,10 +42,7 @@ export class NewGroupPage implements OnInit {
this.documents = this.navParams.get('documents');
}
ngOnInit() {
// this.chatService.refreshtoken();
// console.log(this.documents)
}
ngOnInit() {}
_ionChange(event) {
this.showDuration = event.detail.checked;
@@ -59,136 +60,29 @@ export class NewGroupPage implements OnInit {
async createGroup() {
// let name = this.groupName.split(' ').join('-');
// //Take out all special characters in string
// name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
const result = await this.chatSystemService.createRoom({
roomName: this.groupName,
createdBy: SessionStore.user.UserId,
roomType: 0,
expirationDate: this.displayDuration?.toISOString() ? UDate.GetDateWithTimeZone(this.displayDuration) : null,
members: []
})
// let customFields = {}
// let res: any;
// if(!SessionStore.user?.ChatData?.data) {
// this.toastService._successMessage("Chat temporariamente indisponível")
// }
// try {
// if (this.thedate) {
// let customFields = {
// "countDownDate": this.thedate
// }
// res = await this.ChatSystemService.createPrivateRoom(name, SessionStore.user.UserName, customFields);
// }
// else {
// res = await this.ChatSystemService.createPrivateRoom(name, SessionStore.user.UserName, customFields);
// }
// try {
// this.isGroupCreated = true;
// this.addContacts(res.result);
// this.ChatSystemService.getRoom([res.result]);
// setTimeout(() => {
// this.ChatSystemService.subscribeToRoomUpdate(res.result.rid, res.result);
// }, 10)
// } catch (error) {
// await this.ChatSystemService.getUser();
// await this.ChatSystemService.getAllRooms();
// await this.ChatSystemService.subscribeToRoom();
// this.isGroupCreated = true;
// this.addContacts(res.result);
// this.ChatSystemService.getRoom([res.result]);
// setTimeout(() => {
// this.ChatSystemService.subscribeToRoomUpdate(res.result.rid, res.result);
// }, 10)
// }
// if (res?.result?.rid) {
// this.ChatSystemService.getAllRooms(() => {
// if (!this.ChatSystemService.getGroupRoom(res.result.rid)) {
// this.createGroupWithAttachmentsCath(res)
// } else {
// setTimeout(() => {
// this.createGroupWithAttachments(res)
// }, 500)
// }
// }, res.result.rid);
// } else {
// this.toastService._badRequest('Existe um grupo com este nome!');
// }
// } catch(error) {
// this.toastService._successMessage("Chat temporariamente indisponível")
// }
if(result.isOk()) {
await this.chatSystemService.getRoomById(result.value.id)
this.addContacts(result.value.id)
//this.addGroupMessage.emit(result.value.id);
} else if(result.error instanceof HttpErrorResponse) {
// this.httpErrorHandle.httpStatusHandle(result.error)
} else {
this.toastService._badRequest('Por favor, contacta um administrador.');
}
}
createGroupWithAttachmentsCath(res: any) {
// if (!this.ChatSystemService.getGroupRoom(res.result.rid)) {
// setTimeout(() => {
// this.createGroupWithAttachmentsCath(res)
// }, 1500)
// } else {
// this.createGroupWithAttachments(res)
// }
}
createGroupWithAttachments(res: any) {
// this.ChatSystemService.getGroupRoom(res.result.rid).hasLoadHistory = true;
// if (this.documents) {
// this.documents.forEach(element => {
// this.ChatSystemService.getGroupRoom(res.result.rid).send({
// file: {
// "name": element.Assunto,
// "type": "application/webtrix",
// "ApplicationId": element.ApplicationId,
// "DocId": element.DocId,
// "Assunto": element.Assunto,
// },
// temporaryData: {
// data: {
// selected: {
// Id: element.DocId,
// ApplicationType: element.ApplicationId
// }
// }
// },
// attachments: [{
// "title": element.Assunto,
// "description": element.Assunto,
// "title_link_download": true,
// "type": "webtrix",
// "text": element.Assunto,
// "thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
// }],
// })
// });
// }
// this.ChatSystemService.getAllRooms();
// setTimeout(() => {
// this.groupName = ""
// }, 150);
}
async addContacts(room) {
async addContacts(roomId) {
this.close();
let name = this.groupName.split(' ').join('-');
@@ -197,7 +91,7 @@ export class NewGroupPage implements OnInit {
const modal = await this.modalController.create({
component: GroupContactsPage,
componentProps: {
room: room,
roomId: roomId,
},
cssClass: 'contacts',
backdropDismiss: false