Skip to content

Commit

Permalink
feat: rename events
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle committed Dec 14, 2023
1 parent 3b9bf79 commit 0820503
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type UserToFollow = {
};
type OnUserFollowedPayload = {
userToFollow: UserToFollow;
action: "follow" | "unfollow";
action: "FOLLOW" | "UNFOLLOW";
};

const serverDebug = debug("server");
Expand Down Expand Up @@ -87,35 +87,36 @@ try {
},
);

socket.on("on-user-follow", async (payload: OnUserFollowedPayload) => {
socket.on("user-follow", async (payload: OnUserFollowedPayload) => {
const roomID = `follow_${payload.userToFollow.socketId}`;

switch (payload.action) {
case "follow":
case "FOLLOW": {
await socket.join(roomID);

const sockets = await io.in(roomID).fetchSockets();
const followedBy = sockets.map((socket) => socket.id);

// Notify the user to follow that someone has followed them
// More precisely, send the list of users that are following them
// so that they can make decisions based on that
io.to(payload.userToFollow.socketId).emit(
"follow-room-user-change",
"user-follow-room-change",
followedBy,
);

break;
case "unfollow":
}
case "UNFOLLOW": {
await socket.leave(roomID);
const _sockets = await io.in(roomID).fetchSockets();
const _followedBy = _sockets.map((socket) => socket.id);

const sockets = await io.in(roomID).fetchSockets();
const followedBy = sockets.map((socket) => socket.id);

io.to(payload.userToFollow.socketId).emit(
"follow-room-user-change",
_followedBy,
"user-follow-room-change",
followedBy,
);

break;
}
}
});

Expand Down

0 comments on commit 0820503

Please # to comment.