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": '',
|
"guid": '',
|
||||||
"image_url": capturedImage
|
"image_url": capturedImage
|
||||||
},
|
},
|
||||||
temporary: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
"title": capturedImageTitle ,
|
"title": capturedImageTitle ,
|
||||||
"text": "description",
|
"text": "description",
|
||||||
@@ -535,7 +535,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
"guid": '',
|
"guid": '',
|
||||||
"image_url": imageData
|
"image_url": imageData
|
||||||
},
|
},
|
||||||
temporary: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
"title": file.name ,
|
"title": file.name ,
|
||||||
"text": "description",
|
"text": "description",
|
||||||
|
|||||||
@@ -547,7 +547,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
"text": "description",
|
"text": "description",
|
||||||
"title_link_download": false,
|
"title_link_download": false,
|
||||||
}],
|
}],
|
||||||
temporary: formData
|
temporaryData: formData
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -595,7 +595,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
// "message_link": url_no_options,
|
// "message_link": url_no_options,
|
||||||
"text": res.data.selected.DocTypeDesc,
|
"text": res.data.selected.DocTypeDesc,
|
||||||
"type": "webtrix"
|
"type": "webtrix"
|
||||||
}]
|
}],
|
||||||
})
|
})
|
||||||
|
|
||||||
loader.remove();
|
loader.remove();
|
||||||
@@ -621,7 +621,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
"guid": '',
|
"guid": '',
|
||||||
"image_url": imageData
|
"image_url": imageData
|
||||||
},
|
},
|
||||||
temporary: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
"title": file.name ,
|
"title": file.name ,
|
||||||
"text": "description",
|
"text": "description",
|
||||||
|
|||||||
@@ -155,22 +155,28 @@ export class AuthService {
|
|||||||
if(message.hasFile) {
|
if(message.hasFile) {
|
||||||
if(message.file.type != 'application/webtrix') {
|
if(message.file.type != 'application/webtrix') {
|
||||||
const formData = message.temporaryData
|
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 {
|
} else {
|
||||||
const res = message.temporaryData
|
try {
|
||||||
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
|
const res = message.temporaryData
|
||||||
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
|
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
|
||||||
message.attachments[0].title_link = url_no_options
|
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
|
||||||
message.attachments[0].message_link = url_no_options
|
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 { SessionStore } from 'src/app/store/session.service';
|
||||||
import { capitalizeTxt } from 'src/plugin/text'
|
import { capitalizeTxt } from 'src/plugin/text'
|
||||||
import { NfService } from 'src/app/services/chat/nf.service'
|
import { NfService } from 'src/app/services/chat/nf.service'
|
||||||
|
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
@@ -29,7 +29,8 @@ export class MessageService {
|
|||||||
hasSendAttachment = false
|
hasSendAttachment = false
|
||||||
|
|
||||||
constructor(private storage: Storage,
|
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) {
|
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._updatedAt = _updatedAt || new Date().getTime()
|
||||||
this.file = file
|
this.file = file
|
||||||
this.attachments = attachments
|
this.attachments = attachments
|
||||||
this,temporaryData = {}
|
this.temporaryData = temporaryData
|
||||||
|
|
||||||
if(!this.ts) {
|
if(!this.ts) {
|
||||||
this.offline = true
|
this.offline = true
|
||||||
@@ -90,7 +91,33 @@ export class MessageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendFile() {
|
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 {
|
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() { }
|
constructor() { }
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export class RoomService {
|
|||||||
this.NativeNotificationService.askForPermission()
|
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.customFields = customFields
|
||||||
this.id = id
|
this.id = id
|
||||||
this.name = name
|
this.name = name
|
||||||
@@ -138,6 +138,7 @@ export class RoomService {
|
|||||||
|
|
||||||
addMessageDB(ChatMessage) {
|
addMessageDB(ChatMessage) {
|
||||||
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
||||||
|
delete ChatMessage.temporaryData
|
||||||
messages.push(ChatMessage)
|
messages.push(ChatMessage)
|
||||||
|
|
||||||
this.storage.set('chatmsg' + this.id, messages)
|
this.storage.set('chatmsg' + this.id, messages)
|
||||||
@@ -205,7 +206,7 @@ export class RoomService {
|
|||||||
/**
|
/**
|
||||||
* @description sen text message
|
* @description sen text message
|
||||||
*/
|
*/
|
||||||
send({file = null, attachments = null, temporary= {}}) {
|
async send({file = null, attachments = null, temporaryData = {}}) {
|
||||||
|
|
||||||
|
|
||||||
let offlineChatMessage = {
|
let offlineChatMessage = {
|
||||||
@@ -213,8 +214,10 @@ export class RoomService {
|
|||||||
msg: this.message,
|
msg: this.message,
|
||||||
attachments,
|
attachments,
|
||||||
file,
|
file,
|
||||||
temporary
|
temporaryData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('offlineChatMessage', offlineChatMessage)
|
||||||
|
|
||||||
this.addMessageDB(offlineChatMessage)
|
this.addMessageDB(offlineChatMessage)
|
||||||
const message: MessageService = this.prepareMessage(offlineChatMessage)
|
const message: MessageService = this.prepareMessage(offlineChatMessage)
|
||||||
@@ -235,9 +238,8 @@ export class RoomService {
|
|||||||
} else {
|
} else {
|
||||||
console.log('complex send')
|
console.log('complex send')
|
||||||
|
|
||||||
const result = this.NfService.beforeSendAttachment(message, this)
|
const result = await this.NfService.beforeSendAttachment(message, this)
|
||||||
|
|
||||||
delete message.temporaryData;
|
|
||||||
|
|
||||||
if(result) {
|
if(result) {
|
||||||
message.hasSendAttachment = true
|
message.hasSendAttachment = true
|
||||||
@@ -338,57 +340,58 @@ export class RoomService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
restoreMessageFromDB() {
|
async restoreMessageFromDB() {
|
||||||
this.storage.get('chatmsg' + this.id).then((messages = []) => {
|
await this.storage.get('chatmsg' + this.id).then( async (messages = []) => {
|
||||||
|
|
||||||
let localMessages: MessageService[] = []
|
|
||||||
|
|
||||||
if(messages==null) messages = []
|
if(messages==null) messages = []
|
||||||
|
|
||||||
messages.forEach((ChatMessage, index) => {
|
await messages.forEach( async (ChatMessage, index) => {
|
||||||
const wewMessage = this.prepareMessage(ChatMessage)
|
const wewMessage = this.prepareMessage(ChatMessage)
|
||||||
|
|
||||||
if(wewMessage.offline == true) {
|
if(wewMessage.offline == true) {
|
||||||
// this.WsChatService.send({roomId:this.id, msg:wewMessage.msg, attachments:wewMessage.attachments, file: wewMessage.file}).then((data: any) => {
|
// this.WsChatService.send({roomId:this.id, msg:wewMessage.msg, attachments:wewMessage.attachments, file: wewMessage.file}).then((data: any) => {
|
||||||
// let _ChatMessage = data.result
|
// let _ChatMessage = data.result
|
||||||
// this.redefinedMessage(wewMessage, _ChatMessage)
|
// this.redefinedMessage(wewMessage, _ChatMessage)
|
||||||
|
// messages[index] = _ChatMessage
|
||||||
// this.storage.set('chatmsg' + this.id, messages)
|
// 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
|
// runs onces only
|
||||||
loadHistory(limit = 100) {
|
async loadHistory(limit = 100) {
|
||||||
|
|
||||||
if (this.hasLoadHistory) { return false }
|
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)
|
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 result = alasql(`SELECT * FROM ? WHERE _id = "${message._id}" `,[ this.messages]);
|
||||||
|
// if(result.length == 0) {
|
||||||
const wewMessage = this.prepareMessage(message)
|
// this.prepareMessage(message)
|
||||||
|
// this.storage.set('chatmsg' + this.id, chatHistory.result.messages.concat([message]))
|
||||||
localMessages.push(wewMessage)
|
// }
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.messages = localMessages
|
|
||||||
|
|
||||||
console.log(chatHistory.result.messages);
|
console.log(chatHistory.result.messages);
|
||||||
|
|
||||||
this.storage.set('chatmsg' + this.id, chatHistory.result.messages.reverse())
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -402,7 +405,7 @@ export class RoomService {
|
|||||||
|
|
||||||
prepareMessage(message): MessageService {
|
prepareMessage(message): MessageService {
|
||||||
message = this.fix_updatedAt(message)
|
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)
|
wewMessage.setData(message)
|
||||||
this.messages.push(wewMessage)
|
this.messages.push(wewMessage)
|
||||||
|
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ export class WsChatMethodsService {
|
|||||||
prepareRoom(roomData) {
|
prepareRoom(roomData) {
|
||||||
let room:RoomService;
|
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({
|
room.setData({
|
||||||
customFields: roomData.customFields,
|
customFields: roomData.customFields,
|
||||||
|
|||||||
@@ -565,7 +565,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||||||
"title": capturedImageTitle ,
|
"title": capturedImageTitle ,
|
||||||
"text": "description",
|
"text": "description",
|
||||||
"title_link_download": false,
|
"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",
|
//"thumb_url": "assets/images/webtrix-logo.png",
|
||||||
"text": res.data.selected.DocTypeDesc,
|
"text": res.data.selected.DocTypeDesc,
|
||||||
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
|
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
|
||||||
}]
|
}],
|
||||||
|
temporaryData: res
|
||||||
})
|
})
|
||||||
|
|
||||||
loader.remove();
|
loader.remove();
|
||||||
@@ -642,7 +644,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||||||
"guid": '',
|
"guid": '',
|
||||||
"image_url": imageData
|
"image_url": imageData
|
||||||
},
|
},
|
||||||
temporary: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
"title": file.name ,
|
"title": file.name ,
|
||||||
"text": "description",
|
"text": "description",
|
||||||
|
|||||||
@@ -455,13 +455,15 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("blobFile", blob);
|
formData.append("blobFile", blob);
|
||||||
|
|
||||||
|
console.log('formData', formData)
|
||||||
|
|
||||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": '',
|
||||||
"image_url": capturedImage
|
"image_url": capturedImage
|
||||||
},
|
},
|
||||||
temporary: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
"title": capturedImageTitle ,
|
"title": capturedImageTitle ,
|
||||||
"text": "description",
|
"text": "description",
|
||||||
@@ -513,7 +515,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
"text": res.data.selected.DocTypeDesc,
|
"text": res.data.selected.DocTypeDesc,
|
||||||
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
|
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
|
||||||
}],
|
}],
|
||||||
temporary: res
|
|
||||||
})
|
})
|
||||||
|
|
||||||
loader.remove();
|
loader.remove();
|
||||||
@@ -543,7 +544,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
"title": file.name ,
|
"title": file.name ,
|
||||||
"text": "description",
|
"text": "description",
|
||||||
"title_link_download": false,
|
"title_link_download": false,
|
||||||
}]
|
}],
|
||||||
|
temporaryData: formData
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user