Skip to content

Commit

Permalink
Refactor oye status match
Browse files Browse the repository at this point in the history
  • Loading branch information
DeeTheDev authored and rgalanakis committed Jun 26, 2024
1 parent 6dc9c28 commit 7fdb893
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/suma/member/oye_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _add_contact_id

def _update_contact_status
marketing_subscr = self.marketing_subscription
oye_sms_status = Suma::Oye::TO_OYE_STATUS.fetch(marketing_subscr[:opted_in])
oye_sms_status = Suma::Oye::STATUS_MATCH.invert.fetch(marketing_subscr[:opted_in])
Suma::Oye.bulk_update_contacts(contacts: [{id: self.contact_id, status: oye_sms_status}])
end

Expand Down
12 changes: 4 additions & 8 deletions lib/suma/oye.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ module Suma::Oye
OPTIN_STATUS = "active"
OPTOUT_STATUS = "inactive"

TO_OYE_STATUS = {
true => OPTIN_STATUS,
false => OPTOUT_STATUS,
}.freeze
TO_SUMA_STATUS = {
STATUS_MATCH = {
OPTIN_STATUS => true,
OPTOUT_STATUS => false,
}.freeze
Expand Down Expand Up @@ -67,9 +63,9 @@ def self.sync_contact_sms_preferences
end
next if member.nil?
member_subscr = member.oye.marketing_subscription
contact_opted_in = TO_SUMA_STATUS.fetch(c.fetch("status"))
next if contact_opted_in === member_subscr[:opted_in]
member_subscr.set_from_opted_in(TO_SUMA_STATUS.fetch(c.fetch("status")))
member_opted_in = STATUS_MATCH.fetch(c.fetch("status"))
next if member_opted_in === member_subscr[:opted_in]
member_subscr.set_from_opted_in(member_opted_in)
member.preferences.save_changes
end
end
Expand Down

0 comments on commit 7fdb893

Please sign in to comment.