mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix bug in create new room
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)
|
||||
|
||||
@@ -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,52 @@ 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);
|
||||
}
|
||||
@@ -111,6 +129,10 @@ export class WsChatMethodsService {
|
||||
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]
|
||||
@@ -142,7 +164,7 @@ export class WsChatMethodsService {
|
||||
return roomData._id
|
||||
}
|
||||
|
||||
getRoomLastMessage(roomData: room) {
|
||||
getRoomLastMessage(roomData: room):any {
|
||||
return roomData.lastMessage
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,36 @@ export class WsChatService {
|
||||
|
||||
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