From 5568a17575c27fbb679e95016606dc8b100a365a Mon Sep 17 00:00:00 2001 From: Nicholas Chiang Date: Mon, 19 Apr 2021 20:20:10 -0700 Subject: [PATCH] fix: increase # of emails fetched to find letters Might help fix an issue that @martinsrna was facing where his Substack newsletters weren't showing up in the "Letters" page. I'm guessing that this was because there were no such Substack messages in his last 500 emails and thus the app couldn't detect them. So, I've upped the # of messages fetched to 2500 (in batches of 100). --- components/letters.tsx | 2 +- lib/api/get/letters.ts | 2 +- lib/api/update/gmail-messages.ts | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/letters.tsx b/components/letters.tsx index e8b32a60..c8b3a146 100644 --- a/components/letters.tsx +++ b/components/letters.tsx @@ -163,7 +163,7 @@ export default function Letters() { useEffect(() => { if (!data) return; - void setSize((prev) => (prev >= 10 ? prev : prev + 1)); + void setSize((prev) => (prev >= 25 ? prev : prev + 1)); }, [data, setSize]); useEffect(() => { setSelected(new Set(user.filter.senders)); diff --git a/lib/api/get/letters.ts b/lib/api/get/letters.ts index 813df57b..3a21cd02 100644 --- a/lib/api/get/letters.ts +++ b/lib/api/get/letters.ts @@ -11,7 +11,7 @@ export default async function getLetters( logger.verbose(`Fetching letters for ${user}...`); const client = gmail(user.token); const { data } = await client.users.messages.list({ - maxResults: 50, + maxResults: 100, userId: 'me', pageToken, }); diff --git a/lib/api/update/gmail-messages.ts b/lib/api/update/gmail-messages.ts index 0c998e4b..5e5b6095 100644 --- a/lib/api/update/gmail-messages.ts +++ b/lib/api/update/gmail-messages.ts @@ -7,6 +7,9 @@ import gmail from 'lib/api/gmail'; * 1. Removes the label from messages that are not from our specified senders. * 2. Adds the label to messages that are from our specified senders and do not * yet have the label. + * @todo Ensure that Gmail supports sending us 2500 messages (and doesn't have + * a cap at e.g. 500 letters per request). If it does have a cap, we should use + * the `nextPageToken` to fetch and update a total of 2500 messages. * @todo Implement the removal process using "Doesn't have" Gmail filters: * @example label:tutorbook -{from:team@tutorbook.org} */ @@ -15,7 +18,7 @@ export default async function updateGmailMessages(user: User): Promise { const client = gmail(user.token); const { data } = await client.users.messages.list({ q: `from:(${user.filter.senders.join(' OR ')})`, - maxResults: 1000, + maxResults: 2500, userId: 'me', }); await client.users.messages.batchModify({