MCPcopy Create free account
hub / github.com/dailydotdev/apps / sendQueuedViews

Function sendQueuedViews

packages/shared/src/lib/streakViewQueue.ts:110–141  ·  view source on GitHub ↗
(
  views: QueuedStreakView[],
  sendView: DrainStreakViewQueueProps['sendView'],
  now: Date,
  sent = 0,
)

Source from the content-addressed store, hash-verified

108}
109
110const sendQueuedViews = async (
111 views: QueuedStreakView[],
112 sendView: DrainStreakViewQueueProps['sendView'],
113 now: Date,
114 sent = 0,
115): Promise<number> => {
116 if (!views.length) {
117 return sent;
118 }
119
120 const [view, ...rest] = views;
121
122 if (!isStreakViewCreditable(new Date(view.at), now, view.timezone)) {
123 removeStreakView(view);
124 return sendQueuedViews(rest, sendView, now, sent);
125 }
126
127 try {
128 await sendView(view.postId);
129 } catch (error) {
130 if (isFinalViewRejection(error)) {
131 removeStreakView(view);
132 return sendQueuedViews(rest, sendView, now, sent);
133 }
134
135 // still offline or a transient API error, keep the rest for the next drain
136 return sent;
137 }
138
139 removeStreakView(view);
140 return sendQueuedViews(rest, sendView, now, sent + 1);
141};
142
143// Replays the views queued for this user, oldest first, and resolves with how
144// many the API accepted.

Callers 1

drainStreakViewQueueFunction · 0.85

Calls 3

isStreakViewCreditableFunction · 0.85
removeStreakViewFunction · 0.85
isFinalViewRejectionFunction · 0.85

Tested by

no test coverage detected