summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/providers/gateways/chat_room.gateway.ts3
-rw-r--r--server/providers/services/chat_room.service.ts15
2 files changed, 14 insertions, 4 deletions
diff --git a/server/providers/gateways/chat_room.gateway.ts b/server/providers/gateways/chat_room.gateway.ts
index 9c305bf..76f7bd8 100644
--- a/server/providers/gateways/chat_room.gateway.ts
+++ b/server/providers/gateways/chat_room.gateway.ts
@@ -31,11 +31,12 @@ export class ChatRoomGateway implements OnGatewayInit, OnGatewayConnection, OnGa
) {
setInterval(async () => {
const inactiveRooms = await chatRoomService.inactiveRooms();
+ console.log(inactiveRooms);
inactiveRooms.forEach((room) => {
this.server.to(room.id).emit('inactive', room.id);
chatRoomService.remove(room);
});
- }, 5 * (1000 * 60));
+ }, 1000 * 60 * 5);
}
afterInit(server: Server) {
diff --git a/server/providers/services/chat_room.service.ts b/server/providers/services/chat_room.service.ts
index de08c02..0e8ed71 100644
--- a/server/providers/services/chat_room.service.ts
+++ b/server/providers/services/chat_room.service.ts
@@ -4,6 +4,8 @@ import { Repository, LessThan } from 'typeorm';
import { ChatRoom } from 'server/entities/chat_room.entity';
import { User } from 'server/entities/user.entity';
import { ChatRoomConnection } from 'server/entities/chat_room_connection.entity';
+import { UsersService } from './users.service';
+import { RoleKey } from 'server/entities/role.entity';
@Injectable()
export class ChatRoomService {
@@ -12,6 +14,7 @@ export class ChatRoomService {
private chatRoomRepository: Repository<ChatRoom>,
@InjectRepository(ChatRoomConnection)
private connectedUsersRepository: Repository<ChatRoomConnection>,
+ private usersService: UsersService,
) {}
create(chatRoom: ChatRoom) {
@@ -75,13 +78,19 @@ export class ChatRoomService {
async inactiveRooms() {
const inactiveRooms = await this.chatRoomRepository.find({
+ relations: ['user'],
where: {
- lastModified: LessThan(new Date(Date.now() - 2 * 60 * (1000 * 60))),
+ lastModified: LessThan(new Date(Date.now() - 1000 * 60 * 60 * 2)),
},
});
- return inactiveRooms.filter(async (room) => {
- return !(await this.connectedUsers(room)).length;
+ const isInactivePromises = inactiveRooms.map(async (room) => {
+ const isAdmin = await this.usersService.hasRootRole(room.user.id, RoleKey.ADMIN);
+ const hasMoreThanOneConnections = (await this.connectedUsers(room)).length > 1;
+ return !isAdmin && !hasMoreThanOneConnections;
});
+ const results = await Promise.all(isInactivePromises);
+
+ return inactiveRooms.filter((_, index) => results[index]);
}
save(chatRoom: ChatRoom) {