This commit is contained in:
Peter Maquiran
2022-01-29 19:21:46 +01:00
parent bf0dbf8baf
commit ed77e1aea7
14 changed files with 402 additions and 19 deletions
@@ -10,6 +10,7 @@ import { Platform } from '@ionic/angular';
import { SqliteService } from 'src/app/services/sqlite.service';
import { NativeNotificationService } from 'src/app/services/native-notification.service';
import { SortService } from '../functions/sort.service';
import { chatUser } from 'src/app/models/chatMethod';
@Injectable({
providedIn: 'root'
@@ -28,6 +29,10 @@ export class WsChatMethodsService {
dmCount = 0;
groupCount = 0;
currentRoom = null
users: chatUser[] = []
constructor(
private WsChatService: WsChatService,
private storage: Storage,
@@ -40,10 +45,37 @@ export class WsChatMethodsService {
await this.getAllRooms();
this.subscribeToRoom()
//
await this.getUser()
this.getUserStatus()
})()
}
openRoom(roomId) {
if(this.currentRoom) {
if(this.getDmRoom(this.currentRoom)) {
this.getDmRoom(this.currentRoom).roomLeave()
} else if(this.getGroupRoom(this.currentRoom)) {
this.getGroupRoom(this.currentRoom).roomLeave()
}
}
this.currentRoom = roomId
if(this.currentRoom) {
if(this.getDmRoom(this.currentRoom)) {
this.getDmRoom(this.currentRoom).open()
} else if(this.getGroupRoom(this.currentRoom)) {
this.getGroupRoom(this.currentRoom).open()
}
}
}
async getAllRooms () {
this.loadingWholeList = true
@@ -140,6 +172,7 @@ export class WsChatMethodsService {
}
prepareRoom(roomData) {
let room:RoomService;
@@ -155,6 +188,7 @@ export class WsChatMethodsService {
})
room.receiveMessage()
room.getAllUsers = this.getUsers
room.receiveMessageDelete();
let roomId = this.getRoomId(roomData)
@@ -170,6 +204,51 @@ export class WsChatMethodsService {
}
}
getReceptorName(roomData) {
try {
return roomData.usernames.find((e)=> e != SessionStore.user.RochetChatUser)
} catch(e) {
return '*'
}
}
getUserStatus(id?:string) {
this.WsChatService.getUserStatus((d) => {
const username = d.fields.args[0][1]
const statusNum = d.fields.args[0][2]
console.log('d', d)
const statusText = this.statusNumberToText(statusNum)
this.getUserByName(username).status = statusText
})
}
getUserByName(username) {
return this.users.find((user)=> user.username == username)
}
statusNumberToText(text) {
if(text == '0') {
return "offline"
}
else if(text == '1') {
return "online"
}
else if(text == '2') {
return "away"
}
else if(text == '3') {
return "busy"
}
}
deleteMessage(id?) {
return this.WsChatService.deleteMessage(id);
}
@@ -229,4 +308,28 @@ export class WsChatMethodsService {
return !roomData.fname
}
getUsers = () =>{
return this.users
}
async getUser() {
// let _res = await this.chatService.getAllUsers().toPromise()
// let user = _res['users'].filter(data => data.username != SessionStore.user.RochetChatUser);
// user = user.sort((a,b) => {
// if(a.name < b.name) {
// return -1;
// }
// if(a.name > b.name) {
// return 1;
// }
// return 0;
// });
// this.users = user
}
}