feature/IO-3096-GlobalNotifications -Read Status Sync accross all clients.
This commit is contained in:
@@ -213,6 +213,27 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getUserSocketMappingByBodyshop = async (email, bodyshopId) => {
|
||||
const userKey = `user:${email}`;
|
||||
const socketMappingKey = `${userKey}:socketMapping`;
|
||||
try {
|
||||
// Retrieve all socket mappings for the user
|
||||
const mapping = await pubClient.hgetall(socketMappingKey);
|
||||
const ttl = await pubClient.ttl(socketMappingKey);
|
||||
// Filter socket IDs for the provided bodyshopId
|
||||
const socketIds = Object.entries(mapping).reduce((acc, [socketId, bId]) => {
|
||||
if (bId === bodyshopId) {
|
||||
acc.push(socketId);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
return { socketIds, ttl };
|
||||
} catch (error) {
|
||||
logger.log(`Error retrieving socket mappings for ${email} by bodyshop ${bodyshopId}: ${error}`, "ERROR", "redis");
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const api = {
|
||||
setSessionData,
|
||||
getSessionData,
|
||||
@@ -228,6 +249,7 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
|
||||
getUsersInRoom,
|
||||
addUserSocketMapping,
|
||||
removeUserSocketMapping,
|
||||
getUserSocketMappingByBodyshop,
|
||||
getUserSocketMapping,
|
||||
refreshUserSocketTTL
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user