REFACTOR: dry user/groups extracting from list

REFACTOR: dry user/groups extracting from list

diff --git a/app/controllers/discourse_calendar/post_events_controller.rb b/app/controllers/discourse_calendar/post_events_controller.rb
index 5f1d2b2..5e18c71 100644
--- a/app/controllers/discourse_calendar/post_events_controller.rb
+++ b/app/controllers/discourse_calendar/post_events_controller.rb
@@ -52,11 +52,7 @@ module DiscourseCalendar
       post_event = PostEvent.find(params[:id])
       guardian.ensure_can_act_on_post_event!(post_event)
       invites = Array(params.permit(invites: [])[:invites])
-      users = User.where(
-        id: GroupUser.where(
-          group_id: Group.where(name: invites).select(:id)
-        ).select(:user_id)
-      ).or(User.where(username: invites))
+      users = Invitee.extract_uniq_usernames(invites)
 
       users.each do |user|
         post_event.create_notification!(user, post_event.post)
diff --git a/app/models/discourse_calendar/invitee.rb b/app/models/discourse_calendar/invitee.rb
index 1f321ed..d100403 100644
--- a/app/models/discourse_calendar/invitee.rb
+++ b/app/models/discourse_calendar/invitee.rb
@@ -18,5 +18,13 @@ module DiscourseCalendar
     def update_attendance(params)
       self.update!(params)
     end
+
+    def self.extract_uniq_usernames(user_and_groups_list)
+      User.where(
+        id: GroupUser.where(
+          group_id: Group.where(name: user_and_groups_list).select(:id)
+        ).select(:user_id)
+      ).or(User.where(username: user_and_groups_list))
+    end
   end
 end
diff --git a/app/models/discourse_calendar/post_event.rb b/app/models/discourse_calendar/post_event.rb
index b5e72c2..27156ab 100644
--- a/app/models/discourse_calendar/post_event.rb
+++ b/app/models/discourse_calendar/post_event.rb
@@ -112,11 +112,7 @@ module DiscourseCalendar
     end
 
     def fetch_users
-      @fetched_users ||= User.where(
-        id: GroupUser.where(
-          group_id: Group.where(name: self.raw_invitees).select(:id)
-        ).select(:user_id)
-      ).or(User.where(username: self.raw_invitees))
+      @fetched_users ||= Invitee.extract_uniq_usernames(self.raw_invitees)
     end
 
     def enforce_raw_invitees!

GitHub sha: 26956688