Skip to content

Commit

Permalink
style: make the code more beautiful by removing extra spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzydev committed May 3, 2024
1 parent aca98d0 commit e6054fb
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 27 deletions.
3 changes: 0 additions & 3 deletions src/events/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ import { CoreParticipant, Participant } from './login';
export default class BanOrUnbanParticipant {
async handle({ socket, io, data }: { socket: Socket; io: Server; data: any }) {
const targetUserId = data?.target;

if (!targetUserId) return;

const rooms = Array.from(socket.rooms);

const room = rooms[1];

if (!room) return;

const socketId = socket.id;

const socketRoomParticipants = (await get(`room:${room}:users`)) as Participant[];

if (socketRoomParticipants) {
Expand Down
3 changes: 0 additions & 3 deletions src/events/disconnecting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { del, delWithPattern, get, set } from '@utils/cache';
export default class Disconnect {
async handle({ socket, io }: { socket: Socket; io: Server }) {
const rooms = Array.from(socket.rooms);

const room = rooms[1];

if (!room) return;

const socketId = socket.id;

const socketRoomParticipants = await get(`room:${room}:users`);

if (socketRoomParticipants) {
Expand All @@ -25,7 +23,6 @@ export default class Disconnect {
}

const remainingParticipants = io.sockets.adapter.rooms.get(room);

if (!remainingParticipants) {
await delWithPattern(`room:${room}:*`);
await del(`sid:${socketId}`);
Expand Down
3 changes: 0 additions & 3 deletions src/events/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ import { Participant } from './login';
export default class KickParticipant {
async handle({ socket, io, data }: { socket: Socket; io: Server; data: any }) {
const targetUserId = data?.target;

if (!targetUserId) return;

const rooms = Array.from(socket.rooms);

const room = rooms[1];

if (!room) return;

const socketId = socket.id;

const socketRoomParticipants = (await get(`room:${room}:users`)) as Participant[];

if (socketRoomParticipants) {
Expand Down
8 changes: 2 additions & 6 deletions src/events/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,21 @@ export default class Login {
password = password.trim();
room = room.trim();

const user = await fetch(`${process.env.API_URL}/user`, {
const user = (await fetch(`${process.env.API_URL}/user`, {
headers: {
Authorization: token,
},
});
})) as any;

const json = await user.json();

if (!json?.id) return callback({ error: 'Kullanıcı verisi alınamadı' });

const roomParticipants = await get(`${prefix}:users`);

if (roomParticipants && roomParticipants.find((user) => user.id == json.id)) {
return callback({ error: 'Zaten bu odadasın' });
}

const getPass = await get(`${prefix}:password`);

if (getPass && getPass != password) {
return callback({ error: 'Yanlış şifre' });
}
Expand All @@ -89,7 +86,6 @@ export default class Login {
[]) as CoreParticipant[];

const banned = bannedParticipants.find((x) => x.id == json.id);

if (banned) {
return callback({ error: 'Bu odadan yasaklandınız' });
}
Expand Down
2 changes: 0 additions & 2 deletions src/events/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ export default class CreateMessage {
data.message.trim().length <= 250
) {
const rooms = Array.from(socket.rooms);

const room = rooms[1];

if (!room) return;

const socketRoomParticipants = await get(`room:${room}:users`);

const author = socketRoomParticipants.find((user) => user.sid == socket.id);

if (!author) return;
Expand Down
3 changes: 0 additions & 3 deletions src/events/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import { Participant } from './login';
export default class MakeModeratorOrTakeModerator {
async handle({ socket, io, data }: { socket: Socket; io: Server; data: any }) {
const targetUserId = data?.target;

if (!targetUserId) return;

const rooms = Array.from(socket.rooms);

const room = rooms[1];

if (!room) return;

const socketId = socket.id;

const socketRoomParticipants = (await get(`room:${room}:users`)) as Participant[];

if (socketRoomParticipants) {
Expand Down
3 changes: 0 additions & 3 deletions src/events/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ import { Participant } from './login';
export default class MuteOrUnmuteParticipant {
async handle({ socket, io, data }: { socket: Socket; io: Server; data: any }) {
const targetUserId = data?.target;

if (!targetUserId) return;

const rooms = Array.from(socket.rooms);

const room = rooms[1];

if (!room) return;

const socketId = socket.id;

const socketRoomParticipants = (await get(`room:${room}:users`)) as Participant[];

if (socketRoomParticipants) {
Expand Down
4 changes: 0 additions & 4 deletions src/events/playerTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ import { Participant } from './login';
export default class MuteOrUnmuteParticipant {
async handle({ socket, data }: { socket: Socket; data: any }) {
const videoTimestamp = data?.timestamp;

if (isNaN(videoTimestamp)) return;

const rooms = Array.from(socket.rooms);

const room = rooms[1];

if (!room) return;

const socketId = socket.id;

let pass = false;

const modRequired = (await get(`room:${room}:controlledByMods`)) ?? false;

if (modRequired) {
const socketRoomParticipants = (await get(`room:${room}:users`)) as Participant[];

Expand Down

0 comments on commit e6054fb

Please sign in to comment.