This commit is contained in:
tiago.kayaya
2021-09-06 16:53:58 +01:00
parent d0fee13402
commit 5e4229e210
7 changed files with 84 additions and 7 deletions
@@ -10,6 +10,7 @@ import { NewGroupPage } from '../new-group/new-group.page';
import { GroupContactsPage } from './group-contacts/group-contacts.page';
import {Router} from '@angular/router'
import { EditGroupPage } from '../edit-group/edit-group.page';
import { TimeService } from 'src/app/services/functions/time.service';
@Component({
selector: 'app-group-messages',
@@ -49,7 +50,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
private navParams: NavParams,
private authService: AuthService,
private alertService: AlertService,
private route: Router
private route: Router,
private timeService: TimeService,
) {
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = true;
@@ -178,7 +180,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
showDateDuration(start:any){
let end;
return this.timeService.showDateDuration(start);
/* let end;
end = new Date();
start = new Date(start);
let customizedDate;
@@ -204,7 +207,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
else{
let date = start.getDate() + "/" + (start.getMonth()+1) + "/" + start.getFullYear();
return date;
}
} */
}
addZero(i) {
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { TimeService } from './time.service';
describe('TimeService', () => {
let service: TimeService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TimeService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,47 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class TimeService {
constructor() { }
showDateDuration(start:any){
let end;
end = new Date();
start = new Date(start);
let customizedDate;
const totalSeconds = Math.floor((end - (start))/1000);;
const totalMinutes = Math.floor(totalSeconds/60);
const totalHours = Math.floor(totalMinutes/60);
const totalDays = Math.floor(totalHours/24);
const hours = totalHours - ( totalDays * 24 );
const minutes = totalMinutes - ( totalDays * 24 * 60 ) - ( hours * 60 );
const seconds = totalSeconds - ( totalDays * 24 * 60 * 60 ) - ( hours * 60 * 60 ) - ( minutes * 60 );
if(totalDays == 0){
if(start.getDate() == new Date().getDate()){
let time = start.getHours() + ":" + this.addZero(start.getUTCMinutes());
return time;
}
else{
return 'Ontem';
}
}
else{
let date = start.getDate() + "/" + (start.getMonth()+1) + "/" + start.getFullYear();
return date;
}
}
addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
}
@@ -42,7 +42,7 @@
<div *ngIf="msg.t != 'r'" class='incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45'>
<div class="title">
<ion-label>{{msg.u.name}}</ion-label>
<span class="time">{{msg._updatedAt | date: 'HH:mm' }}</span>
<span class="time">{{showDateDuration(msg._updatedAt)}}</span>
</div>
<div>
<ion-label>{{msg.msg}}</ion-label>
@@ -10,6 +10,7 @@ import { GroupContactsPage } from './group-contacts/group-contacts.page';
import { Router } from '@angular/router'
import { ChatOptionsPopoverPage } from '../../popover/chat-options-popover/chat-options-popover.page';
import { ChatOptionsFeaturesPage } from 'src/app/modals/chat-options-features/chat-options-features.page';
import { TimeService } from 'src/app/services/functions/time.service';
@Component({
selector: 'app-group-messages',
@@ -54,7 +55,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
private authService: AuthService,
private animationController: AnimationController,
private alertService: AlertService,
private route: Router
private route: Router,
private timeService: TimeService,
) {
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = true;
@@ -140,6 +142,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
console.log('here watching');
return this.roomId;
}
showDateDuration(start:any){
return this.timeService.showDateDuration(start);
}
getRoomInfo(){
this.showLoader = true;
@@ -35,7 +35,7 @@
<div class='incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45'>
<div class="title">
<ion-label>{{msg.u.name}}</ion-label>
<span class="time">{{msg._updatedAt | date: 'HH:mm' }}</span>
<span class="time">{{showDateDuration(msg._updatedAt)}}</span>
</div>
<div>
<ion-label>{{msg.msg}}</ion-label>
@@ -12,6 +12,7 @@ import { synchro } from 'src/app/services/socket/synchro.service';
import { ChatOptionsFeaturesPage } from 'src/app/modals/chat-options-features/chat-options-features.page';
import { ChatMessageStore } from 'src/app/store/chat/chat-message.service';
import { ChatUserStorage } from 'src/app/store/chat/chat-user.service';
import { TimeService } from 'src/app/services/functions/time.service';
@Component({
selector: 'app-messages',
@@ -58,7 +59,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
private animationController: AnimationController,
private alertService: AlertService,
private toastService: ToastService,
private route: Router
private route: Router,
private timeService: TimeService,
) {
this.loggedUser = authService.ValidatedUserChat['data'];
@@ -151,6 +153,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.openNewEventPage.emit(data);
}
showDateDuration(start:any){
return this.timeService.showDateDuration(start);
}
sendMessage() {
this.synchro.$send({})