Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions server/email/hooks/onMessageSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ import { EMAIL_SUFFIX_CONTACT } from "../internal/prefixes.ts";

const EMAIL_THROTTLE_INTERVAL_MS = 10 * 60 * 1000; // 10 minutes

export async function onMessageSend(c: Context, fromName: string, toId: string, message: Message) {
export async function onMessageSend(
c: Context,
{
fromName,
inRoomId,
toId,
message,
}: {
fromName: string;
inRoomId: string;
toId: string;
message: Message;
},
) {
const receiver = await prisma.user.findUnique({
where: { id: toId },
select: {
Expand All @@ -34,8 +47,14 @@ export async function onMessageSend(c: Context, fromName: string, toId: string,
// - if it's first message or not
// - user's selected language
const body = `
New message arrived from ${fromName}:
<p>
New message arrived from ${fromName}:
</p>
<p>
${escapeHTML(message.content)}
</p>

<a href="https://ut-bridge.utcode.net/chat/${inRoomId}">See this on ut-bridge</a>

${EMAIL_SUFFIX_CONTACT}
`;
Expand Down Expand Up @@ -79,6 +98,9 @@ const suspiciousChars = [
['"', "&quot;"],
["<", "&lt;"],
[">", "&gt;"],

// postprocess: make newlines into <br> because html doesn't support \n
["\n", "<br>"],
] as const;

function escapeHTML(input: string) {
Expand Down
14 changes: 7 additions & 7 deletions server/email/internal/prefixes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const EMAIL_SUFFIX_CONTACT = `
---
UT-Bridge
Created by ut.code();
Website: <a href="https://utcode.net">https://utcode.net</a>
Contact: [email protected]
---
`;
<p>
--- <br>
UT-Bridge <a href="https://ut-bridge.utcode.net">https://ut-bridge.utcode.net</a> <br>
Created by <a href="https://utcode.net">ut.code();</a> <br>
Contact: [email protected] <br>
---
</p>`;
4 changes: 3 additions & 1 deletion server/email/verification/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export async function sendVerificationEmail(
const url = `${WEB_ORIGIN}/verify?id=${verificationId}&token=${token}`;

const body = `
Visit this page to verify your email: <a href="${url}">${url}</a>
<p>
Visit this page to verify your email: <a href="${url}">${url}</a>
</p>

${EMAIL_SUFFIX_CONTACT}
`;
Expand Down
7 changes: 6 additions & 1 deletion server/routes/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,12 @@ const router = new Hono()
// broadcast mails
for (const receiverId of await receivers) {
if (receiverId !== requester) {
await onMessageSend(c, sender.name, receiverId, message);
await onMessageSend(c, {
fromName: sender.name,
inRoomId: roomId,
toId: receiverId,
message,
});
}
}
})();
Expand Down