mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
remove rocket chat
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AlertController, AnimationController } from '@ionic/angular';
|
||||
import { ChatSystemService } from './chat/chat-system.service';
|
||||
// import { ChatSystemService } from './chat/chat-system.service';
|
||||
import { ToastService } from './toast.service';
|
||||
|
||||
@Injectable({
|
||||
@@ -12,7 +12,7 @@ export class AlertService {
|
||||
public alertController: AlertController,
|
||||
private animationController: AnimationController,
|
||||
private toastService: ToastService,
|
||||
public ChatSystemService: ChatSystemService,
|
||||
// public ChatSystemService: ChatSystemService,
|
||||
) { }
|
||||
|
||||
async presentAlert(message:string) {
|
||||
@@ -58,9 +58,9 @@ export class AlertService {
|
||||
handler: () => {
|
||||
//const loader = this.toastService.loading();
|
||||
|
||||
this.ChatSystemService.deleteMessage(msgId).then(() => {
|
||||
room.deleteMessage(msgId)
|
||||
}).catch((error) => console.error(error))
|
||||
// this.ChatSystemService.deleteMessage(msgId).then(() => {
|
||||
// room.deleteMessage(msgId)
|
||||
// }).catch((error) => console.error(error))
|
||||
//this.ChatSystemService.subscribeToRoomUpdate(room._id, room);
|
||||
//loader.remove();
|
||||
}
|
||||
|
||||
@@ -7,20 +7,19 @@ import { BehaviorSubject, of } from 'rxjs';
|
||||
import { AlertController, Platform } from '@ionic/angular';
|
||||
import { SessionStore } from '../store/session.service';
|
||||
import { AESEncrypt } from '../services/aesencrypt.service';
|
||||
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
|
||||
// import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { NfService } from 'src/app/services/chat/nf.service';
|
||||
import { MessageService } from 'src/app/services/chat/message.service';
|
||||
// import { NfService } from 'src/app/services/chat/nf.service';
|
||||
//import { MessageService } from 'src/app/services/chat/message.service';
|
||||
import { ProcessesService } from 'src/app/services/processes.service';
|
||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||
import { RoomService } from './chat/room.service';
|
||||
//import { RoomService } from './chat/room.service';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { InitialsService } from './functions/initials.service';
|
||||
import { PermissionService } from './permission.service';
|
||||
import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
|
||||
// import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
|
||||
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
||||
import { captureException } from '@sentry/angular';
|
||||
import { CPSession } from '../store/documentManagement';
|
||||
import { catchError, tap } from 'rxjs/operators';
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -40,15 +39,15 @@ export class AuthService {
|
||||
private storageService: StorageService,
|
||||
public alertController: AlertController,
|
||||
private aesencrypt: AESEncrypt,
|
||||
private RochetChatConnectorService: RochetChatConnectorService,
|
||||
// private RochetChatConnectorService: RochetChatConnectorService,
|
||||
private router: Router,
|
||||
private NfService: NfService,
|
||||
// private NfService: NfService,
|
||||
private processesService: ProcessesService,
|
||||
private AttachmentsService: AttachmentsService,
|
||||
private storage: Storage,
|
||||
private initialsService: InitialsService,
|
||||
public p: PermissionService,
|
||||
public ChatSystemService: ChatSystemService,
|
||||
// public ChatSystemService: ChatSystemService,
|
||||
private httpErroHandle: HttpErrorHandle,
|
||||
private errorHandler: ErrorHandler,
|
||||
private platform: Platform,) {
|
||||
@@ -183,110 +182,63 @@ export class AuthService {
|
||||
setTimeout(() => {
|
||||
|
||||
if (SessionStore.user.ChatData?.data) {
|
||||
this.RochetChatConnectorService.logout();
|
||||
this.RochetChatConnectorService.connect();
|
||||
this.RochetChatConnectorService.login().then((message: any) => {
|
||||
console.log('Chat login', message)
|
||||
// this.RochetChatConnectorService.logout();
|
||||
// this.RochetChatConnectorService.connect();
|
||||
// this.RochetChatConnectorService.login().then((message: any) => {
|
||||
// console.log('Chat login', message)
|
||||
|
||||
SessionStore.user.RochetChatUserId = message.result.id
|
||||
SessionStore.save()
|
||||
// SessionStore.user.RochetChatUserId = message.result.id
|
||||
// SessionStore.save()
|
||||
|
||||
this.ChatSystemService.loadChat()
|
||||
this.RochetChatConnectorService.setStatus('online')
|
||||
window['RochetChatConnectorService'] = this.RochetChatConnectorService
|
||||
setTimeout(() => {
|
||||
this.ChatSystemService.getAllRooms();
|
||||
this.RochetChatConnectorService.setStatus('online')
|
||||
}, 200);
|
||||
// this.ChatSystemService.loadChat()
|
||||
// this.RochetChatConnectorService.setStatus('online')
|
||||
// window['RochetChatConnectorService'] = this.RochetChatConnectorService
|
||||
// setTimeout(() => {
|
||||
// this.ChatSystemService.getAllRooms();
|
||||
// this.RochetChatConnectorService.setStatus('online')
|
||||
// }, 200);
|
||||
|
||||
|
||||
}).catch((error) => {
|
||||
console.error(SessionStore.user.ChatData, 'web socket login', error)
|
||||
// }).catch((error) => {
|
||||
// console.error(SessionStore.user.ChatData, 'web socket login', error)
|
||||
|
||||
if(window.location.pathname.includes('/home/')) {
|
||||
setTimeout(() => {
|
||||
this.loginToChatWs();
|
||||
}, 4000)
|
||||
}
|
||||
// if(window.location.pathname.includes('/home/')) {
|
||||
// setTimeout(() => {
|
||||
// this.loginToChatWs();
|
||||
// }, 4000)
|
||||
// }
|
||||
|
||||
})
|
||||
// })
|
||||
}
|
||||
|
||||
|
||||
|
||||
// before sending a message with a attachment
|
||||
this.NfService.beforeSendAttachment = async (message: MessageService, room?: RoomService) => {
|
||||
8
|
||||
// this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => {
|
||||
|
||||
if (message.hasFile) {
|
||||
if (message.file.type != 'application/webtrix') {
|
||||
const formData = message.temporaryData
|
||||
// //
|
||||
// let downloadFile = "";
|
||||
// if (message.file.type == "application/img") {
|
||||
// const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise();
|
||||
|
||||
try {
|
||||
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
|
||||
message.file.guid = guid.path
|
||||
// if (event.type === HttpEventType.DownloadProgress) {
|
||||
// //this.downloadProgess = Math.round((100 * event.loaded) / event.total);
|
||||
// return true
|
||||
// } else if (event.type === HttpEventType.Response) {
|
||||
// downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
||||
|
||||
message.downloadFileMsg()
|
||||
message.uploadingFile = false
|
||||
// message.file = {
|
||||
// guid: message.file.guid,
|
||||
// image_url: downloadFile,
|
||||
// type: message.file.type
|
||||
// }
|
||||
|
||||
return true
|
||||
} catch (e) {
|
||||
window['e'] = e
|
||||
console.error('BeforesendAtachment', e)
|
||||
message.uploadingFile = false
|
||||
this.httpErroHandle.httpStatusHandleUploadFile(e);
|
||||
return false
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
const res = message.temporaryData
|
||||
|
||||
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
|
||||
|
||||
let url_no_options: string = url.replace("webTRIX.Viewer", "webTRIX.Viewer.Branch1");
|
||||
message.attachments[0].title_link = url_no_options
|
||||
message.attachments[0].message_link = url_no_options
|
||||
|
||||
message.uploadingFile = false
|
||||
|
||||
return true
|
||||
} catch (e) {
|
||||
window['e'] = e
|
||||
console.error('BeforesendAtachment', e)
|
||||
message.uploadingFile = false
|
||||
this.httpErroHandle.httpStatusHandleUploadFile(e);
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => {
|
||||
|
||||
//
|
||||
let downloadFile = "";
|
||||
if (message.file.type == "application/img") {
|
||||
const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise();
|
||||
|
||||
if (event.type === HttpEventType.DownloadProgress) {
|
||||
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
|
||||
return true
|
||||
} else if (event.type === HttpEventType.Response) {
|
||||
downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
||||
|
||||
message.file = {
|
||||
guid: message.file.guid,
|
||||
image_url: downloadFile,
|
||||
type: message.file.type
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
};
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
// };
|
||||
|
||||
}, 1)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { PermissionService } from './permission.service';
|
||||
import { SessionStore } from '../store/session.service';
|
||||
import { ChangeProfileService } from 'src/app/services/change-profile.service';
|
||||
import { NetworkServiceService , ConnectionStatus} from 'src/app/services/network-service.service';
|
||||
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
|
||||
// import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -31,7 +31,8 @@ export class ChatService {
|
||||
public p: PermissionService,
|
||||
private changeProfileService: ChangeProfileService,
|
||||
private NetworkServiceService: NetworkServiceService,
|
||||
private RochetChatConnectorService: RochetChatConnectorService) {
|
||||
// private RochetChatConnectorService: RochetChatConnectorService
|
||||
) {
|
||||
|
||||
this.changeProfileService.registerCallback(() => {
|
||||
this.setheader();
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ChangeMessageQueueService } from './change-message-queue.service';
|
||||
|
||||
describe('ChangeMessageQueueService', () => {
|
||||
let service: ChangeMessageQueueService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ChangeMessageQueueService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ChangeMessageQueueService {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ChatMethodsService } from './chat-methods.service';
|
||||
|
||||
describe('ChatMethodsService', () => {
|
||||
let service: ChatMethodsService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ChatMethodsService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,55 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ChatService } from '../chat.service';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ChatMethodsService {
|
||||
|
||||
constructor(
|
||||
private chatService: ChatService) {
|
||||
}
|
||||
|
||||
sendMessage(roomId:string, data:any) {
|
||||
|
||||
let body = {
|
||||
"message":
|
||||
{
|
||||
"rid": roomId,
|
||||
"msg":"",
|
||||
"file": {
|
||||
"type": "application/meeting",
|
||||
"subject": data.subject,
|
||||
"start_date": data.start,
|
||||
"end_date": data.end,
|
||||
"venue": data.venue,
|
||||
"id": data.id,
|
||||
"calendarId": data.calendarId
|
||||
}
|
||||
}
|
||||
}
|
||||
this.chatService.sendMessage(body).subscribe(res=> {});
|
||||
}
|
||||
|
||||
send({roomId, msg, attachments = null, file = null, localReference = null}) {
|
||||
|
||||
let body = {
|
||||
"message":
|
||||
{
|
||||
rid: roomId,
|
||||
localReference: localReference,
|
||||
msg: msg,
|
||||
attachments,
|
||||
file
|
||||
}
|
||||
}
|
||||
|
||||
return this.chatService.sendMessage(body)
|
||||
}
|
||||
|
||||
deleteMessage(body) {
|
||||
return this.chatService.deleteMessage(body)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ChatSystemService } from './chat-system.service';
|
||||
|
||||
describe('ChatSystemService', () => {
|
||||
let service: ChatSystemService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ChatSystemService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,813 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RoomService } from './room.service';
|
||||
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
|
||||
import { MessageService } from 'src/app/services/chat/message.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { capitalizeTxt } from 'src/plugin/text';
|
||||
import { Update as room } from 'src/app/models/chatMethod';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { ModalController, NavController, Platform } from '@ionic/angular';
|
||||
import { SqliteService } from 'src/app/services/sqlite.service';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
import { NativeNotificationService } from 'src/app/services/native-notification.service';
|
||||
import { SortService } from '../functions/sort.service';
|
||||
import { chatUser } from 'src/app/models/chatMethod';
|
||||
import { NfService } from 'src/app/services/chat/nf.service'
|
||||
import { ChangeProfileService } from '../change-profile.service';
|
||||
import { ChatMethodsService } from './chat-methods.service';
|
||||
import { AESEncrypt } from '../aesencrypt.service'
|
||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||
import { NetworkServiceService } from 'src/app/services/network-service.service';
|
||||
import { ViewedMessageService } from './viewed-message.service'
|
||||
import { NotificationsService } from '../notifications.service';
|
||||
import { Subscribe } from '../subcribe';
|
||||
import { Plugins } from '@capacitor/core';
|
||||
|
||||
const { App } = Plugins;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ChatSystemService {
|
||||
|
||||
dm: { [key: string]: RoomService } = {}
|
||||
group: { [key: string]: RoomService } = {}
|
||||
|
||||
_dm: RoomService[] = []
|
||||
_group: RoomService[] = []
|
||||
|
||||
loadingWholeList = false;
|
||||
|
||||
dmCount = 0;
|
||||
groupCount = 0;
|
||||
|
||||
currentRoom: RoomService = null
|
||||
users: chatUser[] = []
|
||||
sessionStore = SessionStore
|
||||
delete = []
|
||||
loadingUsers = false
|
||||
|
||||
onRoomsLoad = new Subscribe({ execute: false, deleteOnExecute: true })
|
||||
private mainChangeDetector: Function = () => {}
|
||||
|
||||
|
||||
constructor(
|
||||
private RochetChatConnectorService: RochetChatConnectorService,
|
||||
private storage: Storage,
|
||||
private platform: Platform,
|
||||
private sqlservice: SqliteService,
|
||||
private NativeNotificationService: NativeNotificationService,
|
||||
private sortService: SortService,
|
||||
private ChatService: ChatService,
|
||||
private NfService: NfService,
|
||||
private changeProfileService: ChangeProfileService,
|
||||
private chatService: ChatService,
|
||||
private ChatMethodsService: ChatMethodsService,
|
||||
private AESEncrypt: AESEncrypt,
|
||||
private AttachmentsService: AttachmentsService,
|
||||
private NetworkServiceService: NetworkServiceService,
|
||||
private ViewedMessageService: ViewedMessageService,
|
||||
private notificationService: NotificationsService,
|
||||
private modalController: ModalController,
|
||||
private navController: NavController
|
||||
) {
|
||||
|
||||
|
||||
// this.RochetChatConnectorService.registerCallback({
|
||||
// type: 'reConnect',
|
||||
// funx: async () => {
|
||||
// /**
|
||||
// * @description when the phone is in the background for a long time it could disconnects from the socket then the socket reconnects automatically,
|
||||
// * when the connection is lost the subscribe is also lost, so we have to subscribe again when reconnection is establish.
|
||||
// */
|
||||
|
||||
// this.RochetChatConnectorService.setStatus('online')
|
||||
// this.getUserStatus();
|
||||
// await this.chatService.refreshtoken();
|
||||
// this.getUser();
|
||||
// this.getAllRooms();
|
||||
// this.subscribeToRoom();
|
||||
// //
|
||||
|
||||
|
||||
// if (this.currentRoom) {
|
||||
// this.currentRoom.loadHistory({ forceUpdate: true })
|
||||
// }
|
||||
|
||||
// for (const id in this.dm) {
|
||||
// this.dm[id].hasLoadHistory = false
|
||||
// }
|
||||
|
||||
// for (const id in this.group) {
|
||||
// this.group[id].hasLoadHistory = false
|
||||
// }
|
||||
|
||||
// }
|
||||
// })
|
||||
|
||||
// if (this.sessionStore.user.Inactivity) {
|
||||
// this.loadChat();
|
||||
// }
|
||||
|
||||
|
||||
// if (SessionStore.user?.ChatData?.data) {
|
||||
// this.restoreRooms();
|
||||
// }
|
||||
|
||||
// document.addEventListener('resume', () => {
|
||||
// this.RochetChatConnectorService.setStatus('online')
|
||||
// if (this._dm?.length == 0 && this._group?.length == 0) {
|
||||
// if (SessionStore.user?.ChatData?.data) {
|
||||
// this.getAllRooms();
|
||||
// }
|
||||
|
||||
// }
|
||||
// });
|
||||
|
||||
// try {
|
||||
// if (!this.platform.is('desktop')) {
|
||||
// App.addListener('appStateChange', ({ isActive }) => {
|
||||
// if (isActive) {
|
||||
// // The app is in the foreground.
|
||||
// console.log('App is in the foreground');
|
||||
|
||||
// if (SessionStore.user?.ChatData?.data) {
|
||||
// this.currentRoom?.loadHistory({ forceUpdate: true })
|
||||
// }
|
||||
|
||||
// setTimeout(() => {
|
||||
// if (SessionStore.user?.ChatData?.data) {
|
||||
// this.subscribeToRoom()
|
||||
// this.RochetChatConnectorService.setStatus('online')
|
||||
// }
|
||||
// }, 1000);
|
||||
|
||||
// /* this.reloadComponent(true) */
|
||||
// } else {
|
||||
// // The app is in the background.
|
||||
// console.log('App is in the background');
|
||||
// // You can perform actions specific to the background state here.
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// } catch(error) {}
|
||||
}
|
||||
|
||||
loadChat() {
|
||||
// if (SessionStore.user?.ChatData?.data) {
|
||||
// this.ReLoadChat()
|
||||
// }
|
||||
}
|
||||
|
||||
private async ReLoadChat() {
|
||||
|
||||
// if (SessionStore.user?.ChatData?.data) {
|
||||
// this.getUserStatus();
|
||||
// await this.chatService.refreshtoken();
|
||||
|
||||
// this.restoreUsers();
|
||||
// await this.getUser();
|
||||
// await this.restoreRooms();
|
||||
// await this.getAllRooms();
|
||||
// this.subscribeToRoom();
|
||||
// }
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
clearChat() {
|
||||
// this.dm = {}
|
||||
// this.group = {}
|
||||
// this._dm = []
|
||||
// this._group = []
|
||||
|
||||
// this.loadingWholeList = false;
|
||||
|
||||
// this.dmCount = 0;
|
||||
// this.groupCount = 0;
|
||||
|
||||
// this.currentRoom = null
|
||||
// this.users = []
|
||||
// this.storage.remove('Users');
|
||||
}
|
||||
|
||||
openRoom(roomId) {
|
||||
|
||||
if (this.currentRoom) {
|
||||
this.currentRoom.roomLeave()
|
||||
}
|
||||
|
||||
if (this.getDmRoom(roomId)) {
|
||||
this.currentRoom = this.getDmRoom(roomId)
|
||||
} else if (this.getGroupRoom(roomId)) {
|
||||
this.currentRoom = this.getGroupRoom(roomId)
|
||||
}
|
||||
|
||||
this.currentRoom.open()
|
||||
|
||||
}
|
||||
|
||||
getRoomById(roomId) {
|
||||
if (this.getDmRoom(roomId)) {
|
||||
return this.getDmRoom(roomId)
|
||||
} else if (this.getGroupRoom(roomId)) {
|
||||
return this.getGroupRoom(roomId)
|
||||
}
|
||||
}
|
||||
|
||||
async restoreRooms() {
|
||||
|
||||
// try {
|
||||
// const _rooms = await this.storage.get('Rooms');
|
||||
|
||||
// if (_rooms) {
|
||||
// for (let roomData of this.sortArrayISODate(_rooms)) {
|
||||
// await this.prepareRoom(roomData);
|
||||
// }
|
||||
// }
|
||||
// } catch (e) { }
|
||||
|
||||
}
|
||||
|
||||
async restoreUsers() {
|
||||
const users = await this.storage.get('Users');
|
||||
|
||||
if (users) {
|
||||
this.users = users
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sortArrayISODate(messages: any): any[] {
|
||||
|
||||
return messages.sort((a, b) =>
|
||||
new Date(b._updatedAt).getTime()
|
||||
-
|
||||
new Date(a._updatedAt).getTime())
|
||||
}
|
||||
|
||||
async getAllRooms(callback: Function = () => { }, roomIdCallback = "") {
|
||||
this.loadingWholeList = true
|
||||
var rooms;
|
||||
|
||||
if (this.RochetChatConnectorService.isLogin) {
|
||||
try {
|
||||
rooms = await this.RochetChatConnectorService.getRooms();
|
||||
} catch (error) {
|
||||
this.loadingWholeList = false
|
||||
console.error('chatgetrooms', error)
|
||||
}
|
||||
try {
|
||||
await this.storage.remove('Rooms');
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
let index = 0
|
||||
|
||||
let _rooms = rooms?.result?.update
|
||||
|
||||
if (_rooms) {
|
||||
|
||||
_rooms = _rooms.map(e => {
|
||||
e["_updatedAt"] = e._updatedAt || e._updatedAt['$date']
|
||||
return e
|
||||
})
|
||||
|
||||
for (let roomData of this.sortArrayISODate(_rooms)) {
|
||||
|
||||
const roomId = this.getRoomId(roomData);
|
||||
|
||||
if (roomData.t == 'd') {
|
||||
await this.prepareRoom(roomData);
|
||||
} else {
|
||||
if (roomData.t === 'p') {
|
||||
await this.prepareRoom(roomData);
|
||||
}
|
||||
else {
|
||||
await this.prepareRoom(roomData);
|
||||
}
|
||||
}
|
||||
|
||||
if (roomId == roomIdCallback) {
|
||||
callback()
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
this.loadingWholeList = false
|
||||
this.sortRoomList()
|
||||
await this.storage.set('Rooms', _rooms);
|
||||
|
||||
this.onRoomsLoad.executor()
|
||||
}
|
||||
|
||||
|
||||
async getRoom(_rooms: any) {
|
||||
this.loadingWholeList = true
|
||||
|
||||
let index = 0
|
||||
|
||||
if (_rooms) {
|
||||
|
||||
_rooms = _rooms.map(e => {
|
||||
e["_updatedAt"] = e._updatedAt || e._updatedAt['$date']
|
||||
return e
|
||||
})
|
||||
|
||||
for (let roomData of this.sortArrayISODate(_rooms)) {
|
||||
|
||||
if (roomData.t == 'd') {
|
||||
|
||||
await this.prepareRoom(roomData);
|
||||
} else {
|
||||
if (roomData.t === 'p') {
|
||||
|
||||
await this.prepareRoom(roomData);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
await this.prepareRoom(roomData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
this.loadingWholeList = false
|
||||
this.sortRoomList()
|
||||
|
||||
this.onRoomsLoad.executor()
|
||||
}
|
||||
|
||||
/**
|
||||
* @description sort room list by last message date
|
||||
*/
|
||||
sortRoomList = () => {
|
||||
|
||||
this._dm = this.sortService.sortDate(this._dm, '_updatedAt').reverse()
|
||||
this._group = this.sortService.sortDate(this._group, '_updatedAt').reverse()
|
||||
}
|
||||
|
||||
/**
|
||||
* @description subscribe all room
|
||||
*/
|
||||
subscribeToRoom() {
|
||||
|
||||
// if (SessionStore.user?.ChatData?.data) {
|
||||
|
||||
// for (const id in this.dm) {
|
||||
// this.defaultSubtribe(id)
|
||||
// }
|
||||
|
||||
// for (const id in this.group) {
|
||||
// this.defaultSubtribe(id)
|
||||
// }
|
||||
|
||||
// this.RochetChatConnectorService.streamNotifyLogged().then((subscription => { }))
|
||||
|
||||
// this.RochetChatConnectorService.subStreamMessageUser().then((subscription => {
|
||||
// console.log({subscription})
|
||||
// }))
|
||||
// } else {
|
||||
|
||||
// setTimeout(() => {
|
||||
// throw ('No chat data');
|
||||
// }, 1000)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @description when a new room is create, needs to subtribe in order to receive updates
|
||||
* @param id
|
||||
* @param roomData
|
||||
*/
|
||||
subscribeToRoomUpdate(id, roomData) {
|
||||
|
||||
// this.defaultSubtribe(id);
|
||||
|
||||
// this.prepareRoom(roomData);
|
||||
|
||||
// this.getGroupRoom(id).loadHistory({});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated things a room need to subscribe on
|
||||
* @param id room id
|
||||
*/
|
||||
private defaultSubtribe(id: any) {
|
||||
|
||||
// const room = this.getRoomById(id);
|
||||
|
||||
// if (!room.subscribeAttempt) {
|
||||
|
||||
// try {
|
||||
|
||||
// room.subscribeAttempt = true;
|
||||
// } catch (error) {
|
||||
// console.log("error")
|
||||
// }
|
||||
|
||||
|
||||
// this.RochetChatConnectorService.streamRoomMessages(id).then((subscription) => {
|
||||
// room.status.receive.message = true;
|
||||
// })
|
||||
|
||||
// this.RochetChatConnectorService.subStreamNotifyRoom(id, 'typing', false).then((subscription) => {
|
||||
// room.status.receive.typing = true;
|
||||
// //
|
||||
// })
|
||||
|
||||
// this.RochetChatConnectorService.subStreamNotifyRoom(id, 'readMessage', false).then((subscription) => {
|
||||
// room.status.receive.readMessage = true;
|
||||
// })
|
||||
|
||||
// this.RochetChatConnectorService.streamNotifyRoomDeleteMessage(id).then((subscription) => {
|
||||
// room.status.receive.deleteMessage = true;
|
||||
// })
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private fix_updatedAt(message) {
|
||||
if (message.result) {
|
||||
message.result._updatedAt = message.result._updatedAt['$date']
|
||||
} else if (message._updatedAt) {
|
||||
if (message._updatedAt.hasOwnProperty('$date')) {
|
||||
message._updatedAt = message._updatedAt['$date']
|
||||
}
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create a representation of an room in these instance this.dm, this.group ...
|
||||
* @param roomData
|
||||
*/
|
||||
prepareRoom(roomData) {
|
||||
|
||||
|
||||
/**
|
||||
* @description data used to define or create room
|
||||
*/
|
||||
|
||||
|
||||
roomData = this.fix_updatedAt(roomData)
|
||||
const setData = {
|
||||
customFields: roomData.customFields,
|
||||
id: this.getRoomId(roomData),
|
||||
name: this.getRoomName(roomData),
|
||||
t: roomData.t,
|
||||
lastMessage: this.getRoomLastMessage(roomData),
|
||||
_updatedAt: new Date(roomData._updatedAt || roomData._updatedAt['$date']),
|
||||
u: roomData.u || {},
|
||||
members: [],
|
||||
membersExcludeMe: []
|
||||
}
|
||||
|
||||
let roomId = this.getRoomId(roomData);
|
||||
|
||||
let chat = false
|
||||
if (roomData?.usernames) {
|
||||
if (roomData?.usernames?.includes("chat.admin")) {
|
||||
chat = true
|
||||
}
|
||||
}
|
||||
|
||||
if (setData.name != 'Rocket Cat' && setData.name != 'general' && chat == false) {
|
||||
// create room
|
||||
if (!this.roomExist(roomId)) {
|
||||
let room: RoomService = new RoomService(this.RochetChatConnectorService, new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this, this.notificationService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this, this.ViewedMessageService, this.notificationService,this.modalController,this.navController)
|
||||
room.setData(setData)
|
||||
room.receiveMessage()
|
||||
room.getAllUsers = this.getUsers
|
||||
room.receiveMessageDelete();
|
||||
room.sortRoomList = this.sortRoomList
|
||||
room.chatServiceDeleteRoom = this.deleteRoom
|
||||
room.isGroup = !this.isIndividual(roomData)
|
||||
room.info()
|
||||
|
||||
|
||||
// create individual room
|
||||
if (this.isIndividual(roomData)) {
|
||||
|
||||
this.dm[roomId] = room
|
||||
this._dm.push(room)
|
||||
this.dmCount++
|
||||
|
||||
} else {
|
||||
// create group room
|
||||
|
||||
this.group[roomId] = room
|
||||
this._group.push(room)
|
||||
this.groupCount++
|
||||
|
||||
}
|
||||
|
||||
this.defaultSubtribe(roomId)
|
||||
} else {
|
||||
// in this case room is already present, therefor it will only be necessary,
|
||||
// to redefine
|
||||
|
||||
if (this.dm[roomId]) {
|
||||
this.dm[roomId].setData(setData)
|
||||
} else if (this.group[roomId]) {
|
||||
this.group[roomId].setData(setData)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
deleteRoom = (roomId) => {
|
||||
|
||||
this.delete.push(roomId)
|
||||
delete this.group[roomId];
|
||||
this._group = this._group.filter((e) => e.id != roomId);
|
||||
}
|
||||
|
||||
deleteRecently(roomId) {
|
||||
return this.delete.includes(roomId)
|
||||
}
|
||||
|
||||
roomExist(roomId) {
|
||||
return this.dm[roomId]?.id || this.group[roomId]?.id
|
||||
}
|
||||
|
||||
getReceptorName(roomData) {
|
||||
try {
|
||||
return roomData.usernames.find((e) => e != SessionStore.user.UserName)
|
||||
} catch (e) {
|
||||
return '*'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update user status. this method is called once only
|
||||
* @param id user ID
|
||||
*/
|
||||
private getUserStatus(id?: string) {
|
||||
|
||||
this.RochetChatConnectorService.getUserStatus(async (d) => {
|
||||
|
||||
const userId = d.fields.args[0][0]
|
||||
const username = d.fields.args[0][1]
|
||||
let statusNum = d.fields.args[0][2]
|
||||
|
||||
const statusText = this.statusNumberToText(statusNum)
|
||||
|
||||
for (const user in this.users) {
|
||||
if (this.users[user]._id == userId) {
|
||||
this.users[user].status = statusText
|
||||
}
|
||||
}
|
||||
|
||||
this.getUser()
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
getUserByName(username) {
|
||||
return this.users.find((user) => user.username == username)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description convert rocketchat statues num to readable string
|
||||
* @param text
|
||||
* @returns
|
||||
*/
|
||||
statusNumberToText(text) {
|
||||
if (text == '0') {
|
||||
return "offline"
|
||||
}
|
||||
else if (text == '1') {
|
||||
return "online"
|
||||
}
|
||||
else if (text == '2') {
|
||||
return "away"
|
||||
}
|
||||
else if (text == '3') {
|
||||
return "busy"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
deleteMessage(id?) {
|
||||
return this.RochetChatConnectorService.deleteMessage(id);
|
||||
}
|
||||
|
||||
leaveRoom(id?) {
|
||||
return this.RochetChatConnectorService.leaveRoom(id);
|
||||
}
|
||||
|
||||
async hideRoom(id) {
|
||||
this._dm.forEach((md, index) => {
|
||||
if (md.id == id) {
|
||||
this._dm.splice(index, 1)
|
||||
delete this.dm[id]
|
||||
}
|
||||
});
|
||||
|
||||
this._group.forEach((group, index) => {
|
||||
if (group.id == id) {
|
||||
this._group.splice(index, 1)
|
||||
delete this.group[id]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
hidingRoom(id?) {
|
||||
|
||||
return this.RochetChatConnectorService.hidingRoom(id).then(() => {
|
||||
// this.hideRoom(id)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
addRoomOwner(roomid, userId) {
|
||||
return this.RochetChatConnectorService.addRoomOwner(roomid, userId);
|
||||
}
|
||||
|
||||
createPrivateRoom(groupName, username, customFields) {
|
||||
return this.RochetChatConnectorService.createPrivateRoom(groupName, username, customFields);
|
||||
}
|
||||
|
||||
getDmRoom(id): RoomService {
|
||||
try {
|
||||
return this.dm[id]
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
getGroupRoom(id): RoomService {
|
||||
try {
|
||||
return this.group[id]
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
getRoomName(roomData: room): string {
|
||||
if (this.isIndividual(roomData)) {
|
||||
const names: String[] = roomData.usernames
|
||||
|
||||
|
||||
if (roomData.t == 'd') {
|
||||
|
||||
const username = roomData.usernames.find(e => e != SessionStore.user.UserName)
|
||||
|
||||
try {
|
||||
const firstName = capitalizeTxt(username.split('.')[0])
|
||||
const lastName = capitalizeTxt(username.split('.')[1])
|
||||
|
||||
return firstName + ' ' + lastName
|
||||
} catch (error) {
|
||||
const username = roomData.usernames.find(e => e != SessionStore.user.UserName)
|
||||
|
||||
const firstName = capitalizeTxt(username.split('.')[0])
|
||||
return firstName
|
||||
}
|
||||
|
||||
} else {
|
||||
if (roomData.t === 'p') {
|
||||
return 'Loading'
|
||||
}
|
||||
else {
|
||||
return 'Loading'
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return roomData.fname
|
||||
}
|
||||
}
|
||||
|
||||
getRoomId(roomData: room) {
|
||||
return roomData._id
|
||||
}
|
||||
|
||||
getRoomLastMessage(roomData: room): any {
|
||||
return roomData.lastMessage
|
||||
}
|
||||
|
||||
private isIndividual(roomData: room) {
|
||||
return !roomData.fname
|
||||
}
|
||||
|
||||
getUsers = () => {
|
||||
return this.users
|
||||
}
|
||||
|
||||
async getUser() {
|
||||
|
||||
this.loadingUsers = true
|
||||
let _res
|
||||
|
||||
try {
|
||||
_res = await this.ChatService.getAllUsers().toPromise();
|
||||
} catch (error) {
|
||||
await this.chatService.refreshtoken();
|
||||
_res = await this.ChatService.getAllUsers().toPromise();
|
||||
}
|
||||
|
||||
let users: chatUser[] = _res['users'].filter(data => data.username != SessionStore.user.UserName);
|
||||
|
||||
users = users.filter((data) => !(data.name == 'Rocket.Cat' || data.name == 'Administrator'))
|
||||
|
||||
const userIds = this.users.map((user) => user._id)
|
||||
|
||||
for (let UserUpdate of users) {
|
||||
if (userIds.includes(UserUpdate._id)) {
|
||||
for (var index = 0; index < this.users.length; index++) {
|
||||
if (UserUpdate._id == this.users[index]._id) {
|
||||
this.users[index] = UserUpdate
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.users.push(UserUpdate)
|
||||
}
|
||||
}
|
||||
|
||||
this.users = this.users.sort((a, b) => {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
await this.storage.set('Users', this.users);
|
||||
|
||||
this.loadingUsers = false
|
||||
|
||||
}
|
||||
|
||||
getUserOfRoom(roomId) {
|
||||
return this.RochetChatConnectorService.getUserOfRoom(roomId);
|
||||
}
|
||||
|
||||
|
||||
async createGroup(name) {
|
||||
const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, {});
|
||||
if (res?.result?.rid) {
|
||||
try {
|
||||
await this.getAllRooms();
|
||||
} catch (e) { }
|
||||
return res
|
||||
} else {
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async createGroup__(name, customFields = {}) {
|
||||
const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, customFields);
|
||||
console.log('room is created', res)
|
||||
if (res?.result?.rid) {
|
||||
try {
|
||||
await this.getAllRooms();
|
||||
return res
|
||||
} catch (e) { }
|
||||
console.log('room is loaded')
|
||||
return res
|
||||
} else {
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
getGroupByName(name) {
|
||||
return this._group.find(e => e.name == name)
|
||||
}
|
||||
|
||||
async waitRoomToCreate(rid): Promise<RoomService> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let sub;
|
||||
|
||||
sub = this.onRoomsLoad.subscribe(() => {
|
||||
const room = this.getRoomById(rid)
|
||||
if (room) {
|
||||
resolve(room)
|
||||
sub.unSubscribe()
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
await this.getAllRooms();
|
||||
} catch (e) { }
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
searchContact(name, username) {
|
||||
return this.users.find(e => e.name == name || e.username == username)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { MessageService } from './message.service';
|
||||
|
||||
describe('MessageService', () => {
|
||||
let service: MessageService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(MessageService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NfService } from './nf.service';
|
||||
|
||||
describe('NfService', () => {
|
||||
let service: NfService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(NfService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageService } from './message.service';
|
||||
import { RoomService } from './room.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NfService {
|
||||
|
||||
beforeSendAttachment = async (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)));
|
||||
downloadFileMsg = async (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)));
|
||||
|
||||
fix_updatedAt(message) {
|
||||
if (message?.result) {
|
||||
message.result._updatedAt = message.result._updatedAt['$date']
|
||||
} else if(message?._updatedAt) {
|
||||
if(message._updatedAt.hasOwnProperty('$date')) {
|
||||
message._updatedAt = message._updatedAt['$date']
|
||||
}
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RochetChatConnectorService } from './rochet-chat-connector.service';
|
||||
|
||||
describe('RochetChatConnectorService', () => {
|
||||
let service: RochetChatConnectorService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RochetChatConnectorService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,961 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { wsCallbacksParams, msgQueue, send } from 'src/app/models/rochet-chat-cliente-service'
|
||||
import { deepFind } from 'src/plugin/deep'
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { chatHistory, Rooms } from 'src/app/models/chatMethod';
|
||||
import { BackgroundService } from '../background.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RochetChatConnectorService {
|
||||
|
||||
isLogin = false;
|
||||
loginResponse = {}
|
||||
|
||||
constructor(private backgroundservice: BackgroundService,) {
|
||||
}
|
||||
|
||||
reConnect() {
|
||||
|
||||
}
|
||||
|
||||
connect() {
|
||||
// dont connect if is already connected
|
||||
if (this.ws.connected == true) {
|
||||
return false
|
||||
}
|
||||
|
||||
this.ws.connect();
|
||||
|
||||
const message = {
|
||||
msg: "connect",
|
||||
version: "1",
|
||||
support: ["1"]
|
||||
}
|
||||
this.ws.send({ message, loginRequired: false, requestId: 'connectMessage' })
|
||||
this.ws.send({ message: { msg: "pong" }, loginRequired: false, requestId: 'connectPong' })
|
||||
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage',
|
||||
key: 'ping-pong',
|
||||
funx: (message: any) => {
|
||||
if (message.msg == "ping") {
|
||||
this.ws.send({ message: { msg: "pong" }, loginRequired: false })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
wsSend({ message, requestId = uuidv4(), loginRequired = true }: send) {
|
||||
// this.ws.send({ message: { msg: "pong" }, loginRequired: false })
|
||||
}
|
||||
|
||||
login() {
|
||||
// dont login if is already login
|
||||
if (this.isLogin == true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(this.loginResponse)
|
||||
})
|
||||
}
|
||||
|
||||
const requestId = uuidv4()
|
||||
//
|
||||
const message = {
|
||||
msg: "method",
|
||||
method: "login",
|
||||
id: requestId,
|
||||
params: [
|
||||
{
|
||||
user: { email: SessionStore.user.Email },
|
||||
password: SessionStore.user.Password
|
||||
}
|
||||
]
|
||||
}
|
||||
this.ws.send({ message, requestId: 'login', loginRequired: false })
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
//
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
//
|
||||
if (message.id == requestId) { // same request send
|
||||
//
|
||||
//
|
||||
if (message.result) {
|
||||
if (message.result.token) {
|
||||
this.isLogin = true
|
||||
this.loginResponse = message
|
||||
|
||||
setTimeout(() => {
|
||||
this.ws.wsMsgQueue()
|
||||
}, 10)
|
||||
|
||||
resolve(message)
|
||||
//
|
||||
}
|
||||
} else {
|
||||
this.isLogin = false
|
||||
//
|
||||
reject(message)
|
||||
}
|
||||
|
||||
reject(message)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
getRooms(roomOlder = 1480377601) {
|
||||
|
||||
|
||||
//const requestId = uuidv4()
|
||||
const requestId = uuidv4()
|
||||
const message = {
|
||||
"msg": "method",
|
||||
"method": "rooms/get",
|
||||
"id": requestId,
|
||||
"params": [{ "$date": 1480377601 }]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
return new Promise<Rooms>((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
readMessage(roomId) {
|
||||
|
||||
//const requestId = uuidv4()
|
||||
const requestId = uuidv4()
|
||||
|
||||
const message = {
|
||||
"msg": "method",
|
||||
"method": "readMessages",
|
||||
"params": [roomId, []],
|
||||
"id": requestId
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
return new Promise<Rooms>((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
getUserOfRoom(roomId) {
|
||||
|
||||
//const requestId = uuidv4()
|
||||
const requestId = uuidv4()
|
||||
|
||||
const message = {
|
||||
"msg": "method",
|
||||
"method": "getUsersOfRoom",
|
||||
"id": requestId,
|
||||
"params": [
|
||||
roomId,
|
||||
false,
|
||||
{
|
||||
"limit": 100,
|
||||
"skip": 0
|
||||
}]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
return new Promise<Rooms>((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.isLogin = false
|
||||
this.ws.connected = false
|
||||
this.ws.disconnect()
|
||||
}
|
||||
|
||||
// send message to room
|
||||
send({ roomId, msg, attachments = null, file = null, localReference = null }) {
|
||||
|
||||
//const requestId = uuidv4()
|
||||
const requestId = uuidv4()
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "sendMessage",
|
||||
id: requestId,
|
||||
params: [{
|
||||
rid: roomId,
|
||||
localReference: localReference,
|
||||
msg: msg,
|
||||
attachments,
|
||||
file
|
||||
}]
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve({ message, requestId })
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
updateMessage(messageObject) {
|
||||
|
||||
//const requestId = uuidv4()
|
||||
const requestId = uuidv4()
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "updateMessage",
|
||||
id: requestId,
|
||||
params: [messageObject]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve({ message, requestId })
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
leaveRoom(roomId) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "leaveRoom",
|
||||
id: requestId,
|
||||
params: [
|
||||
roomId,
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
addRoomOwner(roomId, userId) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "addRoomOwner",
|
||||
id: requestId,
|
||||
params: [
|
||||
roomId,
|
||||
userId
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
hidingRoom(roomId) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "hideRoom",
|
||||
id: requestId,
|
||||
params: [roomId]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
//
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
joinRoom() { }
|
||||
|
||||
deleteMessage(msgId) {
|
||||
//const requestId = uuidv4();
|
||||
const requestId = uuidv4()
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "deleteMessage",
|
||||
id: requestId,
|
||||
params: [{ "_id": msgId }]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) {
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
createPrivateRoom(groupName, username, customFields) {
|
||||
const requestId = uuidv4()
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "createPrivateGroup",
|
||||
id: requestId,
|
||||
params: [
|
||||
groupName,
|
||||
[username],
|
||||
false,
|
||||
customFields,
|
||||
{
|
||||
"broadcast": false,
|
||||
"encrypted": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
sendStreamNotifyRoom(roomId: string, username, event: 'typing', param: any) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
let message = {
|
||||
msg: "method",
|
||||
method: "stream-notify-room",
|
||||
id: requestId,
|
||||
params: [
|
||||
`${roomId}/${event}`,
|
||||
username,
|
||||
param
|
||||
]
|
||||
};
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
subStreamNotifyRoom(roomId: string, event: 'typing' | 'deleteMessage' | 'readMessage', param: any) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
let message = {
|
||||
msg: "sub",
|
||||
id: requestId,
|
||||
name: "stream-notify-room",
|
||||
params: [
|
||||
`${roomId}/${event}`,
|
||||
param
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
|
||||
if (message.id == requestId || message?.subs?.[0] == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
subStreamNotifyUser(param?: any) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
let message = {
|
||||
msg: "sub",
|
||||
id: requestId,
|
||||
name: "stream-notify-user",
|
||||
params: [
|
||||
`${SessionStore.user.ChatData.data.userId}/notification`,
|
||||
param
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
subStreamMessageUser(param?: any) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
try {
|
||||
let message = {
|
||||
msg: "sub",
|
||||
id: requestId,
|
||||
name: "stream-notify-user",
|
||||
params: [
|
||||
`${SessionStore.user.ChatData.data.userId}/message`,
|
||||
param
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
throw (SessionStore)
|
||||
}
|
||||
}
|
||||
|
||||
receiveStreamNotifyRoom(funx: Function) {
|
||||
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage',
|
||||
funx: (message) => {
|
||||
if (message.collection == "stream-notify-room" && message.msg == 'changed') {
|
||||
funx(message)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
getUserStatus(funx: Function) {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage',
|
||||
funx: (message) => {
|
||||
if (message.msg == 'changed' && message.collection == "stream-notify-logged") {
|
||||
funx(message)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
loadHistory(roomId, limit: number = 50) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
const message = {
|
||||
msg: "method",
|
||||
method: "loadHistory",
|
||||
id: requestId,
|
||||
params: [
|
||||
roomId,
|
||||
null,
|
||||
limit,
|
||||
{
|
||||
"$date": 1480377601
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId: 'loadHistory' })
|
||||
|
||||
return new Promise<chatHistory>((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
//
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
loadHistoryUnread(roomId, limit: number = 50) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
const message = {
|
||||
msg: "method",
|
||||
method: "loadHistory",
|
||||
id: requestId,
|
||||
params: [
|
||||
roomId,
|
||||
null,
|
||||
limit,
|
||||
{
|
||||
"$date": 1480377601
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId: 'loadHistory' })
|
||||
|
||||
return new Promise<chatHistory>((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
//
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
setStatus(status: 'online' | 'busy' | 'away' | 'offline') {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
const message = {
|
||||
|
||||
msg: "method",
|
||||
method: `UserPresence:setDefaultStatus`,
|
||||
id: requestId,
|
||||
params: [status]
|
||||
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
}
|
||||
|
||||
subscribeNotifyRoom(roomId: string) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
var message = {
|
||||
"msg": "sub",
|
||||
"id": requestId,
|
||||
"name": "stream-notify-room",
|
||||
"params": [
|
||||
`${roomId}/event`,
|
||||
false
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.msg == 'ready' || deepFind(message, 'subs.0') == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
updateRoomEventss(roomId, collection: string, funx: Function,) {
|
||||
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage',
|
||||
funx: (message) => {
|
||||
//
|
||||
|
||||
if (message.msg == 'changed' && message.collection == collection) {
|
||||
if (message.fields.args[0].rid == roomId) {
|
||||
funx(message)
|
||||
}
|
||||
else if (message.fields.eventName == `${roomId}/deleteMessage`) {
|
||||
funx(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
streamRoomMessages(roomId: string) {
|
||||
|
||||
const requestId = "streamRoomMessages" + uuidv4()
|
||||
|
||||
const message = {
|
||||
"msg": "sub",
|
||||
"id": requestId,
|
||||
"name": "stream-room-messages",
|
||||
"params": [
|
||||
`${roomId}`,
|
||||
false
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
|
||||
|
||||
if (message.id == requestId || message?.subs?.[0] == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
streamNotifyLogged() {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
const message = {
|
||||
"msg": "sub",
|
||||
"id": requestId,
|
||||
"name": "stream-notify-logged",
|
||||
"params": [
|
||||
"user-status",
|
||||
false
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({ message, requestId });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
streamNotifyRoom(roomId: string) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
let message = {
|
||||
"msg": "method",
|
||||
"method": "stream-notify-room",
|
||||
"id": requestId,
|
||||
"params": [
|
||||
`null/typing`,
|
||||
"paulo.pinto",
|
||||
true
|
||||
]
|
||||
};
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
streamNotifyRoomDeleteMessage(roomId: string) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
let message = {
|
||||
"msg": "sub",
|
||||
"id": requestId,
|
||||
"name": "stream-notify-room",
|
||||
"params": [
|
||||
`${roomId}/deleteMessage`,
|
||||
true
|
||||
]
|
||||
};
|
||||
|
||||
this.ws.send({ message, requestId })
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({
|
||||
type: 'Onmessage', funx: (message) => {
|
||||
if (message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
registerCallback(data: wsCallbacksParams) {
|
||||
return this.ws.registerCallback(data)
|
||||
}
|
||||
|
||||
// socket class ==================================================================
|
||||
private socket!: WebSocket;
|
||||
private wsMsgQueue: { [key: string]: msgQueue } = {}
|
||||
private wsCallbacks: { [key: string]: wsCallbacksParams } = {}
|
||||
private wsReconnect = 0
|
||||
|
||||
private n = 0
|
||||
|
||||
ws = {
|
||||
connected: false,
|
||||
registerCallback: (params: wsCallbacksParams) => {
|
||||
|
||||
let id = params.requestId || params.key || uuidv4()
|
||||
//
|
||||
this.wsCallbacks[id] = params
|
||||
this.n++
|
||||
return id
|
||||
},
|
||||
connect: () => {
|
||||
this.socket = new WebSocket(environment.apiWsChatUrl);
|
||||
// bind function
|
||||
this.socket.onopen = this.ws.onopen;
|
||||
this.socket.onmessage = this.ws.onmessage;
|
||||
this.socket.onclose = this.ws.onclose;
|
||||
this.socket.onerror = this.ws.onerror;
|
||||
|
||||
},
|
||||
onopen: async () => {
|
||||
|
||||
|
||||
|
||||
this.ws.connected = true
|
||||
this.backgroundservice.online();
|
||||
|
||||
setTimeout(() => {
|
||||
this.ws.wsMsgQueue()
|
||||
}, 10)
|
||||
console.log('rec conect')
|
||||
|
||||
if (this.wsReconnect >= 1) {
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if (value.type == 'reConnect') {
|
||||
const dontRepeat = await value.funx()
|
||||
|
||||
if (dontRepeat) {
|
||||
this.n--
|
||||
delete this.wsCallbacks[key]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
this.wsReconnect++;
|
||||
},
|
||||
wsMsgQueue: () => {
|
||||
|
||||
for (const [key, item] of Object.entries(this.wsMsgQueue)) {
|
||||
|
||||
if (item.loginRequired == true && this.isLogin == true) {
|
||||
//
|
||||
this.ws.send(item);
|
||||
delete this.wsMsgQueue[key]
|
||||
} else if (item.loginRequired == false) {
|
||||
//
|
||||
this.ws.send(item);
|
||||
delete this.wsMsgQueue[key]
|
||||
}
|
||||
}
|
||||
},
|
||||
send: ({ message, requestId = uuidv4(), loginRequired = true }: send) => {
|
||||
|
||||
if (this.ws.connected == false || loginRequired == true && this.isLogin == false) { // save data to send when back online
|
||||
//
|
||||
//
|
||||
|
||||
this.wsMsgQueue[requestId] = { message, requestId, loginRequired }
|
||||
} else {
|
||||
let messageStr = JSON.stringify(message)
|
||||
this.socket.send(messageStr)
|
||||
}
|
||||
return requestId
|
||||
},
|
||||
|
||||
onmessage: async (event: any) => {
|
||||
|
||||
this.backgroundservice.online();
|
||||
|
||||
const data = JSON.parse(event.data)
|
||||
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if (value.type == 'Onmessage') {
|
||||
const dontRepeat = await value.funx(data)
|
||||
|
||||
if (dontRepeat) {
|
||||
delete this.wsCallbacks[key]
|
||||
this.n--
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
onclose: async (event: any) => {
|
||||
this.ws.connected = false
|
||||
this.isLogin = false
|
||||
|
||||
|
||||
this.connect()
|
||||
this.login()
|
||||
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if (value.type == 'Offline') {
|
||||
const dontRepeat = await value.funx()
|
||||
|
||||
if (dontRepeat) {
|
||||
delete this.wsCallbacks[key]
|
||||
this.n--
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
|
||||
onerror: (event: any) => {
|
||||
|
||||
},
|
||||
disconnect: () => {
|
||||
|
||||
if (this.socket) {
|
||||
this.socket.onopen = (event: any) => { }
|
||||
this.socket.onmessage = (event: any) => { }
|
||||
this.socket.onclose = (event: any) => { }
|
||||
this.socket.onerror = (event: any) => { }
|
||||
this.socket.close()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RoomService } from './room.service';
|
||||
|
||||
describe('RoomService', () => {
|
||||
let service: RoomService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RoomService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ViewedMessageService } from './viewed-message.service';
|
||||
|
||||
describe('ViewedMessageService', () => {
|
||||
let service: ViewedMessageService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ViewedMessageService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,81 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import * as FIFOProcessQueue from 'fifo-process-queue';
|
||||
import { RoomService } from './room.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ViewedMessageService {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
viewQueue = FIFOProcessQueue(async ({room, userId, statusNum, statusText}, callback) => {
|
||||
|
||||
if(room.membersExcludeMe?.map) {
|
||||
const membersIds = room.membersExcludeMe.map((user)=> user._id)
|
||||
|
||||
if(membersIds.includes(userId)) {
|
||||
|
||||
if(statusText != 'offline') {
|
||||
room.deleteMessageToReceive(userId)
|
||||
}
|
||||
|
||||
let n = 0
|
||||
for (const message of room.messages) {
|
||||
if(message.online) {
|
||||
for(let id of membersIds) {
|
||||
if(message.addReceived(id)) {
|
||||
n++
|
||||
// setTimeout(async() => {
|
||||
await message.saveChanges()
|
||||
// }, 100 * n)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
callback();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
viewReadQueue = FIFOProcessQueue(async ({room}, callback) => {
|
||||
|
||||
const membersIds: string[] = room.membersExcludeMe.map((user)=> user._id)
|
||||
|
||||
let n = 0
|
||||
for (const message of room.messages) {
|
||||
if(message.online) {
|
||||
for(let id of membersIds) {
|
||||
|
||||
if(message.addViewed(id)) {
|
||||
message.addReceived(id)
|
||||
n++
|
||||
// setTimeout(async() => {
|
||||
await message.saveChanges()
|
||||
// }, 100 * n)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
callback()
|
||||
},100)
|
||||
|
||||
})
|
||||
|
||||
request(room:RoomService, userId, statusNum, statusText) {
|
||||
this.viewQueue.push({room, userId, statusNum, statusText})
|
||||
}
|
||||
|
||||
requestReadAll(room:RoomService) {
|
||||
this.viewReadQueue.push({room})
|
||||
}
|
||||
}
|
||||
@@ -78,12 +78,12 @@ export class FileService {
|
||||
path: IMAGE_DIR,
|
||||
directory: Directory.Data,
|
||||
}).then(result => {
|
||||
|
||||
|
||||
let lastphoto = result.files[result.files.length - 1]
|
||||
resolve(lastphoto)
|
||||
},
|
||||
async (err) => {
|
||||
|
||||
|
||||
reject('ERROR FILE DOSENT EXIST')
|
||||
// Folder does not yet exists!
|
||||
await Filesystem.mkdir({
|
||||
@@ -127,7 +127,7 @@ export class FileService {
|
||||
|
||||
//new method 4
|
||||
async loadFileData(fileName: string) {
|
||||
|
||||
|
||||
// for (let f of fileNames) {
|
||||
const filePath = `${IMAGE_DIR}/${fileName}`;
|
||||
|
||||
@@ -139,7 +139,7 @@ export class FileService {
|
||||
data: `data:image/jpeg;base64,${readFile.data}`,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
const capturedImage = image.data
|
||||
|
||||
@@ -150,9 +150,7 @@ export class FileService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
getFileFromDevice(types: typeof FileType[]) {
|
||||
getFileFromDevice(types: typeof FileType[]): Promise<File> {
|
||||
const input = this.fileLoaderService.createInput({
|
||||
accept: types
|
||||
})
|
||||
@@ -168,9 +166,6 @@ export class FileService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
getFileFromDeviceBase64(types: typeof FileType[]) {
|
||||
const input = this.fileLoaderService.createInput({
|
||||
accept: types
|
||||
@@ -199,7 +194,7 @@ export class FileService {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
viewDocumentByUrl(url) {
|
||||
const browser = this.iab.create(url,"_parent");
|
||||
@@ -254,8 +249,8 @@ export class FileService {
|
||||
dataURLtoFile(dataurl, filename) {
|
||||
var arr = dataurl.split(','),
|
||||
mime = arr[0].match(/:(.*?);/)[1],
|
||||
bstr = atob(arr[arr.length - 1]),
|
||||
n = bstr.length,
|
||||
bstr = atob(arr[arr.length - 1]),
|
||||
n = bstr.length,
|
||||
u8arr = new Uint8Array(n);
|
||||
while(n--){
|
||||
u8arr[n] = bstr.charCodeAt(n);
|
||||
@@ -267,11 +262,11 @@ export class FileService {
|
||||
contentType = contentType || '';
|
||||
const byteCharacters = atob(base64Data);
|
||||
const byteArray = new Uint8Array(byteCharacters.length);
|
||||
|
||||
|
||||
for (let i = 0; i < byteCharacters.length; i++) {
|
||||
byteArray[i] = byteCharacters.charCodeAt(i);
|
||||
}
|
||||
|
||||
|
||||
return new Blob([byteArray], { type: contentType });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ChatService } from '../chat.service';
|
||||
import { ChatSystemService } from '../chat/chat-system.service';
|
||||
// import { ChatSystemService } from '../chat/chat-system.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -9,8 +9,10 @@ export class TimeService {
|
||||
countDownTime: any;
|
||||
room: any;
|
||||
|
||||
constructor(private chatService: ChatService,
|
||||
public ChatSystemService: ChatSystemService,) { }
|
||||
constructor(
|
||||
//private chatService: ChatService,
|
||||
//public ChatSystemService: ChatSystemService,
|
||||
) { }
|
||||
|
||||
showDateDuration(start:any) {
|
||||
let end;
|
||||
@@ -42,7 +44,7 @@ export class TimeService {
|
||||
}
|
||||
|
||||
countDownDate(date:any, roomId:string){
|
||||
|
||||
|
||||
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));
|
||||
@@ -55,22 +57,22 @@ export class TimeService {
|
||||
|
||||
this.countDownTime = "Expired";
|
||||
let body = { "roomId":roomId, }
|
||||
this.chatService.getRoomInfo(roomId).subscribe(room=>{
|
||||
this.room = room['room'];
|
||||
// this.chatService.getRoomInfo(roomId).subscribe(room=>{
|
||||
// this.room = room['room'];
|
||||
|
||||
if(this.room.t === 'p'){
|
||||
this.chatService.deleteGroup(body).subscribe(res=>{
|
||||
|
||||
});
|
||||
}
|
||||
else{
|
||||
this.chatService.deleteChannel(body).subscribe(res=>{
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
// if(this.room.t === 'p'){
|
||||
// this.chatService.deleteGroup(body).subscribe(res=>{
|
||||
|
||||
// });
|
||||
// }
|
||||
// else{
|
||||
// this.chatService.deleteChannel(body).subscribe(res=>{
|
||||
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
return this.countDownTime;
|
||||
}
|
||||
|
||||
@@ -97,7 +99,7 @@ export class TimeService {
|
||||
// });
|
||||
// }
|
||||
// else{
|
||||
|
||||
|
||||
// this.chatService.deleteChannel(body).subscribe(res=>{
|
||||
// this.ChatSystemService.deleteRoom(roomId)
|
||||
// });
|
||||
|
||||
@@ -8,7 +8,6 @@ import { context, trace, propagation } from '@opentelemetry/api';
|
||||
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
||||
// const { OTLPTraceExporter: OTLPTraceExporterProto } = require("@opentelemetry/exporter-trace-otlp-proto");
|
||||
|
||||
|
||||
function createProvider(serviceName) {
|
||||
const provider = new WebTracerProvider({
|
||||
resource: new Resource({
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NewChatSystemService } from './new-chat-system.service';
|
||||
|
||||
describe('NewChatSystemService', () => {
|
||||
let service: NewChatSystemService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(NewChatSystemService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NewChatSystemService {
|
||||
|
||||
constructor(
|
||||
|
||||
) { }
|
||||
}
|
||||
@@ -16,8 +16,7 @@ import { AngularFireMessaging } from '@angular/fire/messaging';
|
||||
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
import { FCM } from '@capacitor-community/fcm';
|
||||
import { ChatSystemService } from './chat/chat-system.service';
|
||||
import {ChatController} from 'src/app/controller/chat'
|
||||
// import { ChatSystemService } from './chat/chat-system.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -43,8 +42,6 @@ export class NotificationsService {
|
||||
notificationReceived: EventEmitter<void> = new EventEmitter<void>();
|
||||
token = ''
|
||||
|
||||
ChatController = ChatController
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private storageService: StorageService,
|
||||
|
||||
@@ -10,7 +10,6 @@ import { GetTasksListType } from '../models/GetTasksListType';
|
||||
import { fullTaskList } from '../models/dailyworktask.model';
|
||||
import { ChangeProfileService } from './change-profile.service';
|
||||
import { SessionStore } from '../store/session.service';
|
||||
import { CPSession } from '../store/documentManagement';
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { WebNotificationsService } from './webnotifications.service';
|
||||
|
||||
describe('WebNotificationsService', () => {
|
||||
let service: WebNotificationsService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(WebNotificationsService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,213 +0,0 @@
|
||||
import { Injectable, NgZone } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { AuthConnstants } from 'src/app/config/auth-constants';
|
||||
import { Tokenn } from '../models/token.model';
|
||||
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
|
||||
import { NavigationExtras, Router } from '@angular/router';
|
||||
import { ToastService } from './toast.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WebNotificationsService {
|
||||
|
||||
adding: "intervenient" | "CC" = "intervenient";
|
||||
folderId: string;
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private storageService: StorageService,
|
||||
private modalController: ModalController,
|
||||
public modalCtrl: AlertController,
|
||||
private animationController: AnimationController,
|
||||
private platform: Platform,
|
||||
private router: Router,
|
||||
private toastService: ToastService) { }
|
||||
|
||||
|
||||
webconnection() {
|
||||
|
||||
var inicializeObj = {
|
||||
appId: "com.gpr.gabinetedigital",
|
||||
mfpContextRoot: "/mfp",
|
||||
/* serverUrl: "http://gpr-dev-10.gabinetedigital.local:9080",
|
||||
safariWebsitePushId: "http://gpr-dev-10.gabinetedigital.local:9080", */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* MFPPush.initialize({
|
||||
appId: "com.gpr.gabinetedigital",
|
||||
mfpContextRoot: "/mfp",
|
||||
}); */
|
||||
|
||||
/* MFPPush.registerDevice()
|
||||
.then((res) => {
|
||||
|
||||
|
||||
setTimeout(()=>{
|
||||
MFPPush.registerDevice()
|
||||
.then((res) => {
|
||||
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
});
|
||||
}, 1000)
|
||||
|
||||
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
}); */
|
||||
}
|
||||
|
||||
/* getTokenByUserIdAndId(user, userID) {
|
||||
const geturl = environment.apiURL + 'notifications/user/' + userID;
|
||||
|
||||
return this.http.get<Token[]>(`${geturl}`);
|
||||
} */
|
||||
|
||||
/* getAndpostToken(username) {
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
|
||||
} else {
|
||||
|
||||
const geturl = environment.apiURL + 'notifications/token'; */
|
||||
/*
|
||||
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
|
||||
(token) => {
|
||||
|
||||
|
||||
MFPPush.initialize(
|
||||
function (successResponse) {
|
||||
|
||||
},
|
||||
function (failureResponse) {
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
MFPPush.registerDevice(null, (successResponse) => {
|
||||
|
||||
|
||||
this.storageService.store(username, successResponse.deviceId);
|
||||
this.storageService.get(username).then(value => {
|
||||
|
||||
this.storageService.get(AuthConnstants.USER).then(res => {
|
||||
|
||||
const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' };
|
||||
const body = {
|
||||
UserId: res.UserId,
|
||||
TokenId: successResponse.deviceId,
|
||||
Status: 1,
|
||||
Service: 1
|
||||
};
|
||||
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
},
|
||||
function (failureResponse) {
|
||||
|
||||
}
|
||||
);
|
||||
}, (error) => {
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
} */
|
||||
/*
|
||||
async onReceviNotification() {
|
||||
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
|
||||
(token) => {
|
||||
|
||||
|
||||
MFPPush.initialize(
|
||||
function (successResponse) {
|
||||
|
||||
MFPPush.registerNotificationsCallback(notificationReceived);
|
||||
},
|
||||
function (failureResponse) {
|
||||
|
||||
}
|
||||
);
|
||||
var notificationReceived = (message) => {
|
||||
|
||||
var data = JSON.parse(message.payload);
|
||||
|
||||
|
||||
|
||||
|
||||
if(message.actionName){
|
||||
this.notificatinsRoutes(data);
|
||||
} else {
|
||||
this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
|
||||
}
|
||||
|
||||
}
|
||||
}, (error) => {
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
} */
|
||||
|
||||
/* notificatinsRoutes = (data) => {
|
||||
if (data.Service === "agenda") {
|
||||
this.zone.run(() => this.router.navigate(['/home/agenda', data.IdObject, 'agenda']));
|
||||
}
|
||||
else if (data.Service === "gabinete-digital" && data.Object === "expediente") {
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente',data.IdObject,'gabinete-digital']));
|
||||
}
|
||||
else if (data.Service === "gabinete-digital" && data.Object === "event-list") {
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',data.IdObject, 'gabinete-digital']));
|
||||
}else if (data.Service === "gabinete-digital" && data.Object === "despachos") {
|
||||
let navigationExtras: NavigationExtras = {
|
||||
queryParams: {
|
||||
"serialNumber": data.IdObject,
|
||||
}
|
||||
};
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos/despacho'], navigationExtras));
|
||||
}
|
||||
else if (data.Service === "gabinete-digital" && data.Object === "parecer") {
|
||||
let navigationExtras: NavigationExtras = {
|
||||
queryParams: {
|
||||
enterAnimation: "",
|
||||
serialNumber: data.IdObject,
|
||||
}
|
||||
};
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos/pedido'], navigationExtras));
|
||||
}
|
||||
else if (data.Service === "gabinete-digital" && data.Object === "deferimento") {
|
||||
let navigationExtras: NavigationExtras = {
|
||||
queryParams: {
|
||||
enterAnimation: "",
|
||||
serialNumber: data.IdObject,
|
||||
}
|
||||
};
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos/pedido'], navigationExtras));
|
||||
}
|
||||
else if (data.Service === "accoes" && data.Object === "accao") {
|
||||
this.zone.run(() => this.router.navigate(['/home/publications',data.IdObject]));
|
||||
}
|
||||
else if (data.Service === "accoes" && data.Object === "publicacao") {
|
||||
this.zone.run(() => this.router.navigate(['/home/publications/view-publications',data.FolderId,data.IdObject]));
|
||||
}
|
||||
}
|
||||
|
||||
platformVerify() {
|
||||
|
||||
if (this.platform.is('cordova')) {
|
||||
} else {
|
||||
}
|
||||
} */
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user