From 129a7095704d0430575b8a490bb7992f4a241c3c Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Thu, 9 Sep 2021 11:47:49 +0100 Subject: [PATCH] improvements --- .../group-messages/group-messages.page.html | 21 +++++++++++++++-- .../group-messages/group-messages.page.ts | 12 ++++++++++ .../group-messages/group-messages.page.html | 16 +++++++++++-- .../group-messages/group-messages.page.ts | 23 ++++++++++++++++++- .../popover/chat-popover/chat-popover.page.ts | 23 +++++++++++++++---- 5 files changed, 86 insertions(+), 9 deletions(-) diff --git a/src/app/pages/chat/group-messages/group-messages.page.html b/src/app/pages/chat/group-messages/group-messages.page.html index 742513d3f..e1569034a 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -40,7 +40,7 @@ A conversa original mantêm-se como chat individual
-
+
{{msg.u.name}} {{showDateDuration(msg._updatedAt)}} @@ -51,7 +51,24 @@
- Alterou o assunto para "{{msg.msg.split('-').join(' ')}}"
+ Alterou o nome do grupo para "{{msg.msg.split('-').join(' ')}}"
+ {{last ? scrollToBottom() : ''}} +
+
+
+
+ {{user.name}} saiu do grupo
+
+
+ {{last ? scrollToBottom() : ''}} +
+
+
+
+ {{user.name}} foi removido do grupo
+
+
+ {{last ? scrollToBottom() : ''}}
diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index 6ef11c520..83dc2c51e 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -29,6 +29,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { roomName:any; members:any; contacts: string[] = [" Ana M.", "Andre F.", "Bruno G.", "Catarina T", "Tiago"]; + allUsers:any[] = []; roomId: string; loggedUserChat:any; @@ -70,6 +71,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.scrollToBottom(); this.serverLongPull(); this.setStatus('online'); + this.getChatMembers(); } setStatus(status:string){ @@ -125,6 +127,16 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }); } + async getChatMembers(){ + //return await this.chatService.getMembers(roomId).toPromise(); + this.chatService.getAllUsers().subscribe(res=> { + console.log(res); + + this.allUsers = res['users'].filter(data => data.username != this.loggedUserChat.me.username); + console.log(this.allUsers); + }); + } + /* load(){ this.getGroupContacts(); this.loadGroupMessages(); diff --git a/src/app/shared/chat/group-messages/group-messages.page.html b/src/app/shared/chat/group-messages/group-messages.page.html index f39dbe359..c20b18f07 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -39,7 +39,7 @@ A conversa original mantêm-se como chat individual
-
+
{{msg.u.name}} {{showDateDuration(msg._updatedAt)}} @@ -54,7 +54,19 @@ {{last ? scrollToBottom() : ''}}
- O contacto {{msg.msg.split('-').join(' ')}} saiu do grupo
+
+
+ {{user.name}} saiu do grupo
+
+
+ {{last ? scrollToBottom() : ''}} +
+
+
+
+ {{user.name}} foi removido do grupo
+
+
{{last ? scrollToBottom() : ''}}
diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts index c98787c17..4ef4d1fa5 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -24,6 +24,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe message:any; leaveStatus:any; messages:any; + allUsers:any[] = []; room:any = new Array(); @@ -72,6 +73,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe this.serverLongPull(); console.log(this.roomId); this.setStatus('online'); + this.getChatMembers(); } setStatus(status:string){ @@ -116,6 +118,16 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe window.removeEventListener('scroll', this.scrollChangeCallback, true); } + async getChatMembers(){ + //return await this.chatService.getMembers(roomId).toPromise(); + this.chatService.getAllUsers().subscribe(res=> { + console.log(res); + + this.allUsers = res['users'].filter(data => data.username != this.loggedUserChat.me.username); + console.log(this.allUsers); + }); + } + openGroupContactsPage(){ this.openGroupContacts.emit(this.roomId); } @@ -210,7 +222,16 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe let body = { "message": { - "rid": this.roomId, "msg": this.message + "rid": this.roomId, + "msg": this.message, + "attachments": [{ + "color": "#ff0000", + "text": "Yay for gruggy!", + "title": "Attachment Example", + "title_link": "https://youtube.com", + "title_link_download": false, + "image_url": "http://res.guggy.com/logo_128.png", + }] } } diff --git a/src/app/shared/popover/chat-popover/chat-popover.page.ts b/src/app/shared/popover/chat-popover/chat-popover.page.ts index 2f0417fa6..ca1d0742b 100644 --- a/src/app/shared/popover/chat-popover/chat-popover.page.ts +++ b/src/app/shared/popover/chat-popover/chat-popover.page.ts @@ -52,8 +52,16 @@ export class ChatPopoverPage implements OnInit { console.log(res); this.close('leave'); }, - (error)=>{ - this.toastService.badRequest("Não foi possível sair do grupo") + (e)=>{ + if(e.error.errorType = "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.close('cancel'); + } + else{ + this.toastService.badRequest("Não foi possível sair do grupo"); + this.close('cancel'); + } + }, ()=>{ //loader.remove() @@ -64,8 +72,15 @@ export class ChatPopoverPage implements OnInit { console.log(res); this.close('leave'); }, - (error)=>{ - this.toastService.badRequest("Não foi possível sair do grupo") + (e)=>{ + if(e.error.errorType = "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.close('cancel'); + } + else{ + this.toastService.badRequest("Não foi possível sair do grupo"); + this.close('cancel'); + } }, ()=>{ //loader.remove()