Sharkey/src/services/send-email-notification.ts

31 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-02-13 05:28:26 +02:00
import { UserProfiles } from '../models';
import { User } from '../models/entities/user';
import { sendEmail } from './send-email';
import * as locales from '../../locales/';
2021-03-23 10:43:07 +02:00
import { I18n } from '@/misc/i18n';
2021-07-15 14:45:32 +03:00
import { getAcct } from '@/misc/acct';
2021-02-13 05:28:26 +02:00
// TODO: locale ファイルをクライアント用とサーバー用で分けたい
2021-07-15 14:35:43 +03:00
async function follow(userId: User['id'], follower: User) {
2021-02-13 05:28:26 +02:00
const userProfile = await UserProfiles.findOneOrFail({ userId: userId });
if (!userProfile.email || !userProfile.emailNotificationTypes.includes('follow')) return;
const locale = locales[userProfile.lang || 'ja-JP'];
const i18n = new I18n(locale);
2021-07-15 14:35:43 +03:00
// TODO: render user information html
2021-07-15 14:45:32 +03:00
sendEmail(userProfile.email, i18n.t('_email._follow.title'), `${follower.name} (@${getAcct(follower)})`, `${follower.name} (@${getAcct(follower)})`);
2021-02-13 05:28:26 +02:00
}
async function receiveFollowRequest(userId: User['id'], args: {}) {
const userProfile = await UserProfiles.findOneOrFail({ userId: userId });
if (!userProfile.email || !userProfile.emailNotificationTypes.includes('receiveFollowRequest')) return;
const locale = locales[userProfile.lang || 'ja-JP'];
const i18n = new I18n(locale);
sendEmail(userProfile.email, i18n.t('_email._receiveFollowRequest.title'), 'test', 'test');
}
export const sendEmailNotification = {
follow,
receiveFollowRequest,
};