2022-01-12 12:44:51 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { RoomService } from './room.service';
|
2022-09-30 15:13:36 +01:00
|
|
|
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
|
2022-04-26 14:34:52 +01:00
|
|
|
import { MessageService } from 'src/app/services/chat/message.service';
|
2022-01-12 12:44:51 +01:00
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
2022-04-26 14:34:52 +01:00
|
|
|
import { capitalizeTxt } from 'src/plugin/text';
|
2022-09-26 18:15:41 +01:00
|
|
|
import { Update as room } from 'src/app/models/chatMethod';
|
2022-01-19 09:12:30 +01:00
|
|
|
import { Storage } from '@ionic/storage';
|
2022-01-21 16:55:05 +01:00
|
|
|
import { Platform } from '@ionic/angular';
|
|
|
|
|
import { SqliteService } from 'src/app/services/sqlite.service';
|
2022-01-29 19:24:46 +01:00
|
|
|
import { ChatService } from 'src/app/services/chat.service';
|
2022-01-26 17:28:55 +01:00
|
|
|
import { NativeNotificationService } from 'src/app/services/native-notification.service';
|
2022-01-28 15:59:01 +01:00
|
|
|
import { SortService } from '../functions/sort.service';
|
2022-01-29 19:21:46 +01:00
|
|
|
import { chatUser } from 'src/app/models/chatMethod';
|
2022-02-07 17:55:00 +01:00
|
|
|
import { NfService } from 'src/app/services/chat/nf.service'
|
2022-02-10 14:56:06 +01:00
|
|
|
import { ChangeProfileService } from '../change-profile.service';
|
2022-04-26 14:34:52 +01:00
|
|
|
import { ChatMethodsService } from './chat-methods.service';
|
2022-03-10 23:08:29 +01:00
|
|
|
import { AESEncrypt } from '../aesencrypt.service'
|
2022-03-22 16:11:30 +01:00
|
|
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
2023-10-11 16:20:42 +01:00
|
|
|
import { NetworkServiceService } from 'src/app/services/network-service.service';
|
2023-01-05 12:11:50 +01:00
|
|
|
import { ViewedMessageService } from './viewed-message.service'
|
2023-02-02 18:24:26 +01:00
|
|
|
import { NotificationsService } from '../notifications.service';
|
2023-06-22 12:53:35 +01:00
|
|
|
import { Subscribe } from '../subcribe';
|
2023-09-27 08:44:35 +01:00
|
|
|
import { Plugins } from '@capacitor/core';
|
|
|
|
|
|
|
|
|
|
const { App } = Plugins;
|
|
|
|
|
|
2022-01-12 12:44:51 +01:00
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
2022-09-30 15:13:36 +01:00
|
|
|
export class ChatSystemService {
|
2022-01-12 12:44:51 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
dm: { [key: string]: RoomService } = {}
|
|
|
|
|
group: { [key: string]: RoomService } = {}
|
2022-01-28 19:01:24 +01:00
|
|
|
|
2022-02-16 15:52:59 +01:00
|
|
|
_dm: RoomService[] = []
|
|
|
|
|
_group: RoomService[] = []
|
2022-01-28 19:01:24 +01:00
|
|
|
|
2022-04-07 17:51:47 +01:00
|
|
|
loadingWholeList = false;
|
2022-01-12 12:44:51 +01:00
|
|
|
|
|
|
|
|
dmCount = 0;
|
|
|
|
|
groupCount = 0;
|
2022-01-12 14:48:17 +01:00
|
|
|
|
2022-02-10 14:07:16 +01:00
|
|
|
currentRoom: RoomService = null
|
2022-01-29 19:21:46 +01:00
|
|
|
users: chatUser[] = []
|
2022-04-18 15:12:27 +01:00
|
|
|
sessionStore = SessionStore
|
2022-07-04 14:08:51 +01:00
|
|
|
delete = []
|
2022-10-04 11:33:46 +01:00
|
|
|
loadingUsers = false
|
2023-06-22 12:53:35 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
onRoomsLoad = new Subscribe({ execute: false, deleteOnExecute: true })
|
2023-06-22 12:53:35 +01:00
|
|
|
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2022-01-12 12:44:51 +01:00
|
|
|
constructor(
|
2022-09-30 15:13:36 +01:00
|
|
|
private RochetChatConnectorService: RochetChatConnectorService,
|
2022-01-21 16:55:05 +01:00
|
|
|
private storage: Storage,
|
|
|
|
|
private platform: Platform,
|
|
|
|
|
private sqlservice: SqliteService,
|
2022-01-28 16:26:21 +01:00
|
|
|
private NativeNotificationService: NativeNotificationService,
|
2022-01-29 19:24:46 +01:00
|
|
|
private sortService: SortService,
|
2022-02-07 17:55:00 +01:00
|
|
|
private ChatService: ChatService,
|
2022-02-08 17:44:15 +01:00
|
|
|
private NfService: NfService,
|
2022-02-10 14:56:06 +01:00
|
|
|
private changeProfileService: ChangeProfileService,
|
2022-03-03 22:57:33 +01:00
|
|
|
private chatService: ChatService,
|
2023-10-11 16:20:42 +01:00
|
|
|
private ChatMethodsService: ChatMethodsService,
|
2022-03-22 16:11:30 +01:00
|
|
|
private AESEncrypt: AESEncrypt,
|
2023-10-11 16:20:42 +01:00
|
|
|
private AttachmentsService: AttachmentsService,
|
2022-06-08 16:09:40 +01:00
|
|
|
private NetworkServiceService: NetworkServiceService,
|
2023-02-02 18:24:26 +01:00
|
|
|
private ViewedMessageService: ViewedMessageService,
|
|
|
|
|
private notificationService: NotificationsService
|
2022-01-12 12:44:51 +01:00
|
|
|
) {
|
2022-02-11 17:15:01 +01:00
|
|
|
|
2023-08-20 00:26:24 +01:00
|
|
|
|
2022-09-30 15:13:36 +01:00
|
|
|
this.RochetChatConnectorService.registerCallback({
|
2022-01-31 14:44:22 +01:00
|
|
|
type: 'reConnect',
|
2023-10-11 16:20:42 +01:00
|
|
|
funx: async () => {
|
2022-02-10 14:07:16 +01:00
|
|
|
/**
|
|
|
|
|
* @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.
|
|
|
|
|
*/
|
2022-10-04 11:33:46 +01:00
|
|
|
|
2023-09-22 15:17:25 +01:00
|
|
|
this.RochetChatConnectorService.setStatus('online')
|
|
|
|
|
this.getUserStatus();
|
|
|
|
|
await this.chatService.refreshtoken();
|
|
|
|
|
this.getUser();
|
|
|
|
|
this.getAllRooms();
|
|
|
|
|
this.subscribeToRoom();
|
|
|
|
|
//
|
|
|
|
|
|
2022-02-09 17:06:56 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this.currentRoom) {
|
|
|
|
|
this.currentRoom.loadHistory({ forceUpdate: true })
|
2022-02-10 14:56:06 +01:00
|
|
|
}
|
2022-02-10 14:07:16 +01:00
|
|
|
|
|
|
|
|
for (const id in this.dm) {
|
|
|
|
|
this.dm[id].hasLoadHistory = false
|
|
|
|
|
}
|
2022-02-11 17:15:01 +01:00
|
|
|
|
2022-02-10 14:07:16 +01:00
|
|
|
for (const id in this.group) {
|
|
|
|
|
this.group[id].hasLoadHistory = false
|
2022-02-09 17:06:56 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-31 14:44:22 +01:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this.sessionStore.user.Inactivity) {
|
2022-10-04 11:33:46 +01:00
|
|
|
this.loadChat();
|
|
|
|
|
}
|
2022-02-16 15:52:59 +01:00
|
|
|
|
2023-02-08 11:06:27 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (SessionStore.user?.ChatData?.data) {
|
2023-09-27 08:44:35 +01:00
|
|
|
this.restoreRooms();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.addEventListener('resume', () => {
|
2023-09-22 17:25:27 +01:00
|
|
|
this.RochetChatConnectorService.setStatus('online')
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this._dm?.length == 0 && this._group?.length == 0) {
|
2023-10-19 15:03:12 +01:00
|
|
|
if (SessionStore.user?.ChatData?.data) {
|
|
|
|
|
this.getAllRooms();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 11:06:27 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-22 11:40:06 +01:00
|
|
|
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');
|
2023-09-27 08:44:35 +01:00
|
|
|
|
2023-10-19 15:03:12 +01:00
|
|
|
if (SessionStore.user?.ChatData?.data) {
|
2024-02-22 11:40:06 +01:00
|
|
|
this.currentRoom?.loadHistory({ forceUpdate: true })
|
2023-10-19 15:03:12 +01:00
|
|
|
}
|
2023-09-27 08:44:35 +01:00
|
|
|
|
2024-02-22 11:40:06 +01:00
|
|
|
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) {}
|
|
|
|
|
|
|
|
|
|
|
2023-02-09 16:05:36 +01:00
|
|
|
|
2022-01-12 12:44:51 +01:00
|
|
|
}
|
|
|
|
|
|
2022-10-04 11:33:46 +01:00
|
|
|
loadChat() {
|
2023-10-11 16:20:42 +01:00
|
|
|
if (SessionStore.user?.ChatData?.data) {
|
2022-12-17 12:34:56 +01:00
|
|
|
this.ReLoadChat()
|
|
|
|
|
}
|
2022-02-10 14:56:06 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-17 12:34:56 +01:00
|
|
|
private async ReLoadChat() {
|
2022-10-04 11:33:46 +01:00
|
|
|
|
2023-10-19 15:03:12 +01:00
|
|
|
if (SessionStore.user?.ChatData?.data) {
|
|
|
|
|
this.getUserStatus();
|
|
|
|
|
await this.chatService.refreshtoken();
|
2022-02-10 14:56:06 +01:00
|
|
|
|
2023-10-19 15:03:12 +01:00
|
|
|
this.restoreUsers();
|
|
|
|
|
await this.getUser();
|
|
|
|
|
await this.restoreRooms();
|
|
|
|
|
await this.getAllRooms();
|
|
|
|
|
this.subscribeToRoom();
|
|
|
|
|
}
|
2022-02-10 14:56:06 +01:00
|
|
|
//
|
2023-09-22 17:34:39 +01:00
|
|
|
|
2022-02-10 14:56:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearChat() {
|
|
|
|
|
this.dm = {}
|
2022-02-11 17:15:01 +01:00
|
|
|
this.group = {}
|
2022-02-10 14:56:06 +01:00
|
|
|
this._dm = []
|
|
|
|
|
this._group = []
|
|
|
|
|
|
2022-04-07 17:51:47 +01:00
|
|
|
this.loadingWholeList = false;
|
2022-02-10 14:56:06 +01:00
|
|
|
|
|
|
|
|
this.dmCount = 0;
|
|
|
|
|
this.groupCount = 0;
|
2022-02-11 17:15:01 +01:00
|
|
|
|
2022-02-10 14:56:06 +01:00
|
|
|
this.currentRoom = null
|
|
|
|
|
this.users = []
|
2022-10-13 14:37:03 +01:00
|
|
|
this.storage.remove('Users');
|
2022-02-10 14:56:06 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-29 19:21:46 +01:00
|
|
|
openRoom(roomId) {
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this.currentRoom) {
|
2022-02-10 14:07:16 +01:00
|
|
|
this.currentRoom.roomLeave()
|
2022-01-29 19:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this.getDmRoom(roomId)) {
|
2022-02-10 14:07:16 +01:00
|
|
|
this.currentRoom = this.getDmRoom(roomId)
|
2023-10-11 16:20:42 +01:00
|
|
|
} else if (this.getGroupRoom(roomId)) {
|
2022-02-11 17:15:01 +01:00
|
|
|
this.currentRoom = this.getGroupRoom(roomId)
|
2022-01-29 19:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-10 14:07:16 +01:00
|
|
|
this.currentRoom.open()
|
2022-02-11 17:15:01 +01:00
|
|
|
|
2022-01-29 19:21:46 +01:00
|
|
|
}
|
2022-01-28 19:02:44 +01:00
|
|
|
|
2022-09-26 18:15:41 +01:00
|
|
|
getRoomById(roomId) {
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this.getDmRoom(roomId)) {
|
2022-09-26 18:15:41 +01:00
|
|
|
return this.getDmRoom(roomId)
|
2023-10-11 16:20:42 +01:00
|
|
|
} else if (this.getGroupRoom(roomId)) {
|
2022-09-26 18:15:41 +01:00
|
|
|
return this.getGroupRoom(roomId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-08 17:44:15 +01:00
|
|
|
async restoreRooms() {
|
|
|
|
|
|
|
|
|
|
try {
|
2023-09-29 16:40:50 +01:00
|
|
|
const _rooms = await this.storage.get('Rooms');
|
2022-02-08 17:44:15 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (_rooms) {
|
|
|
|
|
for (let roomData of this.sortArrayISODate(_rooms)) {
|
2022-02-08 17:44:15 +01:00
|
|
|
await this.prepareRoom(roomData);
|
2022-09-27 14:52:01 +01:00
|
|
|
}
|
2022-02-08 17:44:15 +01:00
|
|
|
}
|
2023-10-11 16:20:42 +01:00
|
|
|
} catch (e) { }
|
2022-02-08 17:44:15 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
async restoreUsers() {
|
2022-10-13 14:37:03 +01:00
|
|
|
const users = await this.storage.get('Users');
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (users) {
|
2022-10-13 14:37:03 +01:00
|
|
|
this.users = users
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-29 16:40:50 +01:00
|
|
|
sortArrayISODate(messages: any): any[] {
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
return messages.sort((a, b) =>
|
|
|
|
|
new Date(b._updatedAt).getTime()
|
2023-09-29 16:40:50 +01:00
|
|
|
-
|
|
|
|
|
new Date(a._updatedAt).getTime())
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
async getAllRooms(callback: Function = () => { }, roomIdCallback = "") {
|
2022-01-12 12:44:51 +01:00
|
|
|
this.loadingWholeList = true
|
2022-12-20 17:06:19 +01:00
|
|
|
var rooms;
|
2023-01-24 15:56:47 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this.RochetChatConnectorService.isLogin) {
|
2022-09-27 14:52:01 +01:00
|
|
|
try {
|
2023-01-24 15:56:47 +01:00
|
|
|
rooms = await this.RochetChatConnectorService.getRooms();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.loadingWholeList = false
|
2023-10-11 16:20:42 +01:00
|
|
|
console.error('chatgetrooms', error)
|
2023-01-24 15:56:47 +01:00
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await this.storage.remove('Rooms');
|
2023-10-11 16:20:42 +01:00
|
|
|
} catch (e) { }
|
2023-01-24 15:56:47 +01:00
|
|
|
}
|
2022-01-28 19:02:44 +01:00
|
|
|
|
2022-09-26 18:15:41 +01:00
|
|
|
let index = 0
|
|
|
|
|
|
2023-09-29 16:40:50 +01:00
|
|
|
let _rooms = rooms?.result?.update
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (_rooms) {
|
2023-09-29 16:40:50 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
_rooms = _rooms.map(e => {
|
2023-09-29 16:40:50 +01:00
|
|
|
e["_updatedAt"] = e._updatedAt || e._updatedAt['$date']
|
|
|
|
|
return e
|
|
|
|
|
})
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
for (let roomData of this.sortArrayISODate(_rooms)) {
|
2023-09-29 16:40:50 +01:00
|
|
|
|
2022-09-26 16:16:37 +01:00
|
|
|
const roomId = this.getRoomId(roomData);
|
2022-09-30 16:55:09 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (roomData.t == 'd') {
|
2022-04-24 20:05:04 +01:00
|
|
|
await this.prepareRoom(roomData);
|
2022-09-26 16:16:37 +01:00
|
|
|
} else {
|
|
|
|
|
if (roomData.t === 'p') {
|
|
|
|
|
await this.prepareRoom(roomData);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
await this.prepareRoom(roomData);
|
|
|
|
|
}
|
2023-08-15 10:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (roomId == roomIdCallback) {
|
2023-08-15 10:15:08 +01:00
|
|
|
callback()
|
2022-03-03 22:57:33 +01:00
|
|
|
}
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2022-09-26 18:15:41 +01:00
|
|
|
index++;
|
|
|
|
|
}
|
2022-09-26 16:16:37 +01:00
|
|
|
}
|
2022-09-26 18:15:41 +01:00
|
|
|
|
2022-12-17 17:08:13 +01:00
|
|
|
this.loadingWholeList = false
|
2023-01-09 10:49:58 +01:00
|
|
|
this.sortRoomList()
|
2023-09-29 16:40:50 +01:00
|
|
|
await this.storage.set('Rooms', _rooms);
|
2022-04-07 17:51:47 +01:00
|
|
|
|
2023-06-22 12:53:35 +01:00
|
|
|
this.onRoomsLoad.executor()
|
2022-01-12 12:44:51 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 17:41:05 +01:00
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 14:44:22 +01:00
|
|
|
/**
|
|
|
|
|
* @description sort room list by last message date
|
|
|
|
|
*/
|
2022-09-26 18:15:41 +01:00
|
|
|
sortRoomList = () => {
|
2022-03-18 17:05:35 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
this._dm = this.sortService.sortDate(this._dm, '_updatedAt').reverse()
|
|
|
|
|
this._group = this.sortService.sortDate(this._group, '_updatedAt').reverse()
|
2022-01-29 19:44:20 +01:00
|
|
|
}
|
2022-01-28 19:04:46 +01:00
|
|
|
|
2022-01-31 14:44:22 +01:00
|
|
|
/**
|
|
|
|
|
* @description subscribe all room
|
|
|
|
|
*/
|
2022-01-12 12:44:51 +01:00
|
|
|
subscribeToRoom() {
|
2022-01-14 11:47:55 +01:00
|
|
|
|
2023-10-19 15:03:12 +01:00
|
|
|
if (SessionStore.user?.ChatData?.data) {
|
2022-01-12 12:44:51 +01:00
|
|
|
|
2023-10-19 15:03:12 +01:00
|
|
|
for (const id in this.dm) {
|
|
|
|
|
this.defaultSubtribe(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const id in this.group) {
|
|
|
|
|
this.defaultSubtribe(id)
|
|
|
|
|
}
|
2022-01-29 19:54:38 +01:00
|
|
|
|
2023-10-19 15:03:12 +01:00
|
|
|
this.RochetChatConnectorService.streamNotifyLogged().then((subscription => { }))
|
|
|
|
|
|
2024-03-01 14:42:16 +01:00
|
|
|
this.RochetChatConnectorService.subStreamMessageUser().then((subscription => {
|
|
|
|
|
console.log({subscription})
|
|
|
|
|
}))
|
2023-10-19 15:03:12 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
throw ('No chat data');
|
|
|
|
|
}, 1000)
|
|
|
|
|
}
|
2023-01-24 15:56:47 +01:00
|
|
|
|
2022-01-12 12:44:51 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-29 20:16:39 +01:00
|
|
|
/**
|
|
|
|
|
* @description when a new room is create, needs to subtribe in order to receive updates
|
2022-02-02 10:28:36 +01:00
|
|
|
* @param id
|
|
|
|
|
* @param roomData
|
2022-01-29 20:16:39 +01:00
|
|
|
*/
|
2022-01-26 16:37:59 +01:00
|
|
|
subscribeToRoomUpdate(id, roomData) {
|
2022-02-02 10:28:36 +01:00
|
|
|
|
2022-09-30 16:55:09 +01:00
|
|
|
this.defaultSubtribe(id);
|
2022-01-26 16:37:59 +01:00
|
|
|
|
|
|
|
|
this.prepareRoom(roomData);
|
|
|
|
|
|
2022-02-09 17:06:12 +01:00
|
|
|
this.getGroupRoom(id).loadHistory({});
|
2022-01-26 16:37:59 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 19:54:38 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated things a room need to subscribe on
|
2022-01-29 20:01:16 +01:00
|
|
|
* @param id room id
|
2022-01-29 19:54:38 +01:00
|
|
|
*/
|
2022-01-29 20:01:16 +01:00
|
|
|
private defaultSubtribe(id: any) {
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2022-09-30 16:55:09 +01:00
|
|
|
const room = this.getRoomById(id);
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (!room.subscribeAttempt) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
room.subscribeAttempt = true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log("error")
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2022-09-30 16:55:09 +01:00
|
|
|
this.RochetChatConnectorService.streamRoomMessages(id).then((subscription) => {
|
|
|
|
|
room.status.receive.message = true;
|
|
|
|
|
})
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2022-09-30 16:55:09 +01:00
|
|
|
this.RochetChatConnectorService.subStreamNotifyRoom(id, 'typing', false).then((subscription) => {
|
|
|
|
|
room.status.receive.typing = true;
|
|
|
|
|
//
|
|
|
|
|
})
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2022-09-30 16:55:09 +01:00
|
|
|
this.RochetChatConnectorService.subStreamNotifyRoom(id, 'readMessage', false).then((subscription) => {
|
|
|
|
|
room.status.receive.readMessage = true;
|
|
|
|
|
})
|
2023-09-19 10:21:23 +01:00
|
|
|
|
2022-09-30 16:55:09 +01:00
|
|
|
this.RochetChatConnectorService.streamNotifyRoomDeleteMessage(id).then((subscription) => {
|
|
|
|
|
room.status.receive.deleteMessage = true;
|
|
|
|
|
})
|
2023-09-19 10:21:23 +01:00
|
|
|
}
|
2022-03-03 22:57:33 +01:00
|
|
|
|
2022-01-29 19:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-18 17:05:35 +01:00
|
|
|
private fix_updatedAt(message) {
|
|
|
|
|
if (message.result) {
|
|
|
|
|
message.result._updatedAt = message.result._updatedAt['$date']
|
2023-10-11 16:20:42 +01:00
|
|
|
} else if (message._updatedAt) {
|
|
|
|
|
if (message._updatedAt.hasOwnProperty('$date')) {
|
2022-03-18 17:05:35 +01:00
|
|
|
message._updatedAt = message._updatedAt['$date']
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return message
|
|
|
|
|
}
|
2022-02-02 10:28:36 +01:00
|
|
|
|
2022-01-29 20:16:39 +01:00
|
|
|
/**
|
2022-02-02 10:28:36 +01:00
|
|
|
* @description create a representation of an room in these instance this.dm, this.group ...
|
|
|
|
|
* @param roomData
|
2022-01-29 20:16:39 +01:00
|
|
|
*/
|
2022-01-29 17:06:25 +01:00
|
|
|
prepareRoom(roomData) {
|
2022-01-28 16:30:30 +01:00
|
|
|
|
2022-02-10 21:50:15 +01:00
|
|
|
|
2022-02-16 15:52:59 +01:00
|
|
|
/**
|
|
|
|
|
* @description data used to define or create room
|
|
|
|
|
*/
|
2022-03-18 17:05:35 +01:00
|
|
|
|
|
|
|
|
|
2022-03-21 15:12:20 +01:00
|
|
|
roomData = this.fix_updatedAt(roomData)
|
2022-02-10 21:50:15 +01:00
|
|
|
const setData = {
|
2022-01-26 16:37:59 +01:00
|
|
|
customFields: roomData.customFields,
|
|
|
|
|
id: this.getRoomId(roomData),
|
|
|
|
|
name: this.getRoomName(roomData),
|
|
|
|
|
t: roomData.t,
|
|
|
|
|
lastMessage: this.getRoomLastMessage(roomData),
|
2023-10-11 16:20:42 +01:00
|
|
|
_updatedAt: new Date(roomData._updatedAt || roomData._updatedAt['$date']),
|
|
|
|
|
u: roomData.u || {},
|
2023-10-19 15:03:12 +01:00
|
|
|
members: [],
|
|
|
|
|
membersExcludeMe: []
|
2022-02-10 21:50:15 +01:00
|
|
|
}
|
2022-02-11 17:15:01 +01:00
|
|
|
|
2022-06-08 16:09:40 +01:00
|
|
|
let roomId = this.getRoomId(roomData);
|
2022-01-26 16:37:59 +01:00
|
|
|
|
2023-10-19 15:03:12 +01:00
|
|
|
let chat = false
|
|
|
|
|
if (roomData?.usernames) {
|
|
|
|
|
if (roomData?.usernames?.includes("chat.admin")) {
|
|
|
|
|
chat = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (setData.name != 'Rocket Cat' && setData.name != 'general' && chat == false) {
|
2022-09-26 18:15:41 +01:00
|
|
|
// create room
|
2023-10-11 16:20:42 +01:00
|
|
|
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)
|
2022-09-26 18:15:41 +01:00
|
|
|
room.setData(setData)
|
|
|
|
|
room.receiveMessage()
|
|
|
|
|
room.getAllUsers = this.getUsers
|
|
|
|
|
room.receiveMessageDelete();
|
|
|
|
|
room.sortRoomList = this.sortRoomList
|
2022-09-30 14:43:10 +01:00
|
|
|
room.chatServiceDeleteRoom = this.deleteRoom
|
2022-10-03 11:02:32 +01:00
|
|
|
room.isGroup = !this.isIndividual(roomData)
|
2024-03-01 14:42:16 +01:00
|
|
|
room.info()
|
|
|
|
|
|
2022-09-26 18:15:41 +01:00
|
|
|
|
|
|
|
|
// create individual room
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this.isIndividual(roomData)) {
|
2022-02-11 17:15:01 +01:00
|
|
|
|
2022-09-26 18:15:41 +01:00
|
|
|
this.dm[roomId] = room
|
|
|
|
|
this._dm.push(room)
|
|
|
|
|
this.dmCount++
|
2022-02-11 17:15:01 +01:00
|
|
|
|
2022-09-26 18:15:41 +01:00
|
|
|
} else {
|
|
|
|
|
// create group room
|
2022-02-11 17:15:01 +01:00
|
|
|
|
2022-09-26 18:15:41 +01:00
|
|
|
this.group[roomId] = room
|
|
|
|
|
this._group.push(room)
|
|
|
|
|
this.groupCount++
|
|
|
|
|
|
|
|
|
|
}
|
2022-09-30 16:55:09 +01:00
|
|
|
|
|
|
|
|
this.defaultSubtribe(roomId)
|
2022-02-10 21:50:15 +01:00
|
|
|
} else {
|
2022-09-26 18:15:41 +01:00
|
|
|
// in this case room is already present, therefor it will only be necessary,
|
|
|
|
|
// to redefine
|
2022-02-16 15:52:59 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this.dm[roomId]) {
|
2022-09-26 18:15:41 +01:00
|
|
|
this.dm[roomId].setData(setData)
|
2023-10-11 16:20:42 +01:00
|
|
|
} else if (this.group[roomId]) {
|
2022-09-26 18:15:41 +01:00
|
|
|
this.group[roomId].setData(setData)
|
|
|
|
|
}
|
2022-02-11 17:15:01 +01:00
|
|
|
|
2022-02-10 22:15:40 +01:00
|
|
|
}
|
2022-01-26 16:37:59 +01:00
|
|
|
}
|
2022-09-26 18:15:41 +01:00
|
|
|
|
2022-01-26 16:37:59 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 13:36:37 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
deleteRoom = (roomId) => {
|
2022-07-04 14:08:51 +01:00
|
|
|
|
|
|
|
|
this.delete.push(roomId)
|
2022-05-27 13:36:37 +01:00
|
|
|
delete this.group[roomId];
|
2023-10-11 16:20:42 +01:00
|
|
|
this._group = this._group.filter((e) => e.id != roomId);
|
2022-05-27 13:36:37 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-04 14:08:51 +01:00
|
|
|
deleteRecently(roomId) {
|
|
|
|
|
return this.delete.includes(roomId)
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 15:52:59 +01:00
|
|
|
roomExist(roomId) {
|
2023-10-11 16:20:42 +01:00
|
|
|
return this.dm[roomId]?.id || this.group[roomId]?.id
|
2022-02-16 15:52:59 +01:00
|
|
|
}
|
2022-01-29 19:21:46 +01:00
|
|
|
|
|
|
|
|
getReceptorName(roomData) {
|
|
|
|
|
try {
|
2023-10-11 16:20:42 +01:00
|
|
|
return roomData.usernames.find((e) => e != SessionStore.user.UserName)
|
|
|
|
|
} catch (e) {
|
2022-01-29 19:21:46 +01:00
|
|
|
return '*'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 19:54:38 +01:00
|
|
|
/**
|
2022-01-29 20:01:16 +01:00
|
|
|
* @description update user status. this method is called once only
|
2022-01-29 19:54:38 +01:00
|
|
|
* @param id user ID
|
|
|
|
|
*/
|
2023-10-11 16:20:42 +01:00
|
|
|
private getUserStatus(id?: string) {
|
2022-02-02 10:28:36 +01:00
|
|
|
|
2023-01-09 10:49:58 +01:00
|
|
|
this.RochetChatConnectorService.getUserStatus(async (d) => {
|
2022-01-29 19:21:46 +01:00
|
|
|
|
2023-01-09 10:49:58 +01:00
|
|
|
const userId = d.fields.args[0][0]
|
2022-02-16 15:52:59 +01:00
|
|
|
const username = d.fields.args[0][1]
|
2023-09-22 17:25:27 +01:00
|
|
|
let statusNum = d.fields.args[0][2]
|
2022-02-02 10:28:36 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
const statusText = this.statusNumberToText(statusNum)
|
2022-01-29 19:33:32 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
for (const user in this.users) {
|
|
|
|
|
if (this.users[user]._id == userId) {
|
2023-09-22 17:25:27 +01:00
|
|
|
this.users[user].status = statusText
|
2022-03-03 22:57:33 +01:00
|
|
|
}
|
2023-01-09 10:49:58 +01:00
|
|
|
}
|
2022-01-29 19:33:32 +01:00
|
|
|
|
2023-09-26 10:29:29 +01:00
|
|
|
this.getUser()
|
|
|
|
|
|
2022-02-16 15:52:59 +01:00
|
|
|
})
|
2022-01-29 19:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getUserByName(username) {
|
2023-10-11 16:20:42 +01:00
|
|
|
return this.users.find((user) => user.username == username)
|
2022-01-29 19:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-29 20:16:39 +01:00
|
|
|
/**
|
|
|
|
|
* @description convert rocketchat statues num to readable string
|
2022-02-02 10:28:36 +01:00
|
|
|
* @param text
|
|
|
|
|
* @returns
|
2022-01-29 20:16:39 +01:00
|
|
|
*/
|
2022-01-29 19:21:46 +01:00
|
|
|
statusNumberToText(text) {
|
2023-10-11 16:20:42 +01:00
|
|
|
if (text == '0') {
|
2022-01-29 19:21:46 +01:00
|
|
|
return "offline"
|
|
|
|
|
}
|
2023-10-11 16:20:42 +01:00
|
|
|
else if (text == '1') {
|
2022-01-29 19:21:46 +01:00
|
|
|
return "online"
|
|
|
|
|
}
|
2023-10-11 16:20:42 +01:00
|
|
|
else if (text == '2') {
|
2022-01-29 19:21:46 +01:00
|
|
|
return "away"
|
|
|
|
|
}
|
2023-10-11 16:20:42 +01:00
|
|
|
else if (text == '3') {
|
2022-01-29 19:21:46 +01:00
|
|
|
return "busy"
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-02 10:28:36 +01:00
|
|
|
|
2022-01-29 19:21:46 +01:00
|
|
|
|
2022-01-28 15:31:52 +01:00
|
|
|
deleteMessage(id?) {
|
2022-09-30 15:13:36 +01:00
|
|
|
return this.RochetChatConnectorService.deleteMessage(id);
|
2022-01-28 15:31:52 +01:00
|
|
|
}
|
2022-01-26 16:37:59 +01:00
|
|
|
|
2022-01-26 09:19:54 +01:00
|
|
|
leaveRoom(id?) {
|
2022-09-30 15:13:36 +01:00
|
|
|
return this.RochetChatConnectorService.leaveRoom(id);
|
2022-01-26 09:19:54 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-11 17:15:01 +01:00
|
|
|
async hideRoom(id) {
|
2023-10-11 16:20:42 +01:00
|
|
|
this._dm.forEach((md, index) => {
|
|
|
|
|
if (md.id == id) {
|
2022-02-11 17:15:01 +01:00
|
|
|
this._dm.splice(index, 1)
|
|
|
|
|
delete this.dm[id]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
this._group.forEach((group, index) => {
|
|
|
|
|
if (group.id == id) {
|
2022-02-11 17:15:01 +01:00
|
|
|
this._group.splice(index, 1)
|
|
|
|
|
delete this.group[id]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 09:19:54 +01:00
|
|
|
hidingRoom(id?) {
|
2022-03-18 17:05:35 +01:00
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
return this.RochetChatConnectorService.hidingRoom(id).then(() => {
|
2022-03-18 17:05:35 +01:00
|
|
|
// this.hideRoom(id)
|
2022-02-16 15:52:59 +01:00
|
|
|
})
|
|
|
|
|
|
2022-01-26 09:19:54 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-08 16:09:40 +01:00
|
|
|
addRoomOwner(roomid, userId) {
|
2022-09-30 15:13:36 +01:00
|
|
|
return this.RochetChatConnectorService.addRoomOwner(roomid, userId);
|
2022-01-26 09:19:54 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
createPrivateRoom(groupName, username, customFields) {
|
2022-09-30 15:13:36 +01:00
|
|
|
return this.RochetChatConnectorService.createPrivateRoom(groupName, username, customFields);
|
2022-01-26 16:37:59 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-14 10:35:54 +01:00
|
|
|
getDmRoom(id): RoomService {
|
2022-01-12 12:44:51 +01:00
|
|
|
try {
|
|
|
|
|
return this.dm[id]
|
2023-10-11 16:20:42 +01:00
|
|
|
} catch (e) { }
|
2022-01-14 10:35:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getGroupRoom(id): RoomService {
|
|
|
|
|
try {
|
2022-01-12 12:44:51 +01:00
|
|
|
return this.group[id]
|
2023-10-11 16:20:42 +01:00
|
|
|
} catch (e) { }
|
2022-01-12 12:44:51 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 18:15:41 +01:00
|
|
|
getRoomName(roomData: room): string {
|
2023-10-11 16:20:42 +01:00
|
|
|
if (this.isIndividual(roomData)) {
|
2022-01-12 12:44:51 +01:00
|
|
|
const names: String[] = roomData.usernames
|
|
|
|
|
|
2023-10-19 15:03:12 +01:00
|
|
|
|
|
|
|
|
if (roomData.t == 'd') {
|
|
|
|
|
|
|
|
|
|
const username = roomData.usernames.find(e => e != SessionStore.user.UserName)
|
|
|
|
|
|
2022-12-17 17:08:13 +01:00
|
|
|
try {
|
2023-10-19 15:03:12 +01:00
|
|
|
const firstName = capitalizeTxt(username.split('.')[0])
|
|
|
|
|
const lastName = capitalizeTxt(username.split('.')[1])
|
|
|
|
|
|
2022-12-17 17:08:13 +01:00
|
|
|
return firstName + ' ' + lastName
|
2023-10-19 15:03:12 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
const username = roomData.usernames.find(e => e != SessionStore.user.UserName)
|
|
|
|
|
|
|
|
|
|
const firstName = capitalizeTxt(username.split('.')[0])
|
|
|
|
|
return firstName
|
2022-12-17 17:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-23 16:22:09 +01:00
|
|
|
} else {
|
2023-10-19 15:03:12 +01:00
|
|
|
if (roomData.t === 'p') {
|
|
|
|
|
return 'Loading'
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 'Loading'
|
|
|
|
|
}
|
2022-06-23 16:22:09 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-12 12:44:51 +01:00
|
|
|
} else {
|
2022-01-12 14:48:17 +01:00
|
|
|
return roomData.fname
|
2022-01-12 12:44:51 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
getRoomId(roomData: room) {
|
2022-01-14 10:46:44 +01:00
|
|
|
return roomData._id
|
2022-01-12 12:44:51 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
getRoomLastMessage(roomData: room): any {
|
2022-01-12 12:44:51 +01:00
|
|
|
return roomData.lastMessage
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 12:04:33 +01:00
|
|
|
private isIndividual(roomData: room) {
|
2022-01-12 12:44:51 +01:00
|
|
|
return !roomData.fname
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-24 15:56:47 +01:00
|
|
|
getUsers = () => {
|
2022-01-29 19:21:46 +01:00
|
|
|
return this.users
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getUser() {
|
|
|
|
|
|
2022-10-04 11:33:46 +01:00
|
|
|
this.loadingUsers = true
|
|
|
|
|
let _res
|
2022-01-29 19:21:46 +01:00
|
|
|
|
2022-10-04 11:33:46 +01:00
|
|
|
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);
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
users = users.filter((data) => !(data.name == 'Rocket.Cat' || data.name == 'Administrator'))
|
2023-03-31 14:54:03 +01:00
|
|
|
|
2022-10-04 11:33:46 +01:00
|
|
|
const userIds = this.users.map((user) => user._id)
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
for (let UserUpdate of users) {
|
|
|
|
|
if (userIds.includes(UserUpdate._id)) {
|
2022-10-04 11:33:46 +01:00
|
|
|
for (var index = 0; index < this.users.length; index++) {
|
2023-10-11 16:20:42 +01:00
|
|
|
if (UserUpdate._id == this.users[index]._id) {
|
2022-10-04 11:33:46 +01:00
|
|
|
this.users[index] = UserUpdate
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.users.push(UserUpdate)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
this.users = this.users.sort((a, b) => {
|
|
|
|
|
if (a.name < b.name) {
|
2022-01-29 19:24:46 +01:00
|
|
|
return -1;
|
|
|
|
|
}
|
2023-10-11 16:20:42 +01:00
|
|
|
if (a.name > b.name) {
|
2022-01-29 19:24:46 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
2022-01-29 19:21:46 +01:00
|
|
|
|
2023-06-19 12:15:39 +01:00
|
|
|
await this.storage.set('Users', this.users);
|
|
|
|
|
|
2022-10-04 11:33:46 +01:00
|
|
|
this.loadingUsers = false
|
2022-03-03 22:57:33 +01:00
|
|
|
|
2022-01-29 19:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
getUserOfRoom(roomId) {
|
2022-09-30 15:13:36 +01:00
|
|
|
return this.RochetChatConnectorService.getUserOfRoom(roomId);
|
2022-02-02 11:57:11 +01:00
|
|
|
}
|
|
|
|
|
|
2023-06-22 12:53:35 +01:00
|
|
|
|
|
|
|
|
async createGroup(name) {
|
|
|
|
|
const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, {});
|
2023-10-11 16:20:42 +01:00
|
|
|
if (res?.result?.rid) {
|
2023-06-22 12:53:35 +01:00
|
|
|
try {
|
|
|
|
|
await this.getAllRooms();
|
2023-10-11 16:20:42 +01:00
|
|
|
} catch (e) { }
|
2023-06-22 12:53:35 +01:00
|
|
|
return res
|
|
|
|
|
} else {
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 12:15:18 +01:00
|
|
|
|
|
|
|
|
async createGroup__(name, customFields = {}) {
|
|
|
|
|
const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, customFields);
|
|
|
|
|
console.log('room is created', res)
|
2023-10-11 16:20:42 +01:00
|
|
|
if (res?.result?.rid) {
|
2023-08-14 12:15:18 +01:00
|
|
|
try {
|
|
|
|
|
await this.getAllRooms();
|
|
|
|
|
return res
|
2023-10-11 16:20:42 +01:00
|
|
|
} catch (e) { }
|
2023-08-14 12:15:18 +01:00
|
|
|
console.log('room is loaded')
|
|
|
|
|
return res
|
|
|
|
|
} else {
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:20:42 +01:00
|
|
|
getGroupByName(name) {
|
|
|
|
|
return this._group.find(e => e.name == name)
|
2023-06-22 12:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
2023-10-11 16:20:42 +01:00
|
|
|
} catch (e) { }
|
2023-06-22 12:53:35 +01:00
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchContact(name, username) {
|
2023-10-11 16:20:42 +01:00
|
|
|
return this.users.find(e => e.name == name || e.username == username)
|
2023-06-22 12:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-12 12:44:51 +01:00
|
|
|
}
|