bug fix in chat view

This commit is contained in:
tiago.kayaya
2022-01-28 15:31:52 +01:00
parent 8756462665
commit 5a214aebf4
12 changed files with 145 additions and 49 deletions
+37 -3
View File
@@ -52,8 +52,9 @@ export class RoomService {
receiveMessage() {
this.WsChatService.receiveLiveMessageFromRoom(
this.WsChatService.upateRoomEvents(
this.id,
"stream-room-messages",
(ChatMessage) => {
ChatMessage = ChatMessage.fields.args[0]
ChatMessage = this.fix_updatedAt(ChatMessage)
@@ -63,7 +64,7 @@ export class RoomService {
const message = new MessageService()
message.setData(ChatMessage)
this.lastMessage.msg = message.msg
this.lastMessage = message
if (message.t == 'r') { this.name = message.msg }
this.calDateDuration(ChatMessage._updatedAt)
this.massages.push(message)
@@ -84,6 +85,37 @@ export class RoomService {
}
)
this.WsChatService.registerCallback
}
async receiveMessageDelete() {
this.WsChatService.upateRoomEvents(
this.id,
"stream-notify-room",
async (ChatMessage) => {
console.log(ChatMessage.fields.args[0]._id);
const messageId = ChatMessage.fields.args[0]._id;
this.massages.forEach((message, index)=>{
if(message._id == messageId){
this.massages.splice(index, 1)
this.storage.set('chatmsg' + this.id, this.massages).then((value) => {
//console.log('MSG DELETE ON STORAGE', value)
});
//Get previous last message from room
const previousLastMessage = this.massages.slice(-1)[0];
this.lastMessage = previousLastMessage;
this.calDateDuration(previousLastMessage._updatedAt)
}
})
}
)
this.WsChatService.registerCallback
}
send(msg) {
@@ -148,7 +180,7 @@ export class RoomService {
if (message.file) {
if (message.file.guid) {
this.storage.get(message.file.guid).then((image) => {
console.log('IMAGE FROM STORAGE', image)
//console.log('IMAGE FROM STORAGE', image)
message.file.image_url = image
});
}
@@ -188,6 +220,8 @@ export class RoomService {
this.WsChatService.loadHistory(this.id, limit).then(async (chatHistory: chatHistory) => {
const mgsArray = chatHistory.result.messages.reverse();
console.log(mgsArray);
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
await this.storage.remove('chatmsg' + this.id).then(() => {
console.log('MSG REMOVE ON STORAGE')
@@ -58,14 +58,19 @@ export class WsChatMethodsService {
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
console.log('streamRoomMessages', subscription)
})
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{
console.log('streamNotifyRoomDeleteMessage', subscription);
})
}
for (const id in this.group) {
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
console.log('streamRoomMessages', subscription)
})
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{
console.log('streamNotifyRoomDeleteMessage', subscription);
})
}
this.WsChatService.streamNotifyLogged().then((subscription=>{
console.log('streamRoomMessages', subscription)
}))
@@ -82,6 +87,9 @@ export class WsChatMethodsService {
this.WsChatService.streamNotifyLogged().then((subscription=>{
console.log('streamRoomMessages', subscription)
}))
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{
console.log('streamNotifyRoomDeleteMessage', subscription);
})
this.prepareRoom(roomData);
@@ -103,10 +111,13 @@ export class WsChatMethodsService {
})
room.receiveMessage()
room.receiveMessageDelete();
let roomId = this.getRoomId(roomData)
if(this.isIndividual(roomData)) {
console.log(room);
this.dm[roomId] = room
this.dmCount++
} else {
@@ -115,7 +126,9 @@ export class WsChatMethodsService {
}
}
deleteMessage(id?) {
return this.WsChatService.deleteMessage(id);
}
leaveRoom(id?) {
return this.WsChatService.leaveRoom(id);
+57 -3
View File
@@ -228,7 +228,29 @@ export class WsChatService {
}
joinRoom(){}
deleteMessage() {}
deleteMessage(msgId) {
const requestId = uuidv4();
var message = {
msg: "method",
method: "deleteMessage",
id: requestId,
params:[{"_id":msgId}]
}
this.ws.send({message, requestId});
return new Promise ((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message) =>{
if(message.id == requestId || deepFind(message, 'result') == requestId){
resolve(message)
return true
}
}})
});
}
createPrivateRoom(groupName, username, customFields) {
const requestId = uuidv4()
@@ -337,15 +359,20 @@ export class WsChatService {
}
receiveLiveMessageFromRoom(roomId, funx: Function) {
upateRoomEvents(roomId, collection:string, funx: Function, ) {
this.ws.registerCallback({
type:'Onmessage',
funx:(message)=>{
if(message.msg =='changed' && message.collection == 'stream-room-messages') {
//console.log(message);
if(message.msg =='changed' && message.collection == collection) {
if(message.fields.args[0].rid == roomId) {
funx(message)
}
else if(message.fields.eventName ==`${roomId}/deleteMessage`){
funx(message)
}
}
}
})
@@ -432,6 +459,33 @@ export class WsChatService {
}
streamNotifyRoomDeleteMessage(roomId:string) {
const requestId = uuidv4()
let message = {
"msg": "sub",
"id": requestId,
"name": "stream-notify-room",
"params": [
`${roomId}/deleteMessage`,
true
]
};
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
}
}})
});
}
registerCallback(data:wsCallbacksParams) {
return this.ws.registerCallback(data)
}