Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a way to loop through all tickets in the same returned order #9

Open
xdmx opened this issue Jan 30, 2024 · 2 comments
Open

Expose a way to loop through all tickets in the same returned order #9

xdmx opened this issue Jan 30, 2024 · 2 comments

Comments

@xdmx
Copy link

xdmx commented Jan 30, 2024

I'm experimenting with this gem in an application where I batch multiple push notifications that are sent to different users.

For logging reasons I want to store each push notification and associate them to each user, in order to get visibility on how many push notifications someone receive, their status.

From the Expo documentation:

data will contain an array of push tickets in the same order in which the messages were sent

So the idea is to create a PushNotification record matching the user with the position in the returned data.

The problem is that at the moment this doesn't seem possible since there is a tickets.each that only returns ok tickets (filtering out errors) and tickets.each_error that only returns error tickets (filtering out oks).

Given that the position of each ticket is important in order to match the user those two methods cannot be used together for this purpose.

Would you consider adding a new method that'd allow to loop through all ok/error tickets together in the original order that got returned by Expo?

Something like:

      def each_ticket
        results.each do |tickets|
          next if tickets.is_a?(Error)

          tickets.each do |ticket|
            yield ticket
          end
        end
      end

That'd allow to loop through all of them; and in order to prevent that one batch/chunk error out would mess up the position, the whole chunking could be taken care of before sending the messages, which I think would be fine.

@xdmx
Copy link
Author

xdmx commented Jan 30, 2024

Maybe also a each_receipt for receipts, to keep it consistent

@SleeplessByte
Copy link
Owner

That'd allow to loop through all of them
Unless there is a "top-level" error, which makes it less than ideal.

Would a reference back to the receipt and the receipt back to the notification work? Seems like that is what you ultimately want? I also don't mind adding explicit iterators that iterate through everything. Feel free to PR that (and each_receipt + the doc changes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants