FEATURE: notify going invitees of edits on OP during event

FEATURE: notify going invitees of edits on OP during event

diff --git a/app/models/discourse_post_event/event.rb b/app/models/discourse_post_event/event.rb
index 082124a..f9613f4 100644
--- a/app/models/discourse_post_event/event.rb
+++ b/app/models/discourse_post_event/event.rb
@@ -70,6 +70,17 @@ module DiscoursePostEvent
 
     validates :starts_at, presence: true
 
+    def currently_attending_invitees
+      starts_at = self.starts_at
+      ends_at = self.ends_at || starts_at + 1.hour
+
+      if !(starts_at..ends_at).cover?(Time.now)
+        return []
+      end
+
+      invitees.where(status: DiscoursePostEvent::Invitee.statuses[:going])
+    end
+
     MIN_NAME_LENGTH = 5
     MAX_NAME_LENGTH = 30
     validates :name,
diff --git a/plugin.rb b/plugin.rb
index 83ce74a..ca87b60 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -503,5 +503,21 @@ after_initialize do
     on(:user_destroyed) do |user|
       DiscoursePostEvent::Invitee.where(user_id: user.id).destroy_all
     end
+
+    if respond_to?(:add_post_revision_notifier_recipients)
+      add_post_revision_notifier_recipients do |post_revision|
+        ids = []
+        post = post_revision.post
+
+        if post && post.is_first_post?
+          event = DiscoursePostEvent::Event.find(post.id)
+          if event
+            ids.concat(event.currently_attending_invitees.pluck(:user_id))
+          end
+        end
+
+        ids
+      end
+    end
   end
 end
diff --git a/spec/acceptance/post_spec.rb b/spec/acceptance/post_spec.rb
index fdd902c..a4acd34 100644
--- a/spec/acceptance/post_spec.rb
+++ b/spec/acceptance/post_spec.rb
@@ -4,8 +4,8 @@ require 'rails_helper'
 require 'securerandom'
 require_relative '../fabricators/event_fabricator'
 
-def create_post_with_event(user, extra_raw)
-  start = Time.now.utc.iso8601(3)
+def create_post_with_event(user, extra_raw = '')
+  start = (Time.now - 10.seconds).utc.iso8601(3)
 
   PostCreator.create!(
     user,
@@ -16,10 +16,11 @@ end
 
 describe Post do
   Event ||= DiscoursePostEvent::Event
+  Invitee ||= DiscoursePostEvent::Invitee
 
   before do
     freeze_time
-    SiteSetting.queue_jobs = false
+    Jobs.run_immediately!
     SiteSetting.calendar_enabled = true
     SiteSetting.discourse_post_event_enabled = true
   end
@@ -27,7 +28,7 @@ describe Post do
   let(:user) { Fabricate(:user, admin: true) }
   let(:topic) { Fabricate(:topic, user: user) }
   let(:post1) { Fabricate(:post, topic: topic) }
-  let(:post_event) { Fabricate(:event, post: post1) }
+  let!(:post_event) { Fabricate(:event, post: post1, status: Event.statuses[:public]) }
 
   context 'when a post is updated' do
     context 'when the post has a valid event' do
@@ -49,6 +50,35 @@ describe Post do
           expect(post.reload.event).to be(nil)
         end
       end
+
+      context 'when event is on going' do
+        let(:going_user) { Fabricate(:user) }
+        let(:interested_user) { Fabricate(:user) }
+
+        before do
+          SiteSetting.editing_grace_period = 1.minute
+          PostActionNotifier.enable
+        end
+
+        context 'when in edit grace period' do
+          it 'sends a post revision to going invitees' do
+            post = create_post_with_event(user).reload
+
+            Invitee.create_attendance!(going_user.id, post.id, :going)
+            Invitee.create_attendance!(interested_user.id, post.id, :interested)
+
+            revisor = PostRevisor.new(post)
+            revisor.revise!(
+              user,
+              { raw: post.raw + "\nWe are bout half way into our event!" },
+              revised_at: Time.now + 2.minutes
+            )
+
+            expect(going_user.notifications.count).to eq(1)
+            expect(interested_user.notifications.count).to eq(0)
+          end
+        end
+      end
     end
   end
 

GitHub sha: 214899ea