Skip to content

Commit

Permalink
FEATURE: keeps going invitees for recurring events (#632)
Browse files Browse the repository at this point in the history
Prior to this fix when computing the next event date we were resetting the status of every invitees. The status will now only be reset for non going users.
  • Loading branch information
jjaffeux authored Oct 25, 2024
1 parent d05ab78 commit 557d00b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
6 changes: 4 additions & 2 deletions app/models/discourse_post_event/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ def set_next_date
end
end

publish_update!
invitees.update_all(status: nil, notified: false)
invitees.where.not(status: Invitee.statuses[:going]).update_all(status: nil, notified: false)

if !next_dates[:rescheduled]
notify_invitees!
notify_missing_invitees!
end

publish_update!
end

def set_topic_bump
Expand Down
5 changes: 0 additions & 5 deletions app/models/discourse_post_event/event_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ def upsert_topic_custom_field
end
end

after_commit :reset_invitees_status, on: %i[create]
def reset_invitees_status
self.event.invitees.update_all(status: nil)
end

def started?
starts_at <= Time.current
end
Expand Down
20 changes: 12 additions & 8 deletions spec/integration/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,20 @@
expect(event_1.ends_at.to_s).to eq("2020-08-19 16:32:00 UTC")
end

it "it removes status from every invitees" do
expect(event_1.invitees.pluck(:status)).to match_array(
[
DiscoursePostEvent::Invitee.statuses[:going],
DiscoursePostEvent::Invitee.statuses[:interested],
],
)
it "it removes status from non going invitees" do
going_invitee =
event_1.invitees.find_by(status: DiscoursePostEvent::Invitee.statuses[:going])
interested_invitee =
event_1.invitees.find_by(
status: DiscoursePostEvent::Invitee.statuses[:interested],
)

event_1.update_with_params!(original_ends_at: Time.now)
expect(event_1.invitees.pluck(:status).compact).to eq([])

expect(going_invitee.reload.status).to eq(
DiscoursePostEvent::Invitee.statuses[:going],
)
expect(interested_invitee.reload.status).to eq(nil)
end

# that will be handled by new job, uncomment when finished
Expand Down

0 comments on commit 557d00b

Please sign in to comment.