mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
teste/route
This commit is contained in:
@@ -18,7 +18,13 @@ export class MessageService {
|
||||
msg = ''
|
||||
rid = ''
|
||||
ts = {}
|
||||
u = {}
|
||||
|
||||
u = {
|
||||
name: '',
|
||||
username: '',
|
||||
_id: ""
|
||||
}
|
||||
|
||||
t = ''
|
||||
_id =''
|
||||
_updatedAt
|
||||
@@ -35,6 +41,8 @@ export class MessageService {
|
||||
loadHistory = false
|
||||
duration = ''
|
||||
localReference = null
|
||||
viewed = []
|
||||
received = []
|
||||
|
||||
constructor(private storage: Storage,
|
||||
private NfService: NfService,
|
||||
@@ -78,6 +86,7 @@ export class MessageService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.calDateDuration()
|
||||
}
|
||||
|
||||
@@ -140,9 +149,9 @@ export class MessageService {
|
||||
|
||||
console.log('message', message)
|
||||
let ChatMessage = message.result
|
||||
|
||||
|
||||
if (environment.chatOffline) {
|
||||
// this.redefinedMessage(ChatMessage)
|
||||
this.redefinedMessage(ChatMessage)
|
||||
this.offline = false
|
||||
}
|
||||
|
||||
@@ -189,5 +198,47 @@ export class MessageService {
|
||||
this.duration = showDateDuration(date || this._updatedAt);
|
||||
}
|
||||
|
||||
private messageReceptor() {
|
||||
return this.u.username != SessionStore.user.RochetChatUser
|
||||
}
|
||||
|
||||
receptorReceive() {
|
||||
|
||||
if(this.messageReceptor()) {
|
||||
let newMessage = {
|
||||
rid: this._id,
|
||||
msg: this.msg,
|
||||
attachments: this.attachments,
|
||||
file: this.file,
|
||||
localReference: this.localReference,
|
||||
viewed: this.viewed.push('123'),
|
||||
received: this.viewed.push('123'),
|
||||
}
|
||||
|
||||
this.WsChatService.updateMessage(newMessage).then(()=>{
|
||||
console.log('newMessage', newMessage)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
receptorView() {
|
||||
if(this.messageReceptor()) {
|
||||
let newMessage = {
|
||||
rid: this._id,
|
||||
msg: this.msg,
|
||||
attachments: this.attachments,
|
||||
file: this.file,
|
||||
localReference: this.localReference,
|
||||
viewed: this.viewed.push('123'),
|
||||
received: this.viewed.push('123'),
|
||||
}
|
||||
|
||||
this.WsChatService.updateMessage(newMessage).then(()=>{
|
||||
console.log('newMessage', newMessage)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -201,6 +201,40 @@ export class RoomService {
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async updateViewedMessage(id, userId) {
|
||||
if (environment.chatOffline) {
|
||||
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
||||
if(!Array.isArray(messages)) {
|
||||
messages = []
|
||||
}
|
||||
|
||||
let index;
|
||||
const find = messages.find((message, _index)=> {
|
||||
|
||||
if(message._id == id) {
|
||||
index = _index
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if(find) {
|
||||
|
||||
if(!messages[index].hasOwnProperty('viewed') || !Array.isArray(messages[index].viewed)) {
|
||||
messages.viewed = []
|
||||
}
|
||||
|
||||
messages.viewed.push(userId)
|
||||
this.storage.set('chatmsg' + this.id, messages)
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,11 +313,16 @@ export class RoomService {
|
||||
attachments,
|
||||
file,
|
||||
temporaryData,
|
||||
localReference
|
||||
localReference,
|
||||
viewed: [],
|
||||
received: []
|
||||
}
|
||||
|
||||
const message: MessageService = this.prepareMessage(offlineChatMessage, environment.chatOffline)
|
||||
|
||||
/**
|
||||
* @description redefine message offline data "offlineChatMessage" with live ChatMessage
|
||||
*/
|
||||
message.send().then((ChatMessage) => {
|
||||
this.updateMessageDB(ChatMessage, localReference)
|
||||
})
|
||||
@@ -305,6 +344,13 @@ export class RoomService {
|
||||
this.message= ''
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* @param ChatMessage
|
||||
* @description when creating message we use offline data, then we need redefined with live data
|
||||
*/
|
||||
redefinedMessage (message: MessageService, ChatMessage) {
|
||||
|
||||
ChatMessage = this.fix_updatedAt(ChatMessage)
|
||||
@@ -448,7 +494,12 @@ export class RoomService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @description find or create message
|
||||
* @param message
|
||||
* @param save
|
||||
* @returns
|
||||
*/
|
||||
prepareMessage(message, save = true): MessageService {
|
||||
message = this.fix_updatedAt(message)
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService)
|
||||
|
||||
@@ -22,8 +22,8 @@ export class WsChatMethodsService {
|
||||
dm: {[key: string]: RoomService} = {}
|
||||
group: {[key: string]: RoomService} = {}
|
||||
|
||||
_dm = []
|
||||
_group = []
|
||||
_dm: RoomService[] = []
|
||||
_group: RoomService[] = []
|
||||
|
||||
loadingWholeList = false
|
||||
|
||||
@@ -71,7 +71,9 @@ export class WsChatMethodsService {
|
||||
}
|
||||
})
|
||||
|
||||
this.changeProfileService.registerCallback(()=>{
|
||||
|
||||
// on change profile remove a rooms
|
||||
this.changeProfileService.registerCallback(() => {
|
||||
this.clearChat()
|
||||
this.ReLoadChat()
|
||||
this.storage.remove('Rooms');
|
||||
@@ -142,13 +144,6 @@ export class WsChatMethodsService {
|
||||
this.users = []
|
||||
}
|
||||
|
||||
getRoomFromDb() {
|
||||
this.storage.get('Rooms').then((rooms) => {
|
||||
rooms.result.update.forEach((roomData: room) => {
|
||||
this.prepareRoom(roomData);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
openRoom(roomId) {
|
||||
|
||||
@@ -186,7 +181,6 @@ export class WsChatMethodsService {
|
||||
|
||||
async getAllRooms () {
|
||||
this.loadingWholeList = true
|
||||
//this.getRoomFromDb();
|
||||
const rooms = await this.WsChatService.getRooms();
|
||||
await this.storage.remove('Rooms');
|
||||
await this.storage.set('Rooms', rooms);
|
||||
@@ -266,6 +260,9 @@ export class WsChatMethodsService {
|
||||
prepareRoom(roomData) {
|
||||
|
||||
|
||||
/**
|
||||
* @description data used to define or create room
|
||||
*/
|
||||
const setData = {
|
||||
customFields: roomData.customFields,
|
||||
id: this.getRoomId(roomData),
|
||||
@@ -277,14 +274,16 @@ export class WsChatMethodsService {
|
||||
|
||||
let roomId = this.getRoomId(roomData)
|
||||
|
||||
if(!this.dm[roomId] && !this.group[roomId]) {
|
||||
// create room
|
||||
if(!this.roomExist(roomId)) {
|
||||
let room:RoomService = 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(setData)
|
||||
room.receiveMessage()
|
||||
room.getAllUsers = this.getUsers
|
||||
room.receiveMessageDelete();
|
||||
room.sortRoomList = this.sortRoomList
|
||||
|
||||
|
||||
// create individual room
|
||||
if(this.isIndividual(roomData)) {
|
||||
|
||||
this.dm[roomId] = room
|
||||
@@ -292,12 +291,16 @@ export class WsChatMethodsService {
|
||||
this.dmCount++
|
||||
|
||||
} else {
|
||||
// create group room
|
||||
|
||||
this.group[roomId] = room
|
||||
this._group.push(room)
|
||||
this.groupCount++
|
||||
|
||||
}
|
||||
} else {
|
||||
// in this case room is already present, therefor it will only be necessary,
|
||||
// to redefine
|
||||
|
||||
if(this.dm[roomId]) {
|
||||
this.dm[roomId].setData(setData)
|
||||
@@ -306,11 +309,11 @@ export class WsChatMethodsService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
roomExist(roomId) {
|
||||
return this.dm[roomId] && this.group[roomId]
|
||||
}
|
||||
|
||||
getReceptorName(roomData) {
|
||||
try {
|
||||
@@ -326,20 +329,20 @@ export class WsChatMethodsService {
|
||||
*/
|
||||
private getUserStatus(id?:string) {
|
||||
|
||||
// this.WsChatService.getUserStatus((d) => {
|
||||
this.WsChatService.getUserStatus((d) => {
|
||||
|
||||
// const username = d.fields.args[0][1]
|
||||
// const statusNum = d.fields.args[0][2]
|
||||
const username = d.fields.args[0][1]
|
||||
const statusNum = d.fields.args[0][2]
|
||||
|
||||
// const statusText = this.statusNumberToText(statusNum)
|
||||
const statusText = this.statusNumberToText(statusNum)
|
||||
|
||||
// const user = this.getUserByName(username)
|
||||
const user = this.getUserByName(username)
|
||||
|
||||
// if(user) {
|
||||
// user.status = statusText
|
||||
// }
|
||||
if(user) {
|
||||
user.status = statusText
|
||||
}
|
||||
|
||||
// })
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -377,7 +380,11 @@ export class WsChatMethodsService {
|
||||
}
|
||||
|
||||
hidingRoom(id?) {
|
||||
return this.WsChatService.hidingRoom(id);
|
||||
|
||||
return this.WsChatService.hidingRoom(id).then(()=>{
|
||||
// this.hideRoom(id)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
addRoomOwner(roomid, userId){
|
||||
@@ -403,7 +410,7 @@ export class WsChatMethodsService {
|
||||
getRoomName(roomData: room) {
|
||||
if(this.isIndividual(roomData)) {
|
||||
const names: String[] = roomData.usernames
|
||||
const roomName = names.filter((name)=>{
|
||||
const roomName = names.filter((name, index)=>{
|
||||
return name != SessionStore.user.RochetChatUser
|
||||
})[0]
|
||||
|
||||
|
||||
@@ -186,6 +186,29 @@ export class WsChatService {
|
||||
});
|
||||
}
|
||||
|
||||
updateMessage(messageObject) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "updateMessage",
|
||||
id: requestId,
|
||||
params: [messageObject]
|
||||
}
|
||||
|
||||
this.ws.send({message, requestId});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve({message, requestId})
|
||||
return true
|
||||
}
|
||||
}})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
leaveRoom(roomId) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
Reference in New Issue
Block a user