app/models/message.rb in hackathon_manager-0.6.0 vs app/models/message.rb in hackathon_manager-0.6.1
- old
+ new
@@ -73,15 +73,19 @@
def can_edit?
status == "drafted" || trigger.present?
end
+ def can_queue?
+ status == "drafted" && recipients_list.present?
+ end
+
def using_default_template?
template == "default"
end
- def self.possible_recipients
+ def possible_recipients
# Produce an array like:
# ["School: My University", "school::123"]
option = ->(query, model) { [MessageRecipientQuery.friendly_name(query, model), query] }
bus_list_recipients = BusList.select(:id, :name).map do |bus_list|
[
@@ -100,9 +104,17 @@
# Combine all recipients. push(*recipients) is the most efficient,
# as it doesn't create a new array each time (concat() does)
recipients = POSSIBLE_SIMPLE_RECIPIENTS.invert.to_a
recipients.push(*bus_list_recipients)
recipients.push(*school_recipients)
+
+ # Add current recipients if not included
+ self.recipients.each do |recipient|
+ if recipients.none? { |recipient_pair| recipient_pair[1] == recipient }
+ recipients.push([recipient, recipient])
+ end
+ end
+
recipients
end
def self.queue_for_trigger(trigger, user_id)
messages_to_queue = Message.where(trigger: trigger)