@liveblocks/emails 2.21.0-emails2 → 2.21.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 CHANGED
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/emails";
6
- var PKG_VERSION = "2.21.0-emails2";
6
+ var PKG_VERSION = "2.21.0";
7
7
  var PKG_FORMAT = "cjs";
8
8
 
9
9
  // ../../node_modules/lib0/map.js
@@ -7368,9 +7368,6 @@ 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
- };
7374
7371
 
7375
7372
  // src/lexical-editor.ts
7376
7373
  function createSerializedLexicalMapNode(item) {
@@ -8376,9 +8373,11 @@ async function prepareTextMentionNotificationEmailAsHtml(client, event, options
8376
8373
 
8377
8374
 
8378
8375
 
8376
+ // src/comment-body.tsx
8377
+
8378
+
8379
8379
 
8380
8380
 
8381
- // src/comment-body.tsx
8382
8381
 
8383
8382
 
8384
8383
 
@@ -8386,40 +8385,77 @@ async function prepareTextMentionNotificationEmailAsHtml(client, event, options
8386
8385
 
8387
8386
 
8388
8387
 
8389
- async function convertCommentBody(body, options) {
8388
+ var baseComponents2 = {
8389
+ Container: ({ children }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children }),
8390
+ Paragraph: ({ children }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { children }),
8391
+ Text: ({ element }) => {
8392
+ let children = element.text;
8393
+ if (element.bold) {
8394
+ children = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children });
8395
+ }
8396
+ if (element.italic) {
8397
+ children = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "em", { children });
8398
+ }
8399
+ if (element.strikethrough) {
8400
+ children = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "s", { children });
8401
+ }
8402
+ if (element.code) {
8403
+ children = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "code", { children });
8404
+ }
8405
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children });
8406
+ },
8407
+ Link: ({ element, href }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href, target: "_blank", rel: "noopener noreferrer", children: _nullishCoalesce(element.text, () => ( element.url)) }),
8408
+ Mention: ({ element, user }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { "data-mention": true, children: [
8409
+ MENTION_CHARACTER,
8410
+ _nullishCoalesce(_optionalChain([user, 'optionalAccess', _17 => _17.name]), () => ( element.id))
8411
+ ] })
8412
+ };
8413
+ async function convertCommentBodyAsReact(body, options) {
8414
+ const Components = {
8415
+ ...baseComponents2,
8416
+ ..._optionalChain([options, 'optionalAccess', _18 => _18.components])
8417
+ };
8390
8418
  const resolvedUsers = await _core.resolveUsersInCommentBody.call(void 0,
8391
8419
  body,
8392
- _optionalChain([options, 'optionalAccess', _17 => _17.resolveUsers])
8420
+ _optionalChain([options, 'optionalAccess', _19 => _19.resolveUsers])
8393
8421
  );
8394
8422
  const blocks = body.content.map((block, index) => {
8395
8423
  switch (block.type) {
8396
8424
  case "paragraph": {
8397
8425
  const children = block.children.map((inline, inlineIndex) => {
8398
8426
  if (_core.isCommentBodyMention.call(void 0, inline)) {
8399
- return options.elements.mention(
8427
+ return inline.id ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
8428
+ Components.Mention,
8400
8429
  {
8401
8430
  element: inline,
8402
8431
  user: resolvedUsers.get(inline.id)
8403
8432
  },
8404
- inlineIndex
8405
- );
8433
+ `lb-comment-body-mention-${inlineIndex}`
8434
+ ) : null;
8406
8435
  }
8407
8436
  if (_core.isCommentBodyLink.call(void 0, inline)) {
8408
8437
  const href = _nullishCoalesce(_core.toAbsoluteUrl.call(void 0, inline.url), () => ( inline.url));
8409
- return options.elements.link(
8410
- { element: inline, href },
8411
- inlineIndex
8438
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
8439
+ Components.Link,
8440
+ {
8441
+ element: inline,
8442
+ href
8443
+ },
8444
+ `lb-comment-body-link-${inlineIndex}`
8412
8445
  );
8413
8446
  }
8414
8447
  if (_core.isCommentBodyText.call(void 0, inline)) {
8415
- return options.elements.text({ element: inline }, inlineIndex);
8448
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
8449
+ Components.Text,
8450
+ {
8451
+ element: inline
8452
+ },
8453
+ `lb-comment-body-text-${inlineIndex}`
8454
+ );
8416
8455
  }
8417
8456
  return null;
8418
- }).filter(exists);
8419
- return options.elements.paragraph(
8420
- { element: block, children },
8421
- index
8422
- );
8457
+ });
8458
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Components.Paragraph, { children }, `lb-comment-body-paragraph-${index}`);
8423
8459
  }
8424
8460
  default:
8425
8461
  console.warn(
@@ -8427,8 +8463,68 @@ async function convertCommentBody(body, options) {
8427
8463
  );
8428
8464
  return null;
8429
8465
  }
8430
- }).filter(exists);
8431
- return options.elements.container({ children: blocks });
8466
+ });
8467
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Components.Container, { children: blocks }, "lb-comment-body-container");
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, ..._optionalChain([options, 'optionalAccess', _20 => _20.styles]) };
8491
+ const htmlBody = await _core.stringifyCommentBody.call(void 0, body, {
8492
+ format: "html",
8493
+ resolveUsers: _optionalChain([options, 'optionalAccess', _21 => _21.resolveUsers]),
8494
+ elements: {
8495
+ // NOTE: using prettier-ignore to preserve template strings
8496
+ paragraph: ({ children }) => (
8497
+ // prettier-ignore
8498
+ children ? _core.html`<p style="${toInlineCSSString(styles.paragraph)}">${_core.htmlSafe.call(void 0, children)}</p>` : children
8499
+ ),
8500
+ text: ({ element }) => {
8501
+ let children = element.text;
8502
+ if (!children) {
8503
+ return _core.html`${children}`;
8504
+ }
8505
+ if (element.bold) {
8506
+ children = _core.html`<strong style="${toInlineCSSString(styles.strong)}">${children}</strong>`;
8507
+ }
8508
+ if (element.italic) {
8509
+ children = _core.html`<em>${children}</em>`;
8510
+ }
8511
+ if (element.strikethrough) {
8512
+ children = _core.html`<s>${children}</s>`;
8513
+ }
8514
+ if (element.code) {
8515
+ children = _core.html`<code style="${toInlineCSSString(styles.code)}">${children}</code>`;
8516
+ }
8517
+ return _core.html`${children}`;
8518
+ },
8519
+ link: ({ element, href }) => {
8520
+ return _core.html`<a href="${href}" target="_blank" rel="noopener noreferrer" style="${toInlineCSSString(styles.link)}">${element.text ? _core.html`${element.text}` : element.url}</a>`;
8521
+ },
8522
+ mention: ({ element, user }) => {
8523
+ return _core.html`<span data-mention style="${toInlineCSSString(styles.mention)}">${MENTION_CHARACTER}${_optionalChain([user, 'optionalAccess', _22 => _22.name]) ? _core.html`${_optionalChain([user, 'optionalAccess', _23 => _23.name])}` : element.id}</span>`;
8524
+ }
8525
+ }
8526
+ });
8527
+ return htmlBody;
8432
8528
  }
8433
8529
 
8434
8530
  // src/comment-with-body.ts
@@ -8446,7 +8542,6 @@ function filterCommentsWithBody(comments) {
8446
8542
  }
8447
8543
 
8448
8544
  // src/thread-notification.tsx
8449
-
8450
8545
  var getUnreadComments = ({
8451
8546
  comments,
8452
8547
  inboxNotification,
@@ -8500,19 +8595,72 @@ var extractThreadNotificationData = async ({
8500
8595
  comments: unreadComments
8501
8596
  };
8502
8597
  };
8503
- async function prepareThreadNotificationEmail(client, event, options) {
8598
+ var makeCommentEmailBaseData = ({
8599
+ roomInfo,
8600
+ comment
8601
+ }) => {
8602
+ const url = _optionalChain([roomInfo, 'optionalAccess', _24 => _24.url]) ? _core.generateCommentUrl.call(void 0, {
8603
+ roomUrl: _optionalChain([roomInfo, 'optionalAccess', _25 => _25.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: _nullishCoalesce(_optionalChain([roomInfo, 'optionalAccess', _26 => _26.name]), () => ( roomId))
8626
+ };
8504
8627
  const data = await extractThreadNotificationData({ client, event });
8505
8628
  if (data === null) {
8506
8629
  return null;
8507
8630
  }
8508
- const roomInfo = options.resolveRoomInfo ? await options.resolveRoomInfo({ roomId: event.data.roomId }) : void 0;
8509
- const resolvedRoomInfo = {
8510
- ...roomInfo,
8511
- name: _nullishCoalesce(_optionalChain([roomInfo, 'optionalAccess', _18 => _18.name]), () => ( event.data.roomId))
8512
- };
8631
+ switch (data.type) {
8632
+ case "unreadMention":
8633
+ return {
8634
+ type: "unreadMention",
8635
+ comment: makeCommentEmailBaseData({
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
+ }
8513
8661
  const batchUsersResolver = createBatchUsersResolver({
8514
8662
  resolveUsers: options.resolveUsers,
8515
- callerName: "prepareThreadNotificationEmail"
8663
+ callerName: "prepareThreadNotificationEmailAsHtml"
8516
8664
  });
8517
8665
  switch (data.type) {
8518
8666
  case "unreadMention": {
@@ -8521,20 +8669,16 @@ async function prepareThreadNotificationEmail(client, event, options) {
8521
8669
  userIds: [comment.userId],
8522
8670
  resolveUsers: batchUsersResolver.resolveUsers
8523
8671
  });
8524
- const commentBodyPromise = convertCommentBody(comment.body, {
8672
+ const commentBodyPromise = convertCommentBodyAsHtml(comment.rawBody, {
8525
8673
  resolveUsers: batchUsersResolver.resolveUsers,
8526
- elements: options.elements
8674
+ styles: options.styles
8527
8675
  });
8528
8676
  await batchUsersResolver.resolve();
8529
- const [authorsInfo, commentBody] = await Promise.all([
8677
+ const [authorsInfo, commentBodyHtml] = await Promise.all([
8530
8678
  authorsInfoPromise,
8531
8679
  commentBodyPromise
8532
8680
  ]);
8533
8681
  const authorInfo = authorsInfo.get(comment.userId);
8534
- const url = _optionalChain([roomInfo, 'optionalAccess', _19 => _19.url]) ? _core.generateCommentUrl.call(void 0, {
8535
- roomUrl: _optionalChain([roomInfo, 'optionalAccess', _20 => _20.url]),
8536
- commentId: comment.id
8537
- }) : void 0;
8538
8682
  return {
8539
8683
  type: "unreadMention",
8540
8684
  comment: {
@@ -8546,10 +8690,10 @@ async function prepareThreadNotificationEmail(client, event, options) {
8546
8690
  info: _nullishCoalesce(authorInfo, () => ( { name: comment.userId }))
8547
8691
  },
8548
8692
  createdAt: comment.createdAt,
8549
- url,
8550
- body: commentBody
8693
+ url: comment.url,
8694
+ htmlBody: commentBodyHtml
8551
8695
  },
8552
- roomInfo: resolvedRoomInfo
8696
+ roomInfo: data.roomInfo
8553
8697
  };
8554
8698
  }
8555
8699
  case "unreadReplies": {
@@ -8559,9 +8703,9 @@ async function prepareThreadNotificationEmail(client, event, options) {
8559
8703
  resolveUsers: batchUsersResolver.resolveUsers
8560
8704
  });
8561
8705
  const commentBodiesPromises = comments.map(
8562
- (c) => convertCommentBody(c.body, {
8706
+ (c) => convertCommentBodyAsHtml(c.rawBody, {
8563
8707
  resolveUsers: batchUsersResolver.resolveUsers,
8564
- elements: options.elements
8708
+ styles: options.styles
8565
8709
  })
8566
8710
  );
8567
8711
  await batchUsersResolver.resolve();
@@ -8573,11 +8717,7 @@ async function prepareThreadNotificationEmail(client, event, options) {
8573
8717
  type: "unreadReplies",
8574
8718
  comments: comments.map((comment, index) => {
8575
8719
  const authorInfo = authorsInfo.get(comment.userId);
8576
- const commentBody = commentBodies[index];
8577
- const url = _optionalChain([roomInfo, 'optionalAccess', _21 => _21.url]) ? _core.generateCommentUrl.call(void 0, {
8578
- roomUrl: _optionalChain([roomInfo, 'optionalAccess', _22 => _22.url]),
8579
- commentId: comment.id
8580
- }) : void 0;
8720
+ const commentBodyHtml = commentBodies[index];
8581
8721
  return {
8582
8722
  id: comment.id,
8583
8723
  threadId: comment.threadId,
@@ -8587,177 +8727,98 @@ async function prepareThreadNotificationEmail(client, event, options) {
8587
8727
  info: _nullishCoalesce(authorInfo, () => ( { name: comment.userId }))
8588
8728
  },
8589
8729
  createdAt: comment.createdAt,
8590
- url,
8591
- body: commentBody
8730
+ url: comment.url,
8731
+ htmlBody: _nullishCoalesce(commentBodyHtml, () => ( ""))
8592
8732
  };
8593
8733
  }),
8594
- roomInfo: resolvedRoomInfo
8734
+ roomInfo: data.roomInfo
8595
8735
  };
8596
8736
  }
8597
8737
  }
8598
8738
  }
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, ..._optionalChain([options, 'optionalAccess', _23 => _23.styles]) };
8621
- const data = await prepareThreadNotificationEmail(
8622
- client,
8623
- event,
8624
- {
8625
- resolveUsers: options.resolveUsers,
8626
- resolveRoomInfo: options.resolveRoomInfo,
8627
- elements: {
8628
- container: ({ children }) => children.join("\n"),
8629
- paragraph: ({ children }) => {
8630
- const unsafe = children.join("");
8631
- return unsafe ? _core.html`<p style="${toInlineCSSString(styles.paragraph)}">${_core.htmlSafe.call(void 0, unsafe)}</p>` : unsafe;
8632
- },
8633
- text: ({ element }) => {
8634
- let children = element.text;
8635
- if (!children) {
8636
- return _core.html`${children}`;
8637
- }
8638
- if (element.bold) {
8639
- children = _core.html`<strong style="${toInlineCSSString(styles.strong)}">${children}</strong>`;
8640
- }
8641
- if (element.italic) {
8642
- children = _core.html`<em>${children}</em>`;
8643
- }
8644
- if (element.strikethrough) {
8645
- children = _core.html`<s>${children}</s>`;
8646
- }
8647
- if (element.code) {
8648
- children = _core.html`<code style="${toInlineCSSString(styles.code)}">${children}</code>`;
8649
- }
8650
- return _core.html`${children}`;
8651
- },
8652
- link: ({ element, href }) => {
8653
- return _core.html`<a href="${href}" target="_blank" rel="noopener noreferrer" style="${toInlineCSSString(styles.link)}">${element.text ? _core.html`${element.text}` : element.url}</a>`;
8654
- },
8655
- mention: ({ element, user }) => {
8656
- return _core.html`<span data-mention style="${toInlineCSSString(styles.mention)}">${MENTION_CHARACTER}${_optionalChain([user, 'optionalAccess', _24 => _24.name]) ? _core.html`${_optionalChain([user, 'optionalAccess', _25 => _25.name])}` : element.id}</span>`;
8657
- }
8658
- }
8659
- }
8660
- );
8661
- if (data === null) {
8662
- return null;
8663
- }
8664
- switch (data.type) {
8665
- case "unreadMention": {
8666
- return {
8667
- ...data,
8668
- comment: { ...data.comment, htmlBody: data.comment.body }
8669
- };
8670
- }
8671
- case "unreadReplies": {
8672
- return {
8673
- ...data,
8674
- comments: data.comments.map((comment) => ({
8675
- ...comment,
8676
- htmlBody: comment.body
8677
- }))
8678
- };
8679
- }
8680
- }
8681
- }
8682
- var baseComponents2 = {
8683
- Container: ({ children }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children }),
8684
- Paragraph: ({ children }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { children }),
8685
- Text: ({ element }) => {
8686
- let children = element.text;
8687
- if (element.bold) {
8688
- children = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children });
8689
- }
8690
- if (element.italic) {
8691
- children = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "em", { children });
8692
- }
8693
- if (element.strikethrough) {
8694
- children = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "s", { children });
8695
- }
8696
- if (element.code) {
8697
- children = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "code", { children });
8698
- }
8699
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children });
8700
- },
8701
- Link: ({ element, href }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href, target: "_blank", rel: "noopener noreferrer", children: _nullishCoalesce(element.text, () => ( element.url)) }),
8702
- Mention: ({ element, user }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { "data-mention": true, children: [
8703
- MENTION_CHARACTER,
8704
- _nullishCoalesce(_optionalChain([user, 'optionalAccess', _26 => _26.name]), () => ( element.id))
8705
- ] })
8706
- };
8707
8739
  async function prepareThreadNotificationEmailAsReact(client, event, options = {}) {
8708
- const Components = { ...baseComponents2, ..._optionalChain([options, 'optionalAccess', _27 => _27.components]) };
8709
- const data = await prepareThreadNotificationEmail(
8740
+ const data = await prepareThreadNotificationEmailBaseData({
8710
8741
  client,
8711
8742
  event,
8712
- {
8713
- resolveUsers: options.resolveUsers,
8714
- resolveRoomInfo: options.resolveRoomInfo,
8715
- elements: {
8716
- container: ({ children }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Components.Container, { children }, "lb-comment-body-container"),
8717
- paragraph: ({ children }, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Components.Paragraph, { children }, `lb-comment-body-paragraph-${index}`),
8718
- text: ({ element }, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
8719
- Components.Text,
8720
- {
8721
- element
8722
- },
8723
- `lb-comment-body-text-${index}`
8724
- ),
8725
- link: ({ element, href }, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
8726
- Components.Link,
8727
- {
8728
- element,
8729
- href
8730
- },
8731
- `lb-comment-body-link-${index}`
8732
- ),
8733
- mention: ({ element, user }, index) => element.id ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
8734
- Components.Mention,
8735
- {
8736
- element,
8737
- user
8738
- },
8739
- `lb-comment-body-mention-${index}`
8740
- ) : null
8741
- }
8742
- }
8743
- );
8743
+ options: { resolveRoomInfo: options.resolveRoomInfo }
8744
+ });
8744
8745
  if (data === null) {
8745
8746
  return null;
8746
8747
  }
8748
+ const batchUsersResolver = createBatchUsersResolver({
8749
+ resolveUsers: options.resolveUsers,
8750
+ callerName: "prepareThreadNotificationEmailAsReact"
8751
+ });
8747
8752
  switch (data.type) {
8748
8753
  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);
8749
8769
  return {
8750
- ...data,
8751
- comment: { ...data.comment, reactBody: data.comment.body }
8770
+ type: "unreadMention",
8771
+ comment: {
8772
+ id: comment.id,
8773
+ threadId: comment.threadId,
8774
+ roomId: comment.roomId,
8775
+ author: {
8776
+ id: comment.userId,
8777
+ info: _nullishCoalesce(authorInfo, () => ( { name: comment.userId }))
8778
+ },
8779
+ createdAt: comment.createdAt,
8780
+ url: comment.url,
8781
+ reactBody: commentBodyReact
8782
+ },
8783
+ roomInfo: data.roomInfo
8752
8784
  };
8753
8785
  }
8754
8786
  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
+ ]);
8755
8803
  return {
8756
- ...data,
8757
- comments: data.comments.map((comment) => ({
8758
- ...comment,
8759
- reactBody: comment.body
8760
- }))
8804
+ type: "unreadReplies",
8805
+ comments: comments.map((comment, index) => {
8806
+ const authorInfo = authorsInfo.get(comment.userId);
8807
+ const commentBodyReact = commentBodies[index];
8808
+ return {
8809
+ id: comment.id,
8810
+ threadId: comment.threadId,
8811
+ roomId: comment.roomId,
8812
+ author: {
8813
+ id: comment.userId,
8814
+ info: _nullishCoalesce(authorInfo, () => ( { name: comment.userId }))
8815
+ },
8816
+ createdAt: comment.createdAt,
8817
+ url: comment.url,
8818
+ reactBody: _nullishCoalesce(commentBodyReact, () => ( null))
8819
+ };
8820
+ }),
8821
+ roomInfo: data.roomInfo
8761
8822
  };
8762
8823
  }
8763
8824
  }