Merge branch 'feature/ios-notification' of https://bitbucket.org/equilibriumito/gabinete-digital-fo into feature/ios-notification

This commit is contained in:
Eudes Inácio
2023-10-11 17:16:50 +01:00
5 changed files with 172 additions and 142 deletions
+2 -2
View File
@@ -390,7 +390,7 @@
CODE_SIGN_ENTITLEMENTS = App/App.entitlements; CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 42; CURRENT_PROJECT_VERSION = 43;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 94BRNM2LSS; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 94BRNM2LSS;
INFOPLIST_FILE = App/Info.plist; INFOPLIST_FILE = App/Info.plist;
@@ -419,7 +419,7 @@
CODE_SIGN_ENTITLEMENTS = App/App.entitlements; CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 42; CURRENT_PROJECT_VERSION = 43;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 94BRNM2LSS; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 94BRNM2LSS;
INFOPLIST_FILE = App/Info.plist; INFOPLIST_FILE = App/Info.plist;
@@ -80,7 +80,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
durationDisplay = ''; durationDisplay = '';
duration = 0; duration = 0;
showAvatar = true; showAvatar = true;
audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null audioPermissionStatus: 'granted' | 'denied' | 'prompt' | null = null
sessionStore = SessionStore sessionStore = SessionStore
isAdmin = false; isAdmin = false;
constructor( constructor(
@@ -114,10 +114,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
}; };
this.ChatSystemService.getGroupRoom(this.roomId).loadHistory({}); this.open();
this.ChatSystemService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked;
this.ChatSystemService.openRoom(this.roomId)
this.groupNameFormart = this.ChatSystemService.getGroupRoom(this.roomId).name.split('-').join(' ')
setTimeout(() => { setTimeout(() => {
this.scrollToBottomClicked() this.scrollToBottomClicked()
@@ -133,6 +130,20 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
open() {
try {
this.ChatSystemService.getGroupRoom(this.roomId).loadHistory({});
this.ChatSystemService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked;
this.ChatSystemService.openRoom(this.roomId)
this.groupNameFormart = this.ChatSystemService.getGroupRoom(this.roomId).name.split('-').join(' ')
} catch (error) {
setTimeout(() => {
this.open()
}, 3000)
}
}
ngOnInit() { ngOnInit() {
this.loggedUser = this.loggedUserChat; this.loggedUser = this.loggedUserChat;
@@ -166,7 +177,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.scrollChangeCallback = () => this.onContentScrolled(event); this.scrollChangeCallback = () => this.onContentScrolled(event);
window.addEventListener('scroll', this.scrollChangeCallback, true); window.addEventListener('scroll', this.scrollChangeCallback, true);
if(this.room?.customFields?.countDownDate) { if (this.room?.customFields?.countDownDate) {
this.roomCountDownDate = this.timeService.countDownDate(this.room.customFields.countDownDate, this.room._id); this.roomCountDownDate = this.timeService.countDownDate(this.room.customFields.countDownDate, this.room._id);
} }
} }
@@ -249,7 +260,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
if (recordData?.value?.recordDataBase64.includes('data:audio')) { if (recordData?.value?.recordDataBase64.includes('data:audio')) {
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64); this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
} }
else if(recordData?.value?.mimeType && recordData?.value?.recordDataBase64) { else if (recordData?.value?.mimeType && recordData?.value?.recordDataBase64) {
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`); this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
} }
}); });
@@ -290,8 +301,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
async startRecording() { async startRecording() {
VoiceRecorder.requestAudioRecordingPermission(); VoiceRecorder.requestAudioRecordingPermission();
if(await VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) =>{return result.value})){ if (await VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) => { return result.value })) {
if(await VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => {return result.value})){ if (await VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => { return result.value })) {
//if(await this.hasAudioRecordingPermission()){ //if(await this.hasAudioRecordingPermission()){
if (this.recording) { if (this.recording) {
return; return;
@@ -301,11 +312,11 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.calculateDuration(); this.calculateDuration();
//} //}
} }
else{ else {
this.toastService._badRequest('Para gravar uma mensagem de voz, permita o acesso do Gabinete Digital ao seu microfone.'); this.toastService._badRequest('Para gravar uma mensagem de voz, permita o acesso do Gabinete Digital ao seu microfone.');
} }
} }
else{ else {
this.toastService._badRequest('Este dispositivo não tem capacidade para gravação de áudio!'); this.toastService._badRequest('Este dispositivo não tem capacidade para gravação de áudio!');
} }
} }
@@ -388,7 +399,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
if(SessionStore.user.ChatData.data.userId == this.room.u._id){ if (SessionStore.user.ChatData.data.userId == this.room.u._id) {
this.isAdmin = true this.isAdmin = true
} else { } else {
this.isAdmin = false this.isAdmin = false
@@ -796,7 +807,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
_getBase64(file) { _getBase64(file) {
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject) => {
var reader = new FileReader(); var reader = new FileReader();
reader.readAsDataURL(file); reader.readAsDataURL(file);
reader.onload = function () { reader.onload = function () {
@@ -818,7 +829,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") { if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => { const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch((error) => {
console.error(error); console.error(error);
}))); })));
const blob = this.fileService.base64toBlob(encodedData, file.type) const blob = this.fileService.base64toBlob(encodedData, file.type)
@@ -909,7 +920,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
async addContacts() { async addContacts() {
if(this.isAdmin) { if (this.isAdmin) {
const modal = await this.modalController.create({ const modal = await this.modalController.create({
component: GroupContactsPage, component: GroupContactsPage,
@@ -1011,7 +1022,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} else { } else {
//Check if modal is opened //Check if modal is opened
if (document.querySelector('.isGroupChatOpened')) { if (document.querySelector('.isGroupChatOpened')) {
await new Promise(resolve => setTimeout(resolve, 5000)).catch ((error) => { await new Promise(resolve => setTimeout(resolve, 5000)).catch((error) => {
console.error(error); console.error(error);
}); });
await this.serverLongPull(); await this.serverLongPull();
@@ -1120,7 +1131,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
async openPreview(msg: MessageService) { async openPreview(msg: MessageService) {
if(msg?.file?.type === "application/webtrix") { if (msg?.file?.type === "application/webtrix") {
this.viewDocument(msg.file, msg.attachments.image_url) this.viewDocument(msg.file, msg.attachments.image_url)
} else { } else {
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') { if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
@@ -1201,7 +1212,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
// write the ArrayBuffer to a blob, and you're done // write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ab], {type: mimeString}); var blob = new Blob([ab], { type: mimeString });
return blob; return blob;
} }
+3
View File
@@ -15,6 +15,7 @@ import { MessageModel, DeleteMessageModel } from '../../models/beast-orm';
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'; import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
import { ChatSystemService } from 'src/app/services/chat/chat-system.service'; import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
import { ChatService } from 'src/app/services/chat.service'; import { ChatService } from 'src/app/services/chat.service';
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
import { Platform } from '@ionic/angular'; import { Platform } from '@ionic/angular';
import { FirstEnterService } from '../../services/first-enter.service'; import { FirstEnterService } from '../../services/first-enter.service';
import { Storage } from '@ionic/storage'; import { Storage } from '@ionic/storage';
@@ -58,6 +59,7 @@ export class LoginPage implements OnInit {
private FirstEnterService: FirstEnterService, private FirstEnterService: FirstEnterService,
private storage: Storage, private storage: Storage,
private storageService: StorageService, private storageService: StorageService,
private NotificationHolderService: NotificationHolderService
) { } ) { }
ngOnInit() { } ngOnInit() { }
@@ -154,6 +156,7 @@ export class LoginPage implements OnInit {
this.RochetChatConnectorService.logout(); this.RochetChatConnectorService.logout();
this.clearStoreService.clear(); this.clearStoreService.clear();
this.ChatSystemService.clearChat(); this.ChatSystemService.clearChat();
this.NotificationHolderService.clear()
SessionStore.delete(); SessionStore.delete();
window.localStorage.clear(); window.localStorage.clear();
await MessageModel.deleteAll(); await MessageModel.deleteAll();
+102 -95
View File
@@ -17,7 +17,7 @@ import { ChangeProfileService } from '../change-profile.service';
import { ChatMethodsService } from './chat-methods.service'; import { ChatMethodsService } from './chat-methods.service';
import { AESEncrypt } from '../aesencrypt.service' import { AESEncrypt } from '../aesencrypt.service'
import { AttachmentsService } from 'src/app/services/attachments.service'; import { AttachmentsService } from 'src/app/services/attachments.service';
import { NetworkServiceService} from 'src/app/services/network-service.service'; import { NetworkServiceService } from 'src/app/services/network-service.service';
import { ViewedMessageService } from './viewed-message.service' import { ViewedMessageService } from './viewed-message.service'
import { NotificationsService } from '../notifications.service'; import { NotificationsService } from '../notifications.service';
import { Subscribe } from '../subcribe'; import { Subscribe } from '../subcribe';
@@ -30,8 +30,8 @@ const { App } = Plugins;
}) })
export class ChatSystemService { export class ChatSystemService {
dm: {[key: string]: RoomService} = {} dm: { [key: string]: RoomService } = {}
group: {[key: string]: RoomService} = {} group: { [key: string]: RoomService } = {}
_dm: RoomService[] = [] _dm: RoomService[] = []
_group: RoomService[] = [] _group: RoomService[] = []
@@ -47,7 +47,7 @@ export class ChatSystemService {
delete = [] delete = []
loadingUsers = false loadingUsers = false
onRoomsLoad = new Subscribe({execute : false, deleteOnExecute: true}) onRoomsLoad = new Subscribe({ execute: false, deleteOnExecute: true })
constructor( constructor(
@@ -61,9 +61,9 @@ export class ChatSystemService {
private NfService: NfService, private NfService: NfService,
private changeProfileService: ChangeProfileService, private changeProfileService: ChangeProfileService,
private chatService: ChatService, private chatService: ChatService,
private ChatMethodsService:ChatMethodsService, private ChatMethodsService: ChatMethodsService,
private AESEncrypt: AESEncrypt, private AESEncrypt: AESEncrypt,
private AttachmentsService:AttachmentsService, private AttachmentsService: AttachmentsService,
private NetworkServiceService: NetworkServiceService, private NetworkServiceService: NetworkServiceService,
private ViewedMessageService: ViewedMessageService, private ViewedMessageService: ViewedMessageService,
private notificationService: NotificationsService private notificationService: NotificationsService
@@ -87,8 +87,8 @@ export class ChatSystemService {
// //
if(this.currentRoom) { if (this.currentRoom) {
this.currentRoom.loadHistory({forceUpdate: true}) this.currentRoom.loadHistory({ forceUpdate: true })
} }
for (const id in this.dm) { for (const id in this.dm) {
@@ -102,18 +102,18 @@ export class ChatSystemService {
} }
}) })
if(this.sessionStore.user.Inactivity) { if (this.sessionStore.user.Inactivity) {
this.loadChat(); this.loadChat();
} }
if(SessionStore.user?.ChatData?.data) { if (SessionStore.user?.ChatData?.data) {
this.restoreRooms(); this.restoreRooms();
} }
document.addEventListener('resume', () => { document.addEventListener('resume', () => {
this.RochetChatConnectorService.setStatus('online') this.RochetChatConnectorService.setStatus('online')
if(this._dm?.length == 0 && this._group?.length == 0) { if (this._dm?.length == 0 && this._group?.length == 0) {
this.getAllRooms(); this.getAllRooms();
} }
}); });
@@ -124,12 +124,12 @@ export class ChatSystemService {
// The app is in the foreground. // The app is in the foreground.
console.log('App is in the foreground'); console.log('App is in the foreground');
this.currentRoom?.loadHistory({forceUpdate: true}) this.currentRoom?.loadHistory({ forceUpdate: true })
setTimeout(() => { setTimeout(() => {
this.subscribeToRoom() this.subscribeToRoom()
this.RochetChatConnectorService.setStatus('online') this.RochetChatConnectorService.setStatus('online')
},1000); }, 1000);
/* this.reloadComponent(true) */ /* this.reloadComponent(true) */
} else { } else {
@@ -143,7 +143,7 @@ export class ChatSystemService {
} }
loadChat() { loadChat() {
if(SessionStore.user?.ChatData?.data) { if (SessionStore.user?.ChatData?.data) {
this.ReLoadChat() this.ReLoadChat()
} }
} }
@@ -153,7 +153,7 @@ export class ChatSystemService {
this.getUserStatus(); this.getUserStatus();
await this.chatService.refreshtoken(); await this.chatService.refreshtoken();
await this.restoreUsers(); this.restoreUsers();
await this.getUser(); await this.getUser();
await this.restoreRooms(); await this.restoreRooms();
await this.getAllRooms(); await this.getAllRooms();
@@ -181,13 +181,13 @@ export class ChatSystemService {
openRoom(roomId) { openRoom(roomId) {
if(this.currentRoom) { if (this.currentRoom) {
this.currentRoom.roomLeave() this.currentRoom.roomLeave()
} }
if(this.getDmRoom(roomId)) { if (this.getDmRoom(roomId)) {
this.currentRoom = this.getDmRoom(roomId) this.currentRoom = this.getDmRoom(roomId)
} else if(this.getGroupRoom(roomId)) { } else if (this.getGroupRoom(roomId)) {
this.currentRoom = this.getGroupRoom(roomId) this.currentRoom = this.getGroupRoom(roomId)
} }
@@ -196,9 +196,9 @@ export class ChatSystemService {
} }
getRoomById(roomId) { getRoomById(roomId) {
if(this.getDmRoom(roomId)) { if (this.getDmRoom(roomId)) {
return this.getDmRoom(roomId) return this.getDmRoom(roomId)
} else if(this.getGroupRoom(roomId)) { } else if (this.getGroupRoom(roomId)) {
return this.getGroupRoom(roomId) return this.getGroupRoom(roomId)
} }
} }
@@ -208,19 +208,19 @@ export class ChatSystemService {
try { try {
const _rooms = await this.storage.get('Rooms'); const _rooms = await this.storage.get('Rooms');
if(_rooms) { if (_rooms) {
for (let roomData of this.sortArrayISODate(_rooms)) { for (let roomData of this.sortArrayISODate(_rooms)) {
await this.prepareRoom(roomData); await this.prepareRoom(roomData);
} }
} }
} catch(e){} } catch (e) { }
} }
async restoreUsers () { async restoreUsers() {
const users = await this.storage.get('Users'); const users = await this.storage.get('Users');
if(users) { if (users) {
this.users = users this.users = users
} }
@@ -228,45 +228,45 @@ export class ChatSystemService {
sortArrayISODate(messages: any): any[] { sortArrayISODate(messages: any): any[] {
return messages.sort((a,b) => return messages.sort((a, b) =>
new Date(b._updatedAt ).getTime() new Date(b._updatedAt).getTime()
- -
new Date(a._updatedAt).getTime()) new Date(a._updatedAt).getTime())
} }
async getAllRooms (callback:Function = () =>{} , roomIdCallback = "") { async getAllRooms(callback: Function = () => { }, roomIdCallback = "") {
this.loadingWholeList = true this.loadingWholeList = true
var rooms; var rooms;
if(this.RochetChatConnectorService.isLogin) { if (this.RochetChatConnectorService.isLogin) {
try { try {
rooms = await this.RochetChatConnectorService.getRooms(); rooms = await this.RochetChatConnectorService.getRooms();
} catch (error) { } catch (error) {
this.loadingWholeList = false this.loadingWholeList = false
console.error('chatgetrooms',error) console.error('chatgetrooms', error)
} }
try { try {
await this.storage.remove('Rooms'); await this.storage.remove('Rooms');
} catch(e) {} } catch (e) { }
} }
let index = 0 let index = 0
let _rooms = rooms?.result?.update let _rooms = rooms?.result?.update
if(_rooms) { if (_rooms) {
_rooms = _rooms.map( e => { _rooms = _rooms.map(e => {
e["_updatedAt"] = e._updatedAt || e._updatedAt['$date'] e["_updatedAt"] = e._updatedAt || e._updatedAt['$date']
return e return e
}) })
for (let roomData of this.sortArrayISODate(_rooms) ) { for (let roomData of this.sortArrayISODate(_rooms)) {
const roomId = this.getRoomId(roomData); const roomId = this.getRoomId(roomData);
if(roomData.t == 'd') { if (roomData.t == 'd') {
let error = false let error = false
let res; let res;
@@ -278,7 +278,7 @@ export class ChatSystemService {
error = true error = true
} }
if(error) { if (error) {
res = await this.chatService.getMembers(roomId).toPromise(); res = await this.chatService.getMembers(roomId).toPromise();
} }
@@ -301,7 +301,7 @@ export class ChatSystemService {
error = true error = true
} }
if(error) { if (error) {
res = await this.chatService.getGroupMembers(roomId).toPromise() res = await this.chatService.getGroupMembers(roomId).toPromise()
} }
@@ -327,7 +327,7 @@ export class ChatSystemService {
error = true error = true
} }
if(error) { if (error) {
res = await this.chatService.getChannelMembers(roomId).toPromise() res = await this.chatService.getChannelMembers(roomId).toPromise()
} }
@@ -342,7 +342,7 @@ export class ChatSystemService {
} }
if(roomId == roomIdCallback) { if (roomId == roomIdCallback) {
callback() callback()
} }
@@ -363,8 +363,8 @@ export class ChatSystemService {
*/ */
sortRoomList = () => { sortRoomList = () => {
this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse() this._dm = this.sortService.sortDate(this._dm, '_updatedAt').reverse()
this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse() this._group = this.sortService.sortDate(this._group, '_updatedAt').reverse()
} }
/** /**
@@ -380,9 +380,9 @@ export class ChatSystemService {
this.defaultSubtribe(id) this.defaultSubtribe(id)
} }
this.RochetChatConnectorService.streamNotifyLogged().then((subscription => {})) this.RochetChatConnectorService.streamNotifyLogged().then((subscription => { }))
this.RochetChatConnectorService.subStreamMessageUser().then((subscription => {})) this.RochetChatConnectorService.subStreamMessageUser().then((subscription => { }))
} }
/** /**
@@ -409,8 +409,15 @@ export class ChatSystemService {
const room = this.getRoomById(id); const room = this.getRoomById(id);
if(!room.subscribeAttempt) { if (!room.subscribeAttempt) {
try {
room.subscribeAttempt = true; room.subscribeAttempt = true;
} catch (error) {
console.log("error")
}
this.RochetChatConnectorService.streamRoomMessages(id).then((subscription) => { this.RochetChatConnectorService.streamRoomMessages(id).then((subscription) => {
room.status.receive.message = true; room.status.receive.message = true;
@@ -435,8 +442,8 @@ export class ChatSystemService {
private fix_updatedAt(message) { private fix_updatedAt(message) {
if (message.result) { if (message.result) {
message.result._updatedAt = message.result._updatedAt['$date'] message.result._updatedAt = message.result._updatedAt['$date']
} else if(message._updatedAt) { } else if (message._updatedAt) {
if(message._updatedAt.hasOwnProperty('$date')) { if (message._updatedAt.hasOwnProperty('$date')) {
message._updatedAt = message._updatedAt['$date'] message._updatedAt = message._updatedAt['$date']
} }
} }
@@ -462,18 +469,18 @@ export class ChatSystemService {
name: this.getRoomName(roomData), name: this.getRoomName(roomData),
t: roomData.t, t: roomData.t,
lastMessage: this.getRoomLastMessage(roomData), lastMessage: this.getRoomLastMessage(roomData),
_updatedAt: new Date( roomData._updatedAt || roomData._updatedAt['$date']), _updatedAt: new Date(roomData._updatedAt || roomData._updatedAt['$date']),
u : roomData.u || {}, u: roomData.u || {},
members: roomData.members, members: roomData.members,
membersExcludeMe: roomData.membersExcludeMe membersExcludeMe: roomData.membersExcludeMe
} }
let roomId = this.getRoomId(roomData); let roomId = this.getRoomId(roomData);
if (setData.name != 'Rocket Cat' && setData.name != 'general' ) { if (setData.name != 'Rocket Cat' && setData.name != 'general') {
// create room // create room
if(!this.roomExist(roomId)) { 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) 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)
room.setData(setData) room.setData(setData)
room.receiveMessage() room.receiveMessage()
room.getAllUsers = this.getUsers room.getAllUsers = this.getUsers
@@ -483,7 +490,7 @@ export class ChatSystemService {
room.isGroup = !this.isIndividual(roomData) room.isGroup = !this.isIndividual(roomData)
// create individual room // create individual room
if(this.isIndividual(roomData)) { if (this.isIndividual(roomData)) {
this.dm[roomId] = room this.dm[roomId] = room
this._dm.push(room) this._dm.push(room)
@@ -503,9 +510,9 @@ export class ChatSystemService {
// in this case room is already present, therefor it will only be necessary, // in this case room is already present, therefor it will only be necessary,
// to redefine // to redefine
if(this.dm[roomId]) { if (this.dm[roomId]) {
this.dm[roomId].setData(setData) this.dm[roomId].setData(setData)
} else if(this.group[roomId]) { } else if (this.group[roomId]) {
this.group[roomId].setData(setData) this.group[roomId].setData(setData)
} }
@@ -515,11 +522,11 @@ export class ChatSystemService {
} }
deleteRoom =(roomId) => { deleteRoom = (roomId) => {
this.delete.push(roomId) this.delete.push(roomId)
delete this.group[roomId]; delete this.group[roomId];
this._group = this._group.filter((e)=> e.id != roomId); this._group = this._group.filter((e) => e.id != roomId);
} }
deleteRecently(roomId) { deleteRecently(roomId) {
@@ -532,8 +539,8 @@ export class ChatSystemService {
getReceptorName(roomData) { getReceptorName(roomData) {
try { try {
return roomData.usernames.find((e)=> e != SessionStore.user.UserName) return roomData.usernames.find((e) => e != SessionStore.user.UserName)
} catch(e) { } catch (e) {
return '*' return '*'
} }
} }
@@ -542,7 +549,7 @@ export class ChatSystemService {
* @description update user status. this method is called once only * @description update user status. this method is called once only
* @param id user ID * @param id user ID
*/ */
private getUserStatus(id?:string) { private getUserStatus(id?: string) {
this.RochetChatConnectorService.getUserStatus(async (d) => { this.RochetChatConnectorService.getUserStatus(async (d) => {
@@ -552,8 +559,8 @@ export class ChatSystemService {
const statusText = this.statusNumberToText(statusNum) const statusText = this.statusNumberToText(statusNum)
for ( const user in this.users) { for (const user in this.users) {
if(this.users[user]._id == userId) { if (this.users[user]._id == userId) {
this.users[user].status = statusText this.users[user].status = statusText
} }
} }
@@ -564,7 +571,7 @@ export class ChatSystemService {
} }
getUserByName(username) { getUserByName(username) {
return this.users.find((user)=> user.username == username) return this.users.find((user) => user.username == username)
} }
/** /**
@@ -573,16 +580,16 @@ export class ChatSystemService {
* @returns * @returns
*/ */
statusNumberToText(text) { statusNumberToText(text) {
if(text == '0') { if (text == '0') {
return "offline" return "offline"
} }
else if(text == '1') { else if (text == '1') {
return "online" return "online"
} }
else if(text == '2') { else if (text == '2') {
return "away" return "away"
} }
else if(text == '3') { else if (text == '3') {
return "busy" return "busy"
} }
} }
@@ -597,15 +604,15 @@ export class ChatSystemService {
} }
async hideRoom(id) { async hideRoom(id) {
this._dm.forEach((md, index)=>{ this._dm.forEach((md, index) => {
if(md.id == id) { if (md.id == id) {
this._dm.splice(index, 1) this._dm.splice(index, 1)
delete this.dm[id] delete this.dm[id]
} }
}); });
this._group.forEach((group, index)=>{ this._group.forEach((group, index) => {
if(group.id == id) { if (group.id == id) {
this._group.splice(index, 1) this._group.splice(index, 1)
delete this.group[id] delete this.group[id]
} }
@@ -614,7 +621,7 @@ export class ChatSystemService {
hidingRoom(id?) { hidingRoom(id?) {
return this.RochetChatConnectorService.hidingRoom(id).then(()=>{ return this.RochetChatConnectorService.hidingRoom(id).then(() => {
// this.hideRoom(id) // this.hideRoom(id)
}) })
@@ -624,39 +631,39 @@ export class ChatSystemService {
return this.RochetChatConnectorService.addRoomOwner(roomid, userId); return this.RochetChatConnectorService.addRoomOwner(roomid, userId);
} }
createPrivateRoom(groupName, username, customFields){ createPrivateRoom(groupName, username, customFields) {
return this.RochetChatConnectorService.createPrivateRoom(groupName, username, customFields); return this.RochetChatConnectorService.createPrivateRoom(groupName, username, customFields);
} }
getDmRoom(id): RoomService { getDmRoom(id): RoomService {
try { try {
return this.dm[id] return this.dm[id]
} catch(e) {} } catch (e) { }
} }
getGroupRoom(id): RoomService { getGroupRoom(id): RoomService {
try { try {
return this.group[id] return this.group[id]
} catch(e) {} } catch (e) { }
} }
getRoomName(roomData: room): string { getRoomName(roomData: room): string {
if(this.isIndividual(roomData)) { if (this.isIndividual(roomData)) {
const names: String[] = roomData.usernames const names: String[] = roomData.usernames
const roomName = names.filter((name, index)=>{ const roomName = names.filter((name, index) => {
return name != SessionStore.user.UserName return name != SessionStore.user.UserName
})[0] })[0]
if(roomName) { if (roomName) {
try { try {
const firstName = capitalizeTxt(roomName.split('.')[0]) const firstName = capitalizeTxt(roomName.split('.')[0])
const lastName = capitalizeTxt(roomName.split('.')[1]) const lastName = capitalizeTxt(roomName.split('.')[1])
return firstName + ' ' + lastName return firstName + ' ' + lastName
} catch(e) { } catch (e) {
return roomData['membersExcludeMe'][0].name return roomData['membersExcludeMe'][0].name
} }
} else if(roomData.name) { } else if (roomData.name) {
return roomData.name return roomData.name
} else { } else {
return 'Sem nome' return 'Sem nome'
@@ -668,11 +675,11 @@ export class ChatSystemService {
} }
} }
getRoomId(roomData:room) { getRoomId(roomData: room) {
return roomData._id return roomData._id
} }
getRoomLastMessage(roomData: room):any { getRoomLastMessage(roomData: room): any {
return roomData.lastMessage return roomData.lastMessage
} }
@@ -702,10 +709,10 @@ export class ChatSystemService {
const userIds = this.users.map((user) => user._id) const userIds = this.users.map((user) => user._id)
for(let UserUpdate of users) { for (let UserUpdate of users) {
if(userIds.includes(UserUpdate._id)) { if (userIds.includes(UserUpdate._id)) {
for (var index = 0; index < this.users.length; index++) { for (var index = 0; index < this.users.length; index++) {
if(UserUpdate._id == this.users[index]._id) { if (UserUpdate._id == this.users[index]._id) {
this.users[index] = UserUpdate this.users[index] = UserUpdate
} }
} }
@@ -714,11 +721,11 @@ export class ChatSystemService {
} }
} }
this.users = this.users.sort((a,b) => { this.users = this.users.sort((a, b) => {
if(a.name < b.name) { if (a.name < b.name) {
return -1; return -1;
} }
if(a.name > b.name) { if (a.name > b.name) {
return 1; return 1;
} }
return 0; return 0;
@@ -730,7 +737,7 @@ export class ChatSystemService {
} }
getUserOfRoom(roomId){ getUserOfRoom(roomId) {
return this.RochetChatConnectorService.getUserOfRoom(roomId); return this.RochetChatConnectorService.getUserOfRoom(roomId);
} }
@@ -738,10 +745,10 @@ export class ChatSystemService {
async createGroup(name) { async createGroup(name) {
const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, {}); const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, {});
console.log('room is created', res) console.log('room is created', res)
if(res?.result?.rid) { if (res?.result?.rid) {
try { try {
await this.getAllRooms(); await this.getAllRooms();
} catch (e) {} } catch (e) { }
console.log('room is loaded') console.log('room is loaded')
return res return res
} else { } else {
@@ -753,11 +760,11 @@ export class ChatSystemService {
async createGroup__(name, customFields = {}) { async createGroup__(name, customFields = {}) {
const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, customFields); const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, customFields);
console.log('room is created', res) console.log('room is created', res)
if(res?.result?.rid) { if (res?.result?.rid) {
try { try {
await this.getAllRooms(); await this.getAllRooms();
return res return res
} catch (e) {} } catch (e) { }
console.log('room is loaded') console.log('room is loaded')
return res return res
} else { } else {
@@ -765,8 +772,8 @@ export class ChatSystemService {
} }
} }
getGroupByName(name ) { getGroupByName(name) {
return this._group.find( e=> e.name == name) return this._group.find(e => e.name == name)
} }
async waitRoomToCreate(rid): Promise<RoomService> { async waitRoomToCreate(rid): Promise<RoomService> {
@@ -783,13 +790,13 @@ export class ChatSystemService {
try { try {
await this.getAllRooms(); await this.getAllRooms();
} catch (e) {} } catch (e) { }
}) })
} }
searchContact(name, username) { searchContact(name, username) {
return this.users.find( e=> e.name == name || e.username == username) return this.users.find(e => e.name == name || e.username == username)
} }
} }
+17 -8
View File
@@ -18,7 +18,7 @@ export class NotificationHolderService {
try { try {
this.restore() this.restore()
} catch(error) {} } catch (error) { }
} }
@@ -29,11 +29,11 @@ export class NotificationHolderService {
restore() { restore() {
this.storageService.get("Notifications").then((store) => { this.storageService.get("Notifications").then((store) => {
if(Array.isArray(store)) { if (Array.isArray(store)) {
this._notificationList = store this._notificationList = store
this.reverse() this.reverse()
} }
}).catch((error) => {}) }).catch((error) => { })
} }
save() { save() {
@@ -107,10 +107,10 @@ export class NotificationHolderService {
} }
} }
if(!this.notificationExist(notificationObject)) { if (!this.notificationExist(notificationObject)) {
this._notificationList.push(notificationObject) this._notificationList.push(notificationObject)
this.zone.run(()=>{ this.zone.run(() => {
this.reverse() this.reverse()
this.save() this.save()
}) })
@@ -128,7 +128,7 @@ export class NotificationHolderService {
return item.id === notificationObject.id; return item.id === notificationObject.id;
}); });
if(notification?.id) { if (notification?.id) {
return true return true
} else { } else {
return false return false
@@ -146,12 +146,21 @@ export class NotificationHolderService {
} }
removeNotification(notification) { removeNotification(notification) {
this._notificationList = this._notificationList.filter( (e) => { this._notificationList = this._notificationList.filter((e) => {
return e.index != notification.index return e.index != notification.index
}) })
this.zone.run(()=>{ this.zone.run(() => {
this.save()
this.reverse()
})
}
clear() {
this._notificationList = []
this.zone.run(() => {
this.save() this.save()
this.reverse() this.reverse()
}) })