comty/packages/server/services/main/events/user_disconnected.js
2024-03-06 19:43:09 +00:00

19 lines
543 B
JavaScript
Executable File

import { UserFollow } from "@db_models"
export default async (user_id) => {
// get followers of the user
const followers = await UserFollow.find({
to: user_id,
})
// send event to ws clients (if are connected)
followers.forEach((follow) => {
const connectedClient = global.websocket_instance.clients.find((client) => {
return client.user_id === follow.user_id
})
if (connectedClient) {
connectedClient.socket.emit("friend.disconnected", user_id)
}
})
}