@liveblocks/emails 2.21.0 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +200 -259
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +116 -119
- package/dist/index.d.ts +116 -119
- package/dist/index.js +201 -260
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { detectDupes } from "@liveblocks/core";
|
|
|
3
3
|
|
|
4
4
|
// src/version.ts
|
|
5
5
|
var PKG_NAME = "@liveblocks/emails";
|
|
6
|
-
var PKG_VERSION = "2.
|
|
6
|
+
var PKG_VERSION = "2.22.0";
|
|
7
7
|
var PKG_FORMAT = "esm";
|
|
8
8
|
|
|
9
9
|
// ../../node_modules/lib0/map.js
|
|
@@ -7368,6 +7368,9 @@ var isString = (value) => {
|
|
|
7368
7368
|
var isMentionNodeAttributeId = (value) => {
|
|
7369
7369
|
return isString(value) && value.startsWith("in_");
|
|
7370
7370
|
};
|
|
7371
|
+
var exists = (input) => {
|
|
7372
|
+
return input !== null && input !== void 0;
|
|
7373
|
+
};
|
|
7371
7374
|
|
|
7372
7375
|
// src/lexical-editor.ts
|
|
7373
7376
|
function createSerializedLexicalMapNode(item) {
|
|
@@ -8370,51 +8373,20 @@ async function prepareTextMentionNotificationEmailAsHtml(client, event, options
|
|
|
8370
8373
|
// src/thread-notification.tsx
|
|
8371
8374
|
import {
|
|
8372
8375
|
generateCommentUrl,
|
|
8373
|
-
getMentionedIdsFromCommentBody
|
|
8376
|
+
getMentionedIdsFromCommentBody,
|
|
8377
|
+
html as html2,
|
|
8378
|
+
htmlSafe as htmlSafe2
|
|
8374
8379
|
} from "@liveblocks/core";
|
|
8375
8380
|
|
|
8376
8381
|
// src/comment-body.tsx
|
|
8377
8382
|
import {
|
|
8378
|
-
html as html2,
|
|
8379
|
-
htmlSafe as htmlSafe2,
|
|
8380
8383
|
isCommentBodyLink,
|
|
8381
8384
|
isCommentBodyMention,
|
|
8382
8385
|
isCommentBodyText,
|
|
8383
8386
|
resolveUsersInCommentBody,
|
|
8384
|
-
stringifyCommentBody,
|
|
8385
8387
|
toAbsoluteUrl
|
|
8386
8388
|
} from "@liveblocks/core";
|
|
8387
|
-
|
|
8388
|
-
var baseComponents2 = {
|
|
8389
|
-
Container: ({ children }) => /* @__PURE__ */ jsx2("div", { children }),
|
|
8390
|
-
Paragraph: ({ children }) => /* @__PURE__ */ jsx2("p", { children }),
|
|
8391
|
-
Text: ({ element }) => {
|
|
8392
|
-
let children = element.text;
|
|
8393
|
-
if (element.bold) {
|
|
8394
|
-
children = /* @__PURE__ */ jsx2("strong", { children });
|
|
8395
|
-
}
|
|
8396
|
-
if (element.italic) {
|
|
8397
|
-
children = /* @__PURE__ */ jsx2("em", { children });
|
|
8398
|
-
}
|
|
8399
|
-
if (element.strikethrough) {
|
|
8400
|
-
children = /* @__PURE__ */ jsx2("s", { children });
|
|
8401
|
-
}
|
|
8402
|
-
if (element.code) {
|
|
8403
|
-
children = /* @__PURE__ */ jsx2("code", { children });
|
|
8404
|
-
}
|
|
8405
|
-
return /* @__PURE__ */ jsx2("span", { children });
|
|
8406
|
-
},
|
|
8407
|
-
Link: ({ element, href }) => /* @__PURE__ */ jsx2("a", { href, target: "_blank", rel: "noopener noreferrer", children: element.text ?? element.url }),
|
|
8408
|
-
Mention: ({ element, user }) => /* @__PURE__ */ jsxs2("span", { "data-mention": true, children: [
|
|
8409
|
-
MENTION_CHARACTER,
|
|
8410
|
-
user?.name ?? element.id
|
|
8411
|
-
] })
|
|
8412
|
-
};
|
|
8413
|
-
async function convertCommentBodyAsReact(body, options) {
|
|
8414
|
-
const Components = {
|
|
8415
|
-
...baseComponents2,
|
|
8416
|
-
...options?.components
|
|
8417
|
-
};
|
|
8389
|
+
async function convertCommentBody(body, options) {
|
|
8418
8390
|
const resolvedUsers = await resolveUsersInCommentBody(
|
|
8419
8391
|
body,
|
|
8420
8392
|
options?.resolveUsers
|
|
@@ -8424,38 +8396,30 @@ async function convertCommentBodyAsReact(body, options) {
|
|
|
8424
8396
|
case "paragraph": {
|
|
8425
8397
|
const children = block.children.map((inline, inlineIndex) => {
|
|
8426
8398
|
if (isCommentBodyMention(inline)) {
|
|
8427
|
-
return
|
|
8428
|
-
Components.Mention,
|
|
8399
|
+
return options.elements.mention(
|
|
8429
8400
|
{
|
|
8430
8401
|
element: inline,
|
|
8431
8402
|
user: resolvedUsers.get(inline.id)
|
|
8432
8403
|
},
|
|
8433
|
-
|
|
8434
|
-
)
|
|
8404
|
+
inlineIndex
|
|
8405
|
+
);
|
|
8435
8406
|
}
|
|
8436
8407
|
if (isCommentBodyLink(inline)) {
|
|
8437
8408
|
const href = toAbsoluteUrl(inline.url) ?? inline.url;
|
|
8438
|
-
return
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
element: inline,
|
|
8442
|
-
href
|
|
8443
|
-
},
|
|
8444
|
-
`lb-comment-body-link-${inlineIndex}`
|
|
8409
|
+
return options.elements.link(
|
|
8410
|
+
{ element: inline, href },
|
|
8411
|
+
inlineIndex
|
|
8445
8412
|
);
|
|
8446
8413
|
}
|
|
8447
8414
|
if (isCommentBodyText(inline)) {
|
|
8448
|
-
return
|
|
8449
|
-
Components.Text,
|
|
8450
|
-
{
|
|
8451
|
-
element: inline
|
|
8452
|
-
},
|
|
8453
|
-
`lb-comment-body-text-${inlineIndex}`
|
|
8454
|
-
);
|
|
8415
|
+
return options.elements.text({ element: inline }, inlineIndex);
|
|
8455
8416
|
}
|
|
8456
8417
|
return null;
|
|
8457
|
-
});
|
|
8458
|
-
return
|
|
8418
|
+
}).filter(exists);
|
|
8419
|
+
return options.elements.paragraph(
|
|
8420
|
+
{ element: block, children },
|
|
8421
|
+
index
|
|
8422
|
+
);
|
|
8459
8423
|
}
|
|
8460
8424
|
default:
|
|
8461
8425
|
console.warn(
|
|
@@ -8463,68 +8427,8 @@ async function convertCommentBodyAsReact(body, options) {
|
|
|
8463
8427
|
);
|
|
8464
8428
|
return null;
|
|
8465
8429
|
}
|
|
8466
|
-
});
|
|
8467
|
-
return
|
|
8468
|
-
}
|
|
8469
|
-
var baseStyles2 = {
|
|
8470
|
-
paragraph: {
|
|
8471
|
-
fontSize: "14px"
|
|
8472
|
-
},
|
|
8473
|
-
strong: {
|
|
8474
|
-
fontWeight: 500
|
|
8475
|
-
},
|
|
8476
|
-
code: {
|
|
8477
|
-
fontFamily: 'ui-monospace, Menlo, Monaco, "Cascadia Mono", "Segoe UI Mono", "Roboto Mono", "Oxygen Mono", "Ubuntu Mono", "Source Code Pro", "Fira Mono", "Droid Sans Mono", "Consolas", "Courier New", monospace',
|
|
8478
|
-
backgroundColor: "rgba(0,0,0,0.05)",
|
|
8479
|
-
border: "solid 1px rgba(0,0,0,0.1)",
|
|
8480
|
-
borderRadius: "4px"
|
|
8481
|
-
},
|
|
8482
|
-
mention: {
|
|
8483
|
-
color: "blue"
|
|
8484
|
-
},
|
|
8485
|
-
link: {
|
|
8486
|
-
textDecoration: "underline"
|
|
8487
|
-
}
|
|
8488
|
-
};
|
|
8489
|
-
async function convertCommentBodyAsHtml(body, options) {
|
|
8490
|
-
const styles = { ...baseStyles2, ...options?.styles };
|
|
8491
|
-
const htmlBody = await stringifyCommentBody(body, {
|
|
8492
|
-
format: "html",
|
|
8493
|
-
resolveUsers: options?.resolveUsers,
|
|
8494
|
-
elements: {
|
|
8495
|
-
// NOTE: using prettier-ignore to preserve template strings
|
|
8496
|
-
paragraph: ({ children }) => (
|
|
8497
|
-
// prettier-ignore
|
|
8498
|
-
children ? html2`<p style="${toInlineCSSString(styles.paragraph)}">${htmlSafe2(children)}</p>` : children
|
|
8499
|
-
),
|
|
8500
|
-
text: ({ element }) => {
|
|
8501
|
-
let children = element.text;
|
|
8502
|
-
if (!children) {
|
|
8503
|
-
return html2`${children}`;
|
|
8504
|
-
}
|
|
8505
|
-
if (element.bold) {
|
|
8506
|
-
children = html2`<strong style="${toInlineCSSString(styles.strong)}">${children}</strong>`;
|
|
8507
|
-
}
|
|
8508
|
-
if (element.italic) {
|
|
8509
|
-
children = html2`<em>${children}</em>`;
|
|
8510
|
-
}
|
|
8511
|
-
if (element.strikethrough) {
|
|
8512
|
-
children = html2`<s>${children}</s>`;
|
|
8513
|
-
}
|
|
8514
|
-
if (element.code) {
|
|
8515
|
-
children = html2`<code style="${toInlineCSSString(styles.code)}">${children}</code>`;
|
|
8516
|
-
}
|
|
8517
|
-
return html2`${children}`;
|
|
8518
|
-
},
|
|
8519
|
-
link: ({ element, href }) => {
|
|
8520
|
-
return html2`<a href="${href}" target="_blank" rel="noopener noreferrer" style="${toInlineCSSString(styles.link)}">${element.text ? html2`${element.text}` : element.url}</a>`;
|
|
8521
|
-
},
|
|
8522
|
-
mention: ({ element, user }) => {
|
|
8523
|
-
return html2`<span data-mention style="${toInlineCSSString(styles.mention)}">${MENTION_CHARACTER}${user?.name ? html2`${user?.name}` : element.id}</span>`;
|
|
8524
|
-
}
|
|
8525
|
-
}
|
|
8526
|
-
});
|
|
8527
|
-
return htmlBody;
|
|
8430
|
+
}).filter(exists);
|
|
8431
|
+
return options.elements.container({ children: blocks });
|
|
8528
8432
|
}
|
|
8529
8433
|
|
|
8530
8434
|
// src/comment-with-body.ts
|
|
@@ -8542,6 +8446,7 @@ function filterCommentsWithBody(comments) {
|
|
|
8542
8446
|
}
|
|
8543
8447
|
|
|
8544
8448
|
// src/thread-notification.tsx
|
|
8449
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
8545
8450
|
var getUnreadComments = ({
|
|
8546
8451
|
comments,
|
|
8547
8452
|
inboxNotification,
|
|
@@ -8595,72 +8500,19 @@ var extractThreadNotificationData = async ({
|
|
|
8595
8500
|
comments: unreadComments
|
|
8596
8501
|
};
|
|
8597
8502
|
};
|
|
8598
|
-
|
|
8599
|
-
roomInfo,
|
|
8600
|
-
comment
|
|
8601
|
-
}) => {
|
|
8602
|
-
const url = roomInfo?.url ? generateCommentUrl({
|
|
8603
|
-
roomUrl: roomInfo?.url,
|
|
8604
|
-
commentId: comment.id
|
|
8605
|
-
}) : void 0;
|
|
8606
|
-
return {
|
|
8607
|
-
id: comment.id,
|
|
8608
|
-
userId: comment.userId,
|
|
8609
|
-
threadId: comment.threadId,
|
|
8610
|
-
roomId: comment.roomId,
|
|
8611
|
-
createdAt: comment.createdAt,
|
|
8612
|
-
url,
|
|
8613
|
-
rawBody: comment.body
|
|
8614
|
-
};
|
|
8615
|
-
};
|
|
8616
|
-
var prepareThreadNotificationEmailBaseData = async ({
|
|
8617
|
-
client,
|
|
8618
|
-
event,
|
|
8619
|
-
options = {}
|
|
8620
|
-
}) => {
|
|
8621
|
-
const { roomId } = event.data;
|
|
8622
|
-
const roomInfo = options.resolveRoomInfo ? await options.resolveRoomInfo({ roomId }) : void 0;
|
|
8623
|
-
const resolvedRoomInfo = {
|
|
8624
|
-
...roomInfo,
|
|
8625
|
-
name: roomInfo?.name ?? roomId
|
|
8626
|
-
};
|
|
8503
|
+
async function prepareThreadNotificationEmail(client, event, options, elements, callerName) {
|
|
8627
8504
|
const data = await extractThreadNotificationData({ client, event });
|
|
8628
8505
|
if (data === null) {
|
|
8629
8506
|
return null;
|
|
8630
8507
|
}
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
roomInfo,
|
|
8637
|
-
comment: data.comment
|
|
8638
|
-
}),
|
|
8639
|
-
roomInfo: resolvedRoomInfo
|
|
8640
|
-
};
|
|
8641
|
-
case "unreadReplies": {
|
|
8642
|
-
return {
|
|
8643
|
-
type: "unreadReplies",
|
|
8644
|
-
comments: data.comments.map(
|
|
8645
|
-
(comment) => makeCommentEmailBaseData({ roomInfo, comment })
|
|
8646
|
-
),
|
|
8647
|
-
roomInfo: resolvedRoomInfo
|
|
8648
|
-
};
|
|
8649
|
-
}
|
|
8650
|
-
}
|
|
8651
|
-
};
|
|
8652
|
-
async function prepareThreadNotificationEmailAsHtml(client, event, options = {}) {
|
|
8653
|
-
const data = await prepareThreadNotificationEmailBaseData({
|
|
8654
|
-
client,
|
|
8655
|
-
event,
|
|
8656
|
-
options: { resolveRoomInfo: options.resolveRoomInfo }
|
|
8657
|
-
});
|
|
8658
|
-
if (data === null) {
|
|
8659
|
-
return null;
|
|
8660
|
-
}
|
|
8508
|
+
const roomInfo = options.resolveRoomInfo ? await options.resolveRoomInfo({ roomId: event.data.roomId }) : void 0;
|
|
8509
|
+
const resolvedRoomInfo = {
|
|
8510
|
+
...roomInfo,
|
|
8511
|
+
name: roomInfo?.name ?? event.data.roomId
|
|
8512
|
+
};
|
|
8661
8513
|
const batchUsersResolver = createBatchUsersResolver({
|
|
8662
8514
|
resolveUsers: options.resolveUsers,
|
|
8663
|
-
callerName
|
|
8515
|
+
callerName
|
|
8664
8516
|
});
|
|
8665
8517
|
switch (data.type) {
|
|
8666
8518
|
case "unreadMention": {
|
|
@@ -8669,16 +8521,20 @@ async function prepareThreadNotificationEmailAsHtml(client, event, options = {})
|
|
|
8669
8521
|
userIds: [comment.userId],
|
|
8670
8522
|
resolveUsers: batchUsersResolver.resolveUsers
|
|
8671
8523
|
});
|
|
8672
|
-
const commentBodyPromise =
|
|
8524
|
+
const commentBodyPromise = convertCommentBody(comment.body, {
|
|
8673
8525
|
resolveUsers: batchUsersResolver.resolveUsers,
|
|
8674
|
-
|
|
8526
|
+
elements
|
|
8675
8527
|
});
|
|
8676
8528
|
await batchUsersResolver.resolve();
|
|
8677
|
-
const [authorsInfo,
|
|
8529
|
+
const [authorsInfo, commentBody] = await Promise.all([
|
|
8678
8530
|
authorsInfoPromise,
|
|
8679
8531
|
commentBodyPromise
|
|
8680
8532
|
]);
|
|
8681
8533
|
const authorInfo = authorsInfo.get(comment.userId);
|
|
8534
|
+
const url = roomInfo?.url ? generateCommentUrl({
|
|
8535
|
+
roomUrl: roomInfo?.url,
|
|
8536
|
+
commentId: comment.id
|
|
8537
|
+
}) : void 0;
|
|
8682
8538
|
return {
|
|
8683
8539
|
type: "unreadMention",
|
|
8684
8540
|
comment: {
|
|
@@ -8690,10 +8546,10 @@ async function prepareThreadNotificationEmailAsHtml(client, event, options = {})
|
|
|
8690
8546
|
info: authorInfo ?? { name: comment.userId }
|
|
8691
8547
|
},
|
|
8692
8548
|
createdAt: comment.createdAt,
|
|
8693
|
-
url
|
|
8694
|
-
|
|
8549
|
+
url,
|
|
8550
|
+
body: commentBody
|
|
8695
8551
|
},
|
|
8696
|
-
roomInfo:
|
|
8552
|
+
roomInfo: resolvedRoomInfo
|
|
8697
8553
|
};
|
|
8698
8554
|
}
|
|
8699
8555
|
case "unreadReplies": {
|
|
@@ -8703,9 +8559,9 @@ async function prepareThreadNotificationEmailAsHtml(client, event, options = {})
|
|
|
8703
8559
|
resolveUsers: batchUsersResolver.resolveUsers
|
|
8704
8560
|
});
|
|
8705
8561
|
const commentBodiesPromises = comments.map(
|
|
8706
|
-
(c) =>
|
|
8562
|
+
(c) => convertCommentBody(c.body, {
|
|
8707
8563
|
resolveUsers: batchUsersResolver.resolveUsers,
|
|
8708
|
-
|
|
8564
|
+
elements
|
|
8709
8565
|
})
|
|
8710
8566
|
);
|
|
8711
8567
|
await batchUsersResolver.resolve();
|
|
@@ -8717,7 +8573,11 @@ async function prepareThreadNotificationEmailAsHtml(client, event, options = {})
|
|
|
8717
8573
|
type: "unreadReplies",
|
|
8718
8574
|
comments: comments.map((comment, index) => {
|
|
8719
8575
|
const authorInfo = authorsInfo.get(comment.userId);
|
|
8720
|
-
const
|
|
8576
|
+
const commentBody = commentBodies[index];
|
|
8577
|
+
const url = roomInfo?.url ? generateCommentUrl({
|
|
8578
|
+
roomUrl: roomInfo?.url,
|
|
8579
|
+
commentId: comment.id
|
|
8580
|
+
}) : void 0;
|
|
8721
8581
|
return {
|
|
8722
8582
|
id: comment.id,
|
|
8723
8583
|
threadId: comment.threadId,
|
|
@@ -8727,98 +8587,179 @@ async function prepareThreadNotificationEmailAsHtml(client, event, options = {})
|
|
|
8727
8587
|
info: authorInfo ?? { name: comment.userId }
|
|
8728
8588
|
},
|
|
8729
8589
|
createdAt: comment.createdAt,
|
|
8730
|
-
url
|
|
8731
|
-
|
|
8590
|
+
url,
|
|
8591
|
+
body: commentBody
|
|
8732
8592
|
};
|
|
8733
8593
|
}),
|
|
8734
|
-
roomInfo:
|
|
8594
|
+
roomInfo: resolvedRoomInfo
|
|
8735
8595
|
};
|
|
8736
8596
|
}
|
|
8737
8597
|
}
|
|
8738
8598
|
}
|
|
8739
|
-
|
|
8740
|
-
|
|
8599
|
+
var baseStyles2 = {
|
|
8600
|
+
paragraph: {
|
|
8601
|
+
fontSize: "14px"
|
|
8602
|
+
},
|
|
8603
|
+
strong: {
|
|
8604
|
+
fontWeight: 500
|
|
8605
|
+
},
|
|
8606
|
+
code: {
|
|
8607
|
+
fontFamily: 'ui-monospace, Menlo, Monaco, "Cascadia Mono", "Segoe UI Mono", "Roboto Mono", "Oxygen Mono", "Ubuntu Mono", "Source Code Pro", "Fira Mono", "Droid Sans Mono", "Consolas", "Courier New", monospace',
|
|
8608
|
+
backgroundColor: "rgba(0,0,0,0.05)",
|
|
8609
|
+
border: "solid 1px rgba(0,0,0,0.1)",
|
|
8610
|
+
borderRadius: "4px"
|
|
8611
|
+
},
|
|
8612
|
+
mention: {
|
|
8613
|
+
color: "blue"
|
|
8614
|
+
},
|
|
8615
|
+
link: {
|
|
8616
|
+
textDecoration: "underline"
|
|
8617
|
+
}
|
|
8618
|
+
};
|
|
8619
|
+
async function prepareThreadNotificationEmailAsHtml(client, event, options = {}) {
|
|
8620
|
+
const styles = { ...baseStyles2, ...options?.styles };
|
|
8621
|
+
const data = await prepareThreadNotificationEmail(
|
|
8741
8622
|
client,
|
|
8742
8623
|
event,
|
|
8743
|
-
|
|
8744
|
-
|
|
8624
|
+
{
|
|
8625
|
+
resolveUsers: options.resolveUsers,
|
|
8626
|
+
resolveRoomInfo: options.resolveRoomInfo
|
|
8627
|
+
},
|
|
8628
|
+
{
|
|
8629
|
+
container: ({ children }) => children.join("\n"),
|
|
8630
|
+
paragraph: ({ children }) => {
|
|
8631
|
+
const unsafe = children.join("");
|
|
8632
|
+
return unsafe ? html2`<p style="${toInlineCSSString(styles.paragraph)}">${htmlSafe2(unsafe)}</p>` : unsafe;
|
|
8633
|
+
},
|
|
8634
|
+
text: ({ element }) => {
|
|
8635
|
+
let children = element.text;
|
|
8636
|
+
if (!children) {
|
|
8637
|
+
return html2`${children}`;
|
|
8638
|
+
}
|
|
8639
|
+
if (element.bold) {
|
|
8640
|
+
children = html2`<strong style="${toInlineCSSString(styles.strong)}">${children}</strong>`;
|
|
8641
|
+
}
|
|
8642
|
+
if (element.italic) {
|
|
8643
|
+
children = html2`<em>${children}</em>`;
|
|
8644
|
+
}
|
|
8645
|
+
if (element.strikethrough) {
|
|
8646
|
+
children = html2`<s>${children}</s>`;
|
|
8647
|
+
}
|
|
8648
|
+
if (element.code) {
|
|
8649
|
+
children = html2`<code style="${toInlineCSSString(styles.code)}">${children}</code>`;
|
|
8650
|
+
}
|
|
8651
|
+
return html2`${children}`;
|
|
8652
|
+
},
|
|
8653
|
+
link: ({ element, href }) => {
|
|
8654
|
+
return html2`<a href="${href}" target="_blank" rel="noopener noreferrer" style="${toInlineCSSString(styles.link)}">${element.text ? html2`${element.text}` : element.url}</a>`;
|
|
8655
|
+
},
|
|
8656
|
+
mention: ({ element, user }) => {
|
|
8657
|
+
return html2`<span data-mention style="${toInlineCSSString(styles.mention)}">${MENTION_CHARACTER}${user?.name ? html2`${user?.name}` : element.id}</span>`;
|
|
8658
|
+
}
|
|
8659
|
+
},
|
|
8660
|
+
"prepareThreadNotificationEmailAsHtml"
|
|
8661
|
+
);
|
|
8745
8662
|
if (data === null) {
|
|
8746
8663
|
return null;
|
|
8747
8664
|
}
|
|
8748
|
-
const batchUsersResolver = createBatchUsersResolver({
|
|
8749
|
-
resolveUsers: options.resolveUsers,
|
|
8750
|
-
callerName: "prepareThreadNotificationEmailAsReact"
|
|
8751
|
-
});
|
|
8752
8665
|
switch (data.type) {
|
|
8753
8666
|
case "unreadMention": {
|
|
8754
|
-
const { comment } = data;
|
|
8755
|
-
const authorsInfoPromise = resolveAuthorsInfo({
|
|
8756
|
-
userIds: [comment.userId],
|
|
8757
|
-
resolveUsers: batchUsersResolver.resolveUsers
|
|
8758
|
-
});
|
|
8759
|
-
const commentBodyPromise = convertCommentBodyAsReact(comment.rawBody, {
|
|
8760
|
-
resolveUsers: batchUsersResolver.resolveUsers,
|
|
8761
|
-
components: options.components
|
|
8762
|
-
});
|
|
8763
|
-
await batchUsersResolver.resolve();
|
|
8764
|
-
const [authorsInfo, commentBodyReact] = await Promise.all([
|
|
8765
|
-
authorsInfoPromise,
|
|
8766
|
-
commentBodyPromise
|
|
8767
|
-
]);
|
|
8768
|
-
const authorInfo = authorsInfo.get(comment.userId);
|
|
8769
8667
|
return {
|
|
8770
|
-
|
|
8771
|
-
comment: {
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8668
|
+
...data,
|
|
8669
|
+
comment: { ...data.comment, htmlBody: data.comment.body }
|
|
8670
|
+
};
|
|
8671
|
+
}
|
|
8672
|
+
case "unreadReplies": {
|
|
8673
|
+
return {
|
|
8674
|
+
...data,
|
|
8675
|
+
comments: data.comments.map((comment) => ({
|
|
8676
|
+
...comment,
|
|
8677
|
+
htmlBody: comment.body
|
|
8678
|
+
}))
|
|
8679
|
+
};
|
|
8680
|
+
}
|
|
8681
|
+
}
|
|
8682
|
+
}
|
|
8683
|
+
var baseComponents2 = {
|
|
8684
|
+
Container: ({ children }) => /* @__PURE__ */ jsx2("div", { children }),
|
|
8685
|
+
Paragraph: ({ children }) => /* @__PURE__ */ jsx2("p", { children }),
|
|
8686
|
+
Text: ({ element }) => {
|
|
8687
|
+
let children = element.text;
|
|
8688
|
+
if (element.bold) {
|
|
8689
|
+
children = /* @__PURE__ */ jsx2("strong", { children });
|
|
8690
|
+
}
|
|
8691
|
+
if (element.italic) {
|
|
8692
|
+
children = /* @__PURE__ */ jsx2("em", { children });
|
|
8693
|
+
}
|
|
8694
|
+
if (element.strikethrough) {
|
|
8695
|
+
children = /* @__PURE__ */ jsx2("s", { children });
|
|
8696
|
+
}
|
|
8697
|
+
if (element.code) {
|
|
8698
|
+
children = /* @__PURE__ */ jsx2("code", { children });
|
|
8699
|
+
}
|
|
8700
|
+
return /* @__PURE__ */ jsx2("span", { children });
|
|
8701
|
+
},
|
|
8702
|
+
Link: ({ element, href }) => /* @__PURE__ */ jsx2("a", { href, target: "_blank", rel: "noopener noreferrer", children: element.text ?? element.url }),
|
|
8703
|
+
Mention: ({ element, user }) => /* @__PURE__ */ jsxs2("span", { "data-mention": true, children: [
|
|
8704
|
+
MENTION_CHARACTER,
|
|
8705
|
+
user?.name ?? element.id
|
|
8706
|
+
] })
|
|
8707
|
+
};
|
|
8708
|
+
async function prepareThreadNotificationEmailAsReact(client, event, options = {}) {
|
|
8709
|
+
const Components = { ...baseComponents2, ...options?.components };
|
|
8710
|
+
const data = await prepareThreadNotificationEmail(
|
|
8711
|
+
client,
|
|
8712
|
+
event,
|
|
8713
|
+
{
|
|
8714
|
+
resolveUsers: options.resolveUsers,
|
|
8715
|
+
resolveRoomInfo: options.resolveRoomInfo
|
|
8716
|
+
},
|
|
8717
|
+
{
|
|
8718
|
+
container: ({ children }) => /* @__PURE__ */ jsx2(Components.Container, { children }, "lb-comment-body-container"),
|
|
8719
|
+
paragraph: ({ children }, index) => /* @__PURE__ */ jsx2(Components.Paragraph, { children }, `lb-comment-body-paragraph-${index}`),
|
|
8720
|
+
text: ({ element }, index) => /* @__PURE__ */ jsx2(
|
|
8721
|
+
Components.Text,
|
|
8722
|
+
{
|
|
8723
|
+
element
|
|
8724
|
+
},
|
|
8725
|
+
`lb-comment-body-text-${index}`
|
|
8726
|
+
),
|
|
8727
|
+
link: ({ element, href }, index) => /* @__PURE__ */ jsx2(
|
|
8728
|
+
Components.Link,
|
|
8729
|
+
{
|
|
8730
|
+
element,
|
|
8731
|
+
href
|
|
8732
|
+
},
|
|
8733
|
+
`lb-comment-body-link-${index}`
|
|
8734
|
+
),
|
|
8735
|
+
mention: ({ element, user }, index) => element.id ? /* @__PURE__ */ jsx2(
|
|
8736
|
+
Components.Mention,
|
|
8737
|
+
{
|
|
8738
|
+
element,
|
|
8739
|
+
user
|
|
8782
8740
|
},
|
|
8783
|
-
|
|
8741
|
+
`lb-comment-body-mention-${index}`
|
|
8742
|
+
) : null
|
|
8743
|
+
},
|
|
8744
|
+
"prepareThreadNotificationEmailAsReact"
|
|
8745
|
+
);
|
|
8746
|
+
if (data === null) {
|
|
8747
|
+
return null;
|
|
8748
|
+
}
|
|
8749
|
+
switch (data.type) {
|
|
8750
|
+
case "unreadMention": {
|
|
8751
|
+
return {
|
|
8752
|
+
...data,
|
|
8753
|
+
comment: { ...data.comment, reactBody: data.comment.body }
|
|
8784
8754
|
};
|
|
8785
8755
|
}
|
|
8786
8756
|
case "unreadReplies": {
|
|
8787
|
-
const { comments } = data;
|
|
8788
|
-
const authorsInfoPromise = resolveAuthorsInfo({
|
|
8789
|
-
userIds: comments.map((c) => c.userId),
|
|
8790
|
-
resolveUsers: batchUsersResolver.resolveUsers
|
|
8791
|
-
});
|
|
8792
|
-
const commentBodiesPromises = comments.map(
|
|
8793
|
-
(c) => convertCommentBodyAsReact(c.rawBody, {
|
|
8794
|
-
resolveUsers: batchUsersResolver.resolveUsers,
|
|
8795
|
-
components: options.components
|
|
8796
|
-
})
|
|
8797
|
-
);
|
|
8798
|
-
await batchUsersResolver.resolve();
|
|
8799
|
-
const [authorsInfo, ...commentBodies] = await Promise.all([
|
|
8800
|
-
authorsInfoPromise,
|
|
8801
|
-
...commentBodiesPromises
|
|
8802
|
-
]);
|
|
8803
8757
|
return {
|
|
8804
|
-
|
|
8805
|
-
comments: comments.map((comment
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
id: comment.id,
|
|
8810
|
-
threadId: comment.threadId,
|
|
8811
|
-
roomId: comment.roomId,
|
|
8812
|
-
author: {
|
|
8813
|
-
id: comment.userId,
|
|
8814
|
-
info: authorInfo ?? { name: comment.userId }
|
|
8815
|
-
},
|
|
8816
|
-
createdAt: comment.createdAt,
|
|
8817
|
-
url: comment.url,
|
|
8818
|
-
reactBody: commentBodyReact ?? null
|
|
8819
|
-
};
|
|
8820
|
-
}),
|
|
8821
|
-
roomInfo: data.roomInfo
|
|
8758
|
+
...data,
|
|
8759
|
+
comments: data.comments.map((comment) => ({
|
|
8760
|
+
...comment,
|
|
8761
|
+
reactBody: comment.body
|
|
8762
|
+
}))
|
|
8822
8763
|
};
|
|
8823
8764
|
}
|
|
8824
8765
|
}
|