mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
save
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { wsChatMethodsService } from './chat.service';
|
||||
|
||||
describe('ChatService', () => {
|
||||
let service: wsChatMethodsService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(wsChatMethodsService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,114 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RoomService } from './room.service';
|
||||
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
|
||||
import { MessageService } from 'src/app/services/chat/message.service'
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class wsChatMethodsService {
|
||||
|
||||
|
||||
dm: {[key: string]: RoomService} = {}
|
||||
group: {[key: string]: RoomService} = {}
|
||||
|
||||
loadingWholeList = false
|
||||
|
||||
dmCount = 0;
|
||||
groupCount = 0;
|
||||
|
||||
constructor(
|
||||
private WsChatService: WsChatService
|
||||
) {
|
||||
|
||||
(async()=>{
|
||||
await this.getAllRooms();
|
||||
this.subscribeToRoom()
|
||||
})()
|
||||
|
||||
}
|
||||
|
||||
async getAllRooms () {
|
||||
this.loadingWholeList = true
|
||||
|
||||
const rooms: any = await this.WsChatService.getRooms();
|
||||
|
||||
console.log(rooms)
|
||||
|
||||
rooms.result.update.forEach((roomData:any) => {
|
||||
let room:RoomService;
|
||||
|
||||
room = new RoomService(this.WsChatService, new MessageService())
|
||||
room.setData({
|
||||
id: this.getRoomId(roomData),
|
||||
name: this.getRoomName(roomData),
|
||||
lastMessage: this.getRoomLastMessage(roomData),
|
||||
_updatedAt: roomData._updatedAt['$date']
|
||||
})
|
||||
|
||||
room.receiveMessage()
|
||||
|
||||
let roomId = roomData.lastMessage.rid
|
||||
|
||||
if(this.isIndividual(roomData)) {
|
||||
this.dm[roomId] = room
|
||||
this.dmCount++
|
||||
} else {
|
||||
this.group[roomId] = room
|
||||
this.groupCount++
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
this.loadingWholeList = false
|
||||
}
|
||||
|
||||
subscribeToRoom() {
|
||||
for (const id in this.dm) {
|
||||
this.WsChatService.subscribeNotifyRoom(id).then((subscription)=>{
|
||||
console.log('subscription', subscription)
|
||||
})
|
||||
}
|
||||
|
||||
for (const id in this.group) {
|
||||
this.WsChatService.subscribeNotifyRoom(id).then((subscription)=>{
|
||||
console.log('subscription', subscription)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
getRoom(id): RoomService {
|
||||
try {
|
||||
return this.dm[id]
|
||||
} catch(e) {
|
||||
return this.group[id]
|
||||
}
|
||||
}
|
||||
|
||||
getRoomName(roomData) {
|
||||
if(this.isIndividual(roomData)) {
|
||||
const names: String[] = roomData.usernames
|
||||
const roomName = names.filter((name)=>{
|
||||
return name != SessionStore.user.RochetChatUser
|
||||
})[0]
|
||||
|
||||
return roomName
|
||||
} else {
|
||||
return roomData.fName
|
||||
}
|
||||
}
|
||||
|
||||
getRoomId(roomData) {
|
||||
return roomData.lastMessage.rid
|
||||
}
|
||||
|
||||
getRoomLastMessage(roomData) {
|
||||
return roomData.lastMessage
|
||||
}
|
||||
|
||||
private isIndividual(roomData) {
|
||||
return !roomData.fname
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,7 @@ export class WsChatMethodsService {
|
||||
|
||||
dmCount = 0;
|
||||
groupCount = 0;
|
||||
|
||||
|
||||
constructor(
|
||||
private WsChatService: WsChatService
|
||||
) {
|
||||
@@ -28,7 +28,7 @@ export class WsChatMethodsService {
|
||||
await this.getAllRooms();
|
||||
this.subscribeToRoom()
|
||||
})()
|
||||
|
||||
|
||||
}
|
||||
|
||||
async getAllRooms () {
|
||||
@@ -36,11 +36,14 @@ export class WsChatMethodsService {
|
||||
|
||||
const rooms: any = await this.WsChatService.getRooms();
|
||||
|
||||
console.log(rooms)
|
||||
console.log("ROOMS" + rooms)
|
||||
|
||||
rooms.result.update.forEach((roomData:any) => {
|
||||
let room:RoomService;
|
||||
|
||||
|
||||
console.log(roomData);
|
||||
|
||||
|
||||
room = new RoomService(this.WsChatService, new MessageService())
|
||||
room.setData({
|
||||
id: this.getRoomId(roomData),
|
||||
@@ -60,7 +63,7 @@ export class WsChatMethodsService {
|
||||
this.group[roomId] = room
|
||||
this.groupCount++
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
this.loadingWholeList = false
|
||||
@@ -97,7 +100,7 @@ export class WsChatMethodsService {
|
||||
|
||||
return roomName
|
||||
} else {
|
||||
return roomData.fName
|
||||
return roomData.fname
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user