diff --git a/src/app/models/chatMethod.ts b/src/app/models/chatMethod.ts index c813eb88d..2c47f0f4e 100644 --- a/src/app/models/chatMethod.ts +++ b/src/app/models/chatMethod.ts @@ -65,6 +65,7 @@ interface FirstUnread { } export interface Message { + customFields:any; _id: string; rid: string; msg: string; diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index 71a30bd9c..0ce60a14c 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -120,27 +120,27 @@
{{group.value.name.split('-').join(' ')}}
- +
{{group.value.duration}}
+
{{countDownDate(group.value.customFields.countDownDate, group.value.id)}}
- + - +
diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 17c9799fa..61508a0c6 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -32,7 +32,6 @@ import { ThemeService } from 'src/app/services/theme.service' import { DataService } from 'src/app/services/data.service'; import { SqliteService } from 'src/app/services/sqlite.service'; import { StorageService } from 'src/app/services/storage.service'; -import { WebsocketService } from 'src/app/services/websocket.service'; @@ -40,7 +39,6 @@ import { WebsocketService } from 'src/app/services/websocket.service'; selector: 'app-chat', templateUrl: './chat.page.html', styleUrls: ['./chat.page.scss'], - providers: [WebsocketService, ChatService] }) export class ChatPage implements OnInit { @@ -146,7 +144,7 @@ export class ChatPage implements OnInit { console.log("Response from Websocket server: "+msg); }); */ - this.load() + //this.load() } ngOnInit() { @@ -158,9 +156,9 @@ export class ChatPage implements OnInit { this.authService.userData$.subscribe((res: any) => { this.loggedUser = res; //console.log(this.loggedUser); - this.load(); + //this.load(); - this.getDirectMessagesDB(); + //this.getDirectMessagesDB(); }); /* websocket functions */ diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index f589e9f12..9b97b2244 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -49,7 +49,7 @@ -->
-
diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index aff6d21fa..bad98da93 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -108,7 +108,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } }; - this.wsChatMethodsService.getRoom(this.roomId).loadHistory() + this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() } diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 1e4180e07..7373f3c72 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -101,7 +101,7 @@ export class LoginPage implements OnInit { // login to API successfully if (attempt) { - if (attempt.UserId == SessionStore.user.UserId) { + if (attempt.UserId == SessionStore.user.UserId) { await this.authService.SetSession(attempt, this.userattempt); await this.authService.loginChat(this.userattempt); this.getToken(); diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index b5c8616b7..a0001bff1 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -8,7 +8,6 @@ import { environment } from 'src/environments/environment'; import { Storage } from '@ionic/storage'; import { Message } from 'src/app/models/message.model'; import { Observable, Subject } from "rxjs/Rx"; -import { WebsocketService } from './websocket.service'; @Injectable({ providedIn: 'root' @@ -31,7 +30,6 @@ export class ChatService { private authService: AuthService, private storage: Storage, private storageService:StorageService, - private wsService: WebsocketService, ) { this.loggedUserChat = authService.ValidatedUserChat; @@ -42,45 +40,6 @@ export class ChatService { headers: this.headers, }; - /* console.log("CHAT SERVICE"); - - wsService.messages = >this.wsService - .connect(environment.apiWsChatUrl) - .map((response: MessageEvent): any => { - let data = JSON.parse(response.data); - console.log(data); - - if(data.msg == 'ping'){ - wsService.messages.next({msg:'pong'}); - if(!this.authService.isWsAuthenticated){ - //this.authService.loginWsChat(); - - let msg = { - "msg": "method", - "method": "login", - "id":"1", - "params":[ - { - "user": { "username": "paulo.pinto" }, - "password": "tabteste@006" - } - ] - } - wsService.messages.next(msg); - console.log('Authenticate'); - this.authService.isWsAuthenticated = true; - - } - //this.authService.loginWsChat(); - } - if(data.id == '1'){ - this.authService.wsValidatedUserChat = data; - } - return (JSON.stringify(data)); - }); - - console.log(wsService.messages) */; - } getDocumentDetails(url:string){ diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index ffdf4c9cf..9ef101d5d 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -7,6 +7,7 @@ import { chatHistory, ChatMessage, File } from 'src/app/models/chatMethod' }) export class MessageService { + customFields channels = [] mentions = [] msg = '' @@ -20,7 +21,8 @@ export class MessageService { constructor() { } - setData({channels, mentions, msg ,rid ,ts, u, _id, _updatedAt, file, attachments}:Message) { + setData({customFields, channels, mentions, msg ,rid ,ts, u, _id, _updatedAt, file, attachments}:Message) { + this.customFields = customFields this.channels = channels this.mentions = mentions this.msg = msg diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index b33b0d36c..897d610bf 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -14,12 +14,13 @@ export class RoomService { lastMessage: MessageService; chatUser: ChatUserService[] = [] + customFields:any; id = '' name = '' _updatedAt = {} private hasLoadHistory = false duration = '' - + private ToastService = ToastsService constructor( @@ -27,7 +28,8 @@ export class RoomService { private MessageService: MessageService, ) {} - setData({id, name, lastMessage, _updatedAt}) { + setData({customFields, id, name, lastMessage, _updatedAt}) { + this.customFields = customFields this.id = id this.name = name this.lastMessage = lastMessage @@ -62,17 +64,17 @@ export class RoomService { this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => { console.log('loadHistory', chatHistory) - + chatHistory.result.messages.reverse().forEach(message => { - + message = this.fix_updatedAt(message) const wewMessage = new MessageService() wewMessage.setData(message) this.massages.push(wewMessage) }); - }) + }) this.hasLoadHistory = true } diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index bb5788967..b0609edd6 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -36,7 +36,7 @@ export class WsChatMethodsService { this.loadingWholeList = true const rooms = await this.WsChatService.getRooms(); - + // console.log("ROOMS" + JSON.stringify(rooms)) rooms.result.update.forEach((roomData: room) => { @@ -47,10 +47,11 @@ export class WsChatMethodsService { room = new RoomService(this.WsChatService, new MessageService()) room.setData({ + customFields: roomData.customFields, id: this.getRoomId(roomData), name: this.getRoomName(roomData), lastMessage: this.getRoomLastMessage(roomData), - _updatedAt: roomData._updatedAt['$date'] + _updatedAt: new Date(roomData._updatedAt['$date']) }) room.receiveMessage() @@ -65,10 +66,10 @@ export class WsChatMethodsService { this.groupCount++ } - + }); - + console.log('this.group', this.group) this.loadingWholeList = false } @@ -87,12 +88,16 @@ export class WsChatMethodsService { } } - getRoom(id): RoomService { + getDmRoom(id): RoomService { try { return this.dm[id] - } catch(e) { + } catch(e) {} + } + + getGroupRoom(id): RoomService { + try { return this.group[id] - } + } catch(e) {} } getRoomName(roomData: room) { 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 c09032572..5c4a8fa22 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -23,10 +23,10 @@
-
+
@@ -44,7 +44,7 @@ A conversa original mantêm-se como chat individual
-
+
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 12c5a69bc..fc13c348c 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -22,6 +22,7 @@ import { ThemeService } from 'src/app/services/theme.service' import { PreviewCameraPage } from 'src/app/modals/preview-camera/preview-camera.page'; import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page'; import { ViewEventPage } from 'src/app/modals/view-event/view-event.page'; +import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'; /* import * as pdfjsLib from 'pdfjs-dist'; @@ -72,8 +73,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe @ViewChild('scrollMe') private myScrollContainer: ElementRef; - pdfurl = "http://www.africau.edu/images/default/sample.pdf"; - constructor( private menu: MenuController, private modalController: ModalController, @@ -90,7 +89,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe private processesService: ProcessesService, private fileService: FileService, public ThemeService: ThemeService, - private changeDetectorRef: ChangeDetectorRef + private changeDetectorRef: ChangeDetectorRef, + public wsChatMethodsService: WsChatMethodsService ) { this.loggedUserChat = authService.ValidatedUserChat['data']; this.isGroupCreated = true; @@ -101,9 +101,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe ngOnChanges(changes: SimpleChanges): void { this.getRoomInfo(); //this.scrollToBottom(); + this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); + console.log('MESSAGES'+this.wsChatMethodsService.getGroupRoom(this.roomId).massages); } ngOnInit() { + //console.log(this.wsChatMethodsService.getRoom(this.roomId).massages); + this.loggedUser=this.loggedUserChat; this.getRoomInfo(); this.serverLongPull(); diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index df633ae84..053c88603 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -37,7 +37,7 @@
-
+
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 7079eb39e..51577d937 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -84,7 +84,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.loggedUser = authService.ValidatedUserChat['data']; } ngOnChanges(changes: SimpleChanges): void { - this.wsChatMethodsService.getRoom(this.roomId).loadHistory() + this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() } ngOnInit() { @@ -214,7 +214,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } sendMessage() { - this.wsChatMethodsService.getRoom(this.roomId).send(this.message) + this.wsChatMethodsService.getDmRoom(this.roomId).send(this.message) this.message = ""; }