mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
add chat offline
This commit is contained in:
@@ -59,7 +59,7 @@ interface FirstUnread {
|
|||||||
msg: string;
|
msg: string;
|
||||||
ts: Ts2;
|
ts: Ts2;
|
||||||
u: U2;
|
u: U2;
|
||||||
_updatedAt: UpdatedAt2;
|
_updatedAt: string;
|
||||||
mentions: any[];
|
mentions: any[];
|
||||||
channels: any[];
|
channels: any[];
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ export interface Message {
|
|||||||
ts: Ts;
|
ts: Ts;
|
||||||
u: U;
|
u: U;
|
||||||
t: string;
|
t: string;
|
||||||
_updatedAt: UpdatedAt;
|
_updatedAt: '';
|
||||||
mentions: any[];
|
mentions: any[];
|
||||||
channels: any[];
|
channels: any[];
|
||||||
attachments: Attachment[];
|
attachments: Attachment[];
|
||||||
@@ -232,7 +232,7 @@ interface FirstUnread {
|
|||||||
msg: string;
|
msg: string;
|
||||||
ts: Ts2;
|
ts: Ts2;
|
||||||
u: U2;
|
u: U2;
|
||||||
_updatedAt: UpdatedAt2;
|
_updatedAt: string;
|
||||||
mentions: any[];
|
mentions: any[];
|
||||||
channels: any[];
|
channels: any[];
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ export interface Message {
|
|||||||
ts: Ts;
|
ts: Ts;
|
||||||
u: U;
|
u: U;
|
||||||
t: string;
|
t: string;
|
||||||
_updatedAt: UpdatedAt;
|
_updatedAt: '';
|
||||||
mentions: any[];
|
mentions: any[];
|
||||||
channels: any[];
|
channels: any[];
|
||||||
attachments: Attachment[];
|
attachments: Attachment[];
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ export class MessageService {
|
|||||||
u = {}
|
u = {}
|
||||||
t = ''
|
t = ''
|
||||||
_id =''
|
_id =''
|
||||||
_updatedAt = {}
|
_updatedAt = ''
|
||||||
file
|
file
|
||||||
attachments
|
attachments
|
||||||
|
offline = false
|
||||||
|
|
||||||
constructor(private storage: Storage) {
|
constructor(private storage: Storage) {
|
||||||
}
|
}
|
||||||
@@ -47,10 +48,23 @@ export class MessageService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(this.rid == 'offline') {
|
||||||
|
this.offline = true
|
||||||
|
} else {
|
||||||
|
this.offline = false
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete() {}
|
delete() {}
|
||||||
|
|
||||||
showDateDuration() {}
|
showDateDuration() {}
|
||||||
|
|
||||||
|
|
||||||
|
resend() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { SessionStore } from 'src/app/store/session.service';
|
|||||||
import { capitalizeTxt } from 'src/plugin/text'
|
import { capitalizeTxt } from 'src/plugin/text'
|
||||||
import { SortService } from '../functions/sort.service';
|
import { SortService } from '../functions/sort.service';
|
||||||
import { chatUser } from 'src/app/models/chatMethod';
|
import { chatUser } from 'src/app/models/chatMethod';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -51,6 +52,8 @@ export class RoomService {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortRoomList = () => {}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public WsChatService: WsChatService,
|
public WsChatService: WsChatService,
|
||||||
private MessageService: MessageService,
|
private MessageService: MessageService,
|
||||||
@@ -80,40 +83,34 @@ export class RoomService {
|
|||||||
this.id,
|
this.id,
|
||||||
"stream-room-messages",
|
"stream-room-messages",
|
||||||
(ChatMessage) => {
|
(ChatMessage) => {
|
||||||
ChatMessage = ChatMessage.fields.args[0]
|
|
||||||
ChatMessage = this.fix_updatedAt(ChatMessage)
|
|
||||||
console.log('recivemessage', ChatMessage)
|
|
||||||
|
|
||||||
|
if(environment.chatOffline == false) {
|
||||||
|
ChatMessage = ChatMessage.fields.args[0]
|
||||||
|
ChatMessage = this.fix_updatedAt(ChatMessage)
|
||||||
|
console.log('recivemessage', ChatMessage)
|
||||||
|
|
||||||
|
const message = this.prepareMessage(ChatMessage)
|
||||||
|
|
||||||
const message = this.prepareMessage(ChatMessage)
|
this.lastMessage = message
|
||||||
|
if (message.t == 'r') { this.name = message.msg }
|
||||||
|
this.calDateDuration(ChatMessage._updatedAt)
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.scrollDown()
|
||||||
|
}, 100)
|
||||||
|
|
||||||
|
//this.sortService.sortDate(this.messages, '')
|
||||||
|
|
||||||
|
if(SessionStore.user.RochetChatUser != ChatMessage.u.username) {
|
||||||
|
this.NativeNotificationService.sendNotificationChat({
|
||||||
|
message: message.msg,
|
||||||
|
title: this.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.lastMessage = message
|
this.addMessageDB(ChatMessage)
|
||||||
if (message.t == 'r') { this.name = message.msg }
|
|
||||||
this.calDateDuration(ChatMessage._updatedAt)
|
|
||||||
this.messages.push(message)
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
this.scrollDown()
|
|
||||||
}, 100)
|
|
||||||
|
|
||||||
//this.sortService.sortDate(this.messages, '')
|
|
||||||
|
|
||||||
if(SessionStore.user.RochetChatUser != ChatMessage.u.username) {
|
|
||||||
this.NativeNotificationService.sendNotificationChat({
|
|
||||||
message: message.msg,
|
|
||||||
title: this.name
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// save to ionic storage
|
|
||||||
this.storage.get('chatmsg' + this.id).then((messages: any) => {
|
|
||||||
const newListMessages = messages.push(ChatMessage)
|
|
||||||
|
|
||||||
this.storage.set('chatmsg' + this.id, newListMessages).then((value) => {
|
|
||||||
console.log('MSG SAVED ON STORAGE', value)
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -133,6 +130,15 @@ export class RoomService {
|
|||||||
this.WsChatService.registerCallback
|
this.WsChatService.registerCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
addMessageDB(ChatMessage) {
|
||||||
|
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
||||||
|
messages.push(ChatMessage)
|
||||||
|
|
||||||
|
this.storage.set('chatmsg' + this.id, messages)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async receiveMessageDelete() {
|
async receiveMessageDelete() {
|
||||||
|
|
||||||
this.WsChatService.updateRoomEventss(
|
this.WsChatService.updateRoomEventss(
|
||||||
@@ -195,8 +201,60 @@ export class RoomService {
|
|||||||
* @description sen text message
|
* @description sen text message
|
||||||
*/
|
*/
|
||||||
send() {
|
send() {
|
||||||
this.WsChatService.send(this.id, this.message)
|
|
||||||
this.message= ''
|
if(environment.chatOffline == false) {
|
||||||
|
this.WsChatService.send(this.id, this.message)
|
||||||
|
this.message= ''
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const offlineChatMessage = {
|
||||||
|
channels: [],
|
||||||
|
mentions: [],
|
||||||
|
rid: 'offline',
|
||||||
|
msg: this.message,
|
||||||
|
ts: { $date: new Date().getTime() },
|
||||||
|
u: {
|
||||||
|
name: this.usernameToDisplayName(SessionStore.user.RochetChatUser),
|
||||||
|
username: SessionStore.user.RochetChatUser,
|
||||||
|
_id: ""
|
||||||
|
},
|
||||||
|
_updatedAt: new Date().getTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addMessageDB(offlineChatMessage)
|
||||||
|
const message: MessageService = this.prepareMessage(offlineChatMessage)
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.scrollDown()
|
||||||
|
}, 150)
|
||||||
|
|
||||||
|
this.lastMessage = message
|
||||||
|
|
||||||
|
this.redefinedMessage(message)
|
||||||
|
|
||||||
|
this.calDateDuration(message._updatedAt)
|
||||||
|
this.sortRoomList()
|
||||||
|
|
||||||
|
|
||||||
|
this.message= ''
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
redefinedMessage = (message: MessageService) => {
|
||||||
|
this.WsChatService.send(this.id, message.msg).then((data: any) => {
|
||||||
|
let ChatMessage = data.result
|
||||||
|
|
||||||
|
ChatMessage = this.fix_updatedAt(ChatMessage)
|
||||||
|
|
||||||
|
message.setData(ChatMessage)
|
||||||
|
|
||||||
|
if( new Date(this.lastMessage._updatedAt).getTime() < new Date(message._updatedAt).getTime()) {
|
||||||
|
this.lastMessage = message
|
||||||
|
this.calDateDuration(message._updatedAt)
|
||||||
|
}
|
||||||
|
this.sortRoomList()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -266,22 +324,31 @@ export class RoomService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// runs onces only
|
restoreMessageFromDB() {
|
||||||
loadHistory(limit = 100) {
|
|
||||||
|
|
||||||
if (this.hasLoadHistory) { return false }
|
|
||||||
|
|
||||||
this.storage.get('chatmsg' + this.id).then((messages = []) => {
|
this.storage.get('chatmsg' + this.id).then((messages = []) => {
|
||||||
|
|
||||||
let localMessages = []
|
let localMessages = []
|
||||||
|
|
||||||
messages.forEach(message => {
|
messages.forEach((message = []) => {
|
||||||
const wewMessage = this.prepareMessage(message)
|
const wewMessage = this.prepareMessage(message)
|
||||||
|
|
||||||
|
if(wewMessage.rid == 'offline') {
|
||||||
|
this.redefinedMessage(wewMessage)
|
||||||
|
}
|
||||||
|
|
||||||
localMessages.push(wewMessage)
|
localMessages.push(wewMessage)
|
||||||
});
|
});
|
||||||
|
|
||||||
this.messages = localMessages
|
this.messages = localMessages
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// runs onces only
|
||||||
|
loadHistory(limit = 100) {
|
||||||
|
|
||||||
|
if (this.hasLoadHistory) { return false }
|
||||||
|
|
||||||
|
this.restoreMessageFromDB()
|
||||||
|
|
||||||
this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => {
|
this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => {
|
||||||
console.log('loadHistory', chatHistory)
|
console.log('loadHistory', chatHistory)
|
||||||
@@ -317,7 +384,8 @@ export class RoomService {
|
|||||||
message = this.fix_updatedAt(message)
|
message = this.fix_updatedAt(message)
|
||||||
const wewMessage = new MessageService(this.storage)
|
const wewMessage = new MessageService(this.storage)
|
||||||
wewMessage.setData(message)
|
wewMessage.setData(message)
|
||||||
|
this.messages.push(wewMessage)
|
||||||
|
|
||||||
return wewMessage
|
return wewMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +411,7 @@ export class RoomService {
|
|||||||
if (message.result) {
|
if (message.result) {
|
||||||
console.log('FIX UPDATE ', message.result)
|
console.log('FIX UPDATE ', message.result)
|
||||||
message.result._updatedAt = message.result._updatedAt['$date']
|
message.result._updatedAt = message.result._updatedAt['$date']
|
||||||
} else {
|
} else if(message._updatedAt.hasOwnProperty('$date')) {
|
||||||
// console.log('FIX UPDATE 11', message)
|
// console.log('FIX UPDATE 11', message)
|
||||||
message._updatedAt = message._updatedAt['$date']
|
message._updatedAt = message._updatedAt['$date']
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export class WsChatMethodsService {
|
|||||||
/**
|
/**
|
||||||
* @description sort room list by last message date
|
* @description sort room list by last message date
|
||||||
*/
|
*/
|
||||||
sortRoomList() {
|
sortRoomList =() => {
|
||||||
this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse()
|
this._dm = this.sortService.sortDate(this._dm,'_updatedAt').reverse()
|
||||||
this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse()
|
this._group = this.sortService.sortDate(this._group,'_updatedAt').reverse()
|
||||||
}
|
}
|
||||||
@@ -207,6 +207,7 @@ export class WsChatMethodsService {
|
|||||||
room.receiveMessage()
|
room.receiveMessage()
|
||||||
room.getAllUsers = this.getUsers
|
room.getAllUsers = this.getUsers
|
||||||
room.receiveMessageDelete();
|
room.receiveMessageDelete();
|
||||||
|
room.sortRoomList = this.sortRoomList
|
||||||
|
|
||||||
let roomId = this.getRoomId(roomData)
|
let roomId = this.getRoomId(roomData)
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ export class WsChatService {
|
|||||||
support: ["1"]
|
support: ["1"]
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ws.send({message, loginRequired: false})
|
this.ws.send({message, loginRequired: false, requestId: 'connectMessage'})
|
||||||
this.ws.send({message:{msg:"pong"}, loginRequired: false})
|
this.ws.send({message:{msg:"pong"}, loginRequired: false, requestId: 'connectPong'})
|
||||||
|
|
||||||
this.ws.registerCallback({
|
this.ws.registerCallback({
|
||||||
type:'Onmessage',
|
type:'Onmessage',
|
||||||
@@ -65,7 +65,7 @@ export class WsChatService {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
this.ws.send({message, requestId, loginRequired: false})
|
this.ws.send({message, requestId: 'login', loginRequired: false})
|
||||||
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -633,7 +633,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
|||||||
|
|
||||||
if (this.ws.connected == false || loginRequired == true && this.isLogin == false) { // save data to send when back online
|
if (this.ws.connected == false || loginRequired == true && this.isLogin == false) { // save data to send when back online
|
||||||
// console.log('save msgQueue this.ws.connected == false || loginRequired == true && this.isLogin == false',this.ws.connected, loginRequired, this.isLogin)
|
// console.log('save msgQueue this.ws.connected == false || loginRequired == true && this.isLogin == false',this.ws.connected, loginRequired, this.isLogin)
|
||||||
console.log('save msgQueue', requestId)
|
console.log('save msgQueue', requestId, message)
|
||||||
|
|
||||||
this.wsMsgQueue[requestId] = {message, requestId, loginRequired}
|
this.wsMsgQueue[requestId] = {message, requestId, loginRequired}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ export const environment = {
|
|||||||
domain: 'gabinetedigital.local',
|
domain: 'gabinetedigital.local',
|
||||||
defaultuser: '',//paulo.pinto paulo.pinto@gabinetedigital.local
|
defaultuser: '',//paulo.pinto paulo.pinto@gabinetedigital.local
|
||||||
defaultuserpwd: '', //tabteste@006,
|
defaultuserpwd: '', //tabteste@006,
|
||||||
|
chatOffline: true
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export const environment = {
|
|||||||
domain: 'gabinetedigital.local', //gabinetedigital.local
|
domain: 'gabinetedigital.local', //gabinetedigital.local
|
||||||
defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local
|
defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local
|
||||||
defaultuserpwd: 'tabteste@006', //tabteste@006,
|
defaultuserpwd: 'tabteste@006', //tabteste@006,
|
||||||
|
chatOffline: true
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user