2021-08-19 09:33:41 +00:00
|
|
|
import { UserProfiles } from '@/models/index.js';
|
|
|
|
import { User } from '@/models/entities/user.js';
|
|
|
|
import { sendEmail } from './send-email.js';
|
|
|
|
import * as locales from '../../locales/index.js';
|
|
|
|
import { I18n } from '@/misc/i18n.js';
|
|
|
|
import { getAcct } from '@/misc/acct.js';
|
2021-02-13 03:28:26 +00:00
|
|
|
|
|
|
|
// TODO: locale ファイルをクライアント用とサーバー用で分けたい
|
|
|
|
|
2021-07-15 11:35:43 +00:00
|
|
|
async function follow(userId: User['id'], follower: User) {
|
2021-02-13 03:28:26 +00: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 11:35:43 +00:00
|
|
|
// TODO: render user information html
|
2021-07-15 11:45:32 +00:00
|
|
|
sendEmail(userProfile.email, i18n.t('_email._follow.title'), `${follower.name} (@${getAcct(follower)})`, `${follower.name} (@${getAcct(follower)})`);
|
2021-02-13 03:28:26 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 12:08:05 +00:00
|
|
|
async function receiveFollowRequest(userId: User['id'], follower: User) {
|
2021-02-13 03:28:26 +00:00
|
|
|
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);
|
2021-08-11 12:08:05 +00:00
|
|
|
// TODO: render user information html
|
|
|
|
sendEmail(userProfile.email, i18n.t('_email._receiveFollowRequest.title'), `${follower.name} (@${getAcct(follower)})`, `${follower.name} (@${getAcct(follower)})`);
|
2021-02-13 03:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const sendEmailNotification = {
|
|
|
|
follow,
|
|
|
|
receiveFollowRequest,
|
|
|
|
};
|