Add document unsubscribe link in email footer (#5762)
This commit is contained in:
@@ -3,7 +3,7 @@ import * as React from "react";
|
||||
import { NotificationEventType } from "@shared/types";
|
||||
import { Day } from "@shared/utils/time";
|
||||
import env from "@server/env";
|
||||
import { Collection, Comment, Document, User } from "@server/models";
|
||||
import { Collection, Comment, Document } from "@server/models";
|
||||
import DocumentHelper from "@server/models/helpers/DocumentHelper";
|
||||
import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper";
|
||||
import ProsemirrorHelper from "@server/models/helpers/ProsemirrorHelper";
|
||||
@@ -44,7 +44,8 @@ export default class CommentCreatedEmail extends BaseEmail<
|
||||
InputProps,
|
||||
BeforeSend
|
||||
> {
|
||||
protected async beforeSend({ documentId, userId, commentId }: InputProps) {
|
||||
protected async beforeSend(props: InputProps) {
|
||||
const { documentId, commentId } = props;
|
||||
const document = await Document.unscoped().findByPk(documentId);
|
||||
if (!document) {
|
||||
return false;
|
||||
@@ -99,13 +100,17 @@ export default class CommentCreatedEmail extends BaseEmail<
|
||||
isReply,
|
||||
isFirstComment,
|
||||
body,
|
||||
unsubscribeUrl: NotificationSettingsHelper.unsubscribeUrl(
|
||||
await User.findByPk(userId, { rejectOnEmpty: true }),
|
||||
NotificationEventType.CreateComment
|
||||
),
|
||||
unsubscribeUrl: this.unsubscribeUrl(props),
|
||||
};
|
||||
}
|
||||
|
||||
protected unsubscribeUrl({ userId }: InputProps) {
|
||||
return NotificationSettingsHelper.unsubscribeUrl(
|
||||
userId,
|
||||
NotificationEventType.CreateComment
|
||||
);
|
||||
}
|
||||
|
||||
protected subject({ isFirstComment, document }: Props) {
|
||||
return `${isFirstComment ? "" : "Re: "}New comment on “${document.title}”`;
|
||||
}
|
||||
@@ -137,21 +142,22 @@ Open Thread: ${teamUrl}${document.url}?commentId=${commentId}
|
||||
`;
|
||||
}
|
||||
|
||||
protected render({
|
||||
document,
|
||||
actorName,
|
||||
isReply,
|
||||
collection,
|
||||
teamUrl,
|
||||
commentId,
|
||||
unsubscribeUrl,
|
||||
body,
|
||||
}: Props) {
|
||||
protected render(props: Props) {
|
||||
const {
|
||||
document,
|
||||
actorName,
|
||||
isReply,
|
||||
collection,
|
||||
teamUrl,
|
||||
commentId,
|
||||
unsubscribeUrl,
|
||||
body,
|
||||
} = props;
|
||||
const threadLink = `${teamUrl}${document.url}?commentId=${commentId}&ref=notification-email`;
|
||||
|
||||
return (
|
||||
<EmailTemplate
|
||||
previewText={this.preview({ isReply, actorName } as Props)}
|
||||
previewText={this.preview(props)}
|
||||
goToAction={{ url: threadLink, name: "View Thread" }}
|
||||
>
|
||||
<Header />
|
||||
|
||||
Reference in New Issue
Block a user