mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
Merge branch 'developer' of https://bitbucket.org/equilibriumito/gabinete-digital into feature/chatStorage
This commit is contained in:
@@ -39,7 +39,7 @@ export class RoomService {
|
||||
private sqlservice: SqliteService,
|
||||
) { }
|
||||
|
||||
setData({ customFields, id, name, t, lastMessage, _updatedAt }) {
|
||||
setData({ customFields, id, name, t, lastMessage = new MessageService(), _updatedAt }) {
|
||||
this.customFields = customFields
|
||||
this.id = id
|
||||
this.name = name
|
||||
@@ -62,6 +62,7 @@ export class RoomService {
|
||||
/* this.ToastService._chatMessage({message:'Nova mensagem', sender:'Gilson'}) */
|
||||
const message = new MessageService()
|
||||
message.setData(ChatMessage)
|
||||
|
||||
this.lastMessage.msg = message.msg
|
||||
if (message.t == 'r') { this.name = message.msg }
|
||||
this.calDateDuration(ChatMessage._updatedAt)
|
||||
@@ -89,6 +90,10 @@ export class RoomService {
|
||||
this.WsChatService.send(this.id, msg)
|
||||
}
|
||||
|
||||
leave(rid?) {
|
||||
this.WsChatService.leaveRoom(this.id)
|
||||
}
|
||||
|
||||
getMsgFromDBMobile() {
|
||||
console.log('ALL MSG DBBB', this.id)
|
||||
this.sqlservice.getAllChatMSG(this.id).then((msg: any = []) => {
|
||||
@@ -159,7 +164,7 @@ export class RoomService {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// runs onces only
|
||||
loadHistory(limit = 100) {
|
||||
|
||||
@@ -46,35 +46,7 @@ export class WsChatMethodsService {
|
||||
// console.log("ROOMS" + JSON.stringify(rooms))
|
||||
|
||||
rooms.result.update.forEach((roomData: room) => {
|
||||
let room:RoomService;
|
||||
|
||||
//console.log(roomData);
|
||||
|
||||
|
||||
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice)
|
||||
room.setData({
|
||||
customFields: roomData.customFields,
|
||||
id: this.getRoomId(roomData),
|
||||
name: this.getRoomName(roomData),
|
||||
t: roomData.t,
|
||||
lastMessage: this.getRoomLastMessage(roomData),
|
||||
_updatedAt: new Date(roomData._updatedAt['$date'])
|
||||
})
|
||||
|
||||
room.receiveMessage()
|
||||
|
||||
let roomId = this.getRoomId(roomData)
|
||||
|
||||
if(this.isIndividual(roomData)) {
|
||||
this.dm[roomId] = room
|
||||
this.dmCount++
|
||||
} else {
|
||||
this.group[roomId] = room
|
||||
this.groupCount++
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.prepareRoom(roomData);
|
||||
});
|
||||
|
||||
this.loadingWholeList = false
|
||||
@@ -99,6 +71,68 @@ export class WsChatMethodsService {
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
subscribeToRoomUpdate(id, roomData) {
|
||||
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
|
||||
console.log('streamRoomMessages', subscription)
|
||||
})
|
||||
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
|
||||
console.log('streamRoomMessages', subscription)
|
||||
})
|
||||
this.WsChatService.streamNotifyLogged().then((subscription=>{
|
||||
console.log('streamRoomMessages', subscription)
|
||||
}))
|
||||
|
||||
this.prepareRoom(roomData);
|
||||
|
||||
this.getGroupRoom(id).loadHistory();
|
||||
|
||||
}
|
||||
|
||||
prepareRoom(roomData){
|
||||
let room:RoomService;
|
||||
|
||||
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice)
|
||||
room.setData({
|
||||
customFields: roomData.customFields,
|
||||
id: this.getRoomId(roomData),
|
||||
name: this.getRoomName(roomData),
|
||||
t: roomData.t,
|
||||
lastMessage: this.getRoomLastMessage(roomData),
|
||||
_updatedAt: new Date(roomData._updatedAt['$date'])
|
||||
})
|
||||
|
||||
room.receiveMessage()
|
||||
|
||||
let roomId = this.getRoomId(roomData)
|
||||
|
||||
if(this.isIndividual(roomData)) {
|
||||
this.dm[roomId] = room
|
||||
this.dmCount++
|
||||
} else {
|
||||
this.group[roomId] = room
|
||||
this.groupCount++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
leaveRoom(id?) {
|
||||
return this.WsChatService.leaveRoom(id);
|
||||
}
|
||||
|
||||
hidingRoom(id?) {
|
||||
return this.WsChatService.hidingRoom(id);
|
||||
}
|
||||
|
||||
addRoomOwner(roomid, userId){
|
||||
return this.WsChatService.addRoomOwner(roomid, userId);
|
||||
}
|
||||
|
||||
createPrivateRoom(groupName, username, customFields){
|
||||
return this.WsChatService.createPrivateRoom(groupName, username, customFields);
|
||||
}
|
||||
|
||||
getDmRoom(id): RoomService {
|
||||
try {
|
||||
return this.dm[id]
|
||||
@@ -130,7 +164,7 @@ export class WsChatMethodsService {
|
||||
return roomData._id
|
||||
}
|
||||
|
||||
getRoomLastMessage(roomData: room) {
|
||||
getRoomLastMessage(roomData: room):any {
|
||||
return roomData.lastMessage
|
||||
}
|
||||
|
||||
|
||||
@@ -153,9 +153,112 @@ export class WsChatService {
|
||||
});
|
||||
}
|
||||
|
||||
leaveRoom(roomId) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "leaveRoom",
|
||||
id: requestId,
|
||||
params: [
|
||||
roomId,
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({message, requestId});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
}
|
||||
|
||||
addRoomOwner(roomId, userId) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "addRoomOwner",
|
||||
id: requestId,
|
||||
params: [
|
||||
roomId,
|
||||
userId
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({message, requestId});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
}
|
||||
|
||||
hidingRoom(roomId){
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "hideRoom",
|
||||
id: requestId,
|
||||
params: [roomId]
|
||||
}
|
||||
|
||||
this.ws.send({message, requestId});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
}
|
||||
|
||||
joinRoom(){}
|
||||
deleteMessage() {}
|
||||
createRoom() {}
|
||||
createPrivateRoom(groupName, username, customFields) {
|
||||
const requestId = uuidv4()
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
method: "createPrivateGroup",
|
||||
id: requestId,
|
||||
params: [
|
||||
groupName,
|
||||
[username],
|
||||
false,
|
||||
customFields,
|
||||
{
|
||||
"broadcast":false,
|
||||
"encrypted":false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send({message, requestId});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user