FEATURE: allows to extend the edit notifications period

FEATURE: allows to extend the edit notifications period

diff --git a/app/models/discourse_post_event/event.rb b/app/models/discourse_post_event/event.rb
index 4ca1e6a..5d660f3 100644
--- a/app/models/discourse_post_event/event.rb
+++ b/app/models/discourse_post_event/event.rb
@@ -83,9 +83,9 @@ module DiscoursePostEvent
 
     validates :starts_at, presence: true
 
-    def currently_attending_invitees
+    def on_going_event_invitees
       starts_at = self.starts_at
-      ends_at = self.ends_at || starts_at + 1.hour
+      ends_at = (self.ends_at || starts_at + 1.hour) + SiteSetting.discourse_post_event_edit_notifications_time_extension.minutes
 
       if !(starts_at..ends_at).cover?(Time.now)
         return []
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index a5c00c9..cde18d4 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -23,6 +23,7 @@ en:
     display_post_event_date_on_topic_title: "Displays the date of the event after the topic title."
     discourse_post_event_allowed_on_groups: "Groups that are allowed to create events."
     discourse_post_event_allowed_custom_fields: "Allows to let each each event to set the value of custom fields."
+    discourse_post_event_edit_notifications_time_extension: "Extends (in minutes) the period after the end of an event when `going` invitees are still being notified from edit in the original post."
     holiday_calendar_topic_id: "Topic ID of staffs holiday / absence calendar."
     delete_expired_event_posts_after: "Posts with expired events will be automatically deleted after (n) hours. Set to -1 to disable deletion."
     all_day_event_start_time: "Events that do not have a start time specified will start at this time. Format is HH:mm. For 6:00 am, enter 06:00"
diff --git a/config/settings.yml b/config/settings.yml
index 82a5cbd..df17269 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -62,6 +62,9 @@ discourse_post_event:
   discourse_post_event_max_bulk_invitees:
     default: 500
     hidden: true
+  discourse_post_event_edit_notifications_time_extension:
+    default: 0
+    min: 0
   discourse_post_event_allowed_custom_fields:
     type: list
     client: true
diff --git a/plugin.rb b/plugin.rb
index 0991135..3883da7 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -514,7 +514,7 @@ after_initialize do
         post = post_revision.post
 
         if post && post.is_first_post? && post.event
-          ids.concat(post.event.currently_attending_invitees.pluck(:user_id))
+          ids.concat(post.event.on_going_event_invitees.pluck(:user_id))
         end
 
         ids
diff --git a/spec/acceptance/post_spec.rb b/spec/acceptance/post_spec.rb
index 19bfcf8..2887ddb 100644
--- a/spec/acceptance/post_spec.rb
+++ b/spec/acceptance/post_spec.rb
@@ -44,23 +44,27 @@ describe Post do
       context 'when event is on going' do
         let(:going_user) { Fabricate(:user) }
         let(:interested_user) { Fabricate(:user) }
+        let(:post_1) { create_post_with_event(user) }
 
         before do
           SiteSetting.editing_grace_period = 1.minute
           PostActionNotifier.enable
+          SiteSetting.discourse_post_event_edit_notifications_time_extension = 180
         end
 
         context 'when in edit grace period' do
-          it 'sends a post revision to going invitees' do
-            post = create_post_with_event(user).reload
+          before do
+            post_1.reload.event.update!(starts_at: 2.hours.ago)
+          end
 
-            Invitee.create_attendance!(going_user.id, post.id, :going)
-            Invitee.create_attendance!(interested_user.id, post.id, :interested)
+          it 'sends a post revision to going invitees' do
+            Invitee.create_attendance!(going_user.id, post_1.id, :going)
+            Invitee.create_attendance!(interested_user.id, post_1.id, :interested)
 
-            revisor = PostRevisor.new(post)
+            revisor = PostRevisor.new(post_1)
             revisor.revise!(
               user,
-              { raw: post.raw + "\nWe are bout half way into our event!" },
+              { raw: post_1.raw + "\nWe are bout half way into our event!" },
               revised_at: Time.now + 2.minutes
             )
 
@@ -68,6 +72,27 @@ describe Post do
             expect(interested_user.notifications.count).to eq(0)
           end
         end
+
+        context 'when not edit grace period' do
+          before do
+            post_1.reload.event.update!(starts_at: 5.hours.ago)
+          end
+
+          it 'doesn’t send a post revision to anyone' do
+            Invitee.create_attendance!(going_user.id, post_1.id, :going)
+            Invitee.create_attendance!(interested_user.id, post_1.id, :interested)
+
+            revisor = PostRevisor.new(post_1)
+            revisor.revise!(
+              user,
+              { raw: post_1.raw + "\nWe are bout half way into our event!" },
+              revised_at: Time.now + 2.minutes
+            )
+
+            expect(going_user.notifications.count).to eq(0)
+            expect(interested_user.notifications.count).to eq(0)
+          end
+        end
       end
     end
   end

GitHub sha: b5e388a7

This is a very long name. It’s OK because it’s server side but maybe discourse_post_event_edit_time_extension would be better?

yes agreed, I was actually talking of this with @ZogStriP as I wan’t happy of this name, he came up with: discourse_post_event_notify_after_ended_minutes

I think having minutes in the name is cool as it makes it very clear in code what you are dealing with.