mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
message
This commit is contained in:
Generated
+3
-3
@@ -3175,9 +3175,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@ionic-native/network": {
|
"@ionic-native/network": {
|
||||||
"version": "5.36.0",
|
"version": "5.22.0-beta-1",
|
||||||
"resolved": "https://registry.npmjs.org/@ionic-native/network/-/network-5.36.0.tgz",
|
"resolved": "https://registry.npmjs.org/@ionic-native/network/-/network-5.22.0-beta-1.tgz",
|
||||||
"integrity": "sha512-gpa7cJqodEK+zmmViYJCqEpXoKSXcaYLaaRKdv5gn5M++bpmiw2pKM9JH8VoqYWaYDcUwD3S0yYeBBkG5DE0Kg==",
|
"integrity": "sha512-reOgFhHkyzCujqoGc1x8U9AZ40SBzdYT4HCFA6L2RwQT1NMyv+sDsp5er64p419Rfxg1k2QVTaDlEh+xPwhEqQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/cordova": "^0.0.34"
|
"@types/cordova": "^0.0.34"
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-1
@@ -72,7 +72,7 @@
|
|||||||
"@ionic-native/local-notifications": "^4.20.0",
|
"@ionic-native/local-notifications": "^4.20.0",
|
||||||
"@ionic-native/media": "^5.36.0",
|
"@ionic-native/media": "^5.36.0",
|
||||||
"@ionic-native/media-capture": "^5.36.0",
|
"@ionic-native/media-capture": "^5.36.0",
|
||||||
"@ionic-native/network": "^5.36.0",
|
"@ionic-native/network": "^5.22.0-beta-1",
|
||||||
"@ionic-native/photo-viewer": "^5.36.0",
|
"@ionic-native/photo-viewer": "^5.36.0",
|
||||||
"@ionic-native/screen-orientation": "^5.35.0",
|
"@ionic-native/screen-orientation": "^5.35.0",
|
||||||
"@ionic-native/social-sharing": "^5.36.0",
|
"@ionic-native/social-sharing": "^5.36.0",
|
||||||
|
|||||||
@@ -47,13 +47,8 @@ export class ChatMethodsService {
|
|||||||
return this.chatService.sendMessage(body)
|
return this.chatService.sendMessage(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
deleteMessage(body) {
|
deleteMessage(body) {
|
||||||
return this.chatService.deleteMessage(body)
|
return this.chatService.deleteMessage(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ import { MessageModel, DeleteMessageModel } from '../../models/beast-orm'
|
|||||||
import { AESEncrypt } from '../aesencrypt.service'
|
import { AESEncrypt } from '../aesencrypt.service'
|
||||||
import { HttpClient, HttpEventType } from '@angular/common/http';
|
import { HttpClient, HttpEventType } from '@angular/common/http';
|
||||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||||
|
import { NetworkServiceService , ConnectionStatus} from 'src/app/services/network-service.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -62,7 +63,8 @@ export class MessageService {
|
|||||||
private ChatStorageService: ChatStorageService,
|
private ChatStorageService: ChatStorageService,
|
||||||
private ChatMethodsService: ChatMethodsService,
|
private ChatMethodsService: ChatMethodsService,
|
||||||
private AESEncrypt: AESEncrypt,
|
private AESEncrypt: AESEncrypt,
|
||||||
private AttachmentsService: AttachmentsService,) {
|
private AttachmentsService: AttachmentsService,
|
||||||
|
private NetworkServiceService: NetworkServiceService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, }:Message) {
|
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, }:Message) {
|
||||||
@@ -184,14 +186,19 @@ export class MessageService {
|
|||||||
delete params?.attachments?.image_url
|
delete params?.attachments?.image_url
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ChatMethodsService.send(params).subscribe(
|
|
||||||
(response: any) => {
|
if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) {
|
||||||
const ChatMessage = response.message
|
|
||||||
|
this.WsChatService.send(params).then(
|
||||||
|
(ChatMessage: any) => {
|
||||||
|
ChatMessage = ChatMessage.message.result
|
||||||
|
|
||||||
this.messageSend = true
|
this.messageSend = true
|
||||||
this.redefinedMessage(ChatMessage)
|
this.redefinedMessage(ChatMessage)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
},
|
} else {
|
||||||
(error) => {
|
|
||||||
this.WsChatService.registerCallback({
|
this.WsChatService.registerCallback({
|
||||||
type: 'reConnect',
|
type: 'reConnect',
|
||||||
funx: async ()=> {
|
funx: async ()=> {
|
||||||
@@ -201,7 +208,7 @@ export class MessageService {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async redefinedMessage(ChatMessage , update = true) {
|
async redefinedMessage(ChatMessage , update = true) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { DeleteMessageModel, MessageModel } from '../../models/beast-orm'
|
|||||||
import { AESEncrypt } from '../aesencrypt.service'
|
import { AESEncrypt } from '../aesencrypt.service'
|
||||||
import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model';
|
import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model';
|
||||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||||
|
import { ConnectionStatus, NetworkServiceService} from 'src/app/services/network-service.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -77,18 +78,16 @@ export class RoomService {
|
|||||||
private ChatStorageService: ChatStorageService,
|
private ChatStorageService: ChatStorageService,
|
||||||
private ChatMethodsService: ChatMethodsService,
|
private ChatMethodsService: ChatMethodsService,
|
||||||
private AESEncrypt: AESEncrypt,
|
private AESEncrypt: AESEncrypt,
|
||||||
private AttachmentsService: AttachmentsService
|
private AttachmentsService: AttachmentsService,
|
||||||
|
private NetworkServiceService: NetworkServiceService
|
||||||
) {
|
) {
|
||||||
this.NativeNotificationService.askForPermission()
|
this.NativeNotificationService.askForPermission()
|
||||||
|
|
||||||
// this.restoreMessageFromDB()
|
|
||||||
|
|
||||||
this.WsChatService.getUserStatus((d) => {
|
this.WsChatService.getUserStatus((d) => {
|
||||||
|
|
||||||
const userId = d.fields.args[0][0]
|
const userId = d.fields.args[0][0]
|
||||||
const statusNum = d.fields.args[0][2]
|
const statusNum = d.fields.args[0][2]
|
||||||
const statusText = this.statusNumberToText(statusNum)
|
const statusText = this.statusNumberToText(statusNum)
|
||||||
//
|
|
||||||
|
|
||||||
if(this.members?.map) {
|
if(this.members?.map) {
|
||||||
const membersIds = this.members.map((user)=> user._id)
|
const membersIds = this.members.map((user)=> user._id)
|
||||||
@@ -145,7 +144,7 @@ export class RoomService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), _updatedAt }) {
|
setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), _updatedAt }) {
|
||||||
this.customFields = customFields
|
this.customFields = customFields
|
||||||
this.id = id
|
this.id = id
|
||||||
this.name = name
|
this.name = name
|
||||||
@@ -343,7 +342,6 @@ export class RoomService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async receiveMessageDelete() {
|
async receiveMessageDelete() {
|
||||||
|
|
||||||
this.WsChatService.updateRoomEventss(
|
this.WsChatService.updateRoomEventss(
|
||||||
@@ -372,14 +370,6 @@ export class RoomService {
|
|||||||
if(this.messages[i]?._id == id ) {
|
if(this.messages[i]?._id == id ) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Get previous last message from room
|
|
||||||
const previousLastMessage = this.messages.slice(-1)[0];
|
|
||||||
this.lastMessage = previousLastMessage;
|
|
||||||
|
|
||||||
this.calDateDuration(previousLastMessage._updatedAt)
|
|
||||||
this.sortRoomList()
|
|
||||||
|
|
||||||
if (SessionStore.user.RochetChatUser == this.messages[i]?.u?.username) {
|
if (SessionStore.user.RochetChatUser == this.messages[i]?.u?.username) {
|
||||||
const allMemberThatIsOffline = this.getAllMemberThatIsOffline()
|
const allMemberThatIsOffline = this.getAllMemberThatIsOffline()
|
||||||
|
|
||||||
@@ -393,10 +383,14 @@ export class RoomService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.messages[i]?.delateDB()
|
this.messages[i]?.delateDB()
|
||||||
|
|
||||||
// console.log(_id,'==',this.messages[i]?._id, true)
|
|
||||||
this.messages.splice(i, 1)
|
this.messages.splice(i, 1)
|
||||||
|
|
||||||
|
//Get previous last message from room
|
||||||
|
const previousLastMessage = this.messages.slice(-1)[0];
|
||||||
|
this.lastMessage = previousLastMessage;
|
||||||
|
this.calDateDuration(previousLastMessage._updatedAt)
|
||||||
|
this.sortRoomList()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -429,21 +423,13 @@ export class RoomService {
|
|||||||
const message = this.messages.find((e)=>e._id == msgId)
|
const message = this.messages.find((e)=>e._id == msgId)
|
||||||
await message.delateStatusFalse()
|
await message.delateStatusFalse()
|
||||||
|
|
||||||
this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe(
|
if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) {
|
||||||
async (response: any) => {
|
|
||||||
|
|
||||||
|
this.WsChatService.deleteMessage(msgId).then(async() => {
|
||||||
message.delateRequest = true
|
message.delateRequest = true
|
||||||
await message.save()
|
await message.save()
|
||||||
this.deleteMessage(msgId)
|
this.deleteMessage(msgId)
|
||||||
|
})
|
||||||
},
|
|
||||||
async (response) => {
|
|
||||||
|
|
||||||
if (response?.error?.error.startsWith('No message found with the id of')) {
|
|
||||||
|
|
||||||
this.deleteMessage(msgId)
|
|
||||||
message.delateRequest = true
|
|
||||||
await message.save()
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.WsChatService.registerCallback({
|
this.WsChatService.registerCallback({
|
||||||
@@ -457,10 +443,6 @@ export class RoomService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -629,7 +611,7 @@ export class RoomService {
|
|||||||
|
|
||||||
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
|
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
|
||||||
|
|
||||||
console.log('load chatHistory', JSON.stringify(chatHistory))
|
// console.log('load chatHistory', JSON.stringify(chatHistory))
|
||||||
|
|
||||||
const messagesId = this.messages.map((message)=> message._id)
|
const messagesId = this.messages.map((message)=> message._id)
|
||||||
|
|
||||||
@@ -685,7 +667,7 @@ export class RoomService {
|
|||||||
message = this.fix_updatedAt(message)
|
message = this.fix_updatedAt(message)
|
||||||
|
|
||||||
|
|
||||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
|
||||||
wewMessage.setData(message)
|
wewMessage.setData(message)
|
||||||
wewMessage.loadHistory = this.hasLoadHistory
|
wewMessage.loadHistory = this.hasLoadHistory
|
||||||
|
|
||||||
@@ -742,7 +724,7 @@ export class RoomService {
|
|||||||
async prepareCreate({message, save = true}): Promise<MessageService> {
|
async prepareCreate({message, save = true}): Promise<MessageService> {
|
||||||
message = this.fix_updatedAt(message)
|
message = this.fix_updatedAt(message)
|
||||||
|
|
||||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
|
||||||
wewMessage.setData(message)
|
wewMessage.setData(message)
|
||||||
wewMessage.loadHistory = this.hasLoadHistory
|
wewMessage.loadHistory = this.hasLoadHistory
|
||||||
|
|
||||||
@@ -754,7 +736,7 @@ export class RoomService {
|
|||||||
|
|
||||||
simplePrepareMessage(message) {
|
simplePrepareMessage(message) {
|
||||||
message = this.fix_updatedAt(message)
|
message = this.fix_updatedAt(message)
|
||||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
|
||||||
wewMessage.setData(message)
|
wewMessage.setData(message)
|
||||||
wewMessage.loadHistory = this.hasLoadHistory
|
wewMessage.loadHistory = this.hasLoadHistory
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { ChatStorageService } from './chat-storage.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';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -57,7 +58,8 @@ export class WsChatMethodsService {
|
|||||||
private ChatStorageService: ChatStorageService,
|
private ChatStorageService: ChatStorageService,
|
||||||
private ChatMethodsService:ChatMethodsService,
|
private ChatMethodsService:ChatMethodsService,
|
||||||
private AESEncrypt: AESEncrypt,
|
private AESEncrypt: AESEncrypt,
|
||||||
private AttachmentsService:AttachmentsService
|
private AttachmentsService:AttachmentsService,
|
||||||
|
private NetworkServiceService: NetworkServiceService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||||
@@ -314,7 +316,7 @@ export class WsChatMethodsService {
|
|||||||
|
|
||||||
// create room
|
// create room
|
||||||
if(!this.roomExist(roomId)) {
|
if(!this.roomExist(roomId)) {
|
||||||
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService)
|
||||||
room.setData(setData)
|
room.setData(setData)
|
||||||
room.receiveMessage()
|
room.receiveMessage()
|
||||||
room.getAllUsers = this.getUsers
|
room.getAllUsers = this.getUsers
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { NetworkServiceService } from './network-service.service';
|
||||||
|
|
||||||
|
describe('NetworkServiceService', () => {
|
||||||
|
let service: NetworkServiceService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(NetworkServiceService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { ToastController, Platform } from '@ionic/angular';
|
||||||
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
|
import { Network } from '@ionic-native/network/ngx'
|
||||||
|
|
||||||
|
|
||||||
|
export enum ConnectionStatus {
|
||||||
|
Online,
|
||||||
|
Offline
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class NetworkServiceService {
|
||||||
|
private status: BehaviorSubject<ConnectionStatus> = new BehaviorSubject(ConnectionStatus.Offline);
|
||||||
|
|
||||||
|
constructor(private network: Network, private toastController: ToastController, private plt: Platform) {
|
||||||
|
this.plt.ready().then(() => {
|
||||||
|
this.initializeNetworkEvents();
|
||||||
|
let status = this.network.type !== 'none' ? ConnectionStatus.Online : ConnectionStatus.Offline;
|
||||||
|
this.status.next(status);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public initializeNetworkEvents() {
|
||||||
|
|
||||||
|
this.network.onDisconnect().subscribe(() => {
|
||||||
|
if (this.status.getValue() === ConnectionStatus.Online) {
|
||||||
|
this.updateNetworkStatus(ConnectionStatus.Offline);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.network.onConnect().subscribe(() => {
|
||||||
|
if (this.status.getValue() === ConnectionStatus.Offline) {
|
||||||
|
this.updateNetworkStatus(ConnectionStatus.Online);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateNetworkStatus(status: ConnectionStatus) {
|
||||||
|
this.status.next(status);
|
||||||
|
|
||||||
|
let connection = status == ConnectionStatus.Offline ? 'Offline' : 'Online';
|
||||||
|
let toast = this.toastController.create({
|
||||||
|
message: `You are now ${connection}`,
|
||||||
|
duration: 3000,
|
||||||
|
position: 'bottom'
|
||||||
|
});
|
||||||
|
toast.then(toast => toast.present());
|
||||||
|
}
|
||||||
|
|
||||||
|
public onNetworkChange(): Observable<ConnectionStatus> {
|
||||||
|
return this.status.asObservable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public getCurrentNetworkStatus(): ConnectionStatus {
|
||||||
|
return this.status.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,8 +26,8 @@ export class PermissionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for(let permission of (this.SessionStore.user.UserPermissions || [])){
|
for(let permission of (this.SessionStore.user.UserPermissions || [])) {
|
||||||
if (args.includes(permission)){
|
if (args.includes(permission)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ export class PermissionService {
|
|||||||
role = [role]
|
role = [role]
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!UserRoleIsValid) {return false }
|
if(!UserRoleIsValid) { return false }
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user