From 936351b7ec664b21194b3b458153ba7096ea9030 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Mon, 17 Jan 2022 11:27:25 +0100 Subject: [PATCH] added realtime to: - edit group name - adicionar membro - remover membro --- src/app/models/chatMethod.ts | 1 + src/app/pages/chat/chat.page.html | 4 --- src/app/pages/chat/chat.page.ts | 7 ++-- .../group-messages/group-messages.page.html | 13 +++++-- src/app/services/auth.service.ts | 34 +++++++++---------- src/app/services/chat/message.service.ts | 4 ++- src/app/services/chat/room.service.ts | 7 ++-- .../services/chat/ws-chat-methods.service.ts | 3 +- .../group-messages/group-messages.page.html | 12 +++++-- 9 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/app/models/chatMethod.ts b/src/app/models/chatMethod.ts index 2c47f0f4e..3a090d813 100644 --- a/src/app/models/chatMethod.ts +++ b/src/app/models/chatMethod.ts @@ -71,6 +71,7 @@ export interface Message { msg: string; ts: Ts; u: U; + t: string; _updatedAt: UpdatedAt; mentions: any[]; channels: any[]; diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index 0ce60a14c..24b903f75 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -25,9 +25,6 @@ - @@ -178,7 +175,6 @@ (showEmptyContainer)="showEmptyContainer()" (showEmptyContainer)="showEmptyContainer()" (openNewEventPage)="openNewEventPage($event)" - (getDirectMessages)="getDirectMessages($event)" [style.display]="showMessages ? 'flex' : 'none'" [roomId]="roomId" [showMessages]="showMessages" #messagecontainer> diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 086cf839b..d58541d94 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -143,6 +143,9 @@ export class ChatPage implements OnInit { ngOnInit() { + console.log(this.wsChatMethodsService.group); + + this.segment = "Contactos"; this.authService.userData$.subscribe((res: any) => { @@ -366,10 +369,6 @@ export class ChatPage implements OnInit { }, 1000); } - refreshing() { - //this.load(); - } - customRoom() { let params = new HttpParams(); params = params.set("types", "c"); 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 5221c7d99..95720a3e3 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -57,7 +57,7 @@ A conversa original mantêm-se como chat individual
-
+
{{msg.u.name}} {{showDateDuration(msg._updatedAt)}} @@ -98,7 +98,7 @@
-
+
{{msg.u.name}} {{showDateDuration(msg._updatedAt)}} @@ -113,7 +113,6 @@
-
@@ -160,6 +159,14 @@
{{last ? scrollToBottom() : ''}}
+
+
+
+ Adicionou {{user.name}}
+
+
+ {{last ? scrollToBottom() : ''}} +
{{msg.u.name}} criou esta reunião
diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index ebbd691df..4e87e26ed 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -112,30 +112,30 @@ export class AuthService { "password": user.password, } - - setTimeout(()=>{ - console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password) - - this.WsChatService.connect(); - this.WsChatService.login().then((message) => { - console.log('rocket chat login successfully', message) - this.WsChatService.setStatus('online') - }).catch((message)=>{ - console.log('rocket chat login failed', message) - }) - }, 1) - let responseChat = await this.httpService.post('login', postData).toPromise(); if(responseChat) { + + setTimeout(()=>{ + console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password) + + this.WsChatService.connect(); + this.WsChatService.login().then((message) => { + console.log('rocket chat login successfully', message) + this.WsChatService.setStatus('online') + }).catch((message)=>{ + console.log('rocket chat login failed', message) + }) + }, 1) + console.log('Login to Rocket chat OK'); + this.ValidatedUserChat = responseChat; + localStorage.setItem('userChat', JSON.stringify(responseChat)); - localStorage.setItem('Meteor.loginToken', responseChat['data'].authToken); - localStorage.setItem('Meteor.userId',responseChat['data'].userId); - this.cookieService.set('rc_token', responseChat['data'].authToken); - this.cookieService.set('rc_uid', responseChat['data'].userId); + this.storageService.store(AuthConnstants.AUTH, responseChat); + return true; } else{ diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 9ef101d5d..4c28ea287 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -14,6 +14,7 @@ export class MessageService { rid = '' ts = {} u = {} + t = '' _id ='' _updatedAt = {} file @@ -21,7 +22,7 @@ export class MessageService { constructor() { } - setData({customFields, channels, mentions, msg ,rid ,ts, u, _id, _updatedAt, file, attachments}:Message) { + setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments}:Message) { this.customFields = customFields this.channels = channels this.mentions = mentions @@ -29,6 +30,7 @@ export class MessageService { this.rid = rid this.ts = ts this.u = u + this.t = t this._id = _id this._updatedAt = _updatedAt this.file = file diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 24e4c683e..e9dde9382 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -16,6 +16,7 @@ export class RoomService { chatUser: ChatUserService[] = [] customFields:any; id = '' + t = '' name = '' _updatedAt = {} private hasLoadHistory = false @@ -30,10 +31,11 @@ export class RoomService { private MessageService: MessageService, ) {} - setData({customFields, id, name, lastMessage, _updatedAt}) { + setData({customFields, id, name, t, lastMessage, _updatedAt}) { this.customFields = customFields this.id = id this.name = name + this.t = t this.lastMessage = lastMessage this._updatedAt = _updatedAt @@ -52,13 +54,14 @@ export class RoomService { const message = new MessageService() message.setData(ChatMessage) this.lastMessage.msg = message.msg + if(message.t == 'r'){this.name = message.msg} this.calDateDuration(ChatMessage._updatedAt) this.massages.push(message) setTimeout(()=>{ this.scrollDown() }, 100) - + } ) } diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index d1effbdce..a88de802e 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -27,7 +27,7 @@ export class WsChatMethodsService { (async()=>{ await this.getAllRooms(); this.subscribeToRoom() - + })() } @@ -50,6 +50,7 @@ export class WsChatMethodsService { customFields: roomData.customFields, id: this.getRoomId(roomData), name: this.getRoomName(roomData), + t: roomData.t, lastMessage: this.getRoomLastMessage(roomData), _updatedAt: new Date(roomData._updatedAt['$date']) }) 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 e4b1e4988..c52b15317 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -45,7 +45,7 @@
-
+
@@ -93,7 +93,7 @@
-
+
@@ -162,6 +162,14 @@
{{last ? scrollToBottom() : ''}}
+
+
+
+ Adicionou {{user.name}}
+
+
+ {{last ? scrollToBottom() : ''}} +
{{msg.u.name}} criou esta reunião