mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
add show total users in rocket chat server
This commit is contained in:
@@ -1,17 +1,25 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
import { ChatPage } from './chat.page';
|
||||
|
||||
const routes: Routes = [
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
import { ChatPage } from './chat.page';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: ChatPage
|
||||
},
|
||||
{
|
||||
path: 'conversation',
|
||||
loadChildren: () => import('./conversation/conversation.module').then( m => m.ConversationPageModule)
|
||||
},
|
||||
path: '',
|
||||
component: ChatPage
|
||||
{
|
||||
path: 'newchat',
|
||||
loadChildren: () => import('./newchat/newchat.module').then( m => m.NewchatPageModule)
|
||||
];
|
||||
}
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class ChatPageRoutingModule {}
|
||||
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
|
||||
@@ -1,39 +1,51 @@
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-title>chat</ion-title>
|
||||
<ion-title>Chat</ion-title>
|
||||
<ion-icon slot="end" src="assets/images/icons-chat-new-group.svg" class="iconschatnew-group"></ion-icon>
|
||||
<ion-icon slot="end" src="assets/images/icons-chat-new-conversation.svg" class="iconschatnew-conversation" [routerLink]="['/home/chat/newchat']"></ion-icon>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
|
||||
<ion-content>
|
||||
<ion-row *ngFor="let message of messages" class="chat-container">
|
||||
<ion-col size="9" *ngIf="message.user !== currentUser" class="message other-message">
|
||||
<p><b>{{message.user}}</b></p>
|
||||
<span>{{message.msg}}</span>
|
||||
<div class="message-date">{{message.createdAt | date: 'HH:mm'}}</div>
|
||||
</ion-col>
|
||||
<ion-col offset="3" size="9" *ngIf="message.user === currentUser" class="message my-message">
|
||||
<ion-label>
|
||||
<p><b>{{message.user}}</b></p>
|
||||
<span>{{message.msg}}</span>
|
||||
<div class="message-date">{{message.createdAt | date: 'HH:mm'}}</div>
|
||||
</ion-label>
|
||||
</ion-col>
|
||||
|
||||
</ion-row>
|
||||
<ion-toolbar >
|
||||
<ion-segment [(ngModel)]="segment" (ionChange)="onSegmentChange()">
|
||||
<ion-segment-button value="Contactos">
|
||||
Contactos
|
||||
</ion-segment-button>
|
||||
<ion-segment-button value="Grupos">
|
||||
Grupos
|
||||
</ion-segment-button>
|
||||
</ion-segment>
|
||||
</ion-toolbar>
|
||||
<div [ngSwitch]="segment">
|
||||
<ion-list *ngSwitchCase="'Contactos'" >
|
||||
<ion-item-group>
|
||||
<ion-item-sliding>
|
||||
<ion-item>
|
||||
<ion-icon slot="start" src="assets/images/icons-chat-chat-40.svg" class="iconschatchat-40"></ion-icon>
|
||||
<div>
|
||||
<h3>Secretario Assuntos Sociais</h3>
|
||||
<p>Podemos marcar reunião para amanha</p>
|
||||
</div>
|
||||
</ion-item>
|
||||
</ion-item-sliding>
|
||||
</ion-item-group>
|
||||
</ion-list>
|
||||
<ion-list *ngSwitchCase="'Grupos'" >
|
||||
<ion-item-group>
|
||||
<ion-item-sliding>
|
||||
<ion-item>
|
||||
<ion-icon slot="start" src="assets/images/icons-chat-group-chat-40.svg" class="iconschatgroup-chat-40"></ion-icon>
|
||||
<div>
|
||||
<h3>Viagem a Maputo</h3>
|
||||
<p>Grande momento.</p>
|
||||
</div>
|
||||
</ion-item>
|
||||
</ion-item-sliding>
|
||||
</ion-item-group>
|
||||
|
||||
</ion-list>
|
||||
</div>
|
||||
|
||||
</ion-content>
|
||||
<ion-footer class="ion-no-border">
|
||||
<ion-toolbar>
|
||||
<ion-row align-items-center>
|
||||
<ion-col size="10">
|
||||
<ion-textarea auto-grow class="message-input" rows="1" [(ngModel)]="message"></ion-textarea>
|
||||
</ion-col>
|
||||
<ion-col size="2">
|
||||
<ion-button expand="block" fill="clear" color="primary" [disabled]="message === ''" class="msg-btn"
|
||||
(click)="sendMessage()">
|
||||
<ion-icon name="send" slot="icon-only"></ion-icon>
|
||||
</ion-button>
|
||||
</ion-col>
|
||||
</ion-row>
|
||||
</ion-toolbar>
|
||||
</ion-footer>
|
||||
|
||||
|
||||
@@ -1,50 +1,23 @@
|
||||
ion-content{
|
||||
background-color:#fefefe;
|
||||
.iconschatnew-group{
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
object-fit: contain;
|
||||
margin: 0 5px 0 5px;
|
||||
}
|
||||
.chat-container{
|
||||
margin: 10px 10px 0 10px;
|
||||
.iconschatgroup-chat-40 {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
object-fit: contain;
|
||||
}
|
||||
.message {
|
||||
padding: 5px 5px 5px 10px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 10px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.my-message {
|
||||
background: var(--ion-color-primary);
|
||||
color: #fff;
|
||||
}
|
||||
.my-message p{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #9ab8e9;
|
||||
}
|
||||
.message-date{
|
||||
font-size: 10px;
|
||||
text-align: right;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.other-message {
|
||||
background: #f2f3f7;
|
||||
color: #333;
|
||||
}
|
||||
.other-message p{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color:#959ba7;
|
||||
}
|
||||
|
||||
.message-input {
|
||||
margin-top: 0px;
|
||||
border: 1px solid var(--ion-color-medium);
|
||||
border-radius: 20px;
|
||||
background: #fff;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
.iconschatnew-conversation{
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
object-fit: contain;
|
||||
margin: 0 5px 0 5px;
|
||||
}
|
||||
.iconschatchat-40 {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
object-fit: contain;
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Socket } from 'ngx-socket-io';
|
||||
import { ToastController } from '@ionic/angular';
|
||||
import { WebsocketService } from 'src/app/services/websocket.service';
|
||||
import { fromEvent } from 'rxjs';
|
||||
import { AuthService } from 'src/app/services/auth.service';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-chat',
|
||||
@@ -10,43 +8,32 @@ import { fromEvent } from 'rxjs';
|
||||
styleUrls: ['./chat.page.scss'],
|
||||
})
|
||||
export class ChatPage implements OnInit {
|
||||
loggedUser: any;
|
||||
/* Set segment variable */
|
||||
segment:string;
|
||||
groupList: any[];
|
||||
result:any;
|
||||
|
||||
message = '';
|
||||
messages = [];
|
||||
currentUser = '';
|
||||
|
||||
constructor(private websocket:WebsocketService, private socket: Socket) { }
|
||||
constructor(
|
||||
private chatService: ChatService,
|
||||
private authService: AuthService) { }
|
||||
|
||||
ngOnInit() {
|
||||
console.log("ON");
|
||||
this.socket.connect();
|
||||
|
||||
/* Set current user */
|
||||
let name = `User-${new Date().getTime()}`;
|
||||
this.currentUser=name;
|
||||
|
||||
this.socket.emit('set-name', name);
|
||||
|
||||
/* Reat from event calling "fromEvent" */
|
||||
this.socket.fromEvent('users-changed').subscribe(data =>{
|
||||
console.log('gOT data:', data);
|
||||
this.segment = "Contactos";
|
||||
this.authService.userData$.subscribe((res:any)=>{
|
||||
this.loggedUser=res;
|
||||
});
|
||||
|
||||
/* Add message to the array of messages */
|
||||
this.socket.fromEvent('message').subscribe(message =>{
|
||||
console.log('New:', message);
|
||||
this.messages.push(message);
|
||||
/* this.getGroups(); */
|
||||
}
|
||||
onSegmentChange(){
|
||||
this.RefreshEvents();
|
||||
}
|
||||
RefreshEvents(){}
|
||||
/* getGroups(){
|
||||
this.result = this.chatService.getPrivateGroups().subscribe((res:any)=>{
|
||||
this.groupList = res.users;
|
||||
console.log(this.groupList);
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
sendMessage(){
|
||||
this.socket.emit('send-message', {text: this.message});
|
||||
this.message="";
|
||||
}
|
||||
|
||||
ionViewWillLeave(){
|
||||
this.socket.disconnect();
|
||||
}
|
||||
|
||||
} */
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
import { ConversationPage } from './conversation.page';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: ConversationPage
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class ConversationPageRoutingModule {}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
|
||||
import { ConversationPageRoutingModule } from './conversation-routing.module';
|
||||
|
||||
import { ConversationPage } from './conversation.page';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
IonicModule,
|
||||
ConversationPageRoutingModule
|
||||
],
|
||||
declarations: [ConversationPage]
|
||||
})
|
||||
export class ConversationPageModule {}
|
||||
@@ -0,0 +1,49 @@
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-buttons slot="start">
|
||||
<ion-back-button (click)="close()" defaultHref="/home/chat" icon="chevron-back"></ion-back-button>
|
||||
</ion-buttons>
|
||||
<ion-title>{{chatUser.name}}</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
|
||||
<ion-content>
|
||||
<ion-row *ngFor="let message of messages" class="chat-container">
|
||||
<ion-col size="9" *ngIf="message.user !== currentUser" class="message other-message">
|
||||
<p><b>{{message.user}}</b></p>
|
||||
<span>{{message.msg}}</span>
|
||||
<div class="message-date">{{message.createdAt | date: 'HH:mm'}}</div>
|
||||
</ion-col>
|
||||
<ion-col offset="3" size="9" *ngIf="message.user === currentUser" class="message my-message">
|
||||
<ion-label>
|
||||
<p><b>{{message.user}}</b></p>
|
||||
<span>{{message.msg}}</span>
|
||||
<div class="message-date">{{message.createdAt | date: 'HH:mm'}}</div>
|
||||
</ion-label>
|
||||
</ion-col>
|
||||
|
||||
</ion-row>
|
||||
|
||||
</ion-content>
|
||||
<ion-footer class="ion-no-border">
|
||||
<ion-toolbar>
|
||||
<ion-row align-items-center>
|
||||
<ion-col>
|
||||
<ion-item button lines="none">
|
||||
<img src="assets/images/icons-arrow-arrow-down-25.svg">
|
||||
</ion-item>
|
||||
</ion-col>
|
||||
<ion-col>
|
||||
<ion-item lines="none" class="div-message">
|
||||
<ion-textarea placeholder="Escrever uma mensagem" auto-grow class="message-input" rows="1" [(ngModel)]="message"></ion-textarea>
|
||||
<ion-icon slot="end" name="mic-outline"></ion-icon>
|
||||
</ion-item>
|
||||
</ion-col>
|
||||
<ion-col>
|
||||
<ion-item button lines="none" [disabled]="message === ''">
|
||||
<img src="assets/images/icons-chat-send.svg">
|
||||
</ion-item>
|
||||
</ion-col>
|
||||
</ion-row>
|
||||
</ion-toolbar>
|
||||
</ion-footer>
|
||||
@@ -0,0 +1,55 @@
|
||||
ion-content{
|
||||
background-color:#fefefe;
|
||||
}
|
||||
.chat-container{
|
||||
margin: 10px 10px 0 10px;
|
||||
}
|
||||
.message {
|
||||
padding: 5px 5px 5px 10px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 10px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.my-message {
|
||||
background: var(--ion-color-primary);
|
||||
color: #fff;
|
||||
}
|
||||
.my-message p{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #9ab8e9;
|
||||
}
|
||||
.message-date{
|
||||
font-size: 10px;
|
||||
text-align: right;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.other-message {
|
||||
background: #f2f3f7;
|
||||
color: #333;
|
||||
}
|
||||
.other-message p{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color:#959ba7;
|
||||
}
|
||||
|
||||
.message-input {
|
||||
margin-top: 0px;
|
||||
|
||||
background: #fff;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
|
||||
.div-message{
|
||||
border: 1px solid var(--ion-color-medium);
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
|
||||
import { ConversationPage } from './conversation.page';
|
||||
|
||||
describe('ConversationPage', () => {
|
||||
let component: ConversationPage;
|
||||
let fixture: ComponentFixture<ConversationPage>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ConversationPage ],
|
||||
imports: [IonicModule.forRoot()]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ConversationPage);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { ModalController, NavParams } from '@ionic/angular';
|
||||
import { AuthService } from 'src/app/services/auth.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-conversation',
|
||||
templateUrl: './conversation.page.html',
|
||||
styleUrls: ['./conversation.page.scss'],
|
||||
})
|
||||
export class ConversationPage implements OnInit {
|
||||
|
||||
message = '';
|
||||
messages = [];
|
||||
currentUser = '';
|
||||
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private router:Router,
|
||||
private modalController: ModalController,
|
||||
private navParams: NavParams) { }
|
||||
|
||||
loggedUser: any;
|
||||
chatUser: any;
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.userData$.subscribe((res:any)=>{
|
||||
this.loggedUser=res;
|
||||
})
|
||||
this.chatUser = this.navParams.get('user');
|
||||
console.log(this.navParams.get('user'));
|
||||
|
||||
console.log(this.chatUser.name);
|
||||
|
||||
|
||||
/* console.log("ON");
|
||||
this.socket.connect();
|
||||
|
||||
//Set current user
|
||||
let name = `User-${new Date().getTime()}`;
|
||||
this.currentUser=name;
|
||||
|
||||
this.socket.emit('set-name', name);
|
||||
|
||||
//Reat from event calling "fromEvent"
|
||||
this.socket.fromEvent('users-changed').subscribe(data =>{
|
||||
console.log('gOT data:', data);
|
||||
});
|
||||
|
||||
//Add message to the array of messages
|
||||
this.socket.fromEvent('message').subscribe(message =>{
|
||||
console.log('New:', message);
|
||||
this.messages.push(message);
|
||||
}); */
|
||||
|
||||
}
|
||||
close(){
|
||||
this.router.navigate(['/home/chat']);
|
||||
this.modalController.dismiss(null);
|
||||
}
|
||||
sendMessage(){
|
||||
|
||||
}
|
||||
/* sendMessage(){
|
||||
this.socket.emit('send-message', {text: this.message});
|
||||
this.message="";
|
||||
}
|
||||
|
||||
ionViewWillLeave(){
|
||||
this.socket.disconnect();
|
||||
} */
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
import { NewchatPage } from './newchat.page';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: NewchatPage
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class NewchatPageRoutingModule {}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
|
||||
import { NewchatPageRoutingModule } from './newchat-routing.module';
|
||||
|
||||
import { NewchatPage } from './newchat.page';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
IonicModule,
|
||||
NewchatPageRoutingModule
|
||||
],
|
||||
declarations: [NewchatPage]
|
||||
})
|
||||
export class NewchatPageModule {}
|
||||
@@ -0,0 +1,20 @@
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-buttons slot="start">
|
||||
<ion-back-button icon="chevron-back"></ion-back-button>
|
||||
</ion-buttons>
|
||||
<ion-title>Nova Conversa</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
|
||||
<ion-content>
|
||||
<ion-toolbar>
|
||||
<ion-searchbar round (ionChange)="onChange($event)" placeholder="Pesquisar por cantacto" ></ion-searchbar>
|
||||
</ion-toolbar>
|
||||
<ion-list>
|
||||
<ion-item *ngFor="let user of searchedItem" (click)="starConversation(user)">
|
||||
{{user.name}}
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
|
||||
</ion-content>
|
||||
@@ -0,0 +1,3 @@
|
||||
ion-searchbar{
|
||||
--border-radius: 20px;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
|
||||
import { NewchatPage } from './newchat.page';
|
||||
|
||||
describe('NewchatPage', () => {
|
||||
let component: NewchatPage;
|
||||
let fixture: ComponentFixture<NewchatPage>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ NewchatPage ],
|
||||
imports: [IonicModule.forRoot()]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(NewchatPage);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { ModalController } from '@ionic/angular';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
import { ConversationPage } from '../conversation/conversation.page';
|
||||
|
||||
@Component({
|
||||
selector: 'app-newchat',
|
||||
templateUrl: './newchat.page.html',
|
||||
styleUrls: ['./newchat.page.scss'],
|
||||
})
|
||||
export class NewchatPage implements OnInit {
|
||||
userList: any[];
|
||||
|
||||
constructor(
|
||||
private chatService: ChatService,
|
||||
private modalController: ModalController,
|
||||
private router:Router) { }
|
||||
|
||||
result:any;
|
||||
searchCountryString:any;
|
||||
searchedItem:any;
|
||||
|
||||
ngOnInit() {
|
||||
this.getUsers();
|
||||
}
|
||||
|
||||
getUsers(){
|
||||
this.result = this.chatService.getAllUsers().subscribe((res:any)=>{
|
||||
this.userList = res.users;
|
||||
this.searchedItem = this.userList;
|
||||
});
|
||||
}
|
||||
|
||||
userSelected(id){
|
||||
console.log(id);
|
||||
this.router.navigate(['/home/chat/conversation']);
|
||||
|
||||
}
|
||||
onChange(event){
|
||||
const val = event.detail.value;
|
||||
this.searchedItem = this.userList;
|
||||
if(val && val.trim() != ''){
|
||||
this.searchedItem = this.searchedItem.filter((item:any) =>{
|
||||
return (item.name.toLowerCase().indexOf(val.toLowerCase()) > -1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async starConversation(selectedUser) {
|
||||
const modal = await this.modalController.create({
|
||||
component: ConversationPage,
|
||||
cssClass: 'conversation',
|
||||
backdropDismiss: false,
|
||||
componentProps: {
|
||||
user: selectedUser,
|
||||
}
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user