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>
</div>
<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>
@@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } 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 { ThemeService } from 'src/app/services/theme.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 {
textSearch:string = "";
room:any;
roomId:any;
members:any;
constructor(
@@ -25,13 +26,14 @@ export class SetRoomOwnerPage implements OnInit {
private navParams: NavParams,
public ThemeService: ThemeService,
private toastService: ToastService,
public wsChatMethodsService: WsChatMethodsService,
) {
this.room = this.navParams.get('room');
this.roomId = this.navParams.get('roomId');
this.members = this.navParams.get('members');
}
ngOnInit() {
console.log(this.room);
console.log(this.members);
}
@@ -57,23 +59,43 @@ export class SetRoomOwnerPage implements OnInit {
return null;
}
setRoomOwner(user:any){
async setRoomOwner(user:any){
console.log(user);
console.log(this.room);
let res:any = await this.wsChatMethodsService.addRoomOwner(this.roomId, user._id);
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 = {
"roomId": this.room._id,
"roomId": this.roomId,
"userId": user._id
}
this.chatService.addGroupOwner(body).subscribe((res)=>{
alert('here');
console.log(res);
this.close();
}, (error) => {
this.toastService._badRequest('Não foi possível completar a ação, por favor tente novamente.');
});
this.toastService._successMessage('Operação realizada com sucesso');
}, (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>
<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">
<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>
+1 -1
View File
@@ -548,7 +548,7 @@ export class ChatPage implements OnInit {
return dateB - dateA;
});
//console.log('GROUPS FROM DB', this.allGroups)
})
@@ -333,12 +333,14 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
cssClass: 'chat-popover',
componentProps: {
roomId: this.roomId,
members: this.members,
},
});
await modal.present();
modal.onDidDismiss().then(res=>{
if(res.data == 'leave'){
console.log('saiu do grupo');
//this.wsChatMethodsService.subscribeToRoomUpdate(this.roomId, this.room);
}
else if(res.data == '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 { ChatService } from 'src/app/services/chat.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({
selector: 'app-new-group',
@@ -21,6 +23,7 @@ export class NewGroupPage implements OnInit {
thedate:any;
groupName:string;
documents:any;
loggedUserChat: any;
constructor(
private pickerController: PickerController,
@@ -30,8 +33,11 @@ export class NewGroupPage implements OnInit {
public ThemeService: ThemeService,
private chatService: ChatService,
private processesService: ProcessesService,
public wsChatMethodsService: WsChatMethodsService,
private authService: AuthService,
)
{
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = false;
this.groupName = this.navParams.get('name');
this.documents = this.navParams.get('documents');
@@ -55,10 +61,34 @@ export class NewGroupPage implements OnInit {
this.modalController.dismiss();
}
createGroup(){
async createGroup(){
let name = this.groupName.split(' ').join('-');
//Take out all special characters in string
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, }
this.chatService.addGroup(body).subscribe(res=>{
console.log('group created');
@@ -112,7 +142,7 @@ export class NewGroupPage implements OnInit {
this.chatService.sendMessage(body).toPromise();
});
}
});
}); */
}
async addContacts(room){
+7 -2
View File
@@ -39,7 +39,7 @@ export class RoomService {
private sqlservice: SqliteService,
) { }
setData({ customFields, id, name, t, lastMessage, _updatedAt }) {
setData({ customFields, id, name, t, lastMessage = new MessageService(), _updatedAt }) {
this.customFields = customFields
this.id = id
this.name = name
@@ -62,6 +62,7 @@ export class RoomService {
/* this.ToastService._chatMessage({message:'Nova mensagem', sender:'Gilson'}) */
const message = new MessageService()
message.setData(ChatMessage)
this.lastMessage.msg = message.msg
if (message.t == 'r') { this.name = message.msg }
this.calDateDuration(ChatMessage._updatedAt)
@@ -89,6 +90,10 @@ export class RoomService {
this.WsChatService.send(this.id, msg)
}
leave(rid?) {
this.WsChatService.leaveRoom(this.id)
}
getMsgFromDBMobile() {
console.log('ALL MSG DBBB', this.id)
this.sqlservice.getAllChatMSG(this.id).then((msg: any = []) => {
@@ -159,7 +164,7 @@ export class RoomService {
})
}
// runs onces only
loadHistory(limit = 100) {
@@ -46,35 +46,7 @@ export class WsChatMethodsService {
// console.log("ROOMS" + JSON.stringify(rooms))
rooms.result.update.forEach((roomData: room) => {
let room:RoomService;
//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.prepareRoom(roomData);
});
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 {
try {
return this.dm[id]
@@ -130,7 +164,7 @@ export class WsChatMethodsService {
return roomData._id
}
getRoomLastMessage(roomData: room) {
getRoomLastMessage(roomData: room):any {
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(){}
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(){
this.showLoader = true;
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
this.room = room['room'];
this.addContacts(this.room);
this.showLoader = false;
this.openGroupMessage.emit(this.room._id);
});
this.addContacts(this.roomId);
this.openGroupMessage.emit(this.roomId);
this.showLoader = false;
}
openGroupMessagesPage(){
this.showLoader = true;
@@ -259,15 +256,15 @@ export class GroupContactsPage implements OnInit {
user.isChecked = !user.isChecked;
}
addContacts(room:any){
console.log(room);
addContacts(roomId:any){
console.log(roomId);
this.selectedUserList = this.users.filter(function(contact) {
return contact.isChecked == true;
});
console.log( this.selectedUserList);
this.selectedUserList.forEach(user=>{
let body ={
"roomId":room._id,
"roomId":roomId,
"userId":user._id,
}
this.chatService.addUserToGroup(body).subscribe(res=>{
@@ -92,55 +92,62 @@
</div>
</div>
<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-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 class="message">
<ion-label>{{msg.msg}}</ion-label>
<div *ngIf="msg.attachments" class="message-attachments">
<div *ngFor="let file of msg.attachments">
<div (click)="openPreview(msg)">
<img *ngIf="file.image_url" src="{{file.image_url}}" alt="image">
</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.file.type != 'application/meeting'" >
<div *ngIf="msg.file.type != 'application/meeting'">
AQUI
<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 class="message">
<div *ngIf="msg.attachments" class="message-attachments">
<div *ngFor="let file of msg.attachments">
<div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)">
<img *ngIf="file.image_url" src="{{file.image_url}}" alt="image">
</div>
<div *ngIf="msg.file.type != 'application/img'">
<div class="file">
<!-- <canvas id="pdf_canvas"></canvas> -->
<div (click)="viewDocument(msg.file, file.title_link)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<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/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>
</span>
<ion-label class="file-title">{{file.title}}</ion-label>
<!-- <canvas id="pdf_canvas"></canvas> -->
<div (click)="viewDocument(msg.file, file.title_link)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<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/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>
</span>
<ion-label class="file-title">{{file.title}}</ion-label>
</div>
</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 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>
{{last ? scrollToBottom() : ''}}
</div>
{{last ? scrollToBottom() : ''}}
</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 class="message-item-options d-flex justify-content-end">
<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>
<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">
</div>
</div>
@@ -167,7 +173,7 @@
</div>
</div>
</div>
-->
<div *ngIf="msg.t == 'r'" class="info-text">
@@ -198,7 +204,7 @@
</div>
{{last ? scrollToBottom() : ''}}
</div>
<div *ngIf="msg.file" >
<!-- <div *ngIf="msg.file" >
<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 />
@@ -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 />
</div>
{{last ? scrollToBottom() : ''}}
</div>
</div> -->
</div>
</div>
<ion-fab horizontal="end" vertical="bottom" slot="fixed">
@@ -80,9 +80,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
downloadFile: any;
constructor(
private menu: MenuController,
public wsChatMethodsService: WsChatMethodsService,
private modalController: ModalController,
private actionSheetController: ActionSheetController,
public popoverController: PopoverController,
private chatService: ChatService,
private authService: AuthService,
@@ -97,8 +96,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
public ThemeService: ThemeService,
private changeDetectorRef: ChangeDetectorRef,
private storage: Storage,
public wsChatMethodsService: WsChatMethodsService
) {
console.log('OnCONSTRUCTOR');
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = true;
this.roomCountDownDate = "";
@@ -106,11 +106,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
ngOnChanges(changes: SimpleChanges): void {
console.log('OnCHANGES');
this.getRoomInfo();
//this.scrollToBottom();
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory();
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
setTimeout(()=>{
@@ -120,11 +122,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
ngOnInit() {
console.log(this.roomId);
this.loggedUser = this.loggedUserChat;
//console.log(this.wsChatMethodsService.getRoom(this.roomId).massages);
this.loggedUser=this.loggedUserChat;
this.getRoomInfo();
setTimeout(() => {
this.getRoomInfo();
}, 1000);
this.setStatus('online');
this.getChatMembers();
//this.getMessageDB();
@@ -254,6 +258,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
async getRoomInfo() {
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory();
let room = await this.chatService.getRoomInfo(this.roomId).toPromise();
this.room = room['room'];
if (this.room.name) {
@@ -288,29 +293,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
loadGroupMessages(roomId) {
//console.log('here'+room.t);
this.showLoader = true;
//If group is private call getGroupMembers
/* if(room.t === 'p'){
console.log('private'); */
this.chatService.getPrivateGroupMessages(this.roomId).subscribe(res => {
console.log(res);
let msgOnly = res['messages'].filter(data => data.t != 'au');
//this.messages = msgOnly.reverse();
//console.log(res);
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() {
@@ -364,6 +352,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
});
return await popover.present(); */
console.log(this.roomId);
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
@@ -379,6 +370,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
console.log(res);
if (res.data == 'leave') {
this.getRoomInfo();
this.wsChatMethodsService.hidingRoom(this.roomId);
this.closeAllDesktopComponents.emit();
this.showEmptyContainer.emit();
}
+61 -52
View File
@@ -56,63 +56,73 @@
{{last ? scrollToBottom() : ''}}
</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>
<!-- <img *ngIf="file.image_url" src="{{file.image_url}}" alt="image" (click)="imageSize(file.image_url)"> -->
<img src={{msg.image_url}} alt="image">
<!-- <div (click)="openPreview(msg)">
<img *ngIf="file.image_url" src="{{file.image_url}}" alt="image"> -->
</div>
<div *ngIf="msg.file">
<div class="file">
<div (click)="viewDocument(msg, file.title_link)" class="file-details add-ellipsis cursor-pointer"
*ngIf="msg.file">
<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/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 *ngIf="msg.file">
<div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.file.type != 'application/meeting'">
<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>
<div *ngIf="msg.attachments" class="message-attachments">
<div *ngFor="let file of msg.attachments">
<div *ngIf="msg.file.type == 'application/img'" (click)="downloadFileMsg(msg)" dfsdvsvs>
<img src={{msg.image_url}} alt="image">
</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 *ngIf="msg.file.type != 'application/img'">
<div class="file">
<div (click)="viewDocument(msg, file.title_link)" class="file-details add-ellipsis cursor-pointer"
*ngIf="msg.file">
<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/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>
{{last ? scrollToBottom() : ''}}
</div>
{{last ? scrollToBottom() : ''}}
</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 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.type == 'application/img'">
<div class="message-item-options d-flex justify-content-end">
@@ -131,7 +141,6 @@
<div *ngIf="msg.file" class="message-attachments">
<div>
<div (click)="openPreview(msg)">
<!-- <img *ngIf="file.image_url" src="{{file.image_url}}" alt="image" (click)="imageSize(file.image_url)"> -->
File
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image">
</div>
@@ -141,10 +150,10 @@
</div>
</div>
</div>
</div>
</div> -->
<div *ngIf="msg.file">
<!-- <div *ngIf="msg.file">
<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">
@@ -160,7 +169,7 @@
</ion-label><br />
</div>
{{last ? scrollToBottom() : ''}}
</div>
</div> -->
</div>
</div>
<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 { NavigationStart, Router } from '@angular/router';
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 { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { DataService } from 'src/app/services/data.service';
import { ProcessesService } from 'src/app/services/processes.service';
import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page';
@@ -25,6 +27,7 @@ export class NewGroupPage implements OnInit{
//groupName:string;
task:any;
documents: any;
loggedUserChat: any;
@Input() groupName:string;
@Output() addGroupMessage:EventEmitter<any> = new EventEmitter<any>();
@@ -37,8 +40,11 @@ export class NewGroupPage implements OnInit{
private dataService:DataService,
private processesService: ProcessesService,
private router: Router,
public wsChatMethodsService: WsChatMethodsService,
private authService: AuthService,
)
{
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = false;
//this.groupName = this.navParams.get('name');
}
@@ -86,16 +92,38 @@ export class NewGroupPage implements OnInit{
this.addGroupMessage.emit();
}
createGroup(){
async createGroup(){
let name = this.groupName.split(' ').join('-');
//Take out all special characters in string
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, }
this.chatService.addGroup(body).subscribe(res=>{
console.log('group created');
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){
let countDownBody = {
@@ -139,11 +167,11 @@ export class NewGroupPage implements OnInit{
}
this.chatService.sendMessage(body).toPromise();
});
}
} */
});
//});
}
async addContacts(){
@@ -4,6 +4,7 @@ import { ChatService } from 'src/app/services/chat.service';
import { ToastService } from 'src/app/services/toast.service';
import { ThemeService } from 'src/app/services/theme.service'
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({
@@ -22,7 +23,8 @@ export class ChatPopoverPage implements OnInit {
private navParams: NavParams,
private chatService: ChatService,
private toastService: ToastService,
public ThemeService: ThemeService
public ThemeService: ThemeService,
public wsChatMethodsService: WsChatMethodsService,
) {
this.roomId = this.navParams.get('roomId');
this.members = this.navParams.get('members');
@@ -58,21 +60,46 @@ export class ChatPopoverPage implements OnInit {
cssClass: classs,
backdropDismiss: true,
componentProps: {
room: this.room,
roomId: this.roomId,
members: this.members,
}
});
await modal.present();
modal.onDidDismiss().then((res)=>{
this.leaveGroup();
});
}
leaveGroup(){
console.log('leave');
async leaveGroup(){
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'];
if(this.room.t === 'p'){
@@ -117,7 +144,7 @@ export class ChatPopoverPage implements OnInit {
//loader.remove()
});
}
});
}); */
}
//Delete