mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 13:26:08 +00:00
improve
This commit is contained in:
@@ -3,7 +3,7 @@ import { WsChatService } from 'src/app/services/chat/ws-chat.service';
|
||||
import { MessageService } from 'src/app/services/chat/message.service';
|
||||
import { showDateDuration } from 'src/plugin/showDateDuration';
|
||||
import { ToastsService } from '../toast.service';
|
||||
import { chatHistory, ChatMessage } from 'src/app/models/chatMethod';
|
||||
import { chatHistory } from 'src/app/models/chatMethod';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { Platform } from '@ionic/angular';
|
||||
import { SqliteService } from 'src/app/services/sqlite.service';
|
||||
@@ -138,6 +138,8 @@ export class RoomService {
|
||||
|
||||
addMessageDB(ChatMessage) {
|
||||
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
||||
if(messages==null) messages = []
|
||||
|
||||
delete ChatMessage.temporaryData
|
||||
messages.push(ChatMessage)
|
||||
|
||||
@@ -188,6 +190,7 @@ export class RoomService {
|
||||
*/
|
||||
private deleteMessageFromDb(id) {
|
||||
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
||||
if(messages==null) messages = []
|
||||
|
||||
messages.forEach((message, index) => {
|
||||
|
||||
@@ -228,31 +231,7 @@ export class RoomService {
|
||||
|
||||
this.lastMessage = message
|
||||
|
||||
|
||||
if(file == null && attachments == null) {
|
||||
console.log('simple send')
|
||||
this.WsChatService.send({roomId:this.id, msg:message.msg}).then((data: any) => {
|
||||
let ChatMessage = data.result
|
||||
this.redefinedMessage(message, ChatMessage)
|
||||
})
|
||||
} else {
|
||||
console.log('complex send')
|
||||
|
||||
const result = await this.NfService.beforeSendAttachment(message, this)
|
||||
|
||||
|
||||
if(result) {
|
||||
message.hasSendAttachment = true
|
||||
|
||||
this.WsChatService.send({roomId:this.id, msg:message.msg, attachments:offlineChatMessage.attachments, file:offlineChatMessage.file}).then((data: any) => {
|
||||
console.log('send sucees', data.result)
|
||||
let ChatMessage = data.result
|
||||
this.redefinedMessage(message, ChatMessage)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
message.send()
|
||||
|
||||
this.calDateDuration(message._updatedAt)
|
||||
this.sortRoomList()
|
||||
@@ -342,24 +321,17 @@ export class RoomService {
|
||||
|
||||
async restoreMessageFromDB() {
|
||||
await this.storage.get('chatmsg' + this.id).then( async (messages = []) => {
|
||||
|
||||
if(messages==null) messages = []
|
||||
|
||||
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)
|
||||
// })
|
||||
wewMessage.send()
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
this.messages = alasql('SELECT * FROM ? ORDER BY _updatedAt',[ this.messages]);
|
||||
setTimeout(()=> {
|
||||
this.scrollDown()
|
||||
}, 50)
|
||||
@@ -390,8 +362,6 @@ export class RoomService {
|
||||
|
||||
});
|
||||
|
||||
console.log(chatHistory.result.messages);
|
||||
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
@@ -408,14 +378,9 @@ export class RoomService {
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService)
|
||||
wewMessage.setData(message)
|
||||
this.messages.push(wewMessage)
|
||||
|
||||
return wewMessage
|
||||
}
|
||||
|
||||
updateMeessage(messageID, imgbase64) {
|
||||
|
||||
}
|
||||
|
||||
async returnData(res) {
|
||||
|
||||
return res;
|
||||
|
||||
Reference in New Issue
Block a user