app/models/unidom/contact/concerns/as_subscriber.rb in unidom-contact-1.2 vs app/models/unidom/contact/concerns/as_subscriber.rb in unidom-contact-1.3
- old
+ new
@@ -4,15 +4,24 @@
included do |includer|
has_many :contact_subscriptions, class_name: 'Unidom::Contact::ContactSubscription', as: :subscriber
- def subscribe_contact!(contact, at: Time.now, name: nil)
+ def subscribe_contact!(contact, at: Time.now, name: nil, primary: true)
raise ArgumentError.new('The contact argument is required.') if contact.blank?
raise ArgumentError.new('The at argument is required.' ) if at.blank?
- contact_subscriptions.create! contact: contact, opened_at: at, name: name||self.name
+ contact_subscriptions.contact_is(contact).valid_at(now: at).alive.first_or_create! name: name||self.name, elemental: primary, opened_at: at
+
+ end
+
+ def subscribe_contact?(contact, at: Time.now, primary: true)
+
+ raise ArgumentError.new('The contact argument is required.') if contact.blank?
+ raise ArgumentError.new('The at argument is required.' ) if at.blank?
+
+ contact_subscriptions.contact_is(contact).valid_at(now: at).alive.primary(primary).exists?
end
end