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_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 42;
CURRENT_PROJECT_VERSION = 43;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 94BRNM2LSS;
INFOPLIST_FILE = App/Info.plist;
@@ -419,7 +419,7 @@
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 42;
CURRENT_PROJECT_VERSION = 43;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 94BRNM2LSS;
INFOPLIST_FILE = App/Info.plist;
@@ -80,7 +80,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
durationDisplay = '';
duration = 0;
showAvatar = true;
audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null
audioPermissionStatus: 'granted' | 'denied' | 'prompt' | null = null
sessionStore = SessionStore
isAdmin = false;
constructor(
@@ -114,10 +114,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
};
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(' ')
this.open();
setTimeout(() => {
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() {
this.loggedUser = this.loggedUserChat;
@@ -166,7 +177,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.scrollChangeCallback = () => this.onContentScrolled(event);
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);
}
}
@@ -249,7 +260,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
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}`);
}
});
@@ -290,22 +301,22 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
async startRecording() {
VoiceRecorder.requestAudioRecordingPermission();
if(await VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) =>{return result.value})){
if(await VoiceRecorder.requestAudioRecordingPermission().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 this.hasAudioRecordingPermission()){
if (this.recording) {
return;
}
this.recording = true;
VoiceRecorder.startRecording();
this.calculateDuration();
if (this.recording) {
return;
}
this.recording = true;
VoiceRecorder.startRecording();
this.calculateDuration();
//}
}
else{
else {
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!');
}
}
@@ -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
} else {
this.isAdmin = false
@@ -534,7 +545,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
else if (res.data == 'edit') {
this.editGroup(this.roomId);
} else if (res.data == 'addUser') {
} else if (res.data == 'addUser') {
this.addContacts();
} else if (res.data == 'delete') {
@@ -796,7 +807,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
_getBase64(file) {
return new Promise((resolve, reject)=>{
return new Promise((resolve, reject) => {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
@@ -806,7 +817,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.log('Error: ', error);
};
})
}
}
async addFileToChat(types: typeof FileType[]) {
@@ -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") {
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);
})));
const blob = this.fileService.base64toBlob(encodedData, file.type)
@@ -909,7 +920,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
async addContacts() {
if(this.isAdmin) {
if (this.isAdmin) {
const modal = await this.modalController.create({
component: GroupContactsPage,
@@ -1011,7 +1022,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} else {
//Check if modal is opened
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);
});
await this.serverLongPull();
@@ -1100,9 +1111,9 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}).then((dir) => {
console.log('DIR ', dir)
this.fileOpener
.open(dir.uri, type)
.then(() => console.log())
.catch(e => console.error(e))
.open(dir.uri, type)
.then(() => console.log())
.catch(e => console.error(e))
});
}
@@ -1120,7 +1131,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
async openPreview(msg: MessageService) {
if(msg?.file?.type === "application/webtrix") {
if (msg?.file?.type === "application/webtrix") {
this.viewDocument(msg.file, msg.attachments.image_url)
} else {
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
@@ -1197,11 +1208,11 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
// set the bytes of the buffer to the correct values
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
ia[i] = byteString.charCodeAt(i);
}
// 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;
}
+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 { ChatSystemService } from 'src/app/services/chat/chat-system.service';
import { ChatService } from 'src/app/services/chat.service';
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
import { Platform } from '@ionic/angular';
import { FirstEnterService } from '../../services/first-enter.service';
import { Storage } from '@ionic/storage';
@@ -58,6 +59,7 @@ export class LoginPage implements OnInit {
private FirstEnterService: FirstEnterService,
private storage: Storage,
private storageService: StorageService,
private NotificationHolderService: NotificationHolderService
) { }
ngOnInit() { }
@@ -154,6 +156,7 @@ export class LoginPage implements OnInit {
this.RochetChatConnectorService.logout();
this.clearStoreService.clear();
this.ChatSystemService.clearChat();
this.NotificationHolderService.clear()
SessionStore.delete();
window.localStorage.clear();
await MessageModel.deleteAll();
+108 -101
View File
@@ -17,7 +17,7 @@ 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 { NetworkServiceService } from 'src/app/services/network-service.service';
import { ViewedMessageService } from './viewed-message.service'
import { NotificationsService } from '../notifications.service';
import { Subscribe } from '../subcribe';
@@ -30,8 +30,8 @@ const { App } = Plugins;
})
export class ChatSystemService {
dm: {[key: string]: RoomService} = {}
group: {[key: string]: RoomService} = {}
dm: { [key: string]: RoomService } = {}
group: { [key: string]: RoomService } = {}
_dm: RoomService[] = []
_group: RoomService[] = []
@@ -47,7 +47,7 @@ export class ChatSystemService {
delete = []
loadingUsers = false
onRoomsLoad = new Subscribe({execute : false, deleteOnExecute: true})
onRoomsLoad = new Subscribe({ execute: false, deleteOnExecute: true })
constructor(
@@ -61,9 +61,9 @@ export class ChatSystemService {
private NfService: NfService,
private changeProfileService: ChangeProfileService,
private chatService: ChatService,
private ChatMethodsService:ChatMethodsService,
private ChatMethodsService: ChatMethodsService,
private AESEncrypt: AESEncrypt,
private AttachmentsService:AttachmentsService,
private AttachmentsService: AttachmentsService,
private NetworkServiceService: NetworkServiceService,
private ViewedMessageService: ViewedMessageService,
private notificationService: NotificationsService
@@ -72,7 +72,7 @@ export class ChatSystemService {
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: async () => {
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.
@@ -87,8 +87,8 @@ export class ChatSystemService {
//
if(this.currentRoom) {
this.currentRoom.loadHistory({forceUpdate: true})
if (this.currentRoom) {
this.currentRoom.loadHistory({ forceUpdate: true })
}
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();
}
if(SessionStore.user?.ChatData?.data) {
if (SessionStore.user?.ChatData?.data) {
this.restoreRooms();
}
document.addEventListener('resume', () => {
this.RochetChatConnectorService.setStatus('online')
if(this._dm?.length == 0 && this._group?.length == 0) {
if (this._dm?.length == 0 && this._group?.length == 0) {
this.getAllRooms();
}
});
@@ -124,12 +124,12 @@ export class ChatSystemService {
// The app is in the foreground.
console.log('App is in the foreground');
this.currentRoom?.loadHistory({forceUpdate: true})
this.currentRoom?.loadHistory({ forceUpdate: true })
setTimeout(() => {
this.subscribeToRoom()
this.RochetChatConnectorService.setStatus('online')
},1000);
}, 1000);
/* this.reloadComponent(true) */
} else {
@@ -143,7 +143,7 @@ export class ChatSystemService {
}
loadChat() {
if(SessionStore.user?.ChatData?.data) {
if (SessionStore.user?.ChatData?.data) {
this.ReLoadChat()
}
}
@@ -153,7 +153,7 @@ export class ChatSystemService {
this.getUserStatus();
await this.chatService.refreshtoken();
await this.restoreUsers();
this.restoreUsers();
await this.getUser();
await this.restoreRooms();
await this.getAllRooms();
@@ -181,13 +181,13 @@ export class ChatSystemService {
openRoom(roomId) {
if(this.currentRoom) {
if (this.currentRoom) {
this.currentRoom.roomLeave()
}
if(this.getDmRoom(roomId)) {
if (this.getDmRoom(roomId)) {
this.currentRoom = this.getDmRoom(roomId)
} else if(this.getGroupRoom(roomId)) {
} else if (this.getGroupRoom(roomId)) {
this.currentRoom = this.getGroupRoom(roomId)
}
@@ -196,9 +196,9 @@ export class ChatSystemService {
}
getRoomById(roomId) {
if(this.getDmRoom(roomId)) {
if (this.getDmRoom(roomId)) {
return this.getDmRoom(roomId)
} else if(this.getGroupRoom(roomId)) {
} else if (this.getGroupRoom(roomId)) {
return this.getGroupRoom(roomId)
}
}
@@ -208,19 +208,19 @@ export class ChatSystemService {
try {
const _rooms = await this.storage.get('Rooms');
if(_rooms) {
for (let roomData of this.sortArrayISODate(_rooms)) {
if (_rooms) {
for (let roomData of this.sortArrayISODate(_rooms)) {
await this.prepareRoom(roomData);
}
}
} catch(e){}
} catch (e) { }
}
async restoreUsers () {
async restoreUsers() {
const users = await this.storage.get('Users');
if(users) {
if (users) {
this.users = users
}
@@ -228,45 +228,45 @@ export class ChatSystemService {
sortArrayISODate(messages: any): any[] {
return messages.sort((a,b) =>
new Date(b._updatedAt ).getTime()
return messages.sort((a, b) =>
new Date(b._updatedAt).getTime()
-
new Date(a._updatedAt).getTime())
}
async getAllRooms (callback:Function = () =>{} , roomIdCallback = "") {
async getAllRooms(callback: Function = () => { }, roomIdCallback = "") {
this.loadingWholeList = true
var rooms;
if(this.RochetChatConnectorService.isLogin) {
if (this.RochetChatConnectorService.isLogin) {
try {
rooms = await this.RochetChatConnectorService.getRooms();
} catch (error) {
this.loadingWholeList = false
console.error('chatgetrooms',error)
console.error('chatgetrooms', error)
}
try {
await this.storage.remove('Rooms');
} catch(e) {}
} catch (e) { }
}
let index = 0
let _rooms = rooms?.result?.update
if(_rooms) {
if (_rooms) {
_rooms = _rooms.map( e => {
_rooms = _rooms.map(e => {
e["_updatedAt"] = e._updatedAt || e._updatedAt['$date']
return e
})
for (let roomData of this.sortArrayISODate(_rooms) ) {
for (let roomData of this.sortArrayISODate(_rooms)) {
const roomId = this.getRoomId(roomData);
if(roomData.t == 'd') {
if (roomData.t == 'd') {
let error = false
let res;
@@ -278,7 +278,7 @@ export class ChatSystemService {
error = true
}
if(error) {
if (error) {
res = await this.chatService.getMembers(roomId).toPromise();
}
@@ -301,7 +301,7 @@ export class ChatSystemService {
error = true
}
if(error) {
if (error) {
res = await this.chatService.getGroupMembers(roomId).toPromise()
}
@@ -327,7 +327,7 @@ export class ChatSystemService {
error = true
}
if(error) {
if (error) {
res = await this.chatService.getChannelMembers(roomId).toPromise()
}
@@ -342,7 +342,7 @@ export class ChatSystemService {
}
if(roomId == roomIdCallback) {
if (roomId == roomIdCallback) {
callback()
}
@@ -363,8 +363,8 @@ export class ChatSystemService {
*/
sortRoomList = () => {
this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse()
this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse()
this._dm = this.sortService.sortDate(this._dm, '_updatedAt').reverse()
this._group = this.sortService.sortDate(this._group, '_updatedAt').reverse()
}
/**
@@ -380,9 +380,9 @@ export class ChatSystemService {
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);
if(!room.subscribeAttempt) {
room.subscribeAttempt = true;
if (!room.subscribeAttempt) {
try {
room.subscribeAttempt = true;
} catch (error) {
console.log("error")
}
this.RochetChatConnectorService.streamRoomMessages(id).then((subscription) => {
room.status.receive.message = true;
@@ -435,8 +442,8 @@ export class ChatSystemService {
private fix_updatedAt(message) {
if (message.result) {
message.result._updatedAt = message.result._updatedAt['$date']
} else if(message._updatedAt) {
if(message._updatedAt.hasOwnProperty('$date')) {
} else if (message._updatedAt) {
if (message._updatedAt.hasOwnProperty('$date')) {
message._updatedAt = message._updatedAt['$date']
}
}
@@ -462,18 +469,18 @@ export class ChatSystemService {
name: this.getRoomName(roomData),
t: roomData.t,
lastMessage: this.getRoomLastMessage(roomData),
_updatedAt: new Date( roomData._updatedAt || roomData._updatedAt['$date']),
u : roomData.u || {},
_updatedAt: new Date(roomData._updatedAt || roomData._updatedAt['$date']),
u: roomData.u || {},
members: roomData.members,
membersExcludeMe: roomData.membersExcludeMe
}
let roomId = this.getRoomId(roomData);
if (setData.name != 'Rocket Cat' && setData.name != 'general' ) {
if (setData.name != 'Rocket Cat' && setData.name != 'general') {
// 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)
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)
room.setData(setData)
room.receiveMessage()
room.getAllUsers = this.getUsers
@@ -483,7 +490,7 @@ export class ChatSystemService {
room.isGroup = !this.isIndividual(roomData)
// create individual room
if(this.isIndividual(roomData)) {
if (this.isIndividual(roomData)) {
this.dm[roomId] = 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,
// to redefine
if(this.dm[roomId]) {
if (this.dm[roomId]) {
this.dm[roomId].setData(setData)
} else if(this.group[roomId]) {
} else if (this.group[roomId]) {
this.group[roomId].setData(setData)
}
@@ -515,11 +522,11 @@ export class ChatSystemService {
}
deleteRoom =(roomId) => {
deleteRoom = (roomId) => {
this.delete.push(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) {
@@ -527,13 +534,13 @@ export class ChatSystemService {
}
roomExist(roomId) {
return this.dm[roomId]?.id || this.group[roomId]?.id
return this.dm[roomId]?.id || this.group[roomId]?.id
}
getReceptorName(roomData) {
try {
return roomData.usernames.find((e)=> e != SessionStore.user.UserName)
} catch(e) {
return roomData.usernames.find((e) => e != SessionStore.user.UserName)
} catch (e) {
return '*'
}
}
@@ -542,7 +549,7 @@ export class ChatSystemService {
* @description update user status. this method is called once only
* @param id user ID
*/
private getUserStatus(id?:string) {
private getUserStatus(id?: string) {
this.RochetChatConnectorService.getUserStatus(async (d) => {
@@ -552,8 +559,8 @@ export class ChatSystemService {
const statusText = this.statusNumberToText(statusNum)
for ( const user in this.users) {
if(this.users[user]._id == userId) {
for (const user in this.users) {
if (this.users[user]._id == userId) {
this.users[user].status = statusText
}
}
@@ -564,7 +571,7 @@ export class ChatSystemService {
}
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
*/
statusNumberToText(text) {
if(text == '0') {
if (text == '0') {
return "offline"
}
else if(text == '1') {
else if (text == '1') {
return "online"
}
else if(text == '2') {
else if (text == '2') {
return "away"
}
else if(text == '3') {
else if (text == '3') {
return "busy"
}
}
@@ -597,15 +604,15 @@ export class ChatSystemService {
}
async hideRoom(id) {
this._dm.forEach((md, index)=>{
if(md.id == 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.forEach((group, index) => {
if (group.id == id) {
this._group.splice(index, 1)
delete this.group[id]
}
@@ -614,7 +621,7 @@ export class ChatSystemService {
hidingRoom(id?) {
return this.RochetChatConnectorService.hidingRoom(id).then(()=>{
return this.RochetChatConnectorService.hidingRoom(id).then(() => {
// this.hideRoom(id)
})
@@ -624,39 +631,39 @@ export class ChatSystemService {
return this.RochetChatConnectorService.addRoomOwner(roomid, userId);
}
createPrivateRoom(groupName, username, customFields){
createPrivateRoom(groupName, username, customFields) {
return this.RochetChatConnectorService.createPrivateRoom(groupName, username, customFields);
}
getDmRoom(id): RoomService {
try {
return this.dm[id]
} catch(e) {}
} catch (e) { }
}
getGroupRoom(id): RoomService {
try {
return this.group[id]
} catch(e) {}
} catch (e) { }
}
getRoomName(roomData: room): string {
if(this.isIndividual(roomData)) {
if (this.isIndividual(roomData)) {
const names: String[] = roomData.usernames
const roomName = names.filter((name, index)=>{
const roomName = names.filter((name, index) => {
return name != SessionStore.user.UserName
})[0]
if(roomName) {
if (roomName) {
try {
const firstName = capitalizeTxt(roomName.split('.')[0])
const lastName = capitalizeTxt(roomName.split('.')[1])
const lastName = capitalizeTxt(roomName.split('.')[1])
return firstName + ' ' + lastName
} catch(e) {
} catch (e) {
return roomData['membersExcludeMe'][0].name
}
} else if(roomData.name) {
} else if (roomData.name) {
return roomData.name
} else {
return 'Sem nome'
@@ -668,11 +675,11 @@ export class ChatSystemService {
}
}
getRoomId(roomData:room) {
getRoomId(roomData: room) {
return roomData._id
}
getRoomLastMessage(roomData: room):any {
getRoomLastMessage(roomData: room): any {
return roomData.lastMessage
}
@@ -698,14 +705,14 @@ export class ChatSystemService {
let users: chatUser[] = _res['users'].filter(data => data.username != SessionStore.user.UserName);
users = users.filter((data) => !(data.name == 'Rocket.Cat' || data.name == 'Administrator'))
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 (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) {
if (UserUpdate._id == this.users[index]._id) {
this.users[index] = UserUpdate
}
}
@@ -714,11 +721,11 @@ export class ChatSystemService {
}
}
this.users = this.users.sort((a,b) => {
if(a.name < b.name) {
this.users = this.users.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if(a.name > b.name) {
if (a.name > b.name) {
return 1;
}
return 0;
@@ -730,7 +737,7 @@ export class ChatSystemService {
}
getUserOfRoom(roomId){
getUserOfRoom(roomId) {
return this.RochetChatConnectorService.getUserOfRoom(roomId);
}
@@ -738,10 +745,10 @@ export class ChatSystemService {
async createGroup(name) {
const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, {});
console.log('room is created', res)
if(res?.result?.rid) {
if (res?.result?.rid) {
try {
await this.getAllRooms();
} catch (e) {}
} catch (e) { }
console.log('room is loaded')
return res
} else {
@@ -753,11 +760,11 @@ export class ChatSystemService {
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) {
if (res?.result?.rid) {
try {
await this.getAllRooms();
return res
} catch (e) {}
} catch (e) { }
console.log('room is loaded')
return res
} else {
@@ -765,8 +772,8 @@ export class ChatSystemService {
}
}
getGroupByName(name ) {
return this._group.find( e=> e.name == name)
getGroupByName(name) {
return this._group.find(e => e.name == name)
}
async waitRoomToCreate(rid): Promise<RoomService> {
@@ -783,13 +790,13 @@ export class ChatSystemService {
try {
await this.getAllRooms();
} catch (e) {}
} catch (e) { }
})
}
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)
}
}
+18 -9
View File
@@ -18,7 +18,7 @@ export class NotificationHolderService {
try {
this.restore()
} catch(error) {}
} catch (error) { }
}
@@ -29,11 +29,11 @@ export class NotificationHolderService {
restore() {
this.storageService.get("Notifications").then((store) => {
if(Array.isArray(store)) {
if (Array.isArray(store)) {
this._notificationList = store
this.reverse()
}
}).catch((error) => {})
}).catch((error) => { })
}
save() {
@@ -107,10 +107,10 @@ export class NotificationHolderService {
}
}
if(!this.notificationExist(notificationObject)) {
if (!this.notificationExist(notificationObject)) {
this._notificationList.push(notificationObject)
this.zone.run(()=>{
this.zone.run(() => {
this.reverse()
this.save()
})
@@ -124,11 +124,11 @@ export class NotificationHolderService {
notificationExist(notificationObject) {
const notification = this._notificationList.find(item => {
const notification = this._notificationList.find(item => {
return item.id === notificationObject.id;
});
if(notification?.id) {
if (notification?.id) {
return true
} else {
return false
@@ -146,12 +146,21 @@ export class NotificationHolderService {
}
removeNotification(notification) {
this._notificationList = this._notificationList.filter( (e) => {
this._notificationList = this._notificationList.filter((e) => {
return e.index != notification.index
})
this.zone.run(()=>{
this.zone.run(() => {
this.save()
this.reverse()
})
}
clear() {
this._notificationList = []
this.zone.run(() => {
this.save()
this.reverse()
})