mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Merge with websocket branch
This commit is contained in:
+33
-106
@@ -12,6 +12,7 @@ import {
|
||||
import { ModalController, Platform } from '@ionic/angular';
|
||||
import { AuthService } from 'src/app/services/auth.service';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
import { WsChatMethodsService} from 'src/app/services/chat/ws-chat-methods.service'
|
||||
import { GroupMessagesPage } from './group-messages/group-messages.page';
|
||||
import { ContactsPage } from './messages/contacts/contacts.page';
|
||||
import { MessagesPage } from './messages/messages.page';
|
||||
@@ -123,9 +124,10 @@ export class ChatPage implements OnInit {
|
||||
private router: Router,
|
||||
private sqlservice: SqliteService,
|
||||
private platform: Platform,
|
||||
private storageservice: StorageService
|
||||
|
||||
private storageservice: StorageService,
|
||||
public wsChatMethodsService: WsChatMethodsService,
|
||||
) {
|
||||
|
||||
this.loggedUserChat = authService.ValidatedUserChat['data'];
|
||||
this.headers = new HttpHeaders();
|
||||
window.onresize = (event) => {
|
||||
@@ -133,34 +135,31 @@ export class ChatPage implements OnInit {
|
||||
this.modalController.dismiss();
|
||||
}
|
||||
};
|
||||
|
||||
this.showLoader = true;
|
||||
|
||||
//this.load()
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
console.log(this.loggedUserChat);
|
||||
console.log(this.wsChatMethodsService.group);
|
||||
|
||||
|
||||
this.segment = "Contactos";
|
||||
|
||||
this.authService.userData$.subscribe((res: any) => {
|
||||
this.loggedUser = res;
|
||||
console.log(this.loggedUser);
|
||||
this.load();
|
||||
|
||||
this.getDirectMessagesDB();
|
||||
this.getGroupsDB()
|
||||
});
|
||||
|
||||
/* websocket functions */
|
||||
//this.sendMsg();
|
||||
|
||||
/* Fim websocket functions */
|
||||
this.hideRefreshButton();
|
||||
this.getChatMembers();
|
||||
|
||||
//Teste
|
||||
let t = this.showDateDuration(new Date());
|
||||
console.log(t);
|
||||
|
||||
this.setStatus('away');
|
||||
/* if(this.dataService.get("newGroup")){
|
||||
@@ -222,21 +221,6 @@ export class ChatPage implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* loadMessage(){
|
||||
this.chatService.messages.subscribe(msg => {
|
||||
console.log("Response from websocket: " + msg);
|
||||
});
|
||||
} */
|
||||
/* sendMsg() {
|
||||
console.log("new message from client to websocket: ", this.message);
|
||||
this.chatService.messages.next(this.message);
|
||||
this.message.msg = "";
|
||||
} */
|
||||
|
||||
|
||||
/* Fim websockets functions */
|
||||
|
||||
closeAllDesktopComponents() {
|
||||
this.showMessages = false;
|
||||
this.showContacts = false;
|
||||
@@ -379,38 +363,21 @@ export class ChatPage implements OnInit {
|
||||
}
|
||||
|
||||
onSegmentChange() {
|
||||
this.load();
|
||||
//this.load();
|
||||
}
|
||||
|
||||
doRefresh(event) {
|
||||
setTimeout(() => {
|
||||
this.load();
|
||||
//this.load();
|
||||
event.target.complete();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
refreshing() {
|
||||
this.load();
|
||||
}
|
||||
|
||||
load() {
|
||||
switch (this.segment) {
|
||||
case "Contactos":
|
||||
this.showLoader = true;
|
||||
this.getDirectMessages();
|
||||
break;
|
||||
|
||||
case "Grupos":
|
||||
this.showLoader = true;
|
||||
this.getGroups();
|
||||
break;
|
||||
}
|
||||
}
|
||||
customRoom() {
|
||||
let params = new HttpParams();
|
||||
params = params.set("types", "c");
|
||||
this.chatService.customsRooms(params).subscribe(res => {
|
||||
console.log(res);
|
||||
//console.log(res);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -424,9 +391,9 @@ export class ChatPage implements OnInit {
|
||||
var dateB = new Date(b._updatedAt).getTime();
|
||||
return dateB - dateA;
|
||||
});
|
||||
console.log('DIRECTMESSAGE FROM DB', this.userDirectMessages);
|
||||
//console.log('DIRECTMESSAGE FROM DB', this.userDirectMessages);
|
||||
|
||||
console.log('ROOMS FROM DB', rooms)
|
||||
//console.log('ROOMS FROM DB', rooms)
|
||||
})
|
||||
|
||||
this.storageservice.get('chatusers').then((users) => {
|
||||
@@ -434,7 +401,7 @@ export class ChatPage implements OnInit {
|
||||
})
|
||||
} else {
|
||||
this.sqlservice.getAllChatRoom().then((rooms: any) => {
|
||||
console.log('ROOMS FROM DB', rooms)
|
||||
//console.log('ROOMS FROM DB', rooms)
|
||||
let roomsArray = [];
|
||||
rooms.forEach(element => {
|
||||
let roomListDB = {
|
||||
@@ -454,13 +421,13 @@ export class ChatPage implements OnInit {
|
||||
var dateB = new Date(b._updatedAt).getTime();
|
||||
return dateB - dateA;
|
||||
});
|
||||
console.log('DIRECTMESSAGE FROM DB', this.userDirectMessages);
|
||||
//console.log('DIRECTMESSAGE FROM DB', this.userDirectMessages);
|
||||
|
||||
console.log('ROOMS FROM DB', rooms)
|
||||
//console.log('ROOMS FROM DB', rooms)
|
||||
})
|
||||
|
||||
this.sqlservice.getAllChatUsers().then((userslist: any) => {
|
||||
console.log('USERS FOM DB 1', userslist)
|
||||
//console.log('USERS FOM DB 1', userslist)
|
||||
let chatusersArray = [];
|
||||
userslist.forEach(element => {
|
||||
console.log('USERS FOM DB 2', element)
|
||||
@@ -491,7 +458,7 @@ export class ChatPage implements OnInit {
|
||||
_updatedAt: element._updatedAt
|
||||
}
|
||||
|
||||
console.log(' Web TRANSFORM ROOM LIST', roomList)
|
||||
//console.log(' Web TRANSFORM ROOM LIST', roomList)
|
||||
roomsArray.push(roomList)
|
||||
});
|
||||
|
||||
@@ -508,7 +475,7 @@ export class ChatPage implements OnInit {
|
||||
updatedat: element._updatedAt
|
||||
}
|
||||
|
||||
console.log('TRANSFORM ROOM LIST', roomList)
|
||||
//console.log('TRANSFORM ROOM LIST', roomList)
|
||||
this.sqlservice.addChatListRoom(roomList);
|
||||
});
|
||||
}
|
||||
@@ -518,72 +485,31 @@ export class ChatPage implements OnInit {
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
let usersArray = [];
|
||||
users.forEach(element => {
|
||||
console.log('TRANSFORM USER CHAT 1', element)
|
||||
//console.log('TRANSFORM USER CHAT 1', element)
|
||||
let chatusers = {
|
||||
_id: element._id,
|
||||
name: element.name,
|
||||
username: element.username
|
||||
}
|
||||
console.log('TRANSFORM USER CHAT 2', chatusers)
|
||||
//console.log('TRANSFORM USER CHAT 2', chatusers)
|
||||
usersArray.push(chatusers);
|
||||
});
|
||||
await this.storageservice.remove('chatusers');
|
||||
await this.storageservice.store('chatusers',usersArray);
|
||||
} else {
|
||||
users.forEach(element => {
|
||||
console.log('TRANSFORM USER CHAT 1', element)
|
||||
//console.log('TRANSFORM USER CHAT 1', element)
|
||||
let chatusers = {
|
||||
id: element._id,
|
||||
name: element.name,
|
||||
username: element.username
|
||||
}
|
||||
console.log('TRANSFORM USER CHAT 2', chatusers)
|
||||
//console.log('TRANSFORM USER CHAT 2', chatusers)
|
||||
this.sqlservice.addChatListUsers(chatusers);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async getDirectMessages(event?) {
|
||||
this.chatService.getAllDirectMessages().subscribe(async (res: any) => {
|
||||
this.showLoader = false;
|
||||
this.transformDataRoomList(res.ims)
|
||||
this.getDirectMessagesDB()
|
||||
console.log('Chat list', res);
|
||||
|
||||
if (res != 200) {
|
||||
/* if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
this.userDirectMessages = res.ims.sort((a, b) => {
|
||||
var dateA = new Date(a._updatedAt).getTime();
|
||||
var dateB = new Date(b._updatedAt).getTime();
|
||||
return dateB - dateA;
|
||||
});
|
||||
} */
|
||||
//console.log(res.ims);
|
||||
|
||||
//console.log(this.userDirectMessages);
|
||||
|
||||
if (this.route.url != "/home/chat") {
|
||||
//console.log("Timer message stop")
|
||||
}
|
||||
else {
|
||||
//console.log('TIMER');
|
||||
//Check if modal is opened
|
||||
if (this.segment == "Contactos" && this.showMessages != true) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
await this.getDirectMessages();
|
||||
//console.log('Timer contactos list running')
|
||||
}
|
||||
else {
|
||||
//console.log('No timer!');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
await this.getDirectMessages();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
showDateDuration(start: any) {
|
||||
return this.timeService.showDateDuration(start);
|
||||
}
|
||||
@@ -595,13 +521,13 @@ export class ChatPage implements OnInit {
|
||||
async getChatMembers() {
|
||||
//return await this.chatService.getMembers(roomId).toPromise();
|
||||
this.chatService.getAllUsers().subscribe(res => {
|
||||
console.log('chatusers', res);
|
||||
//console.log('chatusers', res);
|
||||
this.transformDataUserList(res['users'])
|
||||
|
||||
/* if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
this.dmUsers = res['users'].filter(data => data.username != this.loggedUserChat.me.username);
|
||||
console.log(this.dmUsers);
|
||||
} */
|
||||
//console.log(this.dmUsers);
|
||||
}*/
|
||||
|
||||
});
|
||||
}
|
||||
@@ -626,6 +552,7 @@ export class ChatPage implements OnInit {
|
||||
});
|
||||
|
||||
|
||||
//console.log('GROUPS FROM DB', this.allGroups)
|
||||
})
|
||||
|
||||
this.storageservice.get('chatusers').then((users) => {
|
||||
@@ -654,7 +581,7 @@ export class ChatPage implements OnInit {
|
||||
var dateB = new Date(b._updatedAt).getTime();
|
||||
return dateB - dateA;
|
||||
});
|
||||
console.log('Group FROM DB', this.allGroups);
|
||||
//console.log('Group FROM DB', this.allGroups);
|
||||
|
||||
})
|
||||
|
||||
@@ -741,18 +668,18 @@ export class ChatPage implements OnInit {
|
||||
//console.log(this.allGroups);
|
||||
/* }); */
|
||||
if (this.route.url != "/home/chat") {
|
||||
console.log("Timer message stop")
|
||||
//console.log("Timer message stop")
|
||||
}
|
||||
else {
|
||||
//Check if modal is opened
|
||||
if (this.segment == "Grupos" && this.showGroupMessages != true) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
await this.getGroups();
|
||||
//await this.getGroups();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
await this.getGroups();
|
||||
//await this.getGroups();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -802,7 +729,7 @@ export class ChatPage implements OnInit {
|
||||
async openMessagesModal(roomId: any) {
|
||||
this.closeAllDesktopComponents();
|
||||
|
||||
console.log(roomId);
|
||||
//console.log(roomId);
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: MessagesPage,
|
||||
|
||||
Reference in New Issue
Block a user