This commit is contained in:
Peter Maquiran
2022-03-29 16:48:24 +01:00
parent 3598d7c851
commit 37ec193f22
9 changed files with 140 additions and 76 deletions
+26 -44
View File
@@ -22,6 +22,7 @@ import { DeleteMessageModel, MessageModel } from '../../models/beast-orm'
import { AESEncrypt } from '../aesencrypt.service'
import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { ConnectionStatus, NetworkServiceService} from 'src/app/services/network-service.service';
@Injectable({
providedIn: 'root'
@@ -77,18 +78,16 @@ export class RoomService {
private ChatStorageService: ChatStorageService,
private ChatMethodsService: ChatMethodsService,
private AESEncrypt: AESEncrypt,
private AttachmentsService: AttachmentsService
private AttachmentsService: AttachmentsService,
private NetworkServiceService: NetworkServiceService
) {
this.NativeNotificationService.askForPermission()
// this.restoreMessageFromDB()
this.WsChatService.getUserStatus((d) => {
const userId = d.fields.args[0][0]
const statusNum = d.fields.args[0][2]
const statusText = this.statusNumberToText(statusNum)
//
if(this.members?.map) {
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.id = id
this.name = name
@@ -343,7 +342,6 @@ export class RoomService {
}
async receiveMessageDelete() {
this.WsChatService.updateRoomEventss(
@@ -372,14 +370,6 @@ export class RoomService {
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) {
const allMemberThatIsOffline = this.getAllMemberThatIsOffline()
@@ -393,10 +383,14 @@ export class RoomService {
}
this.messages[i]?.delateDB()
// console.log(_id,'==',this.messages[i]?._id, true)
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
} else {
@@ -429,40 +423,28 @@ export class RoomService {
const message = this.messages.find((e)=>e._id == msgId)
await message.delateStatusFalse()
this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe(
async (response: any) => {
if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) {
this.WsChatService.deleteMessage(msgId).then(async() => {
message.delateRequest = true
await message.save()
this.deleteMessage(msgId)
})
},
async (response) => {
if (response?.error?.error.startsWith('No message found with the id of')) {
} else {
this.WsChatService.registerCallback({
type: 'reConnect',
funx: async ()=> {
this.deleteMessage(msgId)
message.delateRequest = true
await message.save()
} else {
this.WsChatService.registerCallback({
type: 'reConnect',
funx: async ()=> {
this.sendDeleteRequest(msgId)
return true
}
})
this.sendDeleteRequest(msgId)
return true
}
}
)
})
}
}
/**
* @description sen text message
*/
@@ -629,7 +611,7 @@ export class RoomService {
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)
@@ -685,7 +667,7 @@ export class RoomService {
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.loadHistory = this.hasLoadHistory
@@ -742,7 +724,7 @@ export class RoomService {
async prepareCreate({message, save = true}): Promise<MessageService> {
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.loadHistory = this.hasLoadHistory
@@ -754,7 +736,7 @@ export class RoomService {
simplePrepareMessage(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.loadHistory = this.hasLoadHistory