ankane / mailkick

Email subscriptions for Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ability to add / remove subscriptions with a single method call / query

xdmx opened this issue · comments

commented

Hey Andrew, now that Mailkick works as opt-in it requires to call subscribe multiple times, for example when a new user is created and it needs to be added to different kind of notifications (/lists).

What do you think about changing the subscribe to support an array of lists (with upsert_all maybe?)? That way someone could have something like after_create_commit { subscribe('list1', 'list2', 'list3') }.

unsubscribe should already work, maybe it could be worth to make it clear in the documentation that unsubscribe(['list1', 'list2']) works as well.

Hey @xdmx, thanks for the suggestion. I don't think it's worth the extra complexity right now, but users who need this could use upsert_all to update the table directly.

In the example above, you can also use a transaction to make things more efficient (but not as efficient as a single upsert):

Mailkick::Subscription.transaction do
  ["list1", "list2", "list3"].each { |list| subscribe(list) }
end