This commit is contained in:
tiago.kayaya
2021-03-12 11:56:54 +01:00
parent 13799b7e3d
commit 4d50101a12
18 changed files with 184 additions and 185 deletions
@@ -1,6 +1,7 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { IonicModule } from '@ionic/angular';
@@ -13,6 +14,7 @@ import { PopoverModule } from 'src/app/shared/popover/chat-popover/popover.modul
@NgModule({
imports: [
CommonModule,
BrowserModule,
FormsModule,
IonicModule,
SharedModule,
@@ -4,7 +4,7 @@
<div class="header-top">
<app-btn-modal-dismiss></app-btn-modal-dismiss>
<div class="middle">
<ion-label class="title">{{room.name}}</ion-label>
<ion-label class="title">{{roomName}}</ion-label>
</div>
<div class="right">
<ion-icon (click)="openOptions()" src="assets/images/icons-menu.svg"></ion-icon>
@@ -16,7 +16,7 @@
</div>
<div class="header-bottom-contacts">
<ion-label *ngFor="let member of members" >
{{member.name}},
{{member.name}}
</ion-label>
</div>
</div>
@@ -24,7 +24,6 @@
</ion-toolbar>
</ion-header>
<ion-content>
<ion-refresher name="refresher" slot="fixed" (ionRefresh)="doRefresh($event)">
<ion-progress-bar type="indeterminate" *ngIf="showLoader"></ion-progress-bar>
@@ -32,7 +31,7 @@
</ion-refresher-content>
</ion-refresher>
<div class="welcome-text">
<ion-label> {{message}} Esta conversa passou a grupo</ion-label><br />
<ion-label>Esta conversa passou a grupo</ion-label><br />
<ion-label>A conversa original mantêm-se como chat individual</ion-label>
</div>
<div *ngFor="let msg of messages" class="messages">
@@ -21,6 +21,12 @@
overflow: auto;
padding: 0 !important;
background: #fff;
.left{
width: 37px;
float: left;
font-size: 35px;
overflow: hidden;
}
.middle{
padding: 0!important;
float: left;
@@ -1,4 +1,4 @@
import { AfterViewChecked, Component, OnChanges, OnInit, Input, SimpleChanges, Output } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ActionSheetController, MenuController, ModalController, NavParams, PopoverController } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service';
import { ChatService } from 'src/app/services/chat.service';
@@ -13,7 +13,7 @@ import { GroupContactsPage } from './group-contacts/group-contacts.page';
templateUrl: './group-messages.page.html',
styleUrls: ['./group-messages.page.scss'],
})
export class GroupMessagesPage implements OnInit, OnChanges {
export class GroupMessagesPage implements OnInit {
showLoader: boolean;
isGroupCreated:boolean;
loggedUser: any;
@@ -24,8 +24,7 @@ export class GroupMessagesPage implements OnInit, OnChanges {
room:any;
roomName:any;
members:any;
@Input() roomId:string;
contacts: string[] = [" Ana M.", "Andre F.", "Bruno G.", "Catarina T", "Tiago"];
constructor(
private menu: MenuController,
@@ -33,15 +32,12 @@ export class GroupMessagesPage implements OnInit, OnChanges {
private actionSheetController: ActionSheetController,
public popoverController: PopoverController,
private chatService: ChatService,
/* private navParams: NavParams, */
private navParams: NavParams,
private authService: AuthService,
) {
this.isGroupCreated = true;
/* this.room = this.navParams.get('room'); */
/* this.roomName = this.room.name.split('-').join(' '); */
}
ngOnChanges(changes: SimpleChanges): void {
this.getRoomInfo();
this.room = this.navParams.get('room');
this.roomName = this.room.name.split('-').join(' ');
}
ngOnInit() {
@@ -49,8 +45,11 @@ export class GroupMessagesPage implements OnInit, OnChanges {
this.loggedUser=res;
console.log(this.loggedUser);
});
this.getRoomInfo();
console.log(this.roomId);
this.load();
}
load(){
this.getGroupContacts();
this.loadGroupMessages();
}
close(){
@@ -58,30 +57,16 @@ export class GroupMessagesPage implements OnInit, OnChanges {
}
doRefresh(ev:any){
this.getRoomInfo();
this.load();
ev.target.complete();
}
get watch(){
this.getRoomInfo();
console.log('here watching');
return this.roomId;
}
getRoomInfo(){
this.showLoader = true;
this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
this.room = room['room'];
this.getGroupContacts(this.room);
this.loadGroupMessages(this.room);
this.showLoader = false;
});
}
getGroupContacts(room:any){
getGroupContacts(){
this.showLoader = true;
//If group is private call getGroupMembers
if(room.t === 'p'){
this.chatService.getGroupMembers(this.roomId).subscribe(res=>{
if(this.room.t === 'p'){
this.chatService.getGroupMembers(this.room._id).subscribe(res=>{
console.log(res);
this.members = res['members'];
this.showLoader = false;
@@ -89,33 +74,27 @@ export class GroupMessagesPage implements OnInit, OnChanges {
}
//Otherwise call getChannelMembers for públic groups
else{
this.chatService.getChannelMembers(this.roomId).subscribe(res=>{
this.chatService.getChannelMembers(this.room._id).subscribe(res=>{
console.log(res);
this.members = res['members'];
this.showLoader = false;
});
}
}
loadGroupMessages(room:any){
console.log('here'+room.t);
loadGroupMessages(){
this.showLoader = true;
//If group is private call getGroupMembers
if(room.t === 'p'){
console.log('private');
this.chatService.getPrivateGroupMessages(this.roomId).subscribe(res=>{
if(this.room.t === 'p'){
this.chatService.getPrivateGroupMessages(this.room._id).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=>{
this.chatService.getPublicGroupMessages(this.room._id).subscribe(res=>{
console.log(res);
this.messages = res['messages'].reverse();
});
@@ -126,18 +105,17 @@ export class GroupMessagesPage implements OnInit, OnChanges {
let body = {
"message":
{
"rid": this.roomId, "msg": this.message
"rid": this.room._id, "msg": this.message
}
}
this.chatService.sendMessage(body).subscribe(res=> {
/* this.loadGroupMessages(); */
this.getRoomInfo();
this.loadGroupMessages();
});
this.message = "";
}
/* async openOptions(ev: any) {
async openOptions(ev: any) {
const popover = await this.popoverController.create({
component: ChatPopoverPage,
cssClass: 'chat-popover',
@@ -155,7 +133,7 @@ export class GroupMessagesPage implements OnInit, OnChanges {
console.log(this.roomName);
this.load();
//this.modalController.dismiss();
/* this.modalController.dismiss(); */
};
});
@@ -193,7 +171,7 @@ export class GroupMessagesPage implements OnInit, OnChanges {
this.load();
});
}
*/
/* async actionSheet() {
const actionSheet = await this.actionSheetController.create({
cssClass: 'my-custom-class',
@@ -220,4 +198,4 @@ export class GroupMessagesPage implements OnInit, OnChanges {
}
*/
}
}