feat: move all email to defer queue #185
fix: use relative part for defer func #185 chore: move sendEmail into defer fix: remove anon function to defer #185 feat: implement batch email sending with defer.run #185 chore: debug sendEmails #185 chore: add robots.txt chore: use promise.all in sendEmails chore: debug defer sendEmails #185 chore: try defer sendEmail without loop #105 chore: comment code chore: change loop style #185 chore: use promise.all for vercel edge #185 feat: add await to sendEmailNotification #185 chore: use sendEmails #185 fix: debug sendEmails #185 fix: email not updating in LMS fix: remove early return in sendEmails #185
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
@@ -24,12 +24,12 @@ export async function POST({ request }) {
|
||||
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
|
||||
}
|
||||
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
from: `"${orgName} (via ClassroomIO.com)" <[email protected]>`,
|
||||
to,
|
||||
subject: `[Submitted]: ${exerciseTitle}`,
|
||||
content
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import { getFeedForNotification } from '$lib/utils/services/newsfeed/index';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
import sendEmails from '$defer/sendEmails';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
const sendEmailNotification = async (feedId: string, authorId: string, comment?: string) => {
|
||||
const feed = await getFeedForNotification(feedId, authorId);
|
||||
|
||||
if (!feed) return;
|
||||
|
||||
const postLink = `https://${feed.org.siteName}.classroomio.com/courses/${feed.courseId}?feedId=${feed.id}`;
|
||||
|
||||
if (comment) {
|
||||
// send only to teacher
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
from: `"${feed.org.name} - ClassroomIO" <[email protected]>`,
|
||||
to: feed.teacherEmail,
|
||||
subject: `[${feed.courseTitle}] - News feed comment`,
|
||||
@@ -26,31 +26,35 @@ const sendEmailNotification = async (feedId: string, authorId: string, comment?:
|
||||
<a class="button" href="${postLink}">View comment</a>
|
||||
</div>
|
||||
`
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
// dont continue
|
||||
return;
|
||||
}
|
||||
|
||||
if (!feed.courseMembers.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// else send to everyone except the author of the post
|
||||
Promise.all(
|
||||
feed.courseMembers.map((member) => {
|
||||
return sendEmail({
|
||||
from: `"${feed.org.name} - ClassroomIO" <[email protected]>`,
|
||||
to: member.email,
|
||||
replyTo: feed.teacherEmail,
|
||||
subject: `[${feed.courseTitle}] - New post in course`,
|
||||
content: `
|
||||
<p>${feed.teacherName} made a post in a course you are taking: ${feed.courseTitle}.</p>
|
||||
|
||||
<div style="font-style: italic; margin-top: 10px;">${feed.content}</div>
|
||||
<div>
|
||||
<a class="button" href="${postLink}">View post</a>
|
||||
</div>
|
||||
`
|
||||
});
|
||||
})
|
||||
).then((emails) => console.log(`Sent emails to ${emails.length} students`));
|
||||
const emails = feed.courseMembers.map((member) => ({
|
||||
from: `"${feed.org.name} - ClassroomIO" <[email protected]>`,
|
||||
to: member.email,
|
||||
replyTo: feed.teacherEmail,
|
||||
subject: `[${feed.courseTitle}] - New post in course`,
|
||||
content: `
|
||||
<p>${feed.teacherName} made a post in a course you are taking: ${feed.courseTitle}.</p>
|
||||
|
||||
<div style="font-style: italic; margin-top: 10px;">${feed.content}</div>
|
||||
<div>
|
||||
<a class="button" href="${postLink}">View post</a>
|
||||
</div>
|
||||
`
|
||||
}));
|
||||
console.log('Sending emails to all students', feed.courseMembers.length);
|
||||
|
||||
// This is the defer function with a loop
|
||||
await sendEmails(emails);
|
||||
};
|
||||
|
||||
export async function POST({ request }) {
|
||||
@@ -74,7 +78,7 @@ export async function POST({ request }) {
|
||||
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
|
||||
}
|
||||
|
||||
sendEmailNotification(feedId, authorId, comment);
|
||||
await sendEmailNotification(feedId, authorId, comment);
|
||||
// TODO: Support sending to other platforms like telegram and discord
|
||||
// sendDiscordNotification(); sendTelegramNotification();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
@@ -32,7 +32,7 @@ export async function POST({ request }) {
|
||||
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
|
||||
}
|
||||
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
from: `"${orgName} - ClassroomIO" <[email protected]>`,
|
||||
to,
|
||||
replyTo: teacherEmail,
|
||||
@@ -44,7 +44,7 @@ export async function POST({ request }) {
|
||||
<p>Talk to you soon and see you in class.</p>
|
||||
<p>${orgName}</p>
|
||||
`
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function POST({ request }) {
|
||||
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
|
||||
}
|
||||
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
from: `"${orgName} (via ClassroomIO.com)" <[email protected]>`,
|
||||
to,
|
||||
subject: `${orgName} - Welcome to Class 🎉`,
|
||||
@@ -38,7 +38,7 @@ export async function POST({ request }) {
|
||||
<p>Cheers,</p>
|
||||
<p>${orgName}</p>
|
||||
`
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
@@ -24,12 +24,12 @@ export async function POST({ request }) {
|
||||
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
|
||||
}
|
||||
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
from: `"${orgName} (via ClassroomIO.com)" <[email protected]>`,
|
||||
to,
|
||||
subject: 'Submission Update',
|
||||
content
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function POST({ request }) {
|
||||
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
|
||||
}
|
||||
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
from: `ClassroomIO" <[email protected]>`,
|
||||
to,
|
||||
subject: `[${courseName}] Request to Join Course!`,
|
||||
@@ -44,7 +44,7 @@ export async function POST({ request }) {
|
||||
Email: ${studentEmail}
|
||||
</p>
|
||||
`
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
@@ -25,7 +25,7 @@ export async function POST({ request }) {
|
||||
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
|
||||
}
|
||||
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
from: `"ClassroomIO" <[email protected]>`,
|
||||
to,
|
||||
subject: `[${courseName}] You've got a new student 🎉!`,
|
||||
@@ -36,7 +36,7 @@ export async function POST({ request }) {
|
||||
<p>If you run into any issues, please don’t fail to reach out to us, we’d love to make your teaching
|
||||
experience as easy as possible.</p>
|
||||
`
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function POST({ request }) {
|
||||
const origin = request.headers.get('origin');
|
||||
const inviteLink = `${origin}/org/${orgSiteName}/courses`;
|
||||
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
from: `"${orgName} (via ClassroomIO.com)" <[email protected]>`,
|
||||
to,
|
||||
subject: `You have been invited to a course in ${orgName}!`,
|
||||
@@ -40,7 +40,7 @@ export async function POST({ request }) {
|
||||
<a class="button" href="${inviteLink}">Open Dashboard</a>
|
||||
</div>
|
||||
`
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
@@ -42,7 +42,7 @@ export async function POST({ request }) {
|
||||
const inviteLink = `${origin}/invite/t/${encodeURIComponent(btoa(inviteData))}`;
|
||||
console.log('inviteData', inviteData);
|
||||
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
to: email,
|
||||
subject: `Join ${name} on ClassroomIO 😃`,
|
||||
content: `
|
||||
@@ -53,7 +53,7 @@ export async function POST({ request }) {
|
||||
</div>
|
||||
`,
|
||||
isPersonalEmail: true
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getSupabase } from '$lib/utils/functions/supabase';
|
||||
import { sendEmail } from '$lib/utils/services/notification/send';
|
||||
import sendEmail from '$defer/sendEmail';
|
||||
|
||||
const supabase = getSupabase();
|
||||
|
||||
@@ -25,7 +25,7 @@ export async function POST({ request }) {
|
||||
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
|
||||
}
|
||||
|
||||
sendEmail({
|
||||
await sendEmail({
|
||||
to,
|
||||
subject: 'Thank you so so so much for choosing ClassroomIO!',
|
||||
content: `
|
||||
@@ -48,7 +48,7 @@ export async function POST({ request }) {
|
||||
</div>
|
||||
`,
|
||||
isPersonalEmail: true
|
||||
}).then((info) => console.log('Email sent:', info));
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
deleteNewsFeed,
|
||||
fetchNewsFeeds,
|
||||
handleEditFeed,
|
||||
toggleFeedIsPinned
|
||||
toggleFeedIsPinned,
|
||||
fetchNewsFeedReaction
|
||||
} from '$lib/utils/services/newsfeed';
|
||||
import Box from '$lib/components/Box/index.svelte';
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
@@ -37,7 +38,7 @@
|
||||
id: '',
|
||||
username: '',
|
||||
fullname: '',
|
||||
avatar: ''
|
||||
avatar_url: ''
|
||||
};
|
||||
let newsFeed: Feed[] = [];
|
||||
let query = new URLSearchParams($page.url.search);
|
||||
@@ -66,9 +67,11 @@
|
||||
};
|
||||
|
||||
const addNewReaction = async (reactionType: string, feedId: string, authorId: string) => {
|
||||
const reactedFeed = newsFeed.find((feed) => feed.id === feedId);
|
||||
const { data } = await fetchNewsFeedReaction(feedId);
|
||||
|
||||
if (!reactedFeed) return;
|
||||
if (!data) return;
|
||||
|
||||
const reactedFeed = data || newsFeed.find((feed) => feed.id === feedId);
|
||||
|
||||
let reactedAuthorIds: string[] = reactedFeed.reaction[reactionType];
|
||||
|
||||
@@ -131,12 +134,7 @@
|
||||
const newComment = {
|
||||
id: createdComment.id,
|
||||
author: {
|
||||
profile: {
|
||||
id: author.id,
|
||||
username: author.username,
|
||||
fullname: author.fullname,
|
||||
avatar_url: author.avatar
|
||||
}
|
||||
profile: { ...author }
|
||||
},
|
||||
created_at: createdComment.created_at,
|
||||
content: comment
|
||||
@@ -208,7 +206,7 @@
|
||||
id: currentGroupMember?.id || '',
|
||||
username: $profile.username || '',
|
||||
fullname: $profile.fullname || '',
|
||||
avatar: $profile.avatar_url || ''
|
||||
avatar_url: $profile.avatar_url || ''
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user