Skip to content

Commit

Permalink
fix: increase # of emails fetched to find letters
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
nicholaschiang committed Apr 20, 2021
1 parent d926dd5 commit 5568a17
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/letters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion lib/api/get/letters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
5 changes: 4 additions & 1 deletion lib/api/update/gmail-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -15,7 +18,7 @@ export default async function updateGmailMessages(user: User): Promise<void> {
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({
Expand Down

1 comment on commit 5568a17

@vercel
Copy link

@vercel vercel bot commented on 5568a17 Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.