mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix bug
This commit is contained in:
@@ -14,6 +14,10 @@ import { SortService } from '../functions/sort.service';
|
||||
import { chatUser } from 'src/app/models/chatMethod';
|
||||
import { NfService } from 'src/app/services/chat/nf.service'
|
||||
import { ChangeProfileService } from '../change-profile.service';
|
||||
import { UserSession } from 'src/app/models/user.model';
|
||||
import { AuthService } from '../auth.service';
|
||||
import { ChatStorageService } from './chat-storage.service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -33,6 +37,8 @@ export class WsChatMethodsService {
|
||||
currentRoom: RoomService = null
|
||||
users: chatUser[] = []
|
||||
|
||||
loggedUser: any;
|
||||
|
||||
constructor(
|
||||
private WsChatService: WsChatService,
|
||||
private storage: Storage,
|
||||
@@ -43,8 +49,13 @@ export class WsChatMethodsService {
|
||||
private ChatService: ChatService,
|
||||
private NfService: NfService,
|
||||
private changeProfileService: ChangeProfileService,
|
||||
private chatService: ChatService,
|
||||
private authService: AuthService,
|
||||
private ChatStorageService: ChatStorageService
|
||||
) {
|
||||
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
|
||||
this.loadChat()
|
||||
|
||||
this.WsChatService.registerCallback({
|
||||
@@ -79,39 +90,6 @@ export class WsChatMethodsService {
|
||||
this.storage.remove('Rooms');
|
||||
})
|
||||
|
||||
|
||||
// this.WsChatService.registerCallback({
|
||||
// type:'Onmessage',
|
||||
// funx:(message) => {
|
||||
|
||||
// if(message.msg =='changed' && message.collection == "stream-room-messages") {
|
||||
// if(message.fields.args[0].rid) {
|
||||
// // new message
|
||||
// const ChatMessage = message.fields.args[0]
|
||||
// const messageId = ChatMessage.rid
|
||||
|
||||
// setTimeout(()=>{
|
||||
// this.sortRoomList()
|
||||
// }, 100)
|
||||
|
||||
// }
|
||||
// } else if(message.msg =='changed' && message.collection == "stream-notify-room") {
|
||||
// if(message.fields.eventName.includes('deleteMessage')) {
|
||||
// // delete message
|
||||
// const DeletedMessageId = message.fields.args[0]._id;
|
||||
|
||||
// setTimeout(()=>{
|
||||
// this.sortRoomList()
|
||||
// }, 100)
|
||||
|
||||
// } else if(message.fields.eventName.includes('typing')) {
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
|
||||
|
||||
}
|
||||
|
||||
private loadChat() {
|
||||
@@ -144,7 +122,6 @@ export class WsChatMethodsService {
|
||||
this.users = []
|
||||
}
|
||||
|
||||
|
||||
openRoom(roomId) {
|
||||
|
||||
if(this.currentRoom) {
|
||||
@@ -161,7 +138,6 @@ export class WsChatMethodsService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
async restoreRooms() {
|
||||
|
||||
try {
|
||||
@@ -183,14 +159,46 @@ export class WsChatMethodsService {
|
||||
this.loadingWholeList = true
|
||||
const rooms = await this.WsChatService.getRooms();
|
||||
await this.storage.remove('Rooms');
|
||||
await this.storage.set('Rooms', rooms);
|
||||
|
||||
console.log('rooms', rooms)
|
||||
|
||||
await rooms.result.update.forEach( async (roomData: room) => {
|
||||
await this.prepareRoom(roomData);
|
||||
console.log('rooms ============', rooms)
|
||||
|
||||
await rooms.result.update.forEach( async (roomData: room, index) => {
|
||||
const roomId = this.getRoomId(roomData);
|
||||
|
||||
if(roomData.t == 'd') {
|
||||
|
||||
const res = await this.chatService.getMembers(roomId).toPromise();
|
||||
|
||||
const members = res['members'];
|
||||
const users = members.filter(data => data.username != this.loggedUser.me.username);
|
||||
rooms.result.update[index]['members'] = users
|
||||
|
||||
await this.prepareRoom(roomData);
|
||||
} else {
|
||||
if (roomData.t === 'p') {
|
||||
const res = await this.chatService.getGroupMembers(roomId).toPromise()
|
||||
const members = res['members'];
|
||||
const users = members.filter(data => data.username != this.loggedUser.me.username);
|
||||
|
||||
rooms.result.update[index]['members'] = users
|
||||
|
||||
}
|
||||
else {
|
||||
const res = await this.chatService.getChannelMembers(roomId).toPromise()
|
||||
const members = res['members'];
|
||||
const users = members.filter(data => data.username != this.loggedUser.me.username);
|
||||
|
||||
rooms.result.update[index]['members'] = users
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
await this.storage.set('Rooms', rooms);
|
||||
console.log(rooms.result.update, 'rooms.result.update')
|
||||
|
||||
this.sortRoomList()
|
||||
this.loadingWholeList = false
|
||||
}
|
||||
@@ -247,6 +255,8 @@ export class WsChatMethodsService {
|
||||
})
|
||||
|
||||
this.WsChatService.subStreamNotifyRoom(id, 'typing', false)
|
||||
this.WsChatService.subStreamNotifyRoom(id, 'readMessage', false)
|
||||
|
||||
this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{
|
||||
//console.log('streamNotifyRoomDeleteMessage', subscription);
|
||||
})
|
||||
@@ -269,14 +279,16 @@ export class WsChatMethodsService {
|
||||
name: this.getRoomName(roomData),
|
||||
t: roomData.t,
|
||||
lastMessage: this.getRoomLastMessage(roomData),
|
||||
_updatedAt: new Date(roomData._updatedAt['$date'])
|
||||
_updatedAt: new Date(roomData._updatedAt['$date']),
|
||||
u : roomData.u || {},
|
||||
members: roomData.members
|
||||
}
|
||||
|
||||
let roomId = this.getRoomId(roomData)
|
||||
|
||||
// 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)
|
||||
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService)
|
||||
room.setData(setData)
|
||||
room.receiveMessage()
|
||||
room.getAllUsers = this.getUsers
|
||||
@@ -300,7 +312,6 @@ export class WsChatMethodsService {
|
||||
|
||||
}
|
||||
} else {
|
||||
console.log('have!!!')
|
||||
// in this case room is already present, therefor it will only be necessary,
|
||||
// to redefine
|
||||
|
||||
@@ -336,16 +347,16 @@ export class WsChatMethodsService {
|
||||
const username = d.fields.args[0][1]
|
||||
const statusNum = d.fields.args[0][2]
|
||||
|
||||
|
||||
const statusText = this.statusNumberToText(statusNum)
|
||||
|
||||
const user = this.getUserByName(username)
|
||||
|
||||
if(user) {
|
||||
user.status = statusText
|
||||
}
|
||||
this.users.forEach((user, index) => {
|
||||
if(user.username == username) {
|
||||
this.users[index].status = statusText
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
getUserByName(username) {
|
||||
@@ -460,9 +471,9 @@ export class WsChatMethodsService {
|
||||
|
||||
let _res = await this.ChatService.getAllUsers().toPromise()
|
||||
|
||||
let user = _res['users'].filter(data => data.username != SessionStore.user.RochetChatUser);
|
||||
let users = _res['users'].filter(data => data.username != SessionStore.user.RochetChatUser);
|
||||
|
||||
user = user.sort((a,b) => {
|
||||
users = users.sort((a,b) => {
|
||||
if(a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
@@ -472,7 +483,11 @@ export class WsChatMethodsService {
|
||||
return 0;
|
||||
});
|
||||
|
||||
this.users = user
|
||||
users.forEach((user, index) => {
|
||||
// user[index].status = this.statusNumberToText(user[index].status)
|
||||
})
|
||||
|
||||
this.users = users
|
||||
}
|
||||
|
||||
getUserOfRoom(roomId){
|
||||
|
||||
Reference in New Issue
Block a user