2020-12-21 16:37:44 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-01-21 16:27:04 +01:00
|
|
|
import { ModalController, NavParams, PickerController, PopoverController } from '@ionic/angular';
|
2021-01-06 15:28:42 +01:00
|
|
|
import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page';
|
2021-01-20 16:58:04 +01:00
|
|
|
import { GroupContactsPage } from '../group-messages/group-contacts/group-contacts.page';
|
2022-05-27 13:36:37 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service';
|
2022-09-30 15:13:36 +01:00
|
|
|
import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
|
2022-04-24 19:45:20 +01:00
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
2023-08-21 12:22:19 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2024-03-03 18:14:33 +01:00
|
|
|
import { catchError } from 'rxjs/operators';
|
2020-12-21 16:37:44 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-new-group',
|
|
|
|
|
templateUrl: './new-group.page.html',
|
|
|
|
|
styleUrls: ['./new-group.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class NewGroupPage implements OnInit {
|
2023-10-11 17:41:05 +01:00
|
|
|
isGroupCreated: boolean;
|
2020-12-21 16:37:44 +01:00
|
|
|
showLoader: boolean;
|
2021-01-06 15:28:42 +01:00
|
|
|
displayDuration: any;
|
2021-01-04 16:03:41 +01:00
|
|
|
showDuration: boolean;
|
2023-10-11 17:41:05 +01:00
|
|
|
selectedDuration = ['', '', ''];
|
|
|
|
|
thedate: any;
|
|
|
|
|
groupName: string;
|
|
|
|
|
documents: any;
|
2022-01-26 17:01:50 +01:00
|
|
|
loggedUserChat: any;
|
2020-12-21 16:37:44 +01:00
|
|
|
|
|
|
|
|
constructor(
|
2021-01-06 15:28:42 +01:00
|
|
|
private pickerController: PickerController,
|
|
|
|
|
private popoverController: PopoverController,
|
2021-01-21 16:27:04 +01:00
|
|
|
private modalController: ModalController,
|
|
|
|
|
private navParams: NavParams,
|
2021-10-28 15:40:41 +01:00
|
|
|
public ThemeService: ThemeService,
|
2022-09-30 15:13:36 +01:00
|
|
|
public ChatSystemService: ChatSystemService,
|
2023-08-21 12:22:19 +01:00
|
|
|
private toastService: ToastService,
|
2022-05-27 13:36:37 +01:00
|
|
|
) {
|
2022-10-12 17:01:09 +01:00
|
|
|
this.loggedUserChat = SessionStore.user.ChatData['data'];
|
2021-01-21 16:27:04 +01:00
|
|
|
this.isGroupCreated = false;
|
|
|
|
|
this.groupName = this.navParams.get('name');
|
2021-12-10 10:32:49 +01:00
|
|
|
this.documents = this.navParams.get('documents');
|
2020-12-21 16:37:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2022-10-11 13:56:56 +01:00
|
|
|
// this.chatService.refreshtoken();
|
2022-06-29 15:51:28 +01:00
|
|
|
// console.log(this.documents)
|
2021-01-04 16:03:41 +01:00
|
|
|
}
|
2021-12-10 10:32:49 +01:00
|
|
|
|
2023-09-19 10:21:23 +01:00
|
|
|
_ionChange(event) {
|
2021-01-04 16:03:41 +01:00
|
|
|
this.showDuration = event.detail.checked;
|
2021-10-28 15:40:41 +01:00
|
|
|
|
2023-10-11 17:41:05 +01:00
|
|
|
if (event.detail.checked) {
|
2021-10-28 15:40:41 +01:00
|
|
|
this.thedate = new Date();
|
|
|
|
|
}
|
2023-09-19 10:21:23 +01:00
|
|
|
else {
|
2021-10-28 15:40:41 +01:00
|
|
|
this.thedate = '';
|
|
|
|
|
}
|
2020-12-21 16:37:44 +01:00
|
|
|
}
|
2023-09-19 10:21:23 +01:00
|
|
|
close() {
|
2020-12-21 16:37:44 +01:00
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 17:41:05 +01:00
|
|
|
async createGroup() {
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2021-10-28 15:40:41 +01:00
|
|
|
let name = this.groupName.split(' ').join('-');
|
2021-12-10 11:46:28 +01:00
|
|
|
//Take out all special characters in string
|
2021-11-03 15:35:01 +01:00
|
|
|
name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
2022-01-26 17:01:50 +01:00
|
|
|
|
|
|
|
|
let customFields = {}
|
2023-10-11 17:41:05 +01:00
|
|
|
let res: any;
|
2022-01-26 17:01:50 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
if(!SessionStore.user?.ChatData?.data) {
|
|
|
|
|
this.toastService._successMessage("Chat temporariamente indisponível")
|
2022-01-26 17:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
try {
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
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);
|
|
|
|
|
}
|
2022-01-26 17:01:50 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
try {
|
|
|
|
|
this.isGroupCreated = true;
|
|
|
|
|
this.addContacts(res.result);
|
|
|
|
|
this.ChatSystemService.getRoom([res.result]);
|
2023-08-21 12:22:19 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.ChatSystemService.subscribeToRoomUpdate(res.result.rid, res.result);
|
|
|
|
|
}, 10)
|
2023-08-21 12:22:19 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
await this.ChatSystemService.getUser();
|
|
|
|
|
await this.ChatSystemService.getAllRooms();
|
|
|
|
|
await this.ChatSystemService.subscribeToRoom();
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
this.isGroupCreated = true;
|
|
|
|
|
this.addContacts(res.result);
|
|
|
|
|
this.ChatSystemService.getRoom([res.result]);
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.ChatSystemService.subscribeToRoomUpdate(res.result.rid, res.result);
|
|
|
|
|
}, 10)
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
}
|
2023-08-21 12:22:19 +01:00
|
|
|
|
|
|
|
|
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
if (res?.result?.rid) {
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
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!');
|
|
|
|
|
|
|
|
|
|
}
|
2023-08-21 12:22:19 +01:00
|
|
|
|
2024-03-03 18:14:33 +01:00
|
|
|
} catch(error) {
|
|
|
|
|
this.toastService._successMessage("Chat temporariamente indisponível")
|
2023-08-21 12:22:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createGroupWithAttachmentsCath(res: any) {
|
2023-10-11 17:41:05 +01:00
|
|
|
if (!this.ChatSystemService.getGroupRoom(res.result.rid)) {
|
|
|
|
|
setTimeout(() => {
|
2023-08-21 12:22:19 +01:00
|
|
|
this.createGroupWithAttachmentsCath(res)
|
|
|
|
|
}, 1500)
|
|
|
|
|
} else {
|
|
|
|
|
this.createGroupWithAttachments(res)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createGroupWithAttachments(res: any) {
|
|
|
|
|
this.ChatSystemService.getGroupRoom(res.result.rid).hasLoadHistory = true;
|
|
|
|
|
|
2023-10-11 17:41:05 +01:00
|
|
|
if (this.documents) {
|
2023-08-21 12:22:19 +01:00
|
|
|
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);
|
2021-10-28 15:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 13:36:37 +01:00
|
|
|
async addContacts(room) {
|
2021-01-26 15:18:03 +01:00
|
|
|
this.close();
|
2021-01-21 16:27:04 +01:00
|
|
|
|
2021-01-26 15:18:03 +01:00
|
|
|
let name = this.groupName.split(' ').join('-');
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2021-10-28 15:40:41 +01:00
|
|
|
|
2020-12-22 15:53:30 +01:00
|
|
|
const modal = await this.modalController.create({
|
2021-01-20 16:58:04 +01:00
|
|
|
component: GroupContactsPage,
|
2021-01-21 16:27:04 +01:00
|
|
|
componentProps: {
|
2021-10-28 15:40:41 +01:00
|
|
|
room: room,
|
|
|
|
|
},
|
2020-12-22 15:53:30 +01:00
|
|
|
cssClass: 'contacts',
|
|
|
|
|
backdropDismiss: false
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-15 11:01:09 +01:00
|
|
|
|
2020-12-22 15:53:30 +01:00
|
|
|
modal.onDidDismiss();
|
2023-07-15 11:01:09 +01:00
|
|
|
await modal.present();
|
2020-12-22 15:53:30 +01:00
|
|
|
}
|
2021-10-28 15:40:41 +01:00
|
|
|
|
2021-01-06 15:28:42 +01:00
|
|
|
async setDuration(ev: any) {
|
|
|
|
|
const popover = await this.popoverController.create({
|
|
|
|
|
component: GroupDurationPage,
|
|
|
|
|
cssClass: 'group-duration',
|
|
|
|
|
event: ev,
|
|
|
|
|
translucent: true
|
|
|
|
|
});
|
|
|
|
|
return await popover.present();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-30 16:06:28 +01:00
|
|
|
async showPicker() {
|
2021-01-06 15:28:42 +01:00
|
|
|
const picker = await this.pickerController.create({
|
|
|
|
|
cssClass: '',
|
|
|
|
|
buttons: [
|
2023-10-11 17:41:05 +01:00
|
|
|
{
|
|
|
|
|
text: 'Cancelar', role: 'cancel', cssClass: 'btn-cancel'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: 'Ok',
|
|
|
|
|
cssClass: 'btn-cancel',
|
|
|
|
|
handler: (value: any) => {
|
|
|
|
|
|
|
|
|
|
let now = new Date();
|
|
|
|
|
this.thedate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + value.days.value, now.getHours() + value.hours.value, now.getMinutes() + value.minutes.value, now.getSeconds(), now.getMilliseconds());
|
|
|
|
|
|
|
|
|
|
this.selectedDuration = [
|
|
|
|
|
value.days.value,
|
|
|
|
|
value.hours.value,
|
|
|
|
|
value.minutes.value,
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if (value.days.value != null && value.hours.value != null && value.minutes.value != null) {
|
|
|
|
|
if (value.days.value > 0) {
|
|
|
|
|
if (value.days.value == 1) {
|
|
|
|
|
if (value.hours.value == 1) {
|
|
|
|
|
this.displayDuration = value.days.value + " day " +
|
2021-01-06 15:28:42 +01:00
|
|
|
value.hours.value + " hora " +
|
|
|
|
|
value.minutes.value + " minutos";
|
2023-10-11 17:41:05 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.displayDuration = value.days.value + " days " +
|
2021-01-06 15:28:42 +01:00
|
|
|
value.hours.value + " horas " +
|
|
|
|
|
value.minutes.value + " minutos";
|
|
|
|
|
}
|
2023-10-11 17:41:05 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (value.hours.value == 1) {
|
|
|
|
|
this.displayDuration = value.days.value + " days " +
|
2021-01-06 15:28:42 +01:00
|
|
|
value.hours.value + " hora " +
|
|
|
|
|
value.minutes.value + " minutos";
|
2023-10-11 17:41:05 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.displayDuration = value.days.value + " days " +
|
2021-01-06 15:28:42 +01:00
|
|
|
value.hours.value + " horas " +
|
|
|
|
|
value.minutes.value + " minutos";
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-11 17:41:05 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (value.hours.value == 1) {
|
|
|
|
|
this.displayDuration = value.hours.value + " hora " +
|
2021-01-06 15:28:42 +01:00
|
|
|
value.minutes.value + " minutos";
|
2023-10-11 17:41:05 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.displayDuration = value.hours.value + " horas " +
|
2021-01-06 15:28:42 +01:00
|
|
|
value.minutes.value + " minutos";
|
|
|
|
|
}
|
2021-10-28 15:40:41 +01:00
|
|
|
}
|
2023-10-11 17:41:05 +01:00
|
|
|
}
|
|
|
|
|
},
|
2021-01-06 15:28:42 +01:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
columns: [
|
|
|
|
|
{
|
|
|
|
|
name: 'days',
|
|
|
|
|
prefix: 'Dias',
|
|
|
|
|
options: [
|
|
|
|
|
{ text: '0', value: 0 },
|
|
|
|
|
{ text: '1', value: 1 },
|
|
|
|
|
{ text: '2', value: 2 },
|
|
|
|
|
{ text: '3', value: 3 },
|
|
|
|
|
{ text: '4', value: 4 },
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'hours',
|
|
|
|
|
prefix: 'Horas',
|
|
|
|
|
options: [
|
|
|
|
|
{ text: '0', value: 0 },
|
|
|
|
|
{ text: '1', value: 1 },
|
|
|
|
|
{ text: '2', value: 2 },
|
|
|
|
|
{ text: '3', value: 3 },
|
|
|
|
|
{ text: '4', value: 4 },
|
|
|
|
|
{ text: '5', value: 5 },
|
|
|
|
|
{ text: '6', value: 6 },
|
|
|
|
|
{ text: '7', value: 7 },
|
|
|
|
|
{ text: '8', value: 8 },
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'minutes',
|
|
|
|
|
prefix: 'Minutos',
|
2023-08-31 16:39:13 +01:00
|
|
|
selectedIndex: 0,
|
2021-01-06 15:28:42 +01:00
|
|
|
options: [
|
|
|
|
|
{ text: '5', value: 5 },
|
|
|
|
|
{ text: '10', value: 10 },
|
|
|
|
|
{ text: '15', value: 15 },
|
|
|
|
|
{ text: '20', value: 20 },
|
|
|
|
|
{ text: '25', value: 25 },
|
|
|
|
|
{ text: '30', value: 30 },
|
|
|
|
|
{ text: '35', value: 35 },
|
|
|
|
|
{ text: '45', value: 45 },
|
|
|
|
|
{ text: '50', value: 50 },
|
|
|
|
|
{ text: '55', value: 55 },
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
await picker.present();
|
2023-10-11 17:41:05 +01:00
|
|
|
picker.onDidDismiss().then(async data => {
|
2021-01-06 15:28:42 +01:00
|
|
|
let day = await picker.getColumn('days');
|
2021-10-28 15:40:41 +01:00
|
|
|
let hour = await picker.getColumn('hours');
|
2021-01-06 15:28:42 +01:00
|
|
|
let minutes = await picker.getColumn('minutes');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
2020-12-22 15:53:30 +01:00
|
|
|
|
2020-12-21 16:37:44 +01:00
|
|
|
}
|