Files
doneit-web/src/app/pages/chat/chat.page.ts
T

768 lines
18 KiB
TypeScript
Raw Normal View History

2022-06-08 11:56:56 +01:00
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
2021-07-23 14:43:51 +01:00
import {
Component,
2021-03-11 16:21:09 +01:00
OnInit,
ViewChild,
ViewContainerRef,
Output,
2021-03-11 16:21:09 +01:00
} from '@angular/core';
2021-12-08 19:36:41 +01:00
import { ModalController, Platform } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service';
import { ChatService } from 'src/app/services/chat.service';
2022-09-26 16:16:37 +01:00
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'
2020-12-28 10:11:00 +01:00
import { GroupMessagesPage } from './group-messages/group-messages.page';
import { ContactsPage } from './messages/contacts/contacts.page';
2021-01-07 09:39:36 +01:00
import { MessagesPage } from './messages/messages.page';
import { NewGroupPage } from './new-group/new-group.page';
2021-04-14 13:56:38 +01:00
import { EditGroupPage } from 'src/app/shared/chat/edit-group/edit-group.page';
2022-04-26 16:53:10 +01:00
import { Subject } from "rxjs/Rx";
2022-09-28 16:33:13 +01:00
import { NavigationStart, Router, NavigationEnd } from '@angular/router';
2021-08-18 16:40:58 +01:00
import { EventPerson } from 'src/app/models/eventperson.model';
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
import { environment } from 'src/environments/environment';
2021-09-06 17:02:45 +01:00
import { TimeService } from 'src/app/services/functions/time.service';
2021-10-21 15:55:54 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2021-11-03 15:35:01 +01:00
import { DataService } from 'src/app/services/data.service';
2021-12-08 19:36:41 +01:00
import { SqliteService } from 'src/app/services/sqlite.service';
2021-12-16 16:36:39 +01:00
import { StorageService } from 'src/app/services/storage.service';
import { SessionStore } from 'src/app/store/session.service';
2022-09-26 16:16:37 +01:00
import { ChatDebuggingPage } from 'src/app/shared/popover/chat-debugging/chat-debugging.page';
2021-10-21 15:55:54 +01:00
2020-09-10 09:48:37 +01:00
@Component({
selector: 'app-chat',
templateUrl: './chat.page.html',
styleUrls: ['./chat.page.scss'],
})
export class ChatPage implements OnInit {
2021-01-13 10:02:30 +01:00
2021-01-27 16:01:49 +01:00
showLoader: boolean;
2021-01-13 10:02:30 +01:00
headers: HttpHeaders;
2021-12-08 19:36:41 +01:00
options: any;
X_User_Id: any;
X_Auth_Token: any;
2021-07-23 14:43:51 +01:00
2021-06-03 17:07:29 +01:00
loggedUser: any;
2021-12-08 19:36:41 +01:00
segment: string;
2021-01-13 10:02:30 +01:00
allGroups: any[];
privateGroups: any[];
publicGroups: any[];
2020-11-03 11:52:21 +01:00
userConnectedList: any[];
2021-01-13 10:02:30 +01:00
userRooms: any[];
userChannels: any[];
userDirectMessages: any[];
2021-12-08 19:36:41 +01:00
result: any;
dmUsers: any[] = [];
2021-07-27 00:01:38 +01:00
idSelected: string;
2020-09-10 09:48:37 +01:00
2021-03-04 18:50:26 +01:00
desktopComponent: any = {
2021-03-05 11:58:59 +01:00
showMessages: false,
showGroupMessages: false,
2021-03-04 18:50:26 +01:00
}
2021-03-11 16:21:09 +01:00
@ViewChild('messagecontainer', { read: ViewContainerRef }) entry: ViewContainerRef;
componentRef: any;
2021-12-08 19:36:41 +01:00
roomId: any;
groupRoomId: any;
showEmptyComponent = true;
showMessages = false;
showContacts = false;
showNewGroup = false;
showEditGroup = false;
showGroupMessages = false;
showGroupContacts = false;
showNewEvent = false;
showAttendees = false;
emptyTextDescription = 'Sem conversa selecionada';
2021-03-11 16:21:09 +01:00
@Output() getRoomInfo;
2021-05-18 14:37:43 +01:00
subject: any;
public messages: Subject<any>;
message = {
"msg": "connect",
"version": "1",
"support": ["1"]
};
2021-12-08 19:36:41 +01:00
loggedUserChat: any;
2021-06-17 16:43:18 +01:00
hideRefreshBtn = true;
2021-06-04 11:37:56 +01:00
2021-08-18 16:40:58 +01:00
taskParticipants: any = [];
taskParticipantsCc: any = [];
adding: "intervenient" | "CC" = "intervenient";
2021-12-08 19:36:41 +01:00
profile: 'mdgpr' | 'pr';
2021-08-18 16:40:58 +01:00
eventSelectedDate: Date = new Date();
2021-12-08 19:36:41 +01:00
contacts: EventPerson[];
showEventEditOrOpen: "edit" | "add" | "" | "eventoToApprove" = ""
2021-08-18 16:40:58 +01:00
constructor(
private chatService: ChatService,
2020-11-03 11:52:21 +01:00
private modalController: ModalController,
2021-01-13 10:02:30 +01:00
private authService: AuthService,
2021-08-20 19:10:13 +01:00
private route: Router,
2021-09-06 17:02:45 +01:00
private timeService: TimeService,
2021-11-03 15:35:01 +01:00
public ThemeService: ThemeService,
2021-12-08 19:36:41 +01:00
private dataService: DataService,
2021-11-03 15:35:01 +01:00
private router: Router,
2021-12-08 19:36:41 +01:00
private sqlservice: SqliteService,
2021-12-16 16:36:39 +01:00
private platform: Platform,
2022-01-12 09:29:48 +01:00
private storageservice: StorageService,
2022-01-12 14:48:17 +01:00
public wsChatMethodsService: WsChatMethodsService,
2021-12-08 19:36:41 +01:00
) {
2022-01-11 13:03:43 +01:00
2021-12-08 19:36:41 +01:00
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.headers = new HttpHeaders();
window.onresize = (event) => {
if (window.innerWidth > 701) {
this.modalController.dismiss();
}
};
2021-12-17 16:54:18 +01:00
this.showLoader = true;
2022-01-11 12:12:45 +01:00
2022-07-21 18:05:29 +01:00
this.segment = 'Contactos'
2021-12-08 19:36:41 +01:00
}
2021-05-18 14:37:43 +01:00
2020-09-10 09:48:37 +01:00
ngOnInit() {
2022-06-10 09:42:41 +01:00
this.chatService.refreshtoken();
2022-06-09 10:53:25 +01:00
this.segment = "Contactos";
2021-02-26 08:38:33 +01:00
2021-12-08 19:36:41 +01:00
this.authService.userData$.subscribe((res: any) => {
this.loggedUser = res;
2021-01-13 10:02:30 +01:00
});
2021-07-23 14:43:51 +01:00
2021-12-08 19:36:41 +01:00
this.hideRefreshButton();
this.getChatMembers();
2021-08-20 16:38:58 +01:00
2021-08-23 16:31:06 +01:00
2022-09-28 16:33:13 +01:00
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && event.url == '/home/chat' ||
event instanceof NavigationEnd && event.url == "/home/chat?gbCreateGroup=true") {
2022-09-29 14:51:50 +01:00
this.chatService.refreshtoken();
2022-09-28 16:33:13 +01:00
this.checkCreateGroup();
}
});
}
checkCreateGroup() {
2022-09-26 22:09:08 +01:00
if (this.dataService.get("newGroup")) {
this.openNewGroupPage();
}
2022-09-28 16:33:13 +01:00
else {
2022-09-26 22:09:08 +01:00
this.closeAllDesktopComponents();
this.showEmptyComponent = true;
}
2022-09-28 16:33:13 +01:00
2021-12-08 19:36:41 +01:00
}
2021-08-23 16:31:06 +01:00
2021-12-17 16:54:18 +01:00
numSequence(n: number): Array<number> {
return Array(n);
}
2021-12-08 19:36:41 +01:00
ngOnDestroy() {
this.setStatus('offline');
2022-04-28 09:32:27 +01:00
2021-12-08 19:36:41 +01:00
}
2021-08-23 16:31:06 +01:00
2021-12-08 19:36:41 +01:00
setStatus(status: string) {
let body = {
message: '',
status: status,
}
this.chatService.setUserStatus(body).subscribe(res => {
2022-04-28 09:32:27 +01:00
2021-12-08 19:36:41 +01:00
})
2021-08-23 16:31:06 +01:00
}
2021-06-17 16:43:18 +01:00
2021-12-08 19:36:41 +01:00
hideRefreshButton() {
window.onresize = (event) => {
if (window.innerWidth < 701) {
this.idSelected = '';
this.hideRefreshBtn = false;
}
else {
this.hideRefreshBtn = true;
if (this.idSelected == '') {
this.showEmptyComponent = true;
}
}
}
if (window.innerWidth < 701) {
2021-08-20 11:24:42 +01:00
this.idSelected = '';
2021-06-17 16:43:18 +01:00
this.hideRefreshBtn = false;
}
}
2021-03-12 11:56:54 +01:00
closeAllDesktopComponents() {
2021-12-08 19:36:41 +01:00
this.showMessages = false;
this.showContacts = false;
this.showNewGroup = false;
this.showEditGroup = false;
this.showGroupMessages = false;
this.showEmptyComponent = false;
this.showGroupContacts = false;
this.showNewEvent = false;
this.showAttendees = false;
2022-04-28 09:32:27 +01:00
2021-03-16 14:33:36 +01:00
}
2021-08-18 16:40:58 +01:00
2021-12-08 19:36:41 +01:00
showEmptyContainer() {
2021-08-20 11:24:42 +01:00
this.idSelected = '';
2021-12-08 19:36:41 +01:00
this.showEmptyComponent = true;
2021-04-15 23:57:14 +01:00
}
2021-12-08 19:36:41 +01:00
openGroupContactsPage(data) {
2021-08-20 11:24:42 +01:00
this.idSelected = '';
2021-03-17 09:06:42 +01:00
this.groupRoomId = data;
2021-03-16 14:33:36 +01:00
this.closeAllDesktopComponents();
2022-02-11 17:15:01 +01:00
if (window.innerWidth < 701) {
2021-03-16 14:33:36 +01:00
}
2021-12-08 19:36:41 +01:00
else {
2021-03-16 14:33:36 +01:00
this.showGroupContacts = true;
}
2021-03-11 16:21:09 +01:00
}
openMessagesPage(rid) {
2022-08-04 16:39:38 +01:00
2022-09-29 15:23:27 +01:00
this.chatService.refreshtoken();
2022-08-04 16:39:38 +01:00
this.roomId = rid;
2021-12-08 19:36:41 +01:00
if (window.innerWidth < 701) {
2021-07-26 09:55:57 +01:00
this.openMessagesModal(rid);
2021-03-12 11:56:54 +01:00
}
2021-12-08 19:36:41 +01:00
else {
2021-08-20 11:24:42 +01:00
this.idSelected = rid;
2021-03-12 11:56:54 +01:00
this.closeAllDesktopComponents();
2021-03-15 15:19:07 +01:00
this.showEmptyComponent = false;
2021-12-08 19:36:41 +01:00
this.showMessages = true;
2021-03-12 11:56:54 +01:00
}
2021-03-11 16:21:09 +01:00
}
2021-03-15 15:19:07 +01:00
openContactsPage() {
2022-04-28 09:32:27 +01:00
2021-08-20 11:24:42 +01:00
this.idSelected = '';
2021-03-15 15:19:07 +01:00
this.closeAllDesktopComponents();
2021-07-23 14:43:51 +01:00
2021-12-08 19:36:41 +01:00
if (window.innerWidth < 701) {
2021-03-29 16:01:58 +01:00
this.selectContact();
2021-03-15 15:19:07 +01:00
}
2021-12-08 19:36:41 +01:00
else {
2022-04-28 09:32:27 +01:00
2021-12-08 19:36:41 +01:00
this.showContacts = true;
2021-03-15 15:19:07 +01:00
}
}
2021-03-15 18:09:41 +01:00
openNewGroupPage() {
2021-08-20 11:24:42 +01:00
this.idSelected = '';
2022-02-11 17:15:01 +01:00
if (window.innerWidth < 701) {
2021-03-15 18:09:41 +01:00
this.newGroup();
}
2021-12-08 19:36:41 +01:00
else {
2021-03-15 18:09:41 +01:00
this.closeAllDesktopComponents();
2021-12-08 19:36:41 +01:00
this.showNewGroup = true;
2021-03-15 18:09:41 +01:00
}
}
2021-04-14 13:56:38 +01:00
openEditGroupPage(rid) {
2022-02-11 17:15:01 +01:00
if (window.innerWidth < 701) {
2021-04-14 13:56:38 +01:00
this.editGroup(rid);
}
2021-12-08 19:36:41 +01:00
else {
2021-04-14 13:56:38 +01:00
this.closeAllDesktopComponents();
2021-12-08 19:36:41 +01:00
this.showEditGroup = true;
2021-04-14 13:56:38 +01:00
}
}
2021-07-23 14:43:51 +01:00
openGroupMessagesPage(rid) {
2022-09-29 15:23:27 +01:00
this.chatService.refreshtoken();
2022-08-04 16:39:38 +01:00
this.roomId = rid;
2021-12-08 19:36:41 +01:00
if (window.innerWidth < 701) {
2021-07-23 14:43:51 +01:00
this.openGroupMessagesModal(rid);
2021-03-12 11:56:54 +01:00
}
2021-12-08 19:36:41 +01:00
else {
2021-08-20 11:24:42 +01:00
this.idSelected = rid;
2021-03-12 11:56:54 +01:00
this.closeAllDesktopComponents();
2021-03-15 15:19:07 +01:00
this.showEmptyComponent = false;
2022-08-04 16:39:38 +01:00
2022-04-28 09:32:27 +01:00
2021-12-08 19:36:41 +01:00
this.showGroupMessages = true;
2021-03-12 11:56:54 +01:00
}
2021-03-11 16:21:09 +01:00
}
2021-12-08 19:36:41 +01:00
openNewEventPage(data: any) {
this.taskParticipants = data.members.map((val) => {
2021-08-18 16:40:58 +01:00
return {
Name: val.name,
2021-12-08 19:36:41 +01:00
EmailAddress: val.username + "@" + environment.domain,
2021-08-18 16:40:58 +01:00
IsRequired: "true",
}
});
this.groupRoomId = data.roomId;
2021-08-18 16:40:58 +01:00
this.closeAllDesktopComponents();
2021-12-08 19:36:41 +01:00
if (window.innerWidth < 701) {
2022-04-28 09:32:27 +01:00
2021-08-18 16:40:58 +01:00
}
2021-12-08 19:36:41 +01:00
else {
this.showNewEvent = true;
2021-08-18 16:40:58 +01:00
}
}
async openAttendeesComponent(data) {
this.adding = data.type
this.closeAllDesktopComponents();
this.showAttendees = true;
}
async clearContact() {
this.contacts = [];
}
2021-12-08 19:36:41 +01:00
async setContact(data: EventPerson[]) {
2021-08-18 16:40:58 +01:00
this.contacts = data;
}
async setIntervenient(data) {
this.taskParticipants = removeDuplicate(data)
}
async setIntervenientCC(data) {
this.taskParticipantsCc = removeDuplicate(data)
}
async closeAttendeesComponent() {
this.closeAllDesktopComponents();
2021-12-08 19:36:41 +01:00
this.showNewEvent = true;
2021-08-18 16:40:58 +01:00
}
async closeNewEventComponent() {
this.closeAllDesktopComponents();
this.showEmptyComponent = true;
this.idSelected = "";
}
2022-08-04 16:52:35 +01:00
async closeNewEventComponentAndOpenChat({roomId}) {
2022-08-04 16:39:38 +01:00
this.closeAllDesktopComponents();
2022-08-04 16:52:35 +01:00
console.log(roomId)
2022-08-04 16:39:38 +01:00
this.wsChatMethodsService._group.forEach((room)=>{
2022-08-04 16:52:35 +01:00
if(room.id == roomId) {
2022-08-04 16:39:38 +01:00
2022-08-04 16:52:35 +01:00
this.openGroupMessagesPage(roomId)
2022-08-04 16:39:38 +01:00
}
})
this.wsChatMethodsService._dm.forEach((room)=>{
2022-08-04 16:52:35 +01:00
if(room.id == roomId) {
this.openMessagesPage(roomId)
2022-08-04 16:39:38 +01:00
}
})
}
2021-12-08 19:36:41 +01:00
onSegmentChange() {
2022-07-25 12:29:34 +01:00
this.wsChatMethodsService.getAllRooms();
2021-01-27 16:01:49 +01:00
}
2021-08-19 18:54:50 +01:00
2021-12-08 19:36:41 +01:00
doRefresh(event) {
2021-08-19 18:54:50 +01:00
setTimeout(() => {
event.target.complete();
}, 1000);
}
2021-12-08 19:36:41 +01:00
customRoom() {
2021-01-20 13:17:54 +01:00
let params = new HttpParams();
params = params.set("types", "c");
2021-12-08 19:36:41 +01:00
this.chatService.customsRooms(params).subscribe(res => {
2022-04-28 09:32:27 +01:00
//
2021-01-20 13:17:54 +01:00
});
}
2021-07-23 14:43:51 +01:00
2021-12-08 19:36:41 +01:00
getDirectMessagesDB() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2021-12-16 16:36:39 +01:00
this.storageservice.get("rooms").then((rooms) =>{
2021-12-16 16:36:39 +01:00
this.userDirectMessages = rooms.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
var dateB = new Date(b._updatedAt).getTime();
return dateB - dateA;
});
2022-04-28 09:32:27 +01:00
//
2021-12-16 16:36:39 +01:00
2022-04-28 09:32:27 +01:00
//
2021-12-16 16:36:39 +01:00
})
this.storageservice.get('chatusers').then((users) => {
2022-04-26 14:34:52 +01:00
this.dmUsers = users.filter(data => data.username != SessionStore.user.UserName);
2021-12-16 16:36:39 +01:00
})
2021-12-08 19:36:41 +01:00
} else {
this.sqlservice.getAllChatRoom().then((rooms: any) => {
2022-04-28 09:32:27 +01:00
//
2021-12-08 19:36:41 +01:00
let roomsArray = [];
rooms.forEach(element => {
let roomListDB = {
_id: element.Id,
2021-12-16 16:36:39 +01:00
uids: this.isJson(element.Uids),
usernames: this.isJson(element.Usernames),
lastMessage: this.isJson(element.LastMessage),
2021-12-08 19:36:41 +01:00
_updatedAt: element.UpdatedAt
}
2021-12-16 16:36:39 +01:00
if(element.customFields == "undefined") {
roomsArray.push(roomListDB)
}
2021-12-08 19:36:41 +01:00
});
2021-07-23 14:43:51 +01:00
2021-12-08 19:36:41 +01:00
this.userDirectMessages = roomsArray.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
var dateB = new Date(b._updatedAt).getTime();
return dateB - dateA;
});
2022-04-28 09:32:27 +01:00
//
2021-12-08 19:36:41 +01:00
2022-04-28 09:32:27 +01:00
//
2021-12-08 19:36:41 +01:00
})
this.sqlservice.getAllChatUsers().then((userslist: any) => {
2022-04-28 09:32:27 +01:00
//
2021-12-08 19:36:41 +01:00
let chatusersArray = [];
userslist.forEach(element => {
2022-04-28 09:32:27 +01:00
2021-12-08 19:36:41 +01:00
let userListDB = {
_id: element.Id,
name: element.Name,
username: element.Username
}
2021-08-19 18:54:50 +01:00
2021-12-08 19:36:41 +01:00
chatusersArray.push(userListDB);
});
2022-04-26 14:34:52 +01:00
this.dmUsers = chatusersArray.filter(data => data.username != SessionStore.user.UserName);
2021-12-08 19:36:41 +01:00
})
}
}
transformDataRoomList(data) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2021-12-16 16:36:39 +01:00
let roomsArray = [];
data.forEach(element => {
let roomList = {
_id: element._id,
uids: element.uids,
usernames: element.usernames,
lastMessage: element.lastMessage,
_updatedAt: element._updatedAt
}
2022-04-28 09:32:27 +01:00
//
2021-12-16 16:36:39 +01:00
roomsArray.push(roomList)
});
2022-01-07 16:01:17 +01:00
this.storageservice.remove('rooms');
2021-12-16 16:36:39 +01:00
this.storageservice.store('rooms', roomsArray);
2021-12-08 19:36:41 +01:00
} else {
data.forEach(element => {
let roomList = {
id: element._id,
uids: element.uids,
usernames: element.usernames,
lastMessage: element.lastMessage,
updatedat: element._updatedAt
}
2022-04-28 09:32:27 +01:00
//
2021-12-08 19:36:41 +01:00
this.sqlservice.addChatListRoom(roomList);
});
}
}
2022-01-07 16:01:17 +01:00
async transformDataUserList(users) {
2021-12-08 19:36:41 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2021-12-16 16:36:39 +01:00
let usersArray = [];
users.forEach(element => {
2022-04-28 09:32:27 +01:00
//
2021-12-16 16:36:39 +01:00
let chatusers = {
_id: element._id,
name: element.name,
username: element.username
}
2022-04-28 09:32:27 +01:00
//
2021-12-16 16:36:39 +01:00
usersArray.push(chatusers);
});
2022-01-07 16:01:17 +01:00
await this.storageservice.remove('chatusers');
await this.storageservice.store('chatusers',usersArray);
2021-12-08 19:36:41 +01:00
} else {
users.forEach(element => {
2022-04-28 09:32:27 +01:00
//
2021-12-08 19:36:41 +01:00
let chatusers = {
id: element._id,
name: element.name,
username: element.username
}
2022-04-28 09:32:27 +01:00
//
2021-12-08 19:36:41 +01:00
this.sqlservice.addChatListUsers(chatusers);
});
}
}
showDateDuration(start: any) {
2021-09-06 17:02:45 +01:00
return this.timeService.showDateDuration(start);
2021-08-20 16:38:58 +01:00
}
2021-12-08 19:36:41 +01:00
countDownDate(date: any, roomId: string) {
2021-10-27 08:45:37 +01:00
return this.timeService.countDownDate(date, roomId);
}
2021-12-08 19:36:41 +01:00
async getChatMembers() {
2022-06-08 16:09:40 +01:00
2021-12-08 19:36:41 +01:00
this.chatService.getAllUsers().subscribe(res => {
2022-04-28 09:32:27 +01:00
//
2021-12-08 19:36:41 +01:00
this.transformDataUserList(res['users'])
2021-08-19 18:54:50 +01:00
2021-01-13 10:02:30 +01:00
});
}
2021-08-20 19:10:13 +01:00
2021-12-16 16:36:39 +01:00
getGroupsDB() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storageservice.get("grouprooms").then((rooms) =>{
2022-01-13 17:28:35 +01:00
let k = rooms.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
var dateB = new Date(b._updatedAt).getTime();
return dateB - dateA;
});
2022-04-28 09:32:27 +01:00
2022-01-13 17:28:35 +01:00
2021-12-16 16:36:39 +01:00
this.allGroups = rooms.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
var dateB = new Date(b._updatedAt).getTime();
return dateB - dateA;
});
2022-01-26 12:51:24 +01:00
2022-04-28 09:32:27 +01:00
//
2021-12-16 16:36:39 +01:00
})
this.storageservice.get('chatusers').then((users) => {
2022-04-26 14:34:52 +01:00
this.dmUsers = users.filter(data => data.username != SessionStore.user.UserName);
2021-12-16 16:36:39 +01:00
})
} else {
this.sqlservice.getAllChatRoom().then((rooms: any) => {
2021-12-16 16:36:39 +01:00
let roomsArray = [];
rooms.forEach(element => {
let fddf = this.isJson(element.LastMessage);
let roomListDB = {
_id: element.Id,
customFields: this.isJson(element.customFields),
name: element.name,
lastMessage: this.isJson(element.LastMessage),
_updatedAt: element.UpdatedAt
}
if(element.customFields != "undefined") {
roomsArray.push(roomListDB)
}
});
this.allGroups = roomsArray.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
var dateB = new Date(b._updatedAt).getTime();
return dateB - dateA;
});
2022-04-28 09:32:27 +01:00
//
2021-12-16 16:36:39 +01:00
})
}
}
2022-08-03 14:30:02 +01:00
roomDataFileType(roomData) {
return roomData?.lastMessage?.file?.type || null
}
2022-01-07 16:01:17 +01:00
async transformGroups(data) {
2021-12-16 16:36:39 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
let groupsArray = [];
data.forEach(element => {
let roomList = {
_id: element._id,
uids: element.uids,
usernames: element.usernames,
name: element.name,
customFields: element.customFields,
lastMessage: element.lastMessage,
_updatedAt: element._updatedAt
}
2022-04-28 09:32:27 +01:00
2021-12-16 16:36:39 +01:00
groupsArray.push(roomList)
});
2022-01-07 16:01:17 +01:00
await this.storageservice.remove('grouprooms');
await this.storageservice.store('grouprooms', groupsArray);
2021-12-16 16:36:39 +01:00
} else {
data.forEach(element => {
let roomList = {
id: element._id,
uids: element.uids,
usernames: element.usernames,
customFields: element.customFields,
name: element.name,
lastMessage: element.lastMessage,
updatedat: element._updatedAt
}
2022-04-28 09:32:27 +01:00
2021-12-16 16:36:39 +01:00
this.sqlservice.addChatListRoom(roomList);
});
}
}
2022-07-27 16:12:46 +01:00
async emptyTextDescriptionOpen() {
this.closeAllDesktopComponents()
this.showEmptyComponent = true
}
2021-12-08 19:36:41 +01:00
async getGroups(event?) {
this.result = this.chatService.getAllPrivateGroups().subscribe(async (res: any) => {
2022-04-28 09:32:27 +01:00
//
2021-12-17 16:54:18 +01:00
this.showLoader = false;
2021-12-08 19:36:41 +01:00
if (res.groups != 200) {
2021-08-20 19:10:13 +01:00
2021-12-16 16:36:39 +01:00
this.transformGroups(res.groups);
this.getGroupsDB();
2021-12-08 19:36:41 +01:00
this.privateGroups = res.groups;
2022-04-28 09:32:27 +01:00
2022-06-08 16:09:40 +01:00
2021-12-08 19:36:41 +01:00
if (this.route.url != "/home/chat") {
2022-04-28 09:32:27 +01:00
//
2021-12-08 19:36:41 +01:00
}
else {
//Check if modal is opened
if (this.segment == "Grupos" && this.showGroupMessages != true) {
await new Promise(resolve => setTimeout(resolve, 1000));
2022-01-11 16:07:54 +01:00
//await this.getGroups();
2021-12-08 19:36:41 +01:00
}
}
2021-08-20 19:10:13 +01:00
}
else {
2022-01-11 16:07:54 +01:00
//await this.getGroups();
2021-08-20 19:10:13 +01:00
}
2021-07-23 14:43:51 +01:00
});
}
2021-05-18 14:37:43 +01:00
2021-12-16 16:36:39 +01:00
isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return str;
}
return JSON.parse(str);
}
2021-12-08 19:36:41 +01:00
async selectContact() {
const modal = await this.modalController.create({
component: ContactsPage,
2021-05-21 12:03:50 +01:00
cssClass: 'modal modal-desktop',
});
await modal.present();
2022-07-08 14:17:22 +01:00
modal.onDidDismiss().then((Data) => {
// console.log(Data,'daatatatat');
// let data = Data.data
// let roomId = data.roomId
// this.openMessagesPage(roomId);
});
}
2021-05-18 14:37:43 +01:00
2021-12-08 19:36:41 +01:00
async newGroup() {
const modal = await this.modalController.create({
component: NewGroupPage,
2021-05-21 12:03:50 +01:00
cssClass: 'modal modal-desktop',
});
await modal.present();
modal.onDidDismiss();
}
2021-04-14 13:56:38 +01:00
2021-12-08 19:36:41 +01:00
async editGroup(roomId) {
2021-04-14 13:56:38 +01:00
const modal = await this.modalController.create({
component: EditGroupPage,
2021-05-21 12:03:50 +01:00
cssClass: 'modal modal-desktop',
2021-04-14 13:56:38 +01:00
componentProps: {
roomId: roomId,
},
});
await modal.present();
2021-12-08 19:36:41 +01:00
modal.onDidDismiss().then((res) => {
2022-04-28 09:32:27 +01:00
2021-04-14 14:10:17 +01:00
this.modalController.dismiss(res.data);
});
2021-04-14 13:56:38 +01:00
}
2021-12-08 19:36:41 +01:00
async openMessagesModal(roomId: any) {
this.closeAllDesktopComponents();
2021-03-04 18:50:26 +01:00
2022-04-28 09:32:27 +01:00
//
2021-07-23 14:43:51 +01:00
2020-12-30 11:13:50 +01:00
const modal = await this.modalController.create({
component: MessagesPage,
2021-08-20 11:24:42 +01:00
cssClass: 'modal modal-desktop isMessagesChatOpened',
2021-01-13 10:02:30 +01:00
componentProps: {
2021-03-12 11:56:54 +01:00
roomId: roomId,
2021-01-13 10:02:30 +01:00
},
2020-12-30 11:13:50 +01:00
});
await modal.present();
modal.onDidDismiss();
}
2021-03-05 11:58:59 +01:00
2022-09-26 16:16:37 +01:00
async openChatDebuggingPageModal(roomId?: any) {
const modal = await this.modalController.create({
component: ChatDebuggingPage,
cssClass: 'modal modal-desktop isMessagesChatOpened',
componentProps: {
// roomId: roomId,
},
});
await modal.present();
modal.onDidDismiss();
}
2021-12-08 19:36:41 +01:00
async openGroupMessagesModal(roomId: any) {
2021-05-21 11:57:16 +01:00
2020-12-28 10:11:00 +01:00
const modal = await this.modalController.create({
component: GroupMessagesPage,
2021-08-20 11:24:42 +01:00
cssClass: 'modal modal-desktop isGroupChatOpened',
2021-01-13 10:02:30 +01:00
componentProps: {
roomId: roomId,
2021-01-13 10:02:30 +01:00
},
2020-12-28 10:11:00 +01:00
});
await modal.present();
modal.onDidDismiss();
}
2021-05-18 14:37:43 +01:00
2021-12-08 19:36:41 +01:00
}
2022-06-08 16:09:40 +01:00