summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2021-02-13 12:28:26 +0900
committersyuilo <syuilotan@yahoo.co.jp>2021-02-13 12:28:26 +0900
commitebadd7fd3f255af3dd5035afe1d0d75337fa39a4 (patch)
tree5a441d13c74092560b913b5eef4ff4252f128fd5 /src/services
parentMerge pull request #7187 from syuilo/dependabot/npm_and_yarn/typescript-4.1.5 (diff)
downloadsharkey-ebadd7fd3f255af3dd5035afe1d0d75337fa39a4.tar.gz
sharkey-ebadd7fd3f255af3dd5035afe1d0d75337fa39a4.tar.bz2
sharkey-ebadd7fd3f255af3dd5035afe1d0d75337fa39a4.zip
wip: email notification
Diffstat (limited to 'src/services')
-rw-r--r--src/services/create-notification.ts27
-rw-r--r--src/services/send-email-notification.ts28
-rw-r--r--src/services/send-email.ts8
3 files changed, 49 insertions, 14 deletions
diff --git a/src/services/create-notification.ts b/src/services/create-notification.ts
index 5dddaa5727..6cd116040a 100644
--- a/src/services/create-notification.ts
+++ b/src/services/create-notification.ts
@@ -4,6 +4,7 @@ import { Notifications, Mutings, UserProfiles } from '../models';
import { genId } from '../misc/gen-id';
import { User } from '../models/entities/user';
import { Notification } from '../models/entities/notification';
+import { sendEmailNotification } from './send-email-notification';
export async function createNotification(
notifieeId: User['id'],
@@ -38,20 +39,22 @@ export async function createNotification(
setTimeout(async () => {
const fresh = await Notifications.findOne(notification.id);
if (fresh == null) return; // 既に削除されているかもしれない
- if (!fresh.isRead) {
- //#region ただしミュートしているユーザーからの通知なら無視
- const mutings = await Mutings.find({
- muterId: notifieeId
- });
- if (data.notifierId && mutings.map(m => m.muteeId).includes(data.notifierId)) {
- return;
- }
- //#endregion
+ if (fresh.isRead) return;
- publishMainStream(notifieeId, 'unreadNotification', packed);
-
- pushSw(notifieeId, 'notification', packed);
+ //#region ただしミュートしているユーザーからの通知なら無視
+ const mutings = await Mutings.find({
+ muterId: notifieeId
+ });
+ if (data.notifierId && mutings.map(m => m.muteeId).includes(data.notifierId)) {
+ return;
}
+ //#endregion
+
+ publishMainStream(notifieeId, 'unreadNotification', packed);
+
+ pushSw(notifieeId, 'notification', packed);
+ if (type === 'follow') sendEmailNotification.follow(notifieeId, data);
+ if (type === 'receiveFollowRequest') sendEmailNotification.receiveFollowRequest(notifieeId, data);
}, 2000);
return notification;
diff --git a/src/services/send-email-notification.ts b/src/services/send-email-notification.ts
new file mode 100644
index 0000000000..7579d5b674
--- /dev/null
+++ b/src/services/send-email-notification.ts
@@ -0,0 +1,28 @@
+import { UserProfiles } from '../models';
+import { User } from '../models/entities/user';
+import { sendEmail } from './send-email';
+import * as locales from '../../locales/';
+import { I18n } from '../misc/i18n';
+
+// TODO: locale ファイルをクライアント用とサーバー用で分けたい
+
+async function follow(userId: User['id'], args: {}) {
+ 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);
+ sendEmail(userProfile.email, i18n.t('_email._follow.title'), 'test', 'test');
+}
+
+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,
+};
diff --git a/src/services/send-email.ts b/src/services/send-email.ts
index 151228c7e3..c716b36715 100644
--- a/src/services/send-email.ts
+++ b/src/services/send-email.ts
@@ -5,7 +5,7 @@ import config from '../config';
export const logger = new Logger('email');
-export async function sendEmail(to: string, subject: string, text: string) {
+export async function sendEmail(to: string, subject: string, html: string, text: string) {
const meta = await fetchMeta(true);
const iconUrl = `${config.url}/assets/mi-white.png`;
@@ -44,6 +44,9 @@ export async function sendEmail(to: string, subject: string, text: string) {
body {
padding: 16px;
+ margin: 0;
+ font-family: sans-serif;
+ font-size: 14px;
}
a {
@@ -67,6 +70,7 @@ export async function sendEmail(to: string, subject: string, text: string) {
main > header > img {
max-width: 128px;
max-height: 28px;
+ vertical-align: bottom;
}
main > article {
padding: 32px;
@@ -97,7 +101,7 @@ export async function sendEmail(to: string, subject: string, text: string) {
</header>
<article>
<h1>${ subject }</h1>
- <div>${ text }</div>
+ <div>${ html }</div>
</article>
<footer>
<a href="${ emailSettingUrl }">${ 'Email setting' }</a>