This commit is contained in:
Peter Maquiran
2023-01-24 15:56:47 +01:00
parent 0748612054
commit fbd50137f3
153 changed files with 5997 additions and 953 deletions
@@ -25,6 +25,7 @@ export class ChatMethodsService {
"end_date": data.end,
"venue": data.venue,
"id": data.id,
"calendarId": data.calendarId
}
}
}
+20 -13
View File
@@ -18,7 +18,6 @@ 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 { JsonStore } from '../jsonStore.service';
import { ViewedMessageService } from './viewed-message.service'
@Injectable({
providedIn: 'root'
@@ -97,7 +96,7 @@ export class ChatSystemService {
}
loadChat() {
if(SessionStore.user.ChatData) {
if(SessionStore.user?.ChatData?.data) {
this.ReLoadChat()
}
}
@@ -185,14 +184,18 @@ export class ChatSystemService {
async getAllRooms () {
this.loadingWholeList = true
var rooms;
try {
rooms = await this.RochetChatConnectorService.getRooms();
} catch (error) {
console.error('chatgetrooms',error)
}
if(this.RochetChatConnectorService.isLogin) {
try {
await this.storage.remove('Rooms');
} catch(e) {}
rooms = await this.RochetChatConnectorService.getRooms();
} catch (error) {
this.loadingWholeList = false
console.error('chatgetrooms',error)
}
try {
await this.storage.remove('Rooms');
} catch(e) {}
}
let index = 0
@@ -317,8 +320,12 @@ export class ChatSystemService {
this.defaultSubtribe(id)
}
this.RochetChatConnectorService.streamNotifyLogged().then((subscription=>{
this.RochetChatConnectorService.streamNotifyLogged().then((subscription => {
console.log(subscription)
}))
this.RochetChatConnectorService.subStreamMessageUser().then((subscription => {
console.log(subscription)
}))
}
@@ -407,7 +414,7 @@ export class ChatSystemService {
let roomId = this.getRoomId(roomData);
if (setData.name != 'Rocket Cat') {
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.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this, this.ViewedMessageService)
@@ -615,7 +622,7 @@ export class ChatSystemService {
return !roomData.fname
}
getUsers = () =>{
getUsers = () => {
return this.users
}
+35 -9
View File
@@ -61,6 +61,9 @@ export class MessageService {
downloadAttachmentsTemp = 0;
UploadAttachmentsTemp = 0;
manualRetry = false
origin: 'history' | 'stream' | 'local'
rowInstance: MessageModel
constructor(
private NfService: NfService,
@@ -72,7 +75,7 @@ export class MessageService {
private ChatSystemService: ChatSystemService) {
}
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0 }:Message) {
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0, origin }:Message) {
this.channels = channels || []
this.mentions = mentions || []
@@ -90,6 +93,7 @@ export class MessageService {
this.delate = delate
this.delateRequest = delateRequest
this.sendAttempt = 0
this.origin = origin
if(this.attachments?.length >= 1 && attachments?.length >= 1) {
this.attachments[0] = Object.assign(this.attachments[0], attachments[0])
@@ -257,6 +261,7 @@ export class MessageService {
} catch (error) {
this.uploadingFile = false
this.errorUploadingAttachment = true
this.UploadAttachmentsTemp++
console.error('beforeSendAttachment error:', error)
}
@@ -441,9 +446,11 @@ export class MessageService {
async delateDB() {
const message = await MessageModel.get({id: this.id})
await message.delete()
if(!this.rowInstance) {
this.rowInstance = await this.getRowInstance()
}
await this.rowInstance.delete()
}
@@ -467,6 +474,7 @@ export class MessageService {
u: this.u,
_id: this._id,
id: this.id,
origin: this.origin,
_updatedAt: this._updatedAt,
messageSend: this.messageSend,
offline: this.offline,
@@ -489,6 +497,7 @@ export class MessageService {
delete message.id
const createdMessage = await MessageModel.create(message)
this.rowInstance = createdMessage
this.id = createdMessage.id
if(this.earlySave) {
@@ -497,8 +506,8 @@ export class MessageService {
}
}
async saveChanges() {
async getRowInstance () {
if(this.save) {
const message = this.getChatObj()
@@ -516,12 +525,29 @@ export class MessageService {
a = await MessageModel.get({id: this.id})
}
if(a) {
for( const [name, value] of Object.entries(message)) {
a[name] = value
}
await a.save()
return a
}
}
async saveChanges() {
if(!this.rowInstance) {
this.rowInstance = await this.getRowInstance()
}
if(this.save && this.rowInstance) {
const message = this.getChatObj()
if(!message.id) {
delete message.id
}
for( const [name, value] of Object.entries(message)) {
this.rowInstance[name] = value
}
await this.rowInstance.save()
} else {
this.earlySave = true
@@ -437,6 +437,63 @@ export class RochetChatConnectorService {
}
subStreamNotifyUser(param?: any) {
const requestId = uuidv4()
let message = {
msg: "sub",
id: requestId,
name: "stream-notify-user",
params:[
`${SessionStore.user.ChatData.data.userId}/notification`,
param
]
}
this.ws.send({message, requestId})
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
}})
});
}
subStreamMessageUser(param?: any) {
const requestId = uuidv4()
let message = {
msg: "sub",
id: requestId,
name: "stream-notify-user",
params:[
`${SessionStore.user.ChatData.data.userId}/message`,
param
]
}
this.ws.send({message, requestId})
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
}})
});
}
receiveStreamNotifyRoom(funx: Function) {
this.ws.registerCallback({
+23 -7
View File
@@ -275,18 +275,25 @@ export class RoomService {
if(message.fields.eventName == this.id+'/'+'typing') {
const args = message.fields.args
if (typeof args[1] != 'object') {
this.userThatIsTyping = this.usernameToDisplayName(args[0])
this.isTyping = args[1]
this.otherUserType = args[1]
this.readAllMessage()
const user = args[0]
if(SessionStore.user.UserName != user) {
this.readAllMessage()
}
} else if(args[0]?.method == 'viewMessage' || args[1]?.method == 'viewMessage') {
this.readAllMessage()
const user = args[0]
if(SessionStore.user.UserName != user) {
this.readAllMessage()
}
} else if(args[0]?.method == 'deleteMessage' || args[1]?.method == 'deleteMessage') {
this.deleteMessage(args[1]?.method?._id)
@@ -295,7 +302,6 @@ export class RoomService {
}
} else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}
})
@@ -313,6 +319,7 @@ export class RoomService {
if(!found) {
ChatMessage.origin = 'stream'
const message = await this.prepareCreate({message: ChatMessage, save: true});
this.registerSendMessage(message)
@@ -445,7 +452,13 @@ export class RoomService {
"stream-notify-room",
async (ChatMessage) => {
const DeletedMessageId = ChatMessage.fields.args[0]._id;
this.deleteMessage(DeletedMessageId)
const message = this.messages.find((e) => e._id == DeletedMessageId)
if(message.delate == false) {
this.deleteMessage(DeletedMessageId)
}
}
)
}
@@ -556,7 +569,8 @@ export class RoomService {
attachments,
file,
temporaryData,
localReference
localReference,
origin: 'local'
}
this.message= ''
@@ -657,6 +671,7 @@ export class RoomService {
// this.typing(this.message)
this.chatOpen = true
this.messageUnread = false
this.sendReadMessage()
}
@@ -737,6 +752,7 @@ export class RoomService {
for(let message of chatHistory.result.messages.reverse()) {
if (!messagesId.includes(message._id)) {
message.origin = 'history'
const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message});
if(messagesToSave != null) {
@@ -27,9 +27,9 @@ export class ViewedMessageService {
for(let id of membersIds) {
if(message.addReceived(id)) {
n++
setTimeout(async() => {
// setTimeout(async() => {
await message.saveChanges()
}, 100 * n)
// }, 100 * n)
}
}
}
@@ -56,9 +56,9 @@ export class ViewedMessageService {
if(message.addViewed(id)) {
message.addReceived(id)
n++
setTimeout(async() => {
// setTimeout(async() => {
await message.saveChanges()
}, 100 * n)
// }, 100 * n)
}
}