mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
offline messagens
This commit is contained in:
@@ -23,6 +23,7 @@ export class MessageService {
|
||||
file
|
||||
attachments
|
||||
offline = true
|
||||
displayType = ''
|
||||
|
||||
constructor(private storage: Storage) {
|
||||
}
|
||||
@@ -49,14 +50,16 @@ export class MessageService {
|
||||
|
||||
|
||||
if (this.file) {
|
||||
if (this.file.guid) {
|
||||
this.storage.get(this.file.guid).then((image) => {
|
||||
// console.log('IMAGE FROM STORAGE', image)
|
||||
this.file.image_url = image
|
||||
});
|
||||
this.getFileFromDb()
|
||||
if(this.file.type) {
|
||||
if(this.file.type != 'application/webtrix' && typeof(this.file.type) == 'string') {
|
||||
this.displayType = this.file.type.replace('application/','').toUpperCase()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
delete() {}
|
||||
@@ -75,4 +78,18 @@ export class MessageService {
|
||||
return firstName + ' ' + lastName
|
||||
}
|
||||
|
||||
|
||||
getFileFromDb() {
|
||||
if (this.file) {
|
||||
if (this.file.guid) {
|
||||
this.storage.get(this.file.guid).then((image) => {
|
||||
if(image != null) {
|
||||
this.file.image_url = image
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ export class RoomService {
|
||||
}
|
||||
|
||||
sortRoomList = () => {}
|
||||
uploadAttachment = (formData) => {}
|
||||
|
||||
constructor(
|
||||
public WsChatService: WsChatService,
|
||||
@@ -204,51 +205,9 @@ export class RoomService {
|
||||
/**
|
||||
* @description sen text message
|
||||
*/
|
||||
send() {
|
||||
|
||||
if(environment.chatOffline == false) {
|
||||
this.WsChatService.send(this.id, this.message)
|
||||
this.message= ''
|
||||
} else {
|
||||
|
||||
const offlineChatMessage = {
|
||||
channels: [],
|
||||
mentions: [],
|
||||
rid: this.id,
|
||||
msg: this.message,
|
||||
u: {
|
||||
name: this.usernameToDisplayName(SessionStore.user.RochetChatUser),
|
||||
username: SessionStore.user.RochetChatUser,
|
||||
_id: ""
|
||||
},
|
||||
_updatedAt: new Date().getTime(),
|
||||
offline: true
|
||||
}
|
||||
|
||||
this.addMessageDB(offlineChatMessage)
|
||||
const message: MessageService = this.prepareMessage(offlineChatMessage)
|
||||
|
||||
setTimeout(() => {
|
||||
this.scrollDown()
|
||||
}, 150)
|
||||
|
||||
this.lastMessage = message
|
||||
send({file = null, attachments = null}) {
|
||||
|
||||
|
||||
this.WsChatService.send(this.id, message.msg).then((data: any) => {
|
||||
let ChatMessage = data.result
|
||||
this.redefinedMessage(message, ChatMessage)
|
||||
})
|
||||
|
||||
this.calDateDuration(message._updatedAt)
|
||||
this.sortRoomList()
|
||||
|
||||
this.message= ''
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sendFile({file, attachments, alias = 'document'}) {
|
||||
let offlineChatMessage = {
|
||||
rid: this.id,
|
||||
msg: this.message,
|
||||
@@ -265,16 +224,35 @@ 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')
|
||||
return {
|
||||
message: message,
|
||||
updateMessage: (update)=> {
|
||||
offlineChatMessage = Object.assign(offlineChatMessage, update)
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.calDateDuration(message._updatedAt)
|
||||
this.sortRoomList()
|
||||
|
||||
this.chatService.sendMessage({message:offlineChatMessage}).subscribe((res:any) => {
|
||||
let ChatMessage = res.message
|
||||
console.log('ChatMessage', ChatMessage)
|
||||
this.redefinedMessage(message, ChatMessage)
|
||||
}, (error) => {
|
||||
});
|
||||
|
||||
this.message= ''
|
||||
}
|
||||
|
||||
redefinedMessage (message: MessageService, ChatMessage) {
|
||||
@@ -362,11 +340,13 @@ export class RoomService {
|
||||
|
||||
let localMessages = []
|
||||
|
||||
if(messages==null) messages = []
|
||||
|
||||
messages.forEach((ChatMessage, index) => {
|
||||
const wewMessage = this.prepareMessage(ChatMessage)
|
||||
|
||||
if(wewMessage.offline == true) {
|
||||
this.WsChatService.send(this.id, wewMessage.msg).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
|
||||
this.redefinedMessage(wewMessage, _ChatMessage)
|
||||
this.storage.set('chatmsg' + this.id, messages)
|
||||
|
||||
@@ -162,7 +162,7 @@ export class WsChatService {
|
||||
}
|
||||
|
||||
// send message to room
|
||||
send(roomId, msg) {
|
||||
send({roomId, msg, attachments = null, file = null}) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
@@ -171,9 +171,10 @@ export class WsChatService {
|
||||
method: "sendMessage",
|
||||
id: requestId,
|
||||
params: [{
|
||||
_id: uuidv4(),
|
||||
rid: roomId,
|
||||
msg: msg
|
||||
msg: msg,
|
||||
attachments,
|
||||
file
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -181,7 +182,7 @@ export class WsChatService {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
@@ -206,7 +207,7 @@ export class WsChatService {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
@@ -232,7 +233,7 @@ export class WsChatService {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
@@ -255,7 +256,7 @@ export class WsChatService {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
@@ -310,7 +311,7 @@ export class WsChatService {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
@@ -337,7 +338,7 @@ export class WsChatService {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
@@ -565,7 +566,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
@@ -592,7 +593,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user