2022-01-26 17:28:55 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2022-01-12 12:44:51 +01:00
|
|
|
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
|
2022-01-26 17:28:55 +01:00
|
|
|
import { MessageService } from 'src/app/services/chat/message.service';
|
|
|
|
|
import { showDateDuration } from 'src/plugin/showDateDuration';
|
2022-01-13 10:19:14 +01:00
|
|
|
import { ToastsService } from '../toast.service';
|
2022-02-08 17:44:15 +01:00
|
|
|
import { chatHistory } from 'src/app/models/chatMethod';
|
2022-01-19 09:12:30 +01:00
|
|
|
import { Storage } from '@ionic/storage';
|
2022-01-21 16:55:05 +01:00
|
|
|
import { Platform } from '@ionic/angular';
|
|
|
|
|
import { SqliteService } from 'src/app/services/sqlite.service';
|
2022-01-26 17:28:55 +01:00
|
|
|
import { NativeNotificationService } from 'src/app/services/native-notification.service';
|
|
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
2022-01-28 16:15:20 +01:00
|
|
|
import { capitalizeTxt } from 'src/plugin/text'
|
2022-01-28 15:59:01 +01:00
|
|
|
import { SortService } from '../functions/sort.service';
|
2022-01-29 19:21:46 +01:00
|
|
|
import { chatUser } from 'src/app/models/chatMethod';
|
2022-02-02 20:16:12 +01:00
|
|
|
import { environment } from 'src/environments/environment';
|
2022-02-03 21:01:53 +01:00
|
|
|
import { ChatService } from 'src/app/services/chat.service';
|
2022-02-10 14:56:06 +01:00
|
|
|
import { NfService } from 'src/app/services/chat/nf.service';
|
|
|
|
|
import { v4 as uuidv4 } from 'uuid'
|
2022-03-03 22:57:33 +01:00
|
|
|
import { ChatStorageService } from './chat-storage.service'
|
2022-03-04 14:20:39 +01:00
|
|
|
import { ChatMethodsService } from './chat-methods.service'
|
2022-03-14 14:16:23 +01:00
|
|
|
import { DeleteMessageModel, MessageModel } from '../../models/beast-orm'
|
2022-03-10 23:08:29 +01:00
|
|
|
import { AESEncrypt } from '../aesencrypt.service'
|
2022-03-14 14:16:23 +01:00
|
|
|
import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model';
|
2022-03-22 16:11:30 +01:00
|
|
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
2022-03-10 23:08:29 +01:00
|
|
|
|
2022-01-10 13:31:15 +01:00
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class RoomService {
|
|
|
|
|
|
2022-01-28 15:59:01 +01:00
|
|
|
messages: MessageService[] = []
|
2022-01-20 14:31:49 +01:00
|
|
|
storageMessage: any[] = [];
|
2022-01-11 13:03:43 +01:00
|
|
|
lastMessage: MessageService;
|
2022-02-09 18:18:27 +01:00
|
|
|
|
2022-01-20 14:31:49 +01:00
|
|
|
customFields: any;
|
2022-01-11 13:03:43 +01:00
|
|
|
id = ''
|
2022-01-17 11:27:25 +01:00
|
|
|
t = ''
|
2022-01-13 21:24:43 +01:00
|
|
|
name = ''
|
2022-01-11 20:56:21 +01:00
|
|
|
_updatedAt = {}
|
2022-02-10 14:07:16 +01:00
|
|
|
hasLoadHistory = false
|
2022-03-03 22:57:33 +01:00
|
|
|
restoreFromOffline = false
|
2022-01-20 14:31:49 +01:00
|
|
|
duration = ''
|
2022-01-28 16:15:20 +01:00
|
|
|
isTyping = false
|
|
|
|
|
otherUserType = false
|
|
|
|
|
lastTimeType = null
|
|
|
|
|
message = ''
|
|
|
|
|
lastMessageTxt = ''
|
|
|
|
|
userThatIsTyping = ''
|
2022-01-20 14:31:49 +01:00
|
|
|
mgsArray = [];
|
2022-02-10 18:07:06 +01:00
|
|
|
messagesLocalReference = []
|
2022-03-03 22:57:33 +01:00
|
|
|
members = []
|
|
|
|
|
u
|
2022-02-10 18:07:06 +01:00
|
|
|
|
2022-01-20 14:31:49 +01:00
|
|
|
scrollDown = () => { }
|
2022-01-29 20:16:39 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description get user list from ws-chat-methods.service
|
|
|
|
|
* @returns chatUser[]
|
|
|
|
|
*/
|
2022-01-29 19:21:46 +01:00
|
|
|
getAllUsers = (): chatUser[] => {
|
|
|
|
|
return []
|
|
|
|
|
}
|
2022-01-14 14:50:47 +01:00
|
|
|
|
2022-02-02 20:16:12 +01:00
|
|
|
sortRoomList = () => {}
|
2022-02-04 00:22:35 +01:00
|
|
|
uploadAttachment = (formData) => {}
|
2022-02-02 20:16:12 +01:00
|
|
|
|
2022-01-10 23:52:33 +01:00
|
|
|
constructor(
|
2022-01-12 12:44:51 +01:00
|
|
|
public WsChatService: WsChatService,
|
2022-01-11 20:56:21 +01:00
|
|
|
private MessageService: MessageService,
|
2022-01-19 09:12:30 +01:00
|
|
|
private storage: Storage,
|
2022-01-21 16:55:05 +01:00
|
|
|
private platform: Platform,
|
|
|
|
|
private sqlservice: SqliteService,
|
2022-01-28 16:26:21 +01:00
|
|
|
private NativeNotificationService: NativeNotificationService,
|
2022-01-28 17:34:27 +01:00
|
|
|
private sortService: SortService,
|
2022-02-03 21:01:53 +01:00
|
|
|
private chatService: ChatService,
|
2022-03-03 22:57:33 +01:00
|
|
|
private NfService: NfService,
|
2022-03-04 14:20:39 +01:00
|
|
|
private ChatStorageService: ChatStorageService,
|
2022-03-10 23:08:29 +01:00
|
|
|
private ChatMethodsService: ChatMethodsService,
|
2022-03-22 16:11:30 +01:00
|
|
|
private AESEncrypt: AESEncrypt,
|
|
|
|
|
private AttachmentsService: AttachmentsService
|
2022-01-28 16:37:18 +01:00
|
|
|
) {
|
2022-01-26 17:28:55 +01:00
|
|
|
this.NativeNotificationService.askForPermission()
|
2022-03-03 22:57:33 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
// this.restoreMessageFromDB()
|
2022-03-03 22:57:33 +01:00
|
|
|
|
|
|
|
|
this.WsChatService.getUserStatus((d) => {
|
|
|
|
|
|
|
|
|
|
const userId = d.fields.args[0][0]
|
2022-03-18 12:32:21 +01:00
|
|
|
const statusNum = d.fields.args[0][2]
|
|
|
|
|
const statusText = this.statusNumberToText(statusNum)
|
|
|
|
|
//
|
2022-03-03 22:57:33 +01:00
|
|
|
|
|
|
|
|
if(this.members?.map) {
|
|
|
|
|
const membersIds = this.members.map((user)=> user._id)
|
|
|
|
|
|
|
|
|
|
if(membersIds.includes(userId)) {
|
2022-03-15 15:49:59 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
if(statusText != 'offline') {
|
|
|
|
|
this.deleteMessageToReceive(userId)
|
|
|
|
|
}
|
2022-03-15 15:49:59 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
this.messages.forEach((message, index) => {
|
|
|
|
|
if(!message.messageOwnerById(userId)) {
|
|
|
|
|
|
|
|
|
|
if(!this.messages[index]?.received?.includes(userId)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.messages[index]._id) {
|
|
|
|
|
try {
|
2022-03-10 23:08:29 +01:00
|
|
|
if(!this.messages[index].received.includes(userId)) {
|
|
|
|
|
this.messages[index].received.push(userId)
|
|
|
|
|
}
|
2022-03-03 22:57:33 +01:00
|
|
|
} catch(e) {
|
|
|
|
|
this.messages[index].received = [userId]
|
2022-03-10 23:08:29 +01:00
|
|
|
}
|
2022-03-03 22:57:33 +01:00
|
|
|
this.messages[index].save()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-26 17:28:55 +01:00
|
|
|
}
|
2022-01-10 23:52:33 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
/**
|
|
|
|
|
* @description convert rocketchat statues num to readable string
|
|
|
|
|
* @param text
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
statusNumberToText(text) {
|
|
|
|
|
if(text == '0') {
|
|
|
|
|
return "offline"
|
|
|
|
|
}
|
|
|
|
|
else if(text == '1') {
|
|
|
|
|
return "online"
|
|
|
|
|
}
|
|
|
|
|
else if(text == '2') {
|
|
|
|
|
return "away"
|
|
|
|
|
}
|
|
|
|
|
else if(text == '3') {
|
|
|
|
|
return "busy"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-22 16:11:30 +01:00
|
|
|
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 }) {
|
2022-01-13 21:24:43 +01:00
|
|
|
this.customFields = customFields
|
2022-01-11 13:03:43 +01:00
|
|
|
this.id = id
|
|
|
|
|
this.name = name
|
2022-01-17 11:27:25 +01:00
|
|
|
this.t = t
|
2022-01-11 13:03:43 +01:00
|
|
|
this.lastMessage = lastMessage
|
2022-01-11 20:56:21 +01:00
|
|
|
this._updatedAt = _updatedAt
|
2022-03-03 22:57:33 +01:00
|
|
|
this.u = u
|
|
|
|
|
this.members = members
|
2022-01-11 20:56:21 +01:00
|
|
|
|
|
|
|
|
this.calDateDuration()
|
2022-02-10 21:50:15 +01:00
|
|
|
this.restoreMessageFromDB()
|
2022-01-10 23:52:33 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-03 15:52:21 +01:00
|
|
|
|
|
|
|
|
isSenderIsNotMe(ChatMessage) {
|
|
|
|
|
return SessionStore.user.RochetChatUser != ChatMessage.u.username
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
senderId(ChatMessage) {
|
|
|
|
|
return ChatMessage.u._id
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-11 15:43:09 +01:00
|
|
|
receiveMessage() {
|
2022-01-14 11:47:55 +01:00
|
|
|
|
2022-01-28 17:33:26 +01:00
|
|
|
this.WsChatService.updateRoomEventss(
|
2022-01-14 11:47:55 +01:00
|
|
|
this.id,
|
2022-01-28 15:31:52 +01:00
|
|
|
"stream-room-messages",
|
2022-03-10 23:08:29 +01:00
|
|
|
async (IncomingChatMessage:IncomingChatMessage) => {
|
2022-02-10 20:16:59 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
let IncomingChatMessageArgs = IncomingChatMessage.fields.args[0]
|
|
|
|
|
let ChatMessage : ChatMessageInterface = this.fix_updatedAt(IncomingChatMessageArgs)
|
2022-02-10 21:27:48 +01:00
|
|
|
|
|
|
|
|
if(!this.messagesLocalReference.includes(ChatMessage.localReference)) {
|
2022-03-03 22:57:33 +01:00
|
|
|
|
2022-03-21 15:08:43 +01:00
|
|
|
const message = await this.prepareCreate({message: ChatMessage, save: true})
|
2022-03-03 22:57:33 +01:00
|
|
|
message.messageSend = true
|
|
|
|
|
|
2022-02-10 18:35:33 +01:00
|
|
|
this.lastMessage = message
|
|
|
|
|
this.calDateDuration(ChatMessage._updatedAt)
|
2022-02-02 20:16:12 +01:00
|
|
|
|
2022-02-10 18:35:33 +01:00
|
|
|
if (message.t == 'r') {
|
|
|
|
|
this.name = message.msg
|
|
|
|
|
}
|
2022-02-09 14:39:59 +01:00
|
|
|
|
2022-02-10 18:35:33 +01:00
|
|
|
if(this.isSenderIsNotMe(ChatMessage)) {
|
2022-02-09 14:39:59 +01:00
|
|
|
this.NativeNotificationService.sendNotificationChat({
|
|
|
|
|
message: message.msg,
|
|
|
|
|
title: this.name
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-03-03 22:57:33 +01:00
|
|
|
|
|
|
|
|
message.addMessageDB()
|
2022-02-10 18:35:33 +01:00
|
|
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
this.scrollDown()
|
|
|
|
|
}, 50)
|
2022-03-03 22:57:33 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
this.messages.forEach((message, index)=> {
|
|
|
|
|
if(message.localReference == ChatMessage.localReference) {
|
|
|
|
|
|
|
|
|
|
const membersIds = this.members.map((user)=> user._id)
|
|
|
|
|
|
|
|
|
|
this.getAllUsers().forEach( async (users) => {
|
|
|
|
|
|
|
|
|
|
if(membersIds.includes(users._id)) {
|
|
|
|
|
|
|
|
|
|
if(users.status != 'offline') {
|
|
|
|
|
|
|
|
|
|
this.messages[index].received.push(users._id)
|
2022-03-18 12:32:21 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
message.save()
|
|
|
|
|
}, 150)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-02-10 21:27:48 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
}
|
2022-02-09 14:07:34 +01:00
|
|
|
|
2022-01-14 11:47:55 +01:00
|
|
|
}
|
|
|
|
|
)
|
2022-01-28 16:15:20 +01:00
|
|
|
|
|
|
|
|
this.WsChatService.receiveStreamNotifyRoom((message) => {
|
|
|
|
|
|
|
|
|
|
if(message.fields.eventName == this.id+'/'+'typing') {
|
|
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
const args = message.fields.args
|
2022-03-15 15:49:59 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof args[1] != 'object') {
|
2022-03-03 22:57:33 +01:00
|
|
|
this.userThatIsTyping = this.usernameToDisplayName(args[0])
|
|
|
|
|
console.log(this.userThatIsTyping, 'this.userThatIsTyping')
|
|
|
|
|
this.isTyping = args[1]
|
|
|
|
|
this.otherUserType = args[1]
|
|
|
|
|
this.readAllMessage()
|
2022-03-18 12:32:21 +01:00
|
|
|
|
|
|
|
|
// console.log(JSON.stringify(args))
|
|
|
|
|
// alert(JSON.stringify(args))
|
|
|
|
|
} else if(args[0]?.method == 'viewMessage' || args[1]?.method == 'viewMessage') {
|
2022-03-10 23:08:29 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
this.readAllMessage()
|
2022-03-18 12:32:21 +01:00
|
|
|
} else if(args[0]?.method == 'deleteMessage' || args[1]?.method == 'deleteMessage') {
|
|
|
|
|
|
|
|
|
|
// alert('delete')
|
|
|
|
|
// console.log(args[0], 'receive delete message::()')
|
2022-03-23 23:00:19 +01:00
|
|
|
this.deleteMessage(args[1]?.method?._id)
|
2022-03-18 12:32:21 +01:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// alert('miss')
|
2022-02-10 14:56:06 +01:00
|
|
|
}
|
2022-02-16 15:52:59 +01:00
|
|
|
|
|
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
} else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}
|
2022-02-16 15:52:59 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
})
|
2022-02-10 14:56:06 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-02 20:16:12 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
getRoomMembersIds(): string[] {
|
2022-03-26 08:52:33 +01:00
|
|
|
try {
|
|
|
|
|
return this.members.map((user)=> user._id)
|
|
|
|
|
} catch(error) {
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAllMemberThatIsNotOffline(): string[] {
|
|
|
|
|
|
|
|
|
|
const membersIds = this.getRoomMembersIds()
|
|
|
|
|
const allChatUsers = this.getAllUsers()
|
|
|
|
|
|
|
|
|
|
const AllMemberThatIsNotOffline = []
|
|
|
|
|
|
|
|
|
|
for(let user of allChatUsers) {
|
|
|
|
|
if(membersIds.includes(user._id)) {
|
|
|
|
|
|
|
|
|
|
if(user.status != 'offline') {
|
|
|
|
|
AllMemberThatIsNotOffline.push(user._id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AllMemberThatIsNotOffline
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 15:49:59 +01:00
|
|
|
getAllMemberThatIsOffline(): string[] {
|
|
|
|
|
|
|
|
|
|
const membersIds = this.getRoomMembersIds()
|
|
|
|
|
const allChatUsers = this.getAllUsers()
|
|
|
|
|
|
|
|
|
|
const AllMemberThatIsNotOffline = []
|
|
|
|
|
|
|
|
|
|
for(let user of allChatUsers) {
|
|
|
|
|
if(membersIds.includes(user._id)) {
|
|
|
|
|
|
|
|
|
|
if(user.status == 'offline') {
|
|
|
|
|
AllMemberThatIsNotOffline.push(user._id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AllMemberThatIsNotOffline
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async deleteMessageToReceive(userId) {
|
|
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
const allDeleteMessages = await DeleteMessageModel.filter({rid: this.id}).execute()
|
|
|
|
|
|
|
|
|
|
for(let message_ of allDeleteMessages) {
|
2022-03-15 15:49:59 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
if(message_.needToReceiveBy.includes(userId)) {
|
2022-03-15 15:49:59 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
message_.needToReceiveBy = message_.needToReceiveBy.filter((e)=> e != userId)
|
|
|
|
|
this.sendFalseTypingReadMessage('deleteMessage',{_id:message_.messageId})
|
2022-03-15 15:49:59 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
if(message_.needToReceiveBy.length == 0) {
|
|
|
|
|
|
|
|
|
|
const deleteMessage = await DeleteMessageModel.get({messageId: message_.messageId})
|
|
|
|
|
await deleteMessage.delete()
|
2022-03-15 15:49:59 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
} else {
|
|
|
|
|
await DeleteMessageModel.update(message_)
|
|
|
|
|
}
|
2022-03-15 15:49:59 +01:00
|
|
|
|
|
|
|
|
}
|
2022-03-18 12:32:21 +01:00
|
|
|
|
2022-03-15 15:49:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
|
2022-01-28 15:31:52 +01:00
|
|
|
async receiveMessageDelete() {
|
|
|
|
|
|
2022-01-28 17:33:26 +01:00
|
|
|
this.WsChatService.updateRoomEventss(
|
2022-01-28 15:31:52 +01:00
|
|
|
this.id,
|
|
|
|
|
"stream-notify-room",
|
|
|
|
|
async (ChatMessage) => {
|
2022-01-30 09:34:56 +01:00
|
|
|
|
|
|
|
|
const DeletedMessageId = ChatMessage.fields.args[0]._id;
|
|
|
|
|
this.deleteMessage(DeletedMessageId)
|
2022-01-28 15:31:52 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
)
|
2022-02-08 19:17:44 +01:00
|
|
|
|
2022-01-11 15:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-30 09:34:56 +01:00
|
|
|
/**
|
|
|
|
|
* @description delete message in the view
|
|
|
|
|
* @param id message ID
|
|
|
|
|
*/
|
2022-03-22 14:23:38 +01:00
|
|
|
async deleteMessage(_id) {
|
2022-03-23 23:00:19 +01:00
|
|
|
|
2022-03-22 14:23:38 +01:00
|
|
|
const id = _id
|
|
|
|
|
|
|
|
|
|
for (let i =0; i <= this.messages.length; i++) {
|
|
|
|
|
|
|
|
|
|
if(this.messages[i]?._id == id ) {
|
|
|
|
|
|
2022-03-25 17:39:51 +01:00
|
|
|
|
2022-03-24 17:40:14 +01:00
|
|
|
|
|
|
|
|
//Get previous last message from room
|
|
|
|
|
const previousLastMessage = this.messages.slice(-1)[0];
|
|
|
|
|
this.lastMessage = previousLastMessage;
|
|
|
|
|
|
|
|
|
|
this.calDateDuration(previousLastMessage._updatedAt)
|
|
|
|
|
this.sortRoomList()
|
2022-03-23 22:01:59 +01:00
|
|
|
|
2022-03-25 17:39:51 +01:00
|
|
|
if (SessionStore.user.RochetChatUser == this.messages[i]?.u?.username) {
|
2022-03-23 22:01:59 +01:00
|
|
|
const allMemberThatIsOffline = this.getAllMemberThatIsOffline()
|
2022-03-22 14:23:38 +01:00
|
|
|
|
2022-03-25 14:32:15 +01:00
|
|
|
DeleteMessageModel.create({
|
2022-03-23 22:01:59 +01:00
|
|
|
messageId: this.messages[i]._id,
|
|
|
|
|
rid: this.messages[i].rid,
|
|
|
|
|
ts: this.messages[i].ts,
|
|
|
|
|
u: this.messages[i].u,
|
|
|
|
|
needToReceiveBy: allMemberThatIsOffline
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 17:39:51 +01:00
|
|
|
this.messages[i]?.delateDB()
|
|
|
|
|
|
2022-03-28 16:37:32 +01:00
|
|
|
// console.log(_id,'==',this.messages[i]?._id, true)
|
2022-03-25 17:39:51 +01:00
|
|
|
this.messages.splice(i, 1)
|
2022-03-23 22:01:59 +01:00
|
|
|
|
|
|
|
|
return true
|
2022-01-30 09:34:56 +01:00
|
|
|
|
2022-03-23 22:01:59 +01:00
|
|
|
} else {
|
2022-03-28 16:37:32 +01:00
|
|
|
// console.log(_id,'==',this.messages[i]?._id, false)
|
2022-01-30 09:34:56 +01:00
|
|
|
}
|
2022-03-22 14:23:38 +01:00
|
|
|
}
|
2022-03-03 22:57:33 +01:00
|
|
|
|
2022-01-30 09:34:56 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-21 21:06:54 +01:00
|
|
|
|
|
|
|
|
deleteAll() {
|
|
|
|
|
this.messages.forEach((message)=>{
|
|
|
|
|
if(message?._id) {
|
|
|
|
|
this.sendDeleteRequest(message._id)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 15:49:59 +01:00
|
|
|
async delateMessageToSendToOthers(userId) {
|
2022-03-14 14:16:23 +01:00
|
|
|
|
|
|
|
|
const deleteMessage = await DeleteMessageModel.all()
|
|
|
|
|
|
|
|
|
|
const toSend = deleteMessage.filter((DeleteMessage:string[])=> ! DeleteMessage.includes(userId))
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-03-15 15:49:59 +01:00
|
|
|
async sendDeleteRequest(msgId) {
|
|
|
|
|
|
2022-03-23 23:00:19 +01:00
|
|
|
const message = this.messages.find((e)=>e._id == msgId)
|
2022-03-23 23:01:03 +01:00
|
|
|
await message.delateStatusFalse()
|
2022-03-15 15:49:59 +01:00
|
|
|
|
|
|
|
|
this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe(
|
2022-03-28 16:37:32 +01:00
|
|
|
async (response: any) => {
|
2022-03-23 22:01:59 +01:00
|
|
|
|
2022-03-15 15:49:59 +01:00
|
|
|
message.delateRequest = true
|
2022-03-28 16:37:32 +01:00
|
|
|
await message.save()
|
2022-03-24 16:28:47 +01:00
|
|
|
this.deleteMessage(msgId)
|
2022-03-23 22:01:59 +01:00
|
|
|
|
2022-03-15 15:49:59 +01:00
|
|
|
},
|
2022-03-28 16:37:32 +01:00
|
|
|
async (response) => {
|
2022-03-18 12:32:21 +01:00
|
|
|
|
|
|
|
|
if (response.error.error.startsWith('No message found with the id of')) {
|
2022-03-23 22:01:59 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
this.deleteMessage(msgId)
|
2022-03-23 22:01:59 +01:00
|
|
|
message.delateRequest = true
|
2022-03-28 16:37:32 +01:00
|
|
|
await message.save()
|
2022-03-23 22:01:59 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
} else {
|
|
|
|
|
this.WsChatService.registerCallback({
|
|
|
|
|
type: 'reConnect',
|
|
|
|
|
funx: async ()=> {
|
|
|
|
|
|
|
|
|
|
this.sendDeleteRequest(msgId)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 15:49:59 +01:00
|
|
|
}
|
|
|
|
|
)
|
2022-03-21 21:06:54 +01:00
|
|
|
|
2022-03-15 15:49:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-01-30 09:34:56 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description sen text message
|
|
|
|
|
*/
|
2022-02-07 20:18:48 +01:00
|
|
|
async send({file = null, attachments = null, temporaryData = {}}) {
|
2022-02-02 20:16:12 +01:00
|
|
|
|
2022-02-10 21:50:15 +01:00
|
|
|
const localReference = uuidv4()
|
2022-02-02 20:16:12 +01:00
|
|
|
|
2022-02-03 21:01:53 +01:00
|
|
|
let offlineChatMessage = {
|
|
|
|
|
rid: this.id,
|
|
|
|
|
msg: this.message,
|
|
|
|
|
attachments,
|
|
|
|
|
file,
|
2022-02-10 14:56:06 +01:00
|
|
|
temporaryData,
|
2022-03-03 22:57:33 +01:00
|
|
|
localReference
|
2022-02-03 21:01:53 +01:00
|
|
|
}
|
2022-03-04 14:50:13 +01:00
|
|
|
|
|
|
|
|
this.message= ''
|
2022-03-03 22:57:33 +01:00
|
|
|
|
2022-03-14 14:16:23 +01:00
|
|
|
const message: MessageService = await this.prepareCreate({message:offlineChatMessage, save: environment.chatOffline})
|
2022-02-07 20:18:48 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
this.messagesLocalReference.push(localReference)
|
|
|
|
|
await message.addMessageDB()
|
|
|
|
|
message.send()
|
|
|
|
|
|
2022-02-04 00:22:35 +01:00
|
|
|
|
2022-02-10 14:55:32 +01:00
|
|
|
if (environment.chatOffline) {
|
2022-02-10 18:07:06 +01:00
|
|
|
|
2022-02-10 14:07:16 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollDown()
|
|
|
|
|
}, 150)
|
|
|
|
|
|
|
|
|
|
this.lastMessage = message
|
|
|
|
|
this.calDateDuration(message._updatedAt)
|
|
|
|
|
this.sortRoomList()
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-04 14:50:13 +01:00
|
|
|
|
2022-02-03 21:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 15:52:59 +01:00
|
|
|
|
2022-01-28 16:15:20 +01:00
|
|
|
|
2022-02-10 16:14:25 +01:00
|
|
|
sendTyping(text:string = this.message) {
|
2022-01-28 16:15:20 +01:00
|
|
|
|
|
|
|
|
if(this.lastMessageTxt == text) { return false }
|
|
|
|
|
this.lastTimeType = new Date().getTime()
|
|
|
|
|
|
|
|
|
|
const lastIsTyping = this.isTyping
|
|
|
|
|
if(text.length >= 1) {
|
2022-01-28 17:34:27 +01:00
|
|
|
this.isTyping = true
|
2022-01-28 16:15:20 +01:00
|
|
|
} else {
|
|
|
|
|
this.isTyping = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(lastIsTyping != this.isTyping) {
|
|
|
|
|
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', this.isTyping)
|
|
|
|
|
}
|
2022-01-28 17:34:27 +01:00
|
|
|
|
2022-01-28 16:15:20 +01:00
|
|
|
|
|
|
|
|
this.lastMessageTxt = this.message
|
|
|
|
|
this.typingWatch()
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 15:49:59 +01:00
|
|
|
sendFalseTypingReadMessage(method,param: object) {
|
|
|
|
|
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', {method:method, params: param} as falseTypingMethod)
|
2022-03-03 22:57:33 +01:00
|
|
|
this.setTypingOff()
|
|
|
|
|
}
|
2022-01-28 16:15:20 +01:00
|
|
|
|
|
|
|
|
private typingWatch() {
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
const now = new Date().getTime()
|
|
|
|
|
|
|
|
|
|
if((now - this.lastTimeType) >= 2888) {
|
2022-01-28 17:34:27 +01:00
|
|
|
|
2022-01-28 16:15:20 +01:00
|
|
|
if(this.isTyping == true) {
|
|
|
|
|
this.isTyping = false
|
|
|
|
|
this.WsChatService.sendStreamNotifyRoom(this.id, SessionStore.user.RochetChatUser, 'typing', this.isTyping)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-03-18 12:32:21 +01:00
|
|
|
|
2022-01-28 16:15:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, 3000)
|
2022-01-11 15:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-29 19:21:46 +01:00
|
|
|
private setTypingOff() {
|
2022-02-10 16:14:25 +01:00
|
|
|
this.sendTyping('')
|
2022-01-29 19:21:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
roomLeave() {
|
|
|
|
|
this.setTypingOff()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
open() {
|
|
|
|
|
// this.typing(this.message)
|
|
|
|
|
}
|
2022-02-02 10:01:37 +01:00
|
|
|
|
2022-01-29 19:21:46 +01:00
|
|
|
|
2022-01-26 09:19:54 +01:00
|
|
|
leave(rid?) {
|
|
|
|
|
this.WsChatService.leaveRoom(this.id)
|
|
|
|
|
}
|
2022-02-02 10:01:37 +01:00
|
|
|
|
2022-01-21 16:55:05 +01:00
|
|
|
isJson(str) {
|
|
|
|
|
try {
|
|
|
|
|
JSON.parse(str);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
return JSON.parse(str);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-07 20:18:48 +01:00
|
|
|
async restoreMessageFromDB() {
|
2022-02-10 14:07:16 +01:00
|
|
|
if(environment.chatOffline) {
|
2022-02-02 20:16:12 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
const messages = await MessageModel.filter({rid:this.id}).execute()
|
|
|
|
|
|
|
|
|
|
await messages.forEach( async (ChatMessage, index) => {
|
2022-02-02 20:16:12 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
const wewMessage = await this.simplePrepareMessage(ChatMessage)
|
2022-03-03 22:57:33 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
if(wewMessage.offline == false) {
|
2022-03-21 21:06:54 +01:00
|
|
|
const message = await this.prepareMessageCreateIfNotExist_iD({message:ChatMessage})
|
2022-03-10 23:08:29 +01:00
|
|
|
|
|
|
|
|
message?.decryptMessage()
|
|
|
|
|
} else {
|
2022-01-28 16:37:18 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
const offlineMessage = await this.prepareMessageCreateIfNotExist({message:ChatMessage})
|
2022-02-10 21:27:48 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
if(offlineMessage) {
|
2022-02-10 21:27:48 +01:00
|
|
|
this.messagesLocalReference.push(offlineMessage.localReference)
|
2022-03-04 14:20:39 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
offlineMessage?.decryptMessage()
|
|
|
|
|
offlineMessage.send()
|
|
|
|
|
|
2022-02-10 14:07:16 +01:00
|
|
|
}
|
2022-01-28 16:37:18 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
}
|
2022-02-10 14:55:32 +01:00
|
|
|
|
2022-03-18 12:32:21 +01:00
|
|
|
if(wewMessage.delate && !wewMessage.offline && !wewMessage.delateRequest) {
|
|
|
|
|
this.sendDeleteRequest(wewMessage._id)
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
});
|
2022-02-10 14:55:32 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
setTimeout(()=> {
|
|
|
|
|
this.scrollDown()
|
|
|
|
|
}, 50)
|
2022-02-02 20:16:12 +01:00
|
|
|
|
2022-02-10 14:07:16 +01:00
|
|
|
}
|
2022-02-02 20:16:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// runs onces only
|
2022-03-21 21:06:54 +01:00
|
|
|
async loadHistory({limit = 1000, forceUpdate = false }) {
|
2022-02-02 20:16:12 +01:00
|
|
|
|
2022-02-10 14:07:16 +01:00
|
|
|
if(forceUpdate == false) {
|
2022-02-10 14:55:32 +01:00
|
|
|
if (this.hasLoadHistory) {
|
|
|
|
|
return false
|
2022-02-10 14:07:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-28 15:28:21 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
if(this.restoreFromOffline == false) {
|
|
|
|
|
this.restoreFromOffline = true
|
|
|
|
|
await this.restoreMessageFromDB()
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 16:37:32 +01:00
|
|
|
// await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
|
2022-02-09 15:06:21 +01:00
|
|
|
|
2022-03-28 16:37:32 +01:00
|
|
|
// console.log('load chatHistory', JSON.stringify(chatHistory))
|
2022-03-21 21:06:54 +01:00
|
|
|
|
2022-03-28 16:37:32 +01:00
|
|
|
// const messagesId = this.messages.map((message)=> message._id)
|
2022-02-09 15:06:21 +01:00
|
|
|
|
2022-03-28 16:37:32 +01:00
|
|
|
// chatHistory.result.messages.reverse().forEach(async(message: any) => {
|
2022-03-04 14:20:39 +01:00
|
|
|
|
2022-03-28 16:37:32 +01:00
|
|
|
// if (!messagesId.includes(message._id)) {
|
|
|
|
|
// const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message});
|
|
|
|
|
// if(messagesToSave) {
|
|
|
|
|
// await messagesToSave.addMessageDB()
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2022-03-10 23:08:29 +01:00
|
|
|
|
2022-03-28 16:37:32 +01:00
|
|
|
// })
|
2022-01-21 16:55:05 +01:00
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
|
2022-03-28 16:37:32 +01:00
|
|
|
// })
|
2022-01-28 15:31:52 +01:00
|
|
|
|
2022-01-20 14:31:49 +01:00
|
|
|
setTimeout(() => {
|
2022-01-14 14:58:47 +01:00
|
|
|
this.scrollDown()
|
|
|
|
|
}, 50)
|
|
|
|
|
|
2022-01-11 15:43:09 +01:00
|
|
|
this.hasLoadHistory = true
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
async readAllMessage() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const membersIds = this.members.map((user)=> user._id)
|
|
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
await this.messages.forEach( async (message, index) => {
|
|
|
|
|
if(message._id) {
|
|
|
|
|
if(message.viewed.length == 0) {
|
|
|
|
|
this.messages[index].viewed = membersIds
|
|
|
|
|
this.messages[index].received = membersIds
|
2022-03-10 23:08:29 +01:00
|
|
|
|
|
|
|
|
await this.messages[index].save()
|
2022-03-03 22:57:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
2022-01-20 14:31:49 +01:00
|
|
|
|
2022-02-16 15:52:59 +01:00
|
|
|
/**
|
|
|
|
|
* @description find or create message
|
|
|
|
|
* @param message
|
|
|
|
|
* @param save
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-03-03 22:57:33 +01:00
|
|
|
async prepareMessage({message, save = true, redefined = false}): Promise<MessageService> {
|
2022-01-30 09:34:56 +01:00
|
|
|
message = this.fix_updatedAt(message)
|
2022-03-03 22:57:33 +01:00
|
|
|
|
|
|
|
|
|
2022-03-22 16:11:30 +01:00
|
|
|
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
2022-01-30 09:34:56 +01:00
|
|
|
wewMessage.setData(message)
|
2022-02-10 14:07:16 +01:00
|
|
|
wewMessage.loadHistory = this.hasLoadHistory
|
2022-02-09 14:07:34 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
let foundIndex;
|
|
|
|
|
|
|
|
|
|
const found = this.messages.find((MessageService, index) => {
|
2022-02-10 18:07:06 +01:00
|
|
|
if (MessageService._id == message._id) {
|
2022-03-03 22:57:33 +01:00
|
|
|
foundIndex = index
|
2022-02-10 18:07:06 +01:00
|
|
|
return true
|
|
|
|
|
} else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2022-02-10 14:07:16 +01:00
|
|
|
})
|
2022-01-20 14:31:49 +01:00
|
|
|
|
2022-03-04 14:20:39 +01:00
|
|
|
if(save) {
|
|
|
|
|
if (!found) {
|
|
|
|
|
this.messages.push(wewMessage)
|
|
|
|
|
return wewMessage
|
|
|
|
|
}
|
|
|
|
|
} else if(foundIndex) {
|
|
|
|
|
return this.messages[foundIndex]
|
|
|
|
|
} else {
|
|
|
|
|
return wewMessage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
async ChatMessageIsPresentInTheView(ChatMessage:ChatMessageInterface) {
|
|
|
|
|
let foundIndex;
|
|
|
|
|
|
|
|
|
|
const found = this.messages.find((MessageService, index) => {
|
|
|
|
|
if (MessageService._id == ChatMessage._id) {
|
|
|
|
|
foundIndex = index
|
|
|
|
|
return true
|
|
|
|
|
} else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (foundIndex) {
|
|
|
|
|
return { found, foundIndex}
|
|
|
|
|
} else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-03-04 14:50:13 +01:00
|
|
|
/**
|
|
|
|
|
* @description find or create message
|
|
|
|
|
* @param message
|
|
|
|
|
* @param save
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2022-03-14 14:16:23 +01:00
|
|
|
async prepareCreate({message, save = true}): Promise<MessageService> {
|
2022-03-04 14:50:13 +01:00
|
|
|
message = this.fix_updatedAt(message)
|
|
|
|
|
|
2022-03-22 16:11:30 +01:00
|
|
|
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
2022-03-04 14:50:13 +01:00
|
|
|
wewMessage.setData(message)
|
|
|
|
|
wewMessage.loadHistory = this.hasLoadHistory
|
|
|
|
|
|
2022-03-21 15:08:43 +01:00
|
|
|
this.messages.push(wewMessage)
|
|
|
|
|
return wewMessage
|
2022-03-14 14:16:23 +01:00
|
|
|
|
2022-03-04 14:50:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-03-04 14:20:39 +01:00
|
|
|
simplePrepareMessage(message) {
|
|
|
|
|
message = this.fix_updatedAt(message)
|
2022-03-22 16:11:30 +01:00
|
|
|
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
2022-03-04 14:20:39 +01:00
|
|
|
wewMessage.setData(message)
|
|
|
|
|
wewMessage.loadHistory = this.hasLoadHistory
|
|
|
|
|
|
|
|
|
|
return wewMessage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async prepareMessageCreateIfNotExist({message}) {
|
|
|
|
|
message = this.fix_updatedAt(message)
|
|
|
|
|
|
|
|
|
|
let foundIndex;
|
|
|
|
|
const found = this.messages.find((MessageService, index) => {
|
|
|
|
|
if (MessageService._id == message._id ||
|
|
|
|
|
MessageService.localReference == message.localReference ) {
|
|
|
|
|
foundIndex = index
|
|
|
|
|
return true
|
|
|
|
|
} else {
|
|
|
|
|
return false
|
2022-03-21 21:06:54 +01:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
const wewMessage = this.simplePrepareMessage(message)
|
|
|
|
|
this.messages.push(wewMessage)
|
|
|
|
|
return wewMessage
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async prepareMessageCreateIfNotExist_iD({message}) {
|
|
|
|
|
message = this.fix_updatedAt(message)
|
|
|
|
|
|
|
|
|
|
const found = this.messages.find((MessageService, index) => {
|
|
|
|
|
if (MessageService._id == message._id ) {
|
|
|
|
|
return true
|
|
|
|
|
} else {
|
|
|
|
|
return false
|
2022-03-04 14:20:39 +01:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
const wewMessage = this.simplePrepareMessage(message)
|
2022-02-10 14:07:16 +01:00
|
|
|
this.messages.push(wewMessage)
|
2022-03-03 22:57:33 +01:00
|
|
|
return wewMessage
|
2022-03-04 14:20:39 +01:00
|
|
|
} else {
|
2022-03-10 23:08:29 +01:00
|
|
|
return null
|
2022-02-10 14:07:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-10 23:52:33 +01:00
|
|
|
|
2022-01-11 20:56:21 +01:00
|
|
|
private calDateDuration(date = null) {
|
|
|
|
|
this.duration = showDateDuration(date || this._updatedAt);
|
2022-01-28 19:01:24 +01:00
|
|
|
this._updatedAt = date || this._updatedAt
|
2022-01-11 20:56:21 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-10 23:08:29 +01:00
|
|
|
private fix_updatedAt(message): ChatMessageInterface {
|
2022-03-03 22:57:33 +01:00
|
|
|
if (message?.result) {
|
2022-01-11 20:56:21 +01:00
|
|
|
message.result._updatedAt = message.result._updatedAt['$date']
|
2022-03-03 22:57:33 +01:00
|
|
|
} else if(message?._updatedAt) {
|
2022-02-03 21:01:53 +01:00
|
|
|
if(message._updatedAt.hasOwnProperty('$date')) {
|
|
|
|
|
message._updatedAt = message._updatedAt['$date']
|
|
|
|
|
}
|
2022-01-11 20:56:21 +01:00
|
|
|
}
|
|
|
|
|
return message
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 16:15:20 +01:00
|
|
|
usernameToDisplayName(username) {
|
|
|
|
|
|
|
|
|
|
const firstName = capitalizeTxt(username.split('.')[0])
|
|
|
|
|
const lastName = capitalizeTxt(username.split('.')[1])
|
|
|
|
|
return firstName + ' ' + lastName
|
|
|
|
|
}
|
2022-01-12 16:10:59 +01:00
|
|
|
|
2022-03-03 22:57:33 +01:00
|
|
|
sendReadMessage() {
|
|
|
|
|
this.WsChatService.readMessage(this.id)
|
2022-03-15 15:49:59 +01:00
|
|
|
this.sendFalseTypingReadMessage('viewMessage', {})
|
2022-03-03 22:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-10 13:31:15 +01:00
|
|
|
}
|