Skip to content

Commit c3f7324

Browse files
committed
Address review comment
1 parent 0a9fe92 commit c3f7324

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

app/backend/src/couchers/servicers/events.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,19 @@ def get_users_to_notify_for_new_event(session: Session, occurrence: EventOccurre
235235
"""
236236
Returns the users to notify, as well as the community id that is being notified (None if based on geo search)
237237
"""
238+
# people already attending or organizing the event don't need an invite to it
239+
not_already_involved = User.id.not_in(
240+
select(EventOccurrenceAttendee.user_id)
241+
.where(EventOccurrenceAttendee.occurrence_id == occurrence.id)
242+
.union(select(EventOrganizer.user_id).where(EventOrganizer.event_id == occurrence.event_id))
243+
)
244+
238245
cluster = occurrence.event.parent_node.official_cluster
239246
if occurrence.event.parent_node.node_type.value <= NodeType.region.value:
240247
logger.info("Global, macroregion, and region communities are too big for email notifications.")
241248
return [], occurrence.event.parent_node_id
242249
elif occurrence.creator_user in cluster.admins or cluster.is_leaf:
243-
return list(cluster.members.where(User.is_visible)), occurrence.event.parent_node_id
250+
return list(cluster.members.where(User.is_visible).where(not_already_involved)), occurrence.event.parent_node_id
244251
else:
245252
max_radius = 20000 # m
246253
users = (
@@ -250,6 +257,7 @@ def get_users_to_notify_for_new_event(session: Session, occurrence: EventOccurre
250257
.where(User.is_visible)
251258
.where(ClusterSubscription.cluster_id == cluster.id)
252259
.where(func.ST_DWithin(User.geom, occurrence.geom, max_radius / 111111))
260+
.where(not_already_involved)
253261
)
254262
.scalars()
255263
.all()
@@ -278,16 +286,7 @@ def generate_event_create_notifications(payload: jobs_pb2.GenerateEventCreateNot
278286
logger.error(f"Inviting user {payload.inviting_user_id} is gone while trying to send event notification?")
279287
return
280288

281-
# people already attending or organizing the event don't need an invite to it
282-
already_involved_user_ids = set(
283-
session.execute(
284-
select(EventOccurrenceAttendee.user_id).where(EventOccurrenceAttendee.occurrence_id == occurrence.id)
285-
).scalars()
286-
) | set(session.execute(select(EventOrganizer.user_id).where(EventOrganizer.event_id == event.id)).scalars())
287-
288289
for user in users:
289-
if user.id in already_involved_user_ids:
290-
continue
291290
if is_not_visible(session, user.id, creator.id):
292291
continue
293292
context = make_notification_user_context(user_id=user.id)

app/backend/src/tests/test_events.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,9 +2262,10 @@ def test_community_invite_requests(db, email_collector: EmailCollector, moderato
22622262
res = editor.ListEventCommunityInviteRequests(editor_pb2.ListEventCommunityInviteRequestsReq())
22632263
assert len(res.requests) == 2
22642264
assert res.requests[0].user_id == user1.id
2265-
assert res.requests[0].approx_users_to_notify == 3
2265+
# user1 is the event organizer, so they're excluded from the notify count (only user3 and user4 remain)
2266+
assert res.requests[0].approx_users_to_notify == 2
22662267
assert res.requests[1].user_id == user3.id
2267-
assert res.requests[1].approx_users_to_notify == 3
2268+
assert res.requests[1].approx_users_to_notify == 2
22682269

22692270
editor.DecideEventCommunityInviteRequest(
22702271
editor_pb2.DecideEventCommunityInviteRequestReq(

0 commit comments

Comments
 (0)