Merge branch 'developer' of https://bitbucket.org/equilibriumito/gabinete-digital into feature/chatStorage

This commit is contained in:
Eudes Inácio
2022-01-27 15:57:28 +01:00
15 changed files with 441 additions and 186 deletions
@@ -9,7 +9,7 @@
</button> </button>
</div> </div>
<div class="div-title"> <div class="div-title">
<ion-label class="title">Promover para Administrador</ion-label> <ion-label class="title">Nomear novo administrador</ion-label>
</div> </div>
</div> </div>
</div> </div>
@@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular'; import { ModalController, NavParams } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service'; import { AuthService } from 'src/app/services/auth.service';
import { ChatService } from 'src/app/services/chat.service'; import { ChatService } from 'src/app/services/chat.service';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { ThemeService } from 'src/app/services/theme.service' import { ThemeService } from 'src/app/services/theme.service'
import { ToastService } from 'src/app/services/toast.service'; import { ToastService } from 'src/app/services/toast.service';
@@ -14,7 +15,7 @@ import { ToastService } from 'src/app/services/toast.service';
export class SetRoomOwnerPage implements OnInit { export class SetRoomOwnerPage implements OnInit {
textSearch:string = ""; textSearch:string = "";
room:any; roomId:any;
members:any; members:any;
constructor( constructor(
@@ -25,13 +26,14 @@ export class SetRoomOwnerPage implements OnInit {
private navParams: NavParams, private navParams: NavParams,
public ThemeService: ThemeService, public ThemeService: ThemeService,
private toastService: ToastService, private toastService: ToastService,
public wsChatMethodsService: WsChatMethodsService,
) { ) {
this.room = this.navParams.get('room'); this.roomId = this.navParams.get('roomId');
this.members = this.navParams.get('members'); this.members = this.navParams.get('members');
} }
ngOnInit() { ngOnInit() {
console.log(this.room); console.log(this.members);
} }
@@ -57,23 +59,43 @@ export class SetRoomOwnerPage implements OnInit {
return null; return null;
} }
setRoomOwner(user:any){ async setRoomOwner(user:any){
console.log(user); let res:any = await this.wsChatMethodsService.addRoomOwner(this.roomId, user._id);
console.log(this.room);
console.log(res);
if(res.error){
if(res.error.error == 'error-user-already-owner'){
this.toastService._badRequest('Este utilizador já é administrador');
}
else{
this.toastService._badRequest('Não foi possível completar a ação, por favor tente novamente.');
}
}
else{
this.modalController.dismiss('success');
}
/*
let body = { let body = {
"roomId": this.room._id, "roomId": this.roomId,
"userId": user._id "userId": user._id
} }
this.chatService.addGroupOwner(body).subscribe((res)=>{ this.chatService.addGroupOwner(body).subscribe((res)=>{
alert('here');
console.log(res); console.log(res);
this.close(); this.close();
}, (error) => { this.toastService._successMessage('Operação realizada com sucesso');
this.toastService._badRequest('Não foi possível completar a ação, por favor tente novamente.'); }, (e) => {
}); if(e.error.errorType == 'error-user-already-owner'){
this.toastService._badRequest('Este utilizador já é administrador');
}
else{
this.toastService._badRequest('Não foi possível completar a ação, por favor tente novamente.');
}
}); */
} }
+1 -1
View File
@@ -121,7 +121,7 @@
<div class="item-date" [class.item-date-active]="group.value.id ==idSelected" *ngIf="group.value.customFields.countDownDate">{{countDownDate(group.value.customFields.countDownDate, group.value.id)}}</div> <div class="item-date" [class.item-date-active]="group.value.id ==idSelected" *ngIf="group.value.customFields.countDownDate">{{countDownDate(group.value.customFields.countDownDate, group.value.id)}}</div>
</div> </div>
<div *ngIf="group.value.lastMessage" class="item-description d-flex align-items-center" [class.item-description-active]="group.value.id ==idSelected"> <div *ngIf="group.value.lastMessage" class="item-description d-flex align-items-center" [class.item-description-active]="group.value.id ==idSelected">
<div class="item-message">{{group.value.lastMessage.u.name}}: {{group.value.lastMessage.msg}} </div> <div *ngIf="group.value.lastMessage.u.name" class="item-message">{{group.value.lastMessage.u.name}}: {{group.value.lastMessage.msg}} </div>
<div class="item-files add-ellipsis" *ngIf="group.value.file"> <div class="item-files add-ellipsis" *ngIf="group.value.file">
<fa-icon *ngIf="group.value.lastMessage.file.type != 'application/meeting'" icon="file-alt" class="file-icon" [class.set-active-item-font-to-white]="group.value.id == idSelected"></fa-icon> <fa-icon *ngIf="group.value.lastMessage.file.type != 'application/meeting'" icon="file-alt" class="file-icon" [class.set-active-item-font-to-white]="group.value.id == idSelected"></fa-icon>
<fa-icon *ngIf="group.value.lastMessage.file.type == 'application/meeting'" icon="calendar-alt" class="file-icon" [class.set-active-item-font-to-white]="group.value.id == idSelected"></fa-icon> <fa-icon *ngIf="group.value.lastMessage.file.type == 'application/meeting'" icon="calendar-alt" class="file-icon" [class.set-active-item-font-to-white]="group.value.id == idSelected"></fa-icon>
@@ -333,12 +333,14 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
cssClass: 'chat-popover', cssClass: 'chat-popover',
componentProps: { componentProps: {
roomId: this.roomId, roomId: this.roomId,
members: this.members,
}, },
}); });
await modal.present(); await modal.present();
modal.onDidDismiss().then(res=>{ modal.onDidDismiss().then(res=>{
if(res.data == 'leave'){ if(res.data == 'leave'){
console.log('saiu do grupo'); console.log('saiu do grupo');
//this.wsChatMethodsService.subscribeToRoomUpdate(this.roomId, this.room);
} }
else if(res.data == 'cancel'){ else if(res.data == 'cancel'){
console.log('cancel'); console.log('cancel');
+32 -2
View File
@@ -6,6 +6,8 @@ import { GroupContactsPage } from '../group-messages/group-contacts/group-contac
import { ThemeService } from 'src/app/services/theme.service' import { ThemeService } from 'src/app/services/theme.service'
import { ChatService } from 'src/app/services/chat.service'; import { ChatService } from 'src/app/services/chat.service';
import { ProcessesService } from 'src/app/services/processes.service'; import { ProcessesService } from 'src/app/services/processes.service';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { AuthService } from 'src/app/services/auth.service';
@Component({ @Component({
selector: 'app-new-group', selector: 'app-new-group',
@@ -21,6 +23,7 @@ export class NewGroupPage implements OnInit {
thedate:any; thedate:any;
groupName:string; groupName:string;
documents:any; documents:any;
loggedUserChat: any;
constructor( constructor(
private pickerController: PickerController, private pickerController: PickerController,
@@ -30,8 +33,11 @@ export class NewGroupPage implements OnInit {
public ThemeService: ThemeService, public ThemeService: ThemeService,
private chatService: ChatService, private chatService: ChatService,
private processesService: ProcessesService, private processesService: ProcessesService,
public wsChatMethodsService: WsChatMethodsService,
private authService: AuthService,
) )
{ {
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = false; this.isGroupCreated = false;
this.groupName = this.navParams.get('name'); this.groupName = this.navParams.get('name');
this.documents = this.navParams.get('documents'); this.documents = this.navParams.get('documents');
@@ -55,10 +61,34 @@ export class NewGroupPage implements OnInit {
this.modalController.dismiss(); this.modalController.dismiss();
} }
createGroup(){ async createGroup(){
let name = this.groupName.split(' ').join('-'); let name = this.groupName.split(' ').join('-');
//Take out all special characters in string //Take out all special characters in string
name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
let customFields = {}
let res:any;
if(this.thedate){
let customFields = {
"countDownDate":this.thedate
}
res = await this.wsChatMethodsService.createPrivateRoom(name, this.loggedUserChat.me.username, customFields);
console.log(res);
}
else{
res = await this.wsChatMethodsService.createPrivateRoom(name, this.loggedUserChat.me.username, customFields);
console.log(res);
}
this.isGroupCreated = true;
this.addContacts(res.result);
this.wsChatMethodsService.subscribeToRoomUpdate(res.result.rid, res.result);
//this.addGroupMessage.emit(res.result.rid);
/*
let body = { "name":name, } let body = { "name":name, }
this.chatService.addGroup(body).subscribe(res=>{ this.chatService.addGroup(body).subscribe(res=>{
console.log('group created'); console.log('group created');
@@ -112,7 +142,7 @@ export class NewGroupPage implements OnInit {
this.chatService.sendMessage(body).toPromise(); this.chatService.sendMessage(body).toPromise();
}); });
} }
}); }); */
} }
async addContacts(room){ async addContacts(room){
+6 -1
View File
@@ -39,7 +39,7 @@ export class RoomService {
private sqlservice: SqliteService, private sqlservice: SqliteService,
) { } ) { }
setData({ customFields, id, name, t, lastMessage, _updatedAt }) { setData({ customFields, id, name, t, lastMessage = new MessageService(), _updatedAt }) {
this.customFields = customFields this.customFields = customFields
this.id = id this.id = id
this.name = name this.name = name
@@ -62,6 +62,7 @@ export class RoomService {
/* this.ToastService._chatMessage({message:'Nova mensagem', sender:'Gilson'}) */ /* this.ToastService._chatMessage({message:'Nova mensagem', sender:'Gilson'}) */
const message = new MessageService() const message = new MessageService()
message.setData(ChatMessage) message.setData(ChatMessage)
this.lastMessage.msg = message.msg this.lastMessage.msg = message.msg
if (message.t == 'r') { this.name = message.msg } if (message.t == 'r') { this.name = message.msg }
this.calDateDuration(ChatMessage._updatedAt) this.calDateDuration(ChatMessage._updatedAt)
@@ -89,6 +90,10 @@ export class RoomService {
this.WsChatService.send(this.id, msg) this.WsChatService.send(this.id, msg)
} }
leave(rid?) {
this.WsChatService.leaveRoom(this.id)
}
getMsgFromDBMobile() { getMsgFromDBMobile() {
console.log('ALL MSG DBBB', this.id) console.log('ALL MSG DBBB', this.id)
this.sqlservice.getAllChatMSG(this.id).then((msg: any = []) => { this.sqlservice.getAllChatMSG(this.id).then((msg: any = []) => {
@@ -46,35 +46,7 @@ export class WsChatMethodsService {
// console.log("ROOMS" + JSON.stringify(rooms)) // console.log("ROOMS" + JSON.stringify(rooms))
rooms.result.update.forEach((roomData: room) => { rooms.result.update.forEach((roomData: room) => {
let room:RoomService; this.prepareRoom(roomData);
//console.log(roomData);
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice)
room.setData({
customFields: roomData.customFields,
id: this.getRoomId(roomData),
name: this.getRoomName(roomData),
t: roomData.t,
lastMessage: this.getRoomLastMessage(roomData),
_updatedAt: new Date(roomData._updatedAt['$date'])
})
room.receiveMessage()
let roomId = this.getRoomId(roomData)
if(this.isIndividual(roomData)) {
this.dm[roomId] = room
this.dmCount++
} else {
this.group[roomId] = room
this.groupCount++
}
}); });
this.loadingWholeList = false this.loadingWholeList = false
@@ -99,6 +71,68 @@ export class WsChatMethodsService {
})) }))
} }
subscribeToRoomUpdate(id, roomData) {
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
console.log('streamRoomMessages', subscription)
})
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
console.log('streamRoomMessages', subscription)
})
this.WsChatService.streamNotifyLogged().then((subscription=>{
console.log('streamRoomMessages', subscription)
}))
this.prepareRoom(roomData);
this.getGroupRoom(id).loadHistory();
}
prepareRoom(roomData){
let room:RoomService;
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice)
room.setData({
customFields: roomData.customFields,
id: this.getRoomId(roomData),
name: this.getRoomName(roomData),
t: roomData.t,
lastMessage: this.getRoomLastMessage(roomData),
_updatedAt: new Date(roomData._updatedAt['$date'])
})
room.receiveMessage()
let roomId = this.getRoomId(roomData)
if(this.isIndividual(roomData)) {
this.dm[roomId] = room
this.dmCount++
} else {
this.group[roomId] = room
this.groupCount++
}
}
leaveRoom(id?) {
return this.WsChatService.leaveRoom(id);
}
hidingRoom(id?) {
return this.WsChatService.hidingRoom(id);
}
addRoomOwner(roomid, userId){
return this.WsChatService.addRoomOwner(roomid, userId);
}
createPrivateRoom(groupName, username, customFields){
return this.WsChatService.createPrivateRoom(groupName, username, customFields);
}
getDmRoom(id): RoomService { getDmRoom(id): RoomService {
try { try {
return this.dm[id] return this.dm[id]
@@ -130,7 +164,7 @@ export class WsChatMethodsService {
return roomData._id return roomData._id
} }
getRoomLastMessage(roomData: room) { getRoomLastMessage(roomData: room):any {
return roomData.lastMessage return roomData.lastMessage
} }
+104 -1
View File
@@ -153,9 +153,112 @@ export class WsChatService {
}); });
} }
leaveRoom(roomId) {
const requestId = uuidv4()
var message = {
msg: "method",
method: "leaveRoom",
id: requestId,
params: [
roomId,
]
}
this.ws.send({message, requestId});
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
addRoomOwner(roomId, userId) {
const requestId = uuidv4()
var message = {
msg: "method",
method: "addRoomOwner",
id: requestId,
params: [
roomId,
userId
]
}
this.ws.send({message, requestId});
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
hidingRoom(roomId){
const requestId = uuidv4()
var message = {
msg: "method",
method: "hideRoom",
id: requestId,
params: [roomId]
}
this.ws.send({message, requestId});
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
joinRoom(){} joinRoom(){}
deleteMessage() {} deleteMessage() {}
createRoom() {} createPrivateRoom(groupName, username, customFields) {
const requestId = uuidv4()
var message = {
msg: "method",
method: "createPrivateGroup",
id: requestId,
params: [
groupName,
[username],
false,
customFields,
{
"broadcast":false,
"encrypted":false
}
]
}
this.ws.send({message, requestId});
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
@@ -134,12 +134,9 @@ export class GroupContactsPage implements OnInit {
updateGroup(){ updateGroup(){
this.showLoader = true; this.showLoader = true;
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{ this.addContacts(this.roomId);
this.room = room['room']; this.openGroupMessage.emit(this.roomId);
this.addContacts(this.room); this.showLoader = false;
this.showLoader = false;
this.openGroupMessage.emit(this.room._id);
});
} }
openGroupMessagesPage(){ openGroupMessagesPage(){
this.showLoader = true; this.showLoader = true;
@@ -259,15 +256,15 @@ export class GroupContactsPage implements OnInit {
user.isChecked = !user.isChecked; user.isChecked = !user.isChecked;
} }
addContacts(room:any){ addContacts(roomId:any){
console.log(room); console.log(roomId);
this.selectedUserList = this.users.filter(function(contact) { this.selectedUserList = this.users.filter(function(contact) {
return contact.isChecked == true; return contact.isChecked == true;
}); });
console.log( this.selectedUserList); console.log( this.selectedUserList);
this.selectedUserList.forEach(user=>{ this.selectedUserList.forEach(user=>{
let body ={ let body ={
"roomId":room._id, "roomId":roomId,
"userId":user._id, "userId":user._id,
} }
this.chatService.addUserToGroup(body).subscribe(res=>{ this.chatService.addUserToGroup(body).subscribe(res=>{
@@ -92,55 +92,62 @@
</div> </div>
</div> </div>
<div *ngIf="msg.file">
<div class="message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45" *ngIf="msg.t != 'r' && msg.t != 'ul' && msg.t != 'au' && msg.t != 'ru' && msg.alias =='documento'" > <div class="message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45" *ngIf="msg.t != 'r' && msg.t != 'ul' && msg.t != 'au' && msg.t != 'ru' && msg.file.type != 'application/meeting'" >
<div class="message-item-options d-flex justify-content-end"> <div *ngIf="msg.file.type != 'application/meeting'">
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"></fa-icon> AQUI
<mat-menu #beforeMenu="matMenu" xPosition="before"> <div class="message-item-options d-flex justify-content-end">
<button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button> <fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"></fa-icon>
</mat-menu> <mat-menu #beforeMenu="matMenu" xPosition="before">
</div> <button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button>
<div class="title"> </mat-menu>
<ion-label>{{msg.u.name}}</ion-label> </div>
<span class="time">{{showDateDuration(msg._updatedAt)}}</span> <div class="title">
</div> <ion-label>{{msg.u.name}}</ion-label>
<div class="message"> <span class="time">{{showDateDuration(msg._updatedAt)}}</span>
<ion-label>{{msg.msg}}</ion-label> </div>
<div *ngIf="msg.attachments" class="message-attachments"> <div class="message">
<div *ngFor="let file of msg.attachments"> <div *ngIf="msg.attachments" class="message-attachments">
<div (click)="openPreview(msg)"> <div *ngFor="let file of msg.attachments">
<img *ngIf="file.image_url" src="{{file.image_url}}" alt="image"> <div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)">
</div> <img *ngIf="file.image_url" src="{{file.image_url}}" alt="image">
<div> </div>
<div> <div *ngIf="msg.file.type != 'application/img'">
<div class="file"> <div class="file">
<!-- <canvas id="pdf_canvas"></canvas> --> <!-- <canvas id="pdf_canvas"></canvas> -->
<div (click)="viewDocument(msg.file, file.title_link)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file"> <div (click)="viewDocument(msg.file, file.title_link)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<span *ngIf="msg.file.type"> <span *ngIf="msg.file.type">
<fa-icon *ngIf="msg.file.type == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon> <fa-icon *ngIf="msg.file.type == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon>
<fa-icon *ngIf="msg.file.type == 'application/word'" icon="file-word" class="word-icon"></fa-icon> <fa-icon *ngIf="msg.file.type == 'application/word'" icon="file-word" class="word-icon"></fa-icon>
<fa-icon *ngIf="msg.file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'" icon="file-word" class="excel-icon"></fa-icon> <fa-icon *ngIf="msg.file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'" icon="file-word" class="excel-icon"></fa-icon>
<ion-icon *ngIf="msg.file.type == 'application/webtrix'" src="assets/icon/webtrix.svg"></ion-icon> <ion-icon *ngIf="msg.file.type == 'application/webtrix'" src="assets/icon/webtrix.svg"></ion-icon>
</span> </span>
<ion-label class="file-title">{{file.title}}</ion-label> <ion-label class="file-title">{{file.title}}</ion-label>
</div>
</div> </div>
</div> <div class="file-details-optional">
<div class="file-details-optional"> <ion-label *ngIf="msg.file">
<ion-label *ngIf="msg.file"> <span *ngIf="file.description">{{file.description}}</span>
<span *ngIf="file.description">{{file.description}}</span> <span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span>
<span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span> <span *ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span>
<span *ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span> </ion-label>
</ion-label>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{{last ? scrollToBottom() : ''}}
</div> </div>
{{last ? scrollToBottom() : ''}}
</div> </div>
</div> </div>
<div *ngIf="msg.file.type == 'application/meeting'" class="info-meeting">
<ion-label class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br />
<button (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal"><ion-label class="info-meeting-normal">{{msg.file.subject}}</ion-label></button><br />
<ion-label class="info-meeting-medium"><ion-icon name="calendar-outline"></ion-icon> De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}</ion-label><br />
<ion-label class="info-meeting-medium"><ion-icon></ion-icon><ion-icon name="location-outline"></ion-icon> {{msg.file.venue}}</ion-label><br />
</div>
</div>
<div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.msg ==''"> <!-- <div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.msg ==''">
<div *ngIf="msg.file.type == 'application/img'"> <div *ngIf="msg.file.type == 'application/img'">
<div class="message-item-options d-flex justify-content-end"> <div class="message-item-options d-flex justify-content-end">
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"> <fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer">
@@ -158,7 +165,6 @@
<div *ngIf="msg.file" class="message-attachments"> <div *ngIf="msg.file" class="message-attachments">
<div> <div>
<div (click)="openPreview(msg)"> <div (click)="openPreview(msg)">
<!-- <img *ngIf="file.image_url" src="{{file.image_url}}" alt="image" (click)="imageSize(file.image_url)"> -->
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image"> <img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image">
</div> </div>
</div> </div>
@@ -167,7 +173,7 @@
</div> </div>
</div> </div>
</div> </div>
-->
<div *ngIf="msg.t == 'r'" class="info-text"> <div *ngIf="msg.t == 'r'" class="info-text">
@@ -198,7 +204,7 @@
</div> </div>
{{last ? scrollToBottom() : ''}} {{last ? scrollToBottom() : ''}}
</div> </div>
<div *ngIf="msg.file" > <!-- <div *ngIf="msg.file" >
<div *ngIf="msg.file.type == 'application/meeting'" class="info-meeting"> <div *ngIf="msg.file.type == 'application/meeting'" class="info-meeting">
<ion-label class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br /> <ion-label class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br />
<button (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal"><ion-label class="info-meeting-normal">{{msg.file.subject}}</ion-label></button><br /> <button (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal"><ion-label class="info-meeting-normal">{{msg.file.subject}}</ion-label></button><br />
@@ -206,7 +212,7 @@
<ion-label class="info-meeting-medium"><ion-icon></ion-icon><ion-icon name="location-outline"></ion-icon> {{msg.file.venue}}</ion-label><br /> <ion-label class="info-meeting-medium"><ion-icon></ion-icon><ion-icon name="location-outline"></ion-icon> {{msg.file.venue}}</ion-label><br />
</div> </div>
{{last ? scrollToBottom() : ''}} {{last ? scrollToBottom() : ''}}
</div> </div> -->
</div> </div>
</div> </div>
<ion-fab horizontal="end" vertical="bottom" slot="fixed"> <ion-fab horizontal="end" vertical="bottom" slot="fixed">
@@ -80,9 +80,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
downloadFile: any; downloadFile: any;
constructor( constructor(
private menu: MenuController, public wsChatMethodsService: WsChatMethodsService,
private modalController: ModalController, private modalController: ModalController,
private actionSheetController: ActionSheetController,
public popoverController: PopoverController, public popoverController: PopoverController,
private chatService: ChatService, private chatService: ChatService,
private authService: AuthService, private authService: AuthService,
@@ -97,8 +96,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
public ThemeService: ThemeService, public ThemeService: ThemeService,
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private storage: Storage, private storage: Storage,
public wsChatMethodsService: WsChatMethodsService
) { ) {
console.log('OnCONSTRUCTOR');
this.loggedUserChat = authService.ValidatedUserChat['data']; this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = true; this.isGroupCreated = true;
this.roomCountDownDate = ""; this.roomCountDownDate = "";
@@ -106,11 +106,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
console.log('OnCHANGES');
this.getRoomInfo(); this.getRoomInfo();
//this.scrollToBottom(); //this.scrollToBottom();
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory();
this.wsChatMethodsService.getGroupRoom(this.roomId).getMsgFromDB(); this.wsChatMethodsService.getGroupRoom(this.roomId).getMsgFromDB();
console.log('MESSAGES'+this.wsChatMethodsService.getGroupRoom(this.roomId).massages); console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).massages);
this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked
setTimeout(()=>{ setTimeout(()=>{
@@ -120,11 +122,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
ngOnInit() { ngOnInit() {
console.log(this.roomId);
this.loggedUser = this.loggedUserChat; this.loggedUser = this.loggedUserChat;
//console.log(this.wsChatMethodsService.getRoom(this.roomId).massages);
this.loggedUser=this.loggedUserChat; this.loggedUser=this.loggedUserChat;
this.getRoomInfo(); setTimeout(() => {
this.getRoomInfo();
}, 1000);
this.setStatus('online'); this.setStatus('online');
this.getChatMembers(); this.getChatMembers();
//this.getMessageDB(); //this.getMessageDB();
@@ -254,6 +258,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
async getRoomInfo() { async getRoomInfo() {
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory();
let room = await this.chatService.getRoomInfo(this.roomId).toPromise(); let room = await this.chatService.getRoomInfo(this.roomId).toPromise();
this.room = room['room']; this.room = room['room'];
if (this.room.name) { if (this.room.name) {
@@ -288,29 +293,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
loadGroupMessages(roomId) { loadGroupMessages(roomId) {
//console.log('here'+room.t);
this.showLoader = true; this.showLoader = true;
//If group is private call getGroupMembers
/* if(room.t === 'p'){
console.log('private'); */
this.chatService.getPrivateGroupMessages(this.roomId).subscribe(res => { this.chatService.getPrivateGroupMessages(this.roomId).subscribe(res => {
console.log(res); console.log(res);
let msgOnly = res['messages'].filter(data => data.t != 'au'); let msgOnly = res['messages'].filter(data => data.t != 'au');
//this.messages = msgOnly.reverse();
//console.log(res);
this.showLoader = false; this.showLoader = false;
}); });
/* } */
//Otherwise call getChannelMembers for públic groups
/* else{
this.chatService.getPublicGroupMessages(this.roomId).subscribe(res=>{
console.log(res);
this.messages = res['messages'].reverse();
});
} */
} }
sendMessage() { sendMessage() {
@@ -364,6 +352,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}); });
return await popover.present(); */ return await popover.present(); */
console.log(this.roomId);
const modal = await this.modalController.create({ const modal = await this.modalController.create({
enterAnimation, enterAnimation,
leaveAnimation, leaveAnimation,
@@ -379,6 +370,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
console.log(res); console.log(res);
if (res.data == 'leave') { if (res.data == 'leave') {
this.getRoomInfo(); this.getRoomInfo();
this.wsChatMethodsService.hidingRoom(this.roomId);
this.closeAllDesktopComponents.emit(); this.closeAllDesktopComponents.emit();
this.showEmptyContainer.emit(); this.showEmptyContainer.emit();
} }
+61 -52
View File
@@ -56,63 +56,73 @@
{{last ? scrollToBottom() : ''}} {{last ? scrollToBottom() : ''}}
</div> </div>
</div> </div>
<div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45'
*ngIf="msg.alias == 'documento'">
<div class="message-item-options d-flex justify-content-end">
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer">
</fa-icon>
<mat-menu #beforeMenu="matMenu" xPosition="before">
<button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button>
</mat-menu>
</div>
<div class="title">
<ion-label>{{msg.u.name}}</ion-label>
<span class="time">{{showDateDuration(msg._updatedAt)}}</span>
</div>
<div>
<!-- <ion-label>{{msg.msg}}</ion-label> -->
<div *ngIf="msg.attachments" class="message-attachments">
<div *ngFor="let file of msg.attachments">
<div (click)="downloadFileMsg(msg)" dfsdvsvs> <div *ngIf="msg.file">
<!-- <img *ngIf="file.image_url" src="{{file.image_url}}" alt="image" (click)="imageSize(file.image_url)"> --> <div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.file.type != 'application/meeting'">
<img src={{msg.image_url}} alt="image"> <div class="message-item-options d-flex justify-content-end">
<!-- <div (click)="openPreview(msg)"> <fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer">
<img *ngIf="file.image_url" src="{{file.image_url}}" alt="image"> --> </fa-icon>
</div> <mat-menu #beforeMenu="matMenu" xPosition="before">
<div *ngIf="msg.file"> <button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button>
<div class="file"> </mat-menu>
<div (click)="viewDocument(msg, file.title_link)" class="file-details add-ellipsis cursor-pointer" </div>
*ngIf="msg.file"> <div class="title">
<span *ngIf="msg.file.type"> <ion-label>{{msg.u.name}}</ion-label>
<fa-icon *ngIf="msg.file.type == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon> <span class="time">{{showDateDuration(msg._updatedAt)}}</span>
<fa-icon *ngIf="msg.file.type == 'application/word'" icon="file-word" class="word-icon"></fa-icon> </div>
<fa-icon <div>
*ngIf="msg.file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'" <div *ngIf="msg.attachments" class="message-attachments">
icon="file-word" class="excel-icon"></fa-icon> <div *ngFor="let file of msg.attachments">
<ion-icon *ngIf="msg.file.type == 'application/webtrix'" src="assets/icon/webtrix.svg"></ion-icon> <div *ngIf="msg.file.type == 'application/img'" (click)="downloadFileMsg(msg)" dfsdvsvs>
<ion-icon *ngIf="msg.file.type == 'application/meeting'" src="assets/icon/webtrix.svg"></ion-icon> <img src={{msg.image_url}} alt="image">
</span>
<ion-label class="file-title">{{file.title}}</ion-label>
</div>
</div> </div>
<div class="file-details-optional"> <div *ngIf="msg.file.type != 'application/img'">
<ion-label *ngIf="msg.file"> <div class="file">
<span *ngIf="file.description">{{file.description}}</span> <div (click)="viewDocument(msg, file.title_link)" class="file-details add-ellipsis cursor-pointer"
<span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span> *ngIf="msg.file">
<span <span *ngIf="msg.file.type">
*ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span> <fa-icon *ngIf="msg.file.type == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon>
</ion-label> <fa-icon *ngIf="msg.file.type == 'application/word'" icon="file-word" class="word-icon"></fa-icon>
<fa-icon
*ngIf="msg.file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'"
icon="file-word" class="excel-icon"></fa-icon>
<ion-icon *ngIf="msg.file.type == 'application/webtrix'" src="assets/icon/webtrix.svg"></ion-icon>
<ion-icon *ngIf="msg.file.type == 'application/meeting'" src="assets/icon/webtrix.svg"></ion-icon>
</span>
<ion-label class="file-title">{{file.title}}</ion-label>
</div>
</div>
<div class="file-details-optional">
<ion-label *ngIf="msg.file">
<span *ngIf="file.description">{{file.description}}</span>
<span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span>
<span
*ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span>
</ion-label>
</div>
</div> </div>
</div> </div>
</div> </div>
{{last ? scrollToBottom() : ''}}
</div> </div>
{{last ? scrollToBottom() : ''}}
</div> </div>
<div class="info-meeting" *ngIf="msg.file.type == 'application/meeting'">
<ion-label class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br />
<button (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal">
<ion-label class="info-meeting-normal">{{msg.file.subject}}</ion-label>
</button><br />
<ion-label class="info-meeting-medium">
<ion-icon name="calendar-outline"></ion-icon> De {{showDateDuration(msg.file.start_date)}} a
{{showDateDuration(msg.file.end_date)}}
</ion-label><br />
<ion-label class="info-meeting-medium">
<ion-icon></ion-icon>
<ion-icon name="location-outline"></ion-icon> {{msg.file.venue}}
</ion-label><br />
</div>
</div> </div>
<div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.msg ==''"> <!-- <div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.msg ==''">
<div *ngIf="msg.file"> <div *ngIf="msg.file">
<div *ngIf="msg.file.type == 'application/img'"> <div *ngIf="msg.file.type == 'application/img'">
<div class="message-item-options d-flex justify-content-end"> <div class="message-item-options d-flex justify-content-end">
@@ -131,7 +141,6 @@
<div *ngIf="msg.file" class="message-attachments"> <div *ngIf="msg.file" class="message-attachments">
<div> <div>
<div (click)="openPreview(msg)"> <div (click)="openPreview(msg)">
<!-- <img *ngIf="file.image_url" src="{{file.image_url}}" alt="image" (click)="imageSize(file.image_url)"> -->
File File
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image"> <img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image">
</div> </div>
@@ -141,10 +150,10 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div> -->
<div *ngIf="msg.file"> <!-- <div *ngIf="msg.file">
<div class="info-meeting" *ngIf="msg.file.type == 'application/meeting'"> <div class="info-meeting" *ngIf="msg.file.type == 'application/meeting'">
<ion-label class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br /> <ion-label class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br />
<button (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal"> <button (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal">
@@ -160,7 +169,7 @@
</ion-label><br /> </ion-label><br />
</div> </div>
{{last ? scrollToBottom() : ''}} {{last ? scrollToBottom() : ''}}
</div> </div> -->
</div> </div>
</div> </div>
<ion-fab horizontal="end" vertical="bottom" slot="fixed"> <ion-fab horizontal="end" vertical="bottom" slot="fixed">
@@ -2,7 +2,9 @@ import { analyzeAndValidateNgModules } from '@angular/compiler';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { NavigationStart, Router } from '@angular/router'; import { NavigationStart, Router } from '@angular/router';
import { ModalController, NavParams, PickerController, PopoverController } from '@ionic/angular'; import { ModalController, NavParams, PickerController, PopoverController } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service';
import { ChatService } from 'src/app/services/chat.service'; import { ChatService } from 'src/app/services/chat.service';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { DataService } from 'src/app/services/data.service'; import { DataService } from 'src/app/services/data.service';
import { ProcessesService } from 'src/app/services/processes.service'; import { ProcessesService } from 'src/app/services/processes.service';
import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page'; import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page';
@@ -25,6 +27,7 @@ export class NewGroupPage implements OnInit{
//groupName:string; //groupName:string;
task:any; task:any;
documents: any; documents: any;
loggedUserChat: any;
@Input() groupName:string; @Input() groupName:string;
@Output() addGroupMessage:EventEmitter<any> = new EventEmitter<any>(); @Output() addGroupMessage:EventEmitter<any> = new EventEmitter<any>();
@@ -37,8 +40,11 @@ export class NewGroupPage implements OnInit{
private dataService:DataService, private dataService:DataService,
private processesService: ProcessesService, private processesService: ProcessesService,
private router: Router, private router: Router,
public wsChatMethodsService: WsChatMethodsService,
private authService: AuthService,
) )
{ {
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = false; this.isGroupCreated = false;
//this.groupName = this.navParams.get('name'); //this.groupName = this.navParams.get('name');
} }
@@ -86,16 +92,38 @@ export class NewGroupPage implements OnInit{
this.addGroupMessage.emit(); this.addGroupMessage.emit();
} }
createGroup(){ async createGroup(){
let name = this.groupName.split(' ').join('-'); let name = this.groupName.split(' ').join('-');
//Take out all special characters in string //Take out all special characters in string
name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
let customFields = {}
let res:any;
if(this.thedate){
let customFields = {
"countDownDate":this.thedate
}
res = await this.wsChatMethodsService.createPrivateRoom(name, this.loggedUserChat.me.username, customFields);
console.log(res);
}
else{
res = await this.wsChatMethodsService.createPrivateRoom(name, this.loggedUserChat.me.username, customFields);
console.log(res);
}
this.wsChatMethodsService.subscribeToRoomUpdate(res.result.rid, res.result);
this.addGroupMessage.emit(res.result.rid);
/*
let body = { "name":name, } let body = { "name":name, }
this.chatService.addGroup(body).subscribe(res=>{ this.chatService.addGroup(body).subscribe(res=>{
console.log('group created'); console.log('group created');
console.log(res['group']); console.log(res['group']);
this.addGroupMessage.emit(res['group']._id); this.addGroupMessage.emit(res['group']._id); */
/* this.addGroupMessage.emit(res['group']._id);
if(this.thedate){ if(this.thedate){
let countDownBody = { let countDownBody = {
@@ -139,11 +167,11 @@ export class NewGroupPage implements OnInit{
} }
this.chatService.sendMessage(body).toPromise(); this.chatService.sendMessage(body).toPromise();
}); });
} } */
}); //});
} }
async addContacts(){ async addContacts(){
@@ -4,6 +4,7 @@ import { ChatService } from 'src/app/services/chat.service';
import { ToastService } from 'src/app/services/toast.service'; import { ToastService } from 'src/app/services/toast.service';
import { ThemeService } from 'src/app/services/theme.service' import { ThemeService } from 'src/app/services/theme.service'
import { SetRoomOwnerPage } from 'src/app/modals/set-room-owner/set-room-owner.page'; import { SetRoomOwnerPage } from 'src/app/modals/set-room-owner/set-room-owner.page';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
@Component({ @Component({
@@ -22,7 +23,8 @@ export class ChatPopoverPage implements OnInit {
private navParams: NavParams, private navParams: NavParams,
private chatService: ChatService, private chatService: ChatService,
private toastService: ToastService, private toastService: ToastService,
public ThemeService: ThemeService public ThemeService: ThemeService,
public wsChatMethodsService: WsChatMethodsService,
) { ) {
this.roomId = this.navParams.get('roomId'); this.roomId = this.navParams.get('roomId');
this.members = this.navParams.get('members'); this.members = this.navParams.get('members');
@@ -58,21 +60,46 @@ export class ChatPopoverPage implements OnInit {
cssClass: classs, cssClass: classs,
backdropDismiss: true, backdropDismiss: true,
componentProps: { componentProps: {
room: this.room, roomId: this.roomId,
members: this.members, members: this.members,
} }
}); });
await modal.present(); await modal.present();
modal.onDidDismiss().then((res)=>{ modal.onDidDismiss().then((res)=>{
this.leaveGroup();
}); });
} }
leaveGroup(){ async leaveGroup(){
console.log('leave');
let body = { "roomId":this.roomId, } let body = { "roomId":this.roomId, }
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{ let res:any = await this.wsChatMethodsService.leaveRoom(this.roomId);
console.log(res.error.error);
if(res.error){
if(res.error.error = "error-you-are-last-owner"){
this.toastService._badRequest("Você é o último administrador do grupo. Por favor, defina o novo administrador antes de sair da grupo.");
this.setRoomOwner();
}
else if(res.error.error == 'error-user-not-in-room'){
this.toastService._badRequest("Você já não esta nesta conversa");
}
else{
this.toastService._badRequest("Não foi possível sair do grupo");
}
}
else{
this.close('leave');
}
this.close('leave');
//this.wsChatMethodsService.subscribeToRoomUpdate(this.roomId, res.result);
/* this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
this.room = room['room']; this.room = room['room'];
if(this.room.t === 'p'){ if(this.room.t === 'p'){
@@ -117,7 +144,7 @@ export class ChatPopoverPage implements OnInit {
//loader.remove() //loader.remove()
}); });
} }
}); }); */
} }
//Delete //Delete