mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
performace
This commit is contained in:
@@ -33,7 +33,7 @@ export class AuthService {
|
||||
opts:any;
|
||||
|
||||
tabIsActive = true
|
||||
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private storageService:StorageService,
|
||||
@@ -62,7 +62,7 @@ export class AuthService {
|
||||
if(!this.tabIsActive) {
|
||||
this.tabIsActive = true
|
||||
const data = SessionStore.getDataFromLocalStorage();
|
||||
|
||||
|
||||
if(!data?.user?.Authorization && SessionStore?.user?.Authorization) {
|
||||
window.location.reload();
|
||||
}
|
||||
@@ -72,7 +72,7 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
window.addEventListener('blur', (event) => {
|
||||
this.tabIsActive = false
|
||||
});
|
||||
@@ -91,7 +91,7 @@ export class AuthService {
|
||||
|
||||
try {
|
||||
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
|
||||
|
||||
|
||||
|
||||
if(saveSession) {
|
||||
this.SetSession(response, user)
|
||||
@@ -152,7 +152,7 @@ export class AuthService {
|
||||
}else {
|
||||
session.Profile = 'Unknown'
|
||||
}
|
||||
|
||||
|
||||
session.Password = user.password
|
||||
session.BasicAuthKey = user.BasicAuthKey
|
||||
SessionStore.reset(session)
|
||||
@@ -165,11 +165,11 @@ export class AuthService {
|
||||
|
||||
loginToChatWs() {
|
||||
setTimeout(() => {
|
||||
|
||||
|
||||
if(SessionStore.user.ChatData?.data) {
|
||||
this.RochetChatConnectorService.connect();
|
||||
this.RochetChatConnectorService.login().then((message: any) => {
|
||||
|
||||
|
||||
SessionStore.user.RochetChatUserId = message.result.id
|
||||
SessionStore.save()
|
||||
|
||||
@@ -179,13 +179,13 @@ export class AuthService {
|
||||
this.ChatSystemService.getAllRooms();
|
||||
this.RochetChatConnectorService.setStatus('online')
|
||||
}, 200);
|
||||
|
||||
|
||||
|
||||
}).catch((error) => {
|
||||
// console.error(SessionStore.user.ChatData, 'web socket login',error)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// before sending a message with a attachment
|
||||
@@ -200,6 +200,7 @@ export class AuthService {
|
||||
message.file.guid = guid.path
|
||||
|
||||
message.downloadFileMsg()
|
||||
message.uploadingFile = false
|
||||
|
||||
return true
|
||||
} catch(e) {
|
||||
@@ -219,10 +220,11 @@ export class AuthService {
|
||||
message.attachments[0].title_link = url_no_options
|
||||
message.attachments[0].message_link = url_no_options
|
||||
|
||||
return true
|
||||
message.uploadingFile = false
|
||||
|
||||
return true
|
||||
} catch(e) {
|
||||
window['e'] = e
|
||||
window['e'] = e
|
||||
console.error('BeforesendAtachment', e)
|
||||
message.uploadingFile = false
|
||||
return false
|
||||
@@ -235,7 +237,7 @@ export class AuthService {
|
||||
|
||||
this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => {
|
||||
|
||||
//
|
||||
//
|
||||
let downloadFile = "";
|
||||
if (message.file.type == "application/img") {
|
||||
const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise();
|
||||
@@ -279,7 +281,7 @@ export class AuthService {
|
||||
|
||||
logoutChat() {
|
||||
}
|
||||
|
||||
|
||||
async presentAlert(message: string) {
|
||||
const alert = await this.alertController.create({
|
||||
cssClass: 'my-custom-class',
|
||||
|
||||
@@ -206,19 +206,15 @@ export class ChatSystemService {
|
||||
async restoreRooms() {
|
||||
|
||||
try {
|
||||
const rooms = await this.storage.get('Rooms');
|
||||
const _rooms = await this.storage.get('Rooms');
|
||||
|
||||
if(rooms) {
|
||||
for (let roomData of rooms.result.update) {
|
||||
if(_rooms) {
|
||||
for (let roomData of this.sortArrayISODate(_rooms)) {
|
||||
await this.prepareRoom(roomData);
|
||||
}
|
||||
}
|
||||
} catch(e){}
|
||||
|
||||
setTimeout(() => {
|
||||
this.sortRoomList()
|
||||
}, 10000)
|
||||
|
||||
}
|
||||
|
||||
async restoreUsers () {
|
||||
@@ -230,6 +226,14 @@ export class ChatSystemService {
|
||||
}
|
||||
}
|
||||
|
||||
sortArrayISODate(messages: any): any[] {
|
||||
|
||||
return messages.sort((a,b) =>
|
||||
new Date(b._updatedAt ).getTime()
|
||||
-
|
||||
new Date(a._updatedAt).getTime())
|
||||
}
|
||||
|
||||
async getAllRooms (callback:Function = () =>{} , roomIdCallback = "") {
|
||||
this.loadingWholeList = true
|
||||
var rooms;
|
||||
@@ -248,8 +252,17 @@ export class ChatSystemService {
|
||||
|
||||
let index = 0
|
||||
|
||||
if(rooms?.result?.update) {
|
||||
for (let roomData of rooms.result.update) {
|
||||
let _rooms = rooms?.result?.update
|
||||
|
||||
if(_rooms) {
|
||||
|
||||
_rooms = _rooms.map( e => {
|
||||
e["_updatedAt"] = e._updatedAt || e._updatedAt['$date']
|
||||
return e
|
||||
})
|
||||
|
||||
for (let roomData of this.sortArrayISODate(_rooms) ) {
|
||||
|
||||
|
||||
const roomId = this.getRoomId(roomData);
|
||||
|
||||
@@ -272,8 +285,8 @@ export class ChatSystemService {
|
||||
|
||||
const members = res['members'];
|
||||
const users = members.filter(data => data.username != this.sessionStore.user.UserName);
|
||||
rooms.result.update[index]['members'] = members
|
||||
rooms.result.update[index]['membersExcludeMe'] = users
|
||||
_rooms[index]['members'] = members
|
||||
_rooms[index]['membersExcludeMe'] = users
|
||||
|
||||
await this.prepareRoom(roomData);
|
||||
} else {
|
||||
@@ -295,8 +308,8 @@ export class ChatSystemService {
|
||||
const members = res['members'];
|
||||
const users = members.filter(data => data.username != this.sessionStore.user.UserName);
|
||||
|
||||
rooms.result.update[index]['members'] = members
|
||||
rooms.result.update[index]['membersExcludeMe'] = users
|
||||
_rooms[index]['members'] = members
|
||||
_rooms[index]['membersExcludeMe'] = users
|
||||
|
||||
await this.prepareRoom(roomData);
|
||||
|
||||
@@ -322,8 +335,8 @@ export class ChatSystemService {
|
||||
const members = res['members'];
|
||||
const users = members.filter(data => data.username != this.sessionStore.user.UserName);
|
||||
|
||||
rooms.result.update[index]['members'] = members
|
||||
rooms.result.update[index]['membersExcludeMe'] = users
|
||||
_rooms[index]['members'] = members
|
||||
_rooms[index]['membersExcludeMe'] = users
|
||||
await this.prepareRoom(roomData);
|
||||
}
|
||||
|
||||
@@ -339,17 +352,8 @@ export class ChatSystemService {
|
||||
}
|
||||
|
||||
this.loadingWholeList = false
|
||||
await this.storage.set('Rooms', rooms);
|
||||
|
||||
this.sortRoomList()
|
||||
|
||||
setTimeout(() => {
|
||||
this.sortRoomList()
|
||||
}, 1000)
|
||||
|
||||
setTimeout(() => {
|
||||
this.sortRoomList()
|
||||
}, 10000)
|
||||
await this.storage.set('Rooms', _rooms);
|
||||
|
||||
this.onRoomsLoad.executor()
|
||||
}
|
||||
|
||||
@@ -220,6 +220,7 @@ export class MessageService {
|
||||
this.RochetChatConnectorService.registerCallback({
|
||||
type: 'reConnect',
|
||||
funx: async () => {
|
||||
console.log('send now have login')
|
||||
this.send().catch((error) =>{
|
||||
console.error(error)
|
||||
})
|
||||
@@ -227,7 +228,16 @@ export class MessageService {
|
||||
}
|
||||
})
|
||||
|
||||
console.log('no login')
|
||||
|
||||
} else if (this.UploadAttachmentsTemp <= 3) {
|
||||
console.log('temp'+ this.UploadAttachmentsTemp)
|
||||
setTimeout(async () => {
|
||||
return await this.send()
|
||||
}, 4000)
|
||||
} else if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Offline) {
|
||||
|
||||
console.log('recooonect')
|
||||
this.RochetChatConnectorService.registerCallback({
|
||||
type: 'reConnect',
|
||||
funx: async ()=> {
|
||||
@@ -238,11 +248,8 @@ export class MessageService {
|
||||
return true
|
||||
}
|
||||
})
|
||||
} else if (this.UploadAttachmentsTemp <= 3) {
|
||||
setTimeout(async () => {
|
||||
return await this.send()
|
||||
}, 3000)
|
||||
} else if (this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) {
|
||||
console.log('manual')
|
||||
this.manualRetry = true
|
||||
}
|
||||
|
||||
@@ -256,6 +263,7 @@ export class MessageService {
|
||||
|
||||
async sendRequestAttachment() {
|
||||
|
||||
console.log('sendRequestAttachment')
|
||||
this.uploadingFile = true
|
||||
|
||||
let uploadSuccessfully = false
|
||||
@@ -270,23 +278,30 @@ export class MessageService {
|
||||
await this.generateTemporaryData()
|
||||
}
|
||||
|
||||
console.log('send temp')
|
||||
if(this.hasSendAttachment == false) {
|
||||
try {
|
||||
uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
|
||||
this.UploadAttachmentsTemp++
|
||||
this.uploadingFile = false
|
||||
|
||||
this.manualRetry = false
|
||||
this.errorUploadingAttachment = false
|
||||
this.hasSendAttachment = true
|
||||
this.UploadAttachmentsTemp++
|
||||
|
||||
uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
|
||||
|
||||
this.uploadingFile = false
|
||||
this.hasSendAttachment = uploadSuccessfully
|
||||
|
||||
if(this.hasSendAttachment) {
|
||||
console.log('send uploadSuccessfully')
|
||||
} else {
|
||||
console.log('not send uploadSuccessfully')
|
||||
}
|
||||
|
||||
this.saveChanges()
|
||||
} catch (error) {
|
||||
this.uploadingFile = false
|
||||
|
||||
|
||||
console.log('send not uploadSuccessfully')
|
||||
this.errorUploadingAttachment = true
|
||||
this.UploadAttachmentsTemp++
|
||||
|
||||
this.saveChanges()
|
||||
}
|
||||
@@ -409,14 +424,14 @@ export class MessageService {
|
||||
|
||||
if(!roomObject.isGroup) {
|
||||
var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe
|
||||
this.notificationService.ChatSendMessageNotification(memeberTosend[0].username,ChatMessage.u.name,ChatMessage.msg,this.rid)
|
||||
this.notificationService.ChatSendMessageNotification(memeberTosend[0].username,ChatMessage.u.name,ChatMessage.msg || "Anexo",this.rid)
|
||||
} else {
|
||||
var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe
|
||||
var usersNames = [];
|
||||
for(let i = 0; i < memeberTosend.length; i++) {
|
||||
usersNames.push(memeberTosend[i].username)
|
||||
}
|
||||
this.notificationService.ChatSendMessageNotificationGrup(usersNames,ChatMessage.u.name,ChatMessage.msg,this.rid)
|
||||
this.notificationService.ChatSendMessageNotificationGrup(usersNames,ChatMessage.u.name,ChatMessage.msg || "Anexo",this.rid)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -766,6 +766,7 @@ export class RochetChatConnectorService {
|
||||
setTimeout(()=>{
|
||||
this.ws.wsMsgQueue()
|
||||
}, 10)
|
||||
console.log('rec conect')
|
||||
|
||||
if(this.wsReconnect >= 1) {
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
|
||||
@@ -42,6 +42,7 @@ export class RoomService {
|
||||
name = ''
|
||||
_updatedAt = {}
|
||||
hasLoadHistory = false
|
||||
DoneLoadingHistory = false
|
||||
restoreFromOffline = false
|
||||
duration = ''
|
||||
isTyping = false
|
||||
@@ -327,7 +328,7 @@ export class RoomService {
|
||||
this.registerSendMessage(message)
|
||||
|
||||
message.from = 'stream'
|
||||
message.loadHistory = this.hasLoadHistory
|
||||
message.loadHistory = this.DoneLoadingHistory
|
||||
|
||||
this.lastMessage = message;
|
||||
this.calDateDuration(ChatMessage._updatedAt);
|
||||
@@ -352,6 +353,7 @@ export class RoomService {
|
||||
|
||||
this.messageUnread = true
|
||||
|
||||
// this.sortRoomList()
|
||||
setTimeout(() => {
|
||||
this.scrollDown()
|
||||
}, 50)
|
||||
@@ -550,6 +552,30 @@ export class RoomService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description delete message in the view
|
||||
* @param id message ID
|
||||
*/
|
||||
async deleteMessageFromArray(_id) {
|
||||
|
||||
const id = _id
|
||||
|
||||
for (let i =0; i <= this.messages.length; i++) {
|
||||
|
||||
if(this.messages[i]?._id == id ) {
|
||||
|
||||
this.messages.splice(i, 1)
|
||||
|
||||
return true
|
||||
|
||||
} else {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
deleteAll() {
|
||||
this.messages.forEach((message) => {
|
||||
if(message?._id) {
|
||||
@@ -619,7 +645,7 @@ export class RoomService {
|
||||
}
|
||||
|
||||
|
||||
console.log('offlineChatMessage', offlineChatMessage)
|
||||
//console.log('offlineChatMessage', offlineChatMessage)
|
||||
|
||||
this.message= ''
|
||||
|
||||
@@ -792,7 +818,7 @@ export class RoomService {
|
||||
|
||||
this.messages.push(cloneMessage as any)
|
||||
|
||||
console.log(currentDateMessage)
|
||||
// console.log(currentDateMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -851,9 +877,6 @@ export class RoomService {
|
||||
|
||||
const messages = this.sortArrayISODate(await MessageModel.filter({rid:this.id}).execute()).reverse()
|
||||
|
||||
|
||||
console.log('MessageModel', messages)
|
||||
|
||||
for (let ChatMessage of messages) {
|
||||
|
||||
|
||||
@@ -907,6 +930,7 @@ export class RoomService {
|
||||
|
||||
// runs onces only
|
||||
loadHistoryCount = 0
|
||||
localMessages = []
|
||||
async loadHistory({limit = 1000, forceUpdate = false }) {
|
||||
|
||||
if(forceUpdate == false) {
|
||||
@@ -920,6 +944,8 @@ export class RoomService {
|
||||
await this.restoreMessageFromDB()
|
||||
const chatHistory: chatHistory = await this.RochetChatConnectorService.loadHistory(this.id, limit)
|
||||
|
||||
this.localMessages = this.messages.map( e => e._id)
|
||||
|
||||
if(chatHistory?.result?.messages) {
|
||||
|
||||
const users = this.getUsersByStatus('online')
|
||||
@@ -955,6 +981,8 @@ export class RoomService {
|
||||
|
||||
}
|
||||
|
||||
this.DoneLoadingHistory = true
|
||||
|
||||
if(chatHistory?.result?.messages) {
|
||||
|
||||
if(!this.lastMessage) {
|
||||
@@ -962,10 +990,31 @@ export class RoomService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.deletedMessages(chatHistory)
|
||||
}
|
||||
|
||||
|
||||
deletedMessages(chatHistory: chatHistory) {
|
||||
|
||||
const messagesToDelete = this.localMessages.filter( id => {
|
||||
const found = chatHistory.result.messages.find( e => {
|
||||
return e._id == id
|
||||
})
|
||||
if(!found) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
|
||||
for (const id of messagesToDelete) {
|
||||
if(id != '') {
|
||||
this.deleteMessage(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addMessageDB = FIFOProcessQueue(async ({messagesToSave}, callback) => {
|
||||
|
||||
await messagesToSave.addMessageDB()
|
||||
|
||||
Reference in New Issue
Block a user