From 91d8d27f2d06b513643ffe366f6f45618109019f Mon Sep 17 00:00:00 2001
From: Tom Moor
Date: Sat, 24 Sep 2022 23:29:11 +0200
Subject: [PATCH] feat: Render diffs in email notifications (#4164)
* deps
* diffCompact
* Diffs in email
* test
* fix: Fade deleted images
fix: Don't include empty paragraphs as context
fix: Allow for same image multiple times and refactor
* Remove target _blank
* fix: Table heading incorrect color
---
app/typings/styled-components.d.ts | 1 -
server/commands/revisionCreator.ts | 14 +-
.../templates/DocumentNotificationEmail.tsx | 27 +++-
server/emails/templates/InviteEmail.tsx | 2 +-
.../emails/templates/InviteReminderEmail.tsx | 4 +-
server/emails/templates/WelcomeEmail.tsx | 4 +-
server/emails/templates/components/Diff.tsx | 25 +++
server/models/helpers/DocumentHelper.test.ts | 83 ++++++++++
server/models/helpers/DocumentHelper.tsx | 147 ++++++++++++++++--
server/presenters/document.ts | 30 +---
server/queues/processors/DebounceProcessor.ts | 2 +-
.../processors/NotificationsProcessor.test.ts | 38 +++--
.../processors/NotificationsProcessor.ts | 96 ++++++++++--
shared/editor/components/Styles.ts | 6 +-
shared/styles/theme.ts | 2 -
15 files changed, 396 insertions(+), 85 deletions(-)
create mode 100644 server/emails/templates/components/Diff.tsx
create mode 100644 server/models/helpers/DocumentHelper.test.ts
diff --git a/app/typings/styled-components.d.ts b/app/typings/styled-components.d.ts
index c8e571d58..a51e8e5d0 100644
--- a/app/typings/styled-components.d.ts
+++ b/app/typings/styled-components.d.ts
@@ -16,7 +16,6 @@ declare module "styled-components" {
tableDivider: string;
tableSelected: string;
tableSelectedBackground: string;
- tableHeaderBackground: string;
quote: string;
codeBackground: string;
codeBorder: string;
diff --git a/server/commands/revisionCreator.ts b/server/commands/revisionCreator.ts
index 9ce4db287..962b8fe7f 100644
--- a/server/commands/revisionCreator.ts
+++ b/server/commands/revisionCreator.ts
@@ -10,10 +10,7 @@ export default async function revisionCreator({
user: User;
ip?: string;
}) {
- let transaction;
-
- try {
- transaction = await sequelize.transaction();
+ return sequelize.transaction(async (transaction) => {
const revision = await Revision.createFromDocument(document, {
transaction,
});
@@ -32,13 +29,6 @@ export default async function revisionCreator({
transaction,
}
);
- await transaction.commit();
return revision;
- } catch (err) {
- if (transaction) {
- await transaction.rollback();
- }
-
- throw err;
- }
+ });
}
diff --git a/server/emails/templates/DocumentNotificationEmail.tsx b/server/emails/templates/DocumentNotificationEmail.tsx
index f7c7a54f4..d99a1693b 100644
--- a/server/emails/templates/DocumentNotificationEmail.tsx
+++ b/server/emails/templates/DocumentNotificationEmail.tsx
@@ -3,6 +3,7 @@ import { Document } from "@server/models";
import BaseEmail from "./BaseEmail";
import Body from "./components/Body";
import Button from "./components/Button";
+import Diff from "./components/Diff";
import EmailTemplate from "./components/EmailLayout";
import EmptySpace from "./components/EmptySpace";
import Footer from "./components/Footer";
@@ -17,6 +18,7 @@ type InputProps = {
eventName: string;
teamUrl: string;
unsubscribeUrl: string;
+ content: string;
};
type BeforeSend = {
@@ -73,25 +75,34 @@ Open Document: ${teamUrl}${document.url}
eventName = "published",
teamUrl,
unsubscribeUrl,
+ content,
}: Props) {
+ const link = `${teamUrl}${document.url}?ref=notification-email`;
+
return (
- "{document.title}" {eventName}
+ “{document.title}” {eventName}
- {actorName} {eventName} the document "{document.title}", in the{" "}
- {collectionName} collection.
+ {actorName} {eventName} the document{" "}
+ {document.title}, in the {collectionName}{" "}
+ collection.
-
-
- {document.getSummary()}
-
+ {content && (
+ <>
+
+
+
+
+
+ >
+ )}
-
+
diff --git a/server/emails/templates/InviteEmail.tsx b/server/emails/templates/InviteEmail.tsx
index c7259fa56..a80f0fffe 100644
--- a/server/emails/templates/InviteEmail.tsx
+++ b/server/emails/templates/InviteEmail.tsx
@@ -57,7 +57,7 @@ Join now: ${teamUrl}
-
+