mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix
This commit is contained in:
@@ -457,7 +457,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
"guid": '',
|
||||
"image_url": capturedImage
|
||||
},
|
||||
temporary: formData,
|
||||
temporaryData: formData,
|
||||
attachments: [{
|
||||
"title": capturedImageTitle ,
|
||||
"text": "description",
|
||||
@@ -535,7 +535,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
"guid": '',
|
||||
"image_url": imageData
|
||||
},
|
||||
temporary: formData,
|
||||
temporaryData: formData,
|
||||
attachments: [{
|
||||
"title": file.name ,
|
||||
"text": "description",
|
||||
|
||||
@@ -547,7 +547,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
"text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporary: formData
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
}
|
||||
@@ -595,7 +595,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
// "message_link": url_no_options,
|
||||
"text": res.data.selected.DocTypeDesc,
|
||||
"type": "webtrix"
|
||||
}]
|
||||
}],
|
||||
})
|
||||
|
||||
loader.remove();
|
||||
@@ -621,7 +621,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
"guid": '',
|
||||
"image_url": imageData
|
||||
},
|
||||
temporary: formData,
|
||||
temporaryData: formData,
|
||||
attachments: [{
|
||||
"title": file.name ,
|
||||
"text": "description",
|
||||
|
||||
@@ -155,22 +155,28 @@ export class AuthService {
|
||||
if(message.hasFile) {
|
||||
if(message.file.type != 'application/webtrix') {
|
||||
const formData = message.temporaryData
|
||||
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
|
||||
message.file.guid = guid.path
|
||||
await this.storage.set(guid.path, message.file.image_url).then(() => {
|
||||
console.log('add picture to chat IMAGE SAVED')
|
||||
message.getFileFromDb()
|
||||
});
|
||||
|
||||
return true
|
||||
try {
|
||||
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
|
||||
message.file.guid = guid.path
|
||||
await this.storage.set(guid.path, message.file.image_url).then(() => {
|
||||
console.log('add picture to chat IMAGE SAVED')
|
||||
message.getFileFromDb()
|
||||
return true
|
||||
});
|
||||
} catch(e) {}
|
||||
|
||||
} else {
|
||||
const res = message.temporaryData
|
||||
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
|
||||
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
|
||||
message.attachments[0].title_link = url_no_options
|
||||
message.attachments[0].message_link = url_no_options
|
||||
try {
|
||||
const res = message.temporaryData
|
||||
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
|
||||
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
|
||||
message.attachments[0].title_link = url_no_options
|
||||
message.attachments[0].message_link = url_no_options
|
||||
return true
|
||||
|
||||
return true
|
||||
} catch(e) {}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Storage } from '@ionic/storage';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { capitalizeTxt } from 'src/plugin/text'
|
||||
import { NfService } from 'src/app/services/chat/nf.service'
|
||||
|
||||
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -29,7 +29,8 @@ export class MessageService {
|
||||
hasSendAttachment = false
|
||||
|
||||
constructor(private storage: Storage,
|
||||
private NfService: NfService) {
|
||||
private NfService: NfService,
|
||||
private WsChatService: WsChatService) {
|
||||
}
|
||||
|
||||
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData}:Message) {
|
||||
@@ -45,7 +46,7 @@ export class MessageService {
|
||||
this._updatedAt = _updatedAt || new Date().getTime()
|
||||
this.file = file
|
||||
this.attachments = attachments
|
||||
this,temporaryData = {}
|
||||
this.temporaryData = temporaryData
|
||||
|
||||
if(!this.ts) {
|
||||
this.offline = true
|
||||
@@ -90,7 +91,33 @@ export class MessageService {
|
||||
}
|
||||
|
||||
sendFile() {
|
||||
|
||||
if(this.file == null && this.attachments == null) {
|
||||
console.log('simple send')
|
||||
this.WsChatService.send({roomId:this.rid, msg:this.msg}).then((data: any) => {
|
||||
let ChatMessage = data.result
|
||||
this.redefinedMessage(this, ChatMessage)
|
||||
})
|
||||
} else {
|
||||
console.log('complex send')
|
||||
|
||||
const result = this.NfService.beforeSendAttachment(this)
|
||||
|
||||
|
||||
if(result) {
|
||||
this.hasSendAttachment = true
|
||||
|
||||
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file}).then((data: any) => {
|
||||
console.log('send sucees', data.result)
|
||||
let ChatMessage = data.result
|
||||
this.redefinedMessage(this, ChatMessage)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
redefinedMessage(messagem, ChatMessage){
|
||||
this.setData(ChatMessage)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { RoomService } from './room.service';
|
||||
})
|
||||
export class NfService {
|
||||
|
||||
beforeSendAttachment = (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)))
|
||||
beforeSendAttachment = async (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)))
|
||||
|
||||
|
||||
constructor() { }
|
||||
|
||||
@@ -69,7 +69,7 @@ export class RoomService {
|
||||
this.NativeNotificationService.askForPermission()
|
||||
}
|
||||
|
||||
setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage, this.NfService), _updatedAt }) {
|
||||
setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService), _updatedAt }) {
|
||||
this.customFields = customFields
|
||||
this.id = id
|
||||
this.name = name
|
||||
@@ -138,6 +138,7 @@ export class RoomService {
|
||||
|
||||
addMessageDB(ChatMessage) {
|
||||
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
||||
delete ChatMessage.temporaryData
|
||||
messages.push(ChatMessage)
|
||||
|
||||
this.storage.set('chatmsg' + this.id, messages)
|
||||
@@ -205,7 +206,7 @@ export class RoomService {
|
||||
/**
|
||||
* @description sen text message
|
||||
*/
|
||||
send({file = null, attachments = null, temporary= {}}) {
|
||||
async send({file = null, attachments = null, temporaryData = {}}) {
|
||||
|
||||
|
||||
let offlineChatMessage = {
|
||||
@@ -213,8 +214,10 @@ export class RoomService {
|
||||
msg: this.message,
|
||||
attachments,
|
||||
file,
|
||||
temporary
|
||||
temporaryData
|
||||
}
|
||||
|
||||
console.log('offlineChatMessage', offlineChatMessage)
|
||||
|
||||
this.addMessageDB(offlineChatMessage)
|
||||
const message: MessageService = this.prepareMessage(offlineChatMessage)
|
||||
@@ -235,9 +238,8 @@ export class RoomService {
|
||||
} else {
|
||||
console.log('complex send')
|
||||
|
||||
const result = this.NfService.beforeSendAttachment(message, this)
|
||||
|
||||
delete message.temporaryData;
|
||||
const result = await this.NfService.beforeSendAttachment(message, this)
|
||||
|
||||
|
||||
if(result) {
|
||||
message.hasSendAttachment = true
|
||||
@@ -338,57 +340,58 @@ export class RoomService {
|
||||
}
|
||||
|
||||
|
||||
restoreMessageFromDB() {
|
||||
this.storage.get('chatmsg' + this.id).then((messages = []) => {
|
||||
|
||||
let localMessages: MessageService[] = []
|
||||
async restoreMessageFromDB() {
|
||||
await this.storage.get('chatmsg' + this.id).then( async (messages = []) => {
|
||||
|
||||
if(messages==null) messages = []
|
||||
|
||||
messages.forEach((ChatMessage, index) => {
|
||||
await messages.forEach( async (ChatMessage, index) => {
|
||||
const wewMessage = this.prepareMessage(ChatMessage)
|
||||
|
||||
if(wewMessage.offline == true) {
|
||||
// this.WsChatService.send({roomId:this.id, msg:wewMessage.msg, attachments:wewMessage.attachments, file: wewMessage.file}).then((data: any) => {
|
||||
// let _ChatMessage = data.result
|
||||
// this.redefinedMessage(wewMessage, _ChatMessage)
|
||||
// messages[index] = _ChatMessage
|
||||
// this.storage.set('chatmsg' + this.id, messages)
|
||||
// })
|
||||
}
|
||||
|
||||
localMessages.push(wewMessage)
|
||||
});
|
||||
|
||||
this.messages = alasql('SELECT * FROM ? ORDER BY _updatedAt',[localMessages]);
|
||||
this.messages = alasql('SELECT * FROM ? ORDER BY _updatedAt',[ this.messages]);
|
||||
setTimeout(()=> {
|
||||
this.scrollDown()
|
||||
}, 50)
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// runs onces only
|
||||
loadHistory(limit = 100) {
|
||||
async loadHistory(limit = 100) {
|
||||
|
||||
if (this.hasLoadHistory) { return false }
|
||||
|
||||
this.restoreMessageFromDB()
|
||||
await this.restoreMessageFromDB()
|
||||
|
||||
this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => {
|
||||
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
|
||||
console.log('loadHistory', chatHistory)
|
||||
this.messages = []
|
||||
|
||||
let localMessages = []
|
||||
await chatHistory.result.messages.reverse().forEach( async (message) => {
|
||||
this.prepareMessage(message)
|
||||
|
||||
chatHistory.result.messages.reverse().forEach(message => {
|
||||
|
||||
const wewMessage = this.prepareMessage(message)
|
||||
|
||||
localMessages.push(wewMessage)
|
||||
// const result = alasql(`SELECT * FROM ? WHERE _id = "${message._id}" `,[ this.messages]);
|
||||
// if(result.length == 0) {
|
||||
// this.prepareMessage(message)
|
||||
// this.storage.set('chatmsg' + this.id, chatHistory.result.messages.concat([message]))
|
||||
// }
|
||||
|
||||
});
|
||||
|
||||
this.messages = localMessages
|
||||
|
||||
console.log(chatHistory.result.messages);
|
||||
|
||||
this.storage.set('chatmsg' + this.id, chatHistory.result.messages.reverse())
|
||||
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
@@ -402,7 +405,7 @@ export class RoomService {
|
||||
|
||||
prepareMessage(message): MessageService {
|
||||
message = this.fix_updatedAt(message)
|
||||
const wewMessage = new MessageService(this.storage, this.NfService)
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService)
|
||||
wewMessage.setData(message)
|
||||
this.messages.push(wewMessage)
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ export class WsChatMethodsService {
|
||||
prepareRoom(roomData) {
|
||||
let room:RoomService;
|
||||
|
||||
room = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService)
|
||||
room = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService)
|
||||
|
||||
room.setData({
|
||||
customFields: roomData.customFields,
|
||||
|
||||
@@ -565,7 +565,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
"title": capturedImageTitle ,
|
||||
"text": "description",
|
||||
"title_link_download": false,
|
||||
}]
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
}
|
||||
@@ -616,7 +617,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
//"thumb_url": "assets/images/webtrix-logo.png",
|
||||
"text": res.data.selected.DocTypeDesc,
|
||||
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
|
||||
}]
|
||||
}],
|
||||
temporaryData: res
|
||||
})
|
||||
|
||||
loader.remove();
|
||||
@@ -642,7 +644,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
"guid": '',
|
||||
"image_url": imageData
|
||||
},
|
||||
temporary: formData,
|
||||
temporaryData: formData,
|
||||
attachments: [{
|
||||
"title": file.name ,
|
||||
"text": "description",
|
||||
|
||||
@@ -455,13 +455,15 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
|
||||
console.log('formData', formData)
|
||||
|
||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": "application/img",
|
||||
"guid": '',
|
||||
"image_url": capturedImage
|
||||
},
|
||||
temporary: formData,
|
||||
temporaryData: formData,
|
||||
attachments: [{
|
||||
"title": capturedImageTitle ,
|
||||
"text": "description",
|
||||
@@ -513,7 +515,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
"text": res.data.selected.DocTypeDesc,
|
||||
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
|
||||
}],
|
||||
temporary: res
|
||||
})
|
||||
|
||||
loader.remove();
|
||||
@@ -543,7 +544,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
"title": file.name ,
|
||||
"text": "description",
|
||||
"title_link_download": false,
|
||||
}]
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user