This commit is contained in:
Peter Maquiran
2022-06-08 16:09:40 +01:00
parent b3186c6eed
commit 16ae54d8d1
8 changed files with 114 additions and 156 deletions
-3
View File
@@ -19,9 +19,6 @@ export class LoginGuard implements CanActivate {
route: ActivatedRouteSnapshot, route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
// console.log(SessionStore.exist, SessionStore.user.Inactivity, SessionStore.user.LoginPreference)
console.log(SessionStore.exist, SessionStore.user.Inactivity, SessionStore.user.LoginPreference)
if(SessionStore.exist && SessionStore.user.Inactivity && SessionStore.user.LoginPreference != 'Pin' ) { if(SessionStore.exist && SessionStore.user.Inactivity && SessionStore.user.LoginPreference != 'Pin' ) {
this.router.navigate(['/home/events']); this.router.navigate(['/home/events']);
return false return false
+1 -1
View File
@@ -128,7 +128,7 @@
<ion-label>{{group.name.split('-').join(' ')}}</ion-label> <ion-label>{{group.name.split('-').join(' ')}}</ion-label>
</div> </div>
<div class="item-date" [class.item-date-active]="group.id ==idSelected" *ngIf="group.lastMessage && !group.customFields.countDownDate">{{group.duration}}</div> <div class="item-date" [class.item-date-active]="group.id ==idSelected" *ngIf="group.lastMessage && !group.customFields.countDownDate">{{group.duration}}</div>
<div class="item-date" [class.item-date-active]="group.id ==idSelected" *ngIf="group.customFields.countDownDate">{{countDownDate(group.customFields.countDownDate, group.id)}}</div> <div class="item-date" [class.item-date-active]="group.id ==idSelected" *ngIf="group.customFields.countDownDate">{{group.countDownTime}}</div>
</div> </div>
<div *ngIf="group.lastMessage" class="item-description d-flex align-items-center" [class.item-description-active]="group.id ==idSelected"> <div *ngIf="group.lastMessage" class="item-description d-flex align-items-center" [class.item-description-active]="group.id ==idSelected">
<div class="item-message" *ngIf="group.otherUserType == false">{{group.lastMessage.u.name}}: {{group.lastMessage.msg}} </div> <div class="item-message" *ngIf="group.otherUserType == false">{{group.lastMessage.u.name}}: {{group.lastMessage.msg}} </div>
+3 -43
View File
@@ -44,7 +44,6 @@ export class ChatPage implements OnInit {
X_Auth_Token: any; X_Auth_Token: any;
loggedUser: any; loggedUser: any;
/* Set segment variable */
segment: string; segment: string;
allGroups: any[]; allGroups: any[];
privateGroups: any[]; privateGroups: any[];
@@ -90,8 +89,6 @@ export class ChatPage implements OnInit {
"support": ["1"] "support": ["1"]
}; };
/* Fim websockets variables*/
loggedUserChat: any; loggedUserChat: any;
hideRefreshBtn = true; hideRefreshBtn = true;
@@ -128,7 +125,6 @@ export class ChatPage implements OnInit {
this.showLoader = true; this.showLoader = true;
//this.load()
} }
ngOnInit() { ngOnInit() {
@@ -497,16 +493,11 @@ export class ChatPage implements OnInit {
} }
async getChatMembers() { async getChatMembers() {
//return await this.chatService.getMembers(roomId).toPromise();
this.chatService.getAllUsers().subscribe(res => { this.chatService.getAllUsers().subscribe(res => {
// //
this.transformDataUserList(res['users']) this.transformDataUserList(res['users'])
/* if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.dmUsers = res['users'].filter(data => data.username != this.loggedUserChat.me.username);
//
}*/
}); });
} }
@@ -563,23 +554,6 @@ export class ChatPage implements OnInit {
}) })
/* this.sqlservice.getAllChatUsers().then((userslist: any) => {
let chatusersArray = [];
userslist.forEach(element => {
let userListDB = {
_id: element.Id,
name: element.Name,
username: element.Username
}
chatusersArray.push(userListDB);
});
this.dmUsers = chatusersArray.filter(data => data.username != this.loggedUserChat.me.username);
}) */
} }
} }
@@ -635,16 +609,7 @@ export class ChatPage implements OnInit {
this.privateGroups = res.groups; this.privateGroups = res.groups;
/* this.result = this.chatService.getAllUserChannels().subscribe((res:any)=>{
this.publicGroups = res.channels; */
//let all = this.privateGroups.concat(this.publicGroups);
/* this.allGroups = this.privateGroups.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
var dateB = new Date(b._updatedAt).getTime();
return dateB - dateA;
}); */
//
/* }); */
if (this.route.url != "/home/chat") { if (this.route.url != "/home/chat") {
// //
} }
@@ -735,10 +700,5 @@ export class ChatPage implements OnInit {
modal.onDidDismiss(); modal.onDidDismiss();
} }
// this.crop.crop('path/to/image.jpg', {quality: 75})
// .then(
// newImage =>
// error => console.error('Error cropping image', error)
// );
} }
+1 -1
View File
@@ -58,7 +58,7 @@ export class AlertService {
handler: () => { handler: () => {
//const loader = this.toastService.loading(); //const loader = this.toastService.loading();
this.wsChatMethodsService.deleteMessage(msgId).then(()=>{ this.wsChatMethodsService.deleteMessage(msgId).then(() => {
room.deleteMessage(msgId) room.deleteMessage(msgId)
}) })
//this.wsChatMethodsService.subscribeToRoomUpdate(room._id, room); //this.wsChatMethodsService.subscribeToRoomUpdate(room._id, room);
+60 -6
View File
@@ -2,7 +2,6 @@ import { Injectable } from '@angular/core';
import { WsChatService } from 'src/app/services/chat/ws-chat.service'; import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { MessageService } from 'src/app/services/chat/message.service'; import { MessageService } from 'src/app/services/chat/message.service';
import { showDateDuration } from 'src/plugin/showDateDuration'; import { showDateDuration } from 'src/plugin/showDateDuration';
import { ToastsService } from '../toast.service';
import { chatHistory } from 'src/app/models/chatMethod'; import { chatHistory } from 'src/app/models/chatMethod';
import { Storage } from '@ionic/storage'; import { Storage } from '@ionic/storage';
import { Platform } from '@ionic/angular'; import { Platform } from '@ionic/angular';
@@ -16,13 +15,14 @@ import { environment } from 'src/environments/environment';
import { ChatService } from 'src/app/services/chat.service'; import { ChatService } from 'src/app/services/chat.service';
import { NfService } from 'src/app/services/chat/nf.service'; import { NfService } from 'src/app/services/chat/nf.service';
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { ChatStorageService } from './chat-storage.service' import { ChatStorageService } from './chat-storage.service';
import { ChatMethodsService } from './chat-methods.service' import { ChatMethodsService } from './chat-methods.service';
import { DeleteMessageModel, MessageModel } from '../../models/beast-orm' import { DeleteMessageModel, MessageModel } from '../../models/beast-orm';
import { AESEncrypt } from '../aesencrypt.service' import { AESEncrypt } from '../aesencrypt.service';
import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model'; import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model';
import { AttachmentsService } from 'src/app/services/attachments.service'; import { AttachmentsService } from 'src/app/services/attachments.service';
import { ConnectionStatus, NetworkServiceService} from 'src/app/services/network-service.service'; import { ConnectionStatus, NetworkServiceService} from 'src/app/services/network-service.service';
import { WsChatMethodsService } from './ws-chat-methods.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -52,6 +52,7 @@ export class RoomService {
members = [] members = []
u u
sessionStore = SessionStore sessionStore = SessionStore
countDownTime = ''
scrollDown = () => { } scrollDown = () => { }
@@ -80,7 +81,8 @@ export class RoomService {
private ChatMethodsService: ChatMethodsService, private ChatMethodsService: ChatMethodsService,
private AESEncrypt: AESEncrypt, private AESEncrypt: AESEncrypt,
private AttachmentsService: AttachmentsService, private AttachmentsService: AttachmentsService,
private NetworkServiceService: NetworkServiceService private NetworkServiceService: NetworkServiceService,
private wsChatMethodsService: WsChatMethodsService
) { ) {
this.NativeNotificationService.askForPermission() this.NativeNotificationService.askForPermission()
@@ -157,6 +159,58 @@ export class RoomService {
this.calDateDuration() this.calDateDuration()
this.restoreMessageFromDB() this.restoreMessageFromDB()
if(this.customFields?.countDownDate) {
this.countDownDate(this.customFields.countDownDate);
}
}
countDownDate(date) {
let difference = new Date(date).getTime() - new Date().getTime();
let c_day = Math.floor(difference/(1000*60*60*24));
let c_hours = Math.floor((difference % (1000*60*60*24)) / (1000*60*60));
let c_minutes = Math.floor((difference % (1000*60*60)) / (1000*60));
let c_seconds = Math.floor((difference % (1000*60)) / 1000);
this.countDownTime = this.addZero(c_day) + " : " + this.addZero(c_hours) + " : " + this.addZero(c_minutes) + " : " + this.addZero(c_seconds) ;
if(difference < 0) {
this.deleteRoom()
} else {
setTimeout(() => {
this.countDownDate(date)
}, 1000)
}
}
addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
deleteRoom() {
this.countDownTime = "Expired";
let body = { "roomId": this.id }
this.chatService.getRoomInfo(this.id).subscribe(room=>{
if(this.t === 'p') {
this.chatService.deleteGroup(body).subscribe(res=>{
this.wsChatMethodsService.deleteRoom(this.id)
});
}
else {
this.chatService.deleteChannel(body).subscribe(res=>{
this.wsChatMethodsService.deleteRoom(this.id)
});
}
});
} }
@@ -60,7 +60,7 @@ export class WsChatMethodsService {
private ChatMethodsService:ChatMethodsService, private ChatMethodsService:ChatMethodsService,
private AESEncrypt: AESEncrypt, private AESEncrypt: AESEncrypt,
private AttachmentsService:AttachmentsService, private AttachmentsService:AttachmentsService,
private NetworkServiceService: NetworkServiceService private NetworkServiceService: NetworkServiceService,
) { ) {
this.loggedUser = authService.ValidatedUserChat['data']; this.loggedUser = authService.ValidatedUserChat['data'];
@@ -106,14 +106,14 @@ export class WsChatMethodsService {
} }
async ReLoadChat() { async ReLoadChat() {
await this.restoreRooms() await this.restoreRooms();
await this.getAllRooms(); await this.getAllRooms();
this.subscribeToRoom() this.subscribeToRoom();
// //
await this.getUser() await this.getUser();
this.getUserStatus() this.getUserStatus();
} }
clearChat() { clearChat() {
@@ -321,11 +321,11 @@ export class WsChatMethodsService {
members: roomData.members members: roomData.members
} }
let roomId = this.getRoomId(roomData) let roomId = this.getRoomId(roomData);
// create room // create room
if(!this.roomExist(roomId)) { if(!this.roomExist(roomId)) {
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this)
room.setData(setData) room.setData(setData)
room.receiveMessage() room.receiveMessage()
room.getAllUsers = this.getUsers room.getAllUsers = this.getUsers
@@ -365,10 +365,7 @@ export class WsChatMethodsService {
deleteRoom(roomId) { deleteRoom(roomId) {
delete this.group[roomId]; delete this.group[roomId];
this._group = this._group.filter((e)=> e.id != roomId);
const index = this._group.findIndex((e)=> e.id == roomId);
this._group = this._group.splice(index, 1);
} }
roomExist(roomId) { roomExist(roomId) {
@@ -463,7 +460,7 @@ export class WsChatMethodsService {
} }
addRoomOwner(roomid, userId){ addRoomOwner(roomid, userId) {
return this.WsChatService.addRoomOwner(roomid, userId); return this.WsChatService.addRoomOwner(roomid, userId);
} }
+38 -37
View File
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { ChatService } from '../chat.service'; import { ChatService } from '../chat.service';
import { WsChatMethodsService } from '../chat/ws-chat-methods.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -8,14 +9,13 @@ export class TimeService {
countDownTime: any; countDownTime: any;
room: any; room: any;
constructor(private chatService: ChatService) { } constructor(private chatService: ChatService,
public wsChatMethodsService: WsChatMethodsService,) { }
showDateDuration(start:any){ showDateDuration(start:any) {
let end; let end;
end = new Date(); end = new Date();
start = new Date(start); start = new Date(start);
let customizedDate;
const totalSeconds = Math.floor((end - (start))/1000);; const totalSeconds = Math.floor((end - (start))/1000);;
const totalMinutes = Math.floor(totalSeconds/60); const totalMinutes = Math.floor(totalSeconds/60);
@@ -26,51 +26,51 @@ export class TimeService {
const minutes = totalMinutes - ( totalDays * 24 * 60 ) - ( hours * 60 ); const minutes = totalMinutes - ( totalDays * 24 * 60 ) - ( hours * 60 );
const seconds = totalSeconds - ( totalDays * 24 * 60 * 60 ) - ( hours * 60 * 60 ) - ( minutes * 60 ); const seconds = totalSeconds - ( totalDays * 24 * 60 * 60 ) - ( hours * 60 * 60 ) - ( minutes * 60 );
if(totalDays == 0){ if(totalDays == 0) {
if(start.getDate() == new Date().getDate()){ if(start.getDate() == new Date().getDate()) {
let time = start.getHours() + ":" + this.addZero(start.getUTCMinutes()); let time = start.getHours() + ":" + this.addZero(start.getUTCMinutes());
return time; return time;
} }
else{ else {
return 'Ontem'; return 'Ontem';
} }
} }
else{ else {
let date = this.addZero(start.getDate()) + "/" + this.addZero(start.getMonth()+1) + "/" + start.getFullYear(); let date = this.addZero(start.getDate()) + "/" + this.addZero(start.getMonth()+1) + "/" + start.getFullYear();
return date; return date;
} }
} }
countDownDate(date:any, roomId:string){ countDownDate(date:any, roomId:string){
/* let timer = setInterval(() =>{ */
let difference = new Date(date).getTime() - new Date().getTime(); let difference = new Date(date).getTime() - new Date().getTime();
let c_day = Math.floor(difference/(1000*60*60*24)); let c_day = Math.floor(difference/(1000*60*60*24));
let c_hours = Math.floor((difference % (1000*60*60*24)) / (1000*60*60)); let c_hours = Math.floor((difference % (1000*60*60*24)) / (1000*60*60));
let c_minutes = Math.floor((difference % (1000*60*60)) / (1000*60)); let c_minutes = Math.floor((difference % (1000*60*60)) / (1000*60));
let c_seconds = Math.floor((difference % (1000*60)) / 1000); let c_seconds = Math.floor((difference % (1000*60)) / 1000);
this.countDownTime = this.addZero(c_day) + " : " + this.addZero(c_hours) + " : " + this.addZero(c_minutes) + " : " + this.addZero(c_seconds) ; this.countDownTime = this.addZero(c_day) + " : " + this.addZero(c_hours) + " : " + this.addZero(c_minutes) + " : " + this.addZero(c_seconds) ;
if(difference < 0){ if(difference < 0){
//clearInterval(timer);
this.countDownTime = "Expired";
let body = { "roomId":roomId, }
this.chatService.getRoomInfo(roomId).subscribe(room=>{
this.room = room['room'];
if(this.room.t === 'p'){ this.countDownTime = "Expired";
this.chatService.deleteGroup(body).subscribe(res=>{ let body = { "roomId":roomId, }
this.chatService.getRoomInfo(roomId).subscribe(room=>{
}); this.room = room['room'];
}
else{ if(this.room.t === 'p'){
this.chatService.deleteChannel(body).subscribe(res=>{ this.chatService.deleteGroup(body).subscribe(res=>{
}); });
} }
}); else{
} this.chatService.deleteChannel(body).subscribe(res=>{
//})
});
}
});
}
return this.countDownTime; return this.countDownTime;
} }
@@ -84,7 +84,7 @@ export class TimeService {
this.countDownTime = this.addZero(c_day) + " : " + this.addZero(c_hours) + " : " + this.addZero(c_minutes) + " : " + this.addZero(c_seconds) ; this.countDownTime = this.addZero(c_day) + " : " + this.addZero(c_hours) + " : " + this.addZero(c_minutes) + " : " + this.addZero(c_seconds) ;
if(difference < 0){ if(difference < 0) {
clearInterval(timer); clearInterval(timer);
this.countDownTime = "Expired"; this.countDownTime = "Expired";
let body = { "roomId":roomId, } let body = { "roomId":roomId, }
@@ -93,12 +93,13 @@ export class TimeService {
if(this.room.t === 'p'){ if(this.room.t === 'p'){
this.chatService.deleteGroup(body).subscribe(res=>{ this.chatService.deleteGroup(body).subscribe(res=>{
this.wsChatMethodsService.deleteRoom(roomId)
}); });
} }
else{ else{
this.chatService.deleteChannel(body).subscribe(res=>{ this.chatService.deleteChannel(body).subscribe(res=>{
this.wsChatMethodsService.deleteRoom(roomId)
}); });
} }
}); });
@@ -79,9 +79,6 @@ export class ChatPopoverPage implements OnInit {
let res:any = await this.wsChatMethodsService.leaveRoom(this.roomId); let res:any = await this.wsChatMethodsService.leaveRoom(this.roomId);
this.wsChatMethodsService.deleteRoom(this.roomId) this.wsChatMethodsService.deleteRoom(this.roomId)
if(res.error){ if(res.error){
if(res.error.error = "error-you-are-last-owner"){ if(res.error.error = "error-you-are-last-owner"){
@@ -101,55 +98,7 @@ export class ChatPopoverPage implements OnInit {
} }
this.close('leave'); this.close('leave');
//this.wsChatMethodsService.subscribeToRoomUpdate(this.roomId, res.result);
/* this.chatService.getRoomInfo(this.roomId).subscribe(room=>{
this.room = room['room'];
if(this.room.t === 'p'){
this.chatService.leaveGroup(body).subscribe(res=>{
this.close('leave');
},
(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');
this.setRoomOwner();
}
else{
this.toastService._badRequest("Não foi possível sair do grupo");
this.close('cancel');
}
},
()=>{
//loader.remove()
});
}
else{
this.chatService.leaveChannel(body).subscribe(res=>{
this.close('leave');
},
(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()
});
}
}); */
} }
//Delete //Delete
@@ -160,12 +109,12 @@ export class ChatPopoverPage implements OnInit {
if(this.room.t === 'p'){ if(this.room.t === 'p'){
this.chatService.deleteGroup(body).subscribe(res=>{ this.chatService.deleteGroup(body).subscribe(res=>{
this.wsChatMethodsService.deleteRoom(this.roomId)
}); });
} }
else{ else{
this.chatService.deleteChannel(body).subscribe(res=>{ this.chatService.deleteChannel(body).subscribe(res=>{
this.wsChatMethodsService.deleteRoom(this.roomId)
}); });
} }
}); });