This commit is contained in:
Peter Maquiran
2022-01-14 12:16:09 +01:00
6 changed files with 8 additions and 155 deletions
+3 -97
View File
@@ -138,39 +138,21 @@ export class ChatPage implements OnInit {
this.showLoader = true;
console.log("CHAT PAGE");
/* wsService.messages.subscribe(msg => {
console.log("Response from Websocket server: "+msg);
}); */
//this.load()
}
ngOnInit() {
console.log(this.loggedUserChat);
this.segment = "Contactos";
this.authService.userData$.subscribe((res: any) => {
this.loggedUser = res;
//console.log(this.loggedUser);
//this.load();
//this.getDirectMessagesDB();
});
/* websocket functions */
//this.sendMsg();
/* Fim websocket functions */
this.hideRefreshButton();
this.getChatMembers();
//Teste
let t = this.showDateDuration(new Date());
//console.log(t);
this.setStatus('away');
/* if(this.dataService.get("newGroup")){
@@ -232,28 +214,6 @@ export class ChatPage implements OnInit {
}
}
/* loadWsChatMessages(){
this.chatService.messages.subscribe(msg => {
console.log("Response from Websocket server: "+msg);
});
} */
/* loadMessage(){
this.wsService.messages.subscribe(msg => {
console.log("Response from websocket: " + msg);
});
}
sendMsg() {
console.log("new message from client to websocket: ", this.message);
this.wsService.messages.next(this.message);
this.message.msg = "";
this.loadMessage();
} */
/* Fim websockets functions */
closeAllDesktopComponents() {
this.showMessages = false;
this.showContacts = false;
@@ -396,33 +356,20 @@ export class ChatPage implements OnInit {
}
onSegmentChange() {
this.load();
//this.load();
}
doRefresh(event) {
setTimeout(() => {
this.load();
//this.load();
event.target.complete();
}, 1000);
}
refreshing() {
this.load();
//this.load();
}
load() {
switch (this.segment) {
case "Contactos":
this.showLoader = true;
this.getDirectMessages();
break;
case "Grupos":
this.showLoader = true;
this.getGroups();
break;
}
}
customRoom() {
let params = new HttpParams();
params = params.set("types", "c");
@@ -558,47 +505,6 @@ export class ChatPage implements OnInit {
}
}
async getDirectMessages(event?) {
this.chatService.getAllDirectMessages().subscribe(async (res: any) => {
this.showLoader = false;
this.transformDataRoomList(res.ims)
this.getDirectMessagesDB()
//console.log('Chat list', res);
if (res != 200) {
/* if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.userDirectMessages = res.ims.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
var dateB = new Date(b._updatedAt).getTime();
return dateB - dateA;
});
} */
//console.log(res.ims);
//console.log(this.userDirectMessages);
if (this.route.url != "/home/chat") {
//console.log("Timer message stop")
}
else {
//console.log('TIMER');
//Check if modal is opened
if (this.segment == "Contactos" && this.showMessages != true) {
await new Promise(resolve => setTimeout(resolve, 1000));
//await this.getDirectMessages();
//console.log('Timer contactos list running')
}
else {
//console.log('No timer!');
}
}
}
else {
//await this.getDirectMessages();
}
});
}
showDateDuration(start: any) {
return this.timeService.showDateDuration(start);
}
@@ -56,7 +56,7 @@
<ion-label>Esta conversa passou a grupo TIAGO</ion-label><br />
<ion-label>A conversa original mantêm-se como chat individual</ion-label>
</div>
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of messages; let last = last" [class.messages-list-item-wrapper-active]="msg._id == selectedMsgId">
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getGroupRoom(roomId).massages; let last = last" [class.messages-list-item-wrapper-active]="msg._id == selectedMsgId">
<div *ngIf="msg.t != 'r' && msg.t != 'ul' && msg.t != 'ru' && msg.msg !=''" (press)="handlePress(msg._id)" class='message-container incoming-{{msg.u.username!=loggedUser.me.username}}'>
<div class="title">
<ion-label>{{msg.u.name}}</ion-label>
@@ -23,6 +23,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';
@Component({
selector: 'app-group-messages',
@@ -82,7 +83,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
private fileService: FileService,
private toastService: ToastService,
public ThemeService: ThemeService,
private changeDetectorRef: ChangeDetectorRef
private changeDetectorRef: ChangeDetectorRef,
public wsChatMethodsService: WsChatMethodsService
) {
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = true;
@@ -92,6 +94,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.modalController.dismiss();
}
};
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory();
}
ngOnInit() {
-13
View File
@@ -39,18 +39,6 @@ export class RoomService {
}
receiveMessage() {
this.WsChatService.receiveMyMessageConfirmation(
this.id,
(ChatMessage:ChatMessage) => {
ChatMessage = this.fix_updatedAt(ChatMessage)
const message = new MessageService()
message.setData(ChatMessage.result)
// this.massages.push(message)
this.calDateDuration(ChatMessage.result._updatedAt)
//this.ToastService.presentToast('nova mensagem')
}
)
this.WsChatService.receiveLiveMessageFromRoom(
this.id,
@@ -62,7 +50,6 @@ export class RoomService {
const message = new MessageService()
message.setData(ChatMessage)
this.lastMessage.msg = message.msg
console.log('ChatMessage.result._updatedAt', ChatMessage._updatedAt)
this.calDateDuration(ChatMessage._updatedAt)
this.massages.push(message)
}
@@ -24,7 +24,6 @@ export class WsChatMethodsService {
constructor(
private WsChatService: WsChatService
) {
(async()=>{
await this.getAllRooms();
this.subscribeToRoom()
@@ -110,7 +110,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.loggedUser=this.loggedUserChat;
this.getRoomInfo();
this.serverLongPull();
this.setStatus('online');
this.getChatMembers();
}
@@ -755,47 +754,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
});
}
async serverLongPull(){
if(this.route.url != "/home/chat" && document.querySelector('app-group-messages')){
console.log("Timer message stop")
}
else
{
this.chatService.getPrivateGroupMessages(this.roomId).subscribe(async res =>
{
if(res['success'] == true) {
// Show Error
//showMessage(response.statusText);
//this.loadMessages()
let msgOnly = res['messages'].filter(data => data.t != 'au');
this.messages = msgOnly.reverse();
console.log(this.messages);
// Reconnect in one second
if(document.querySelector('app-group-messages')){
await new Promise(resolve => setTimeout(resolve,5000));
this.getGroups.emit();
console.log('Timer message running')
await this.serverLongPull();
}
}
else {
alert('HEY2')
// Got message
//let message = await response.text();
//this.loadMessages()
await this.serverLongPull();
}
}, (error)=>{
console.log(error);
this.serverLongPull();
});
}
}
sliderOpts = {
zoom: false,