Skip to content

Commit

Permalink
Merge pull request #382 from RunTerror/group_subscription
Browse files Browse the repository at this point in the history
Group subscription
  • Loading branch information
Akshatji800 authored Sep 28, 2024
2 parents 0a6104a + d96491a commit 6cbbad5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,44 @@ const resolvers = {
}
),
},
groupUpdate: {
subscribe: withFilter(
(_, __, { pubsub }) => pubsub.asyncIterator(["GROUP_UPDATE"]),
(payload, variables, { user }) => {
const { groupID, groupMembers, groupLeader, groupUpdate } = payload;

let { newBeacon, groupId, deletedBeacon, updatedBeacon, newUser } = groupUpdate;

Check failure on line 716 in graphql/resolvers.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'newUser' is assigned a value but never used
if (newBeacon != null) {
if (newBeacon.leader._id == user.id) {
// stopping to listen to the creator of beacon
return false;
}
payload.groupUpdate.newBeacon = parseBeaconObject(newBeacon);
} else if (deletedBeacon != null) {
if (deletedBeacon.leader.toString() === user._id.toString()) {
// stopping to listen to the creator of beacon
return false;
}
payload.groupUpdate.deletedBeacon = parseBeaconObject(deletedBeacon);
} else if (updatedBeacon != null) {
if (updatedBeacon.leader._id == user.id) {
// stopping to listen to the creator of beacon
return false;
}
payload.groupUpdate.updatedBeacon = parseBeaconObject(updatedBeacon);
}
if (!variables.groupIds.includes(groupID)) {
return false;
}
// checking if user is part of group or not
const isGroupLeader = groupLeader === user.id.toString();
const isGroupMember = groupMembers.includes(user.id);

let istrue = isGroupLeader || isGroupMember;
return istrue && variables.groupIds.includes(groupId);
}
),
},
},
}),
};
Expand Down

0 comments on commit 6cbbad5

Please sign in to comment.