@banta/sdk 5.8.3 → 5.8.5

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.
@@ -7587,6 +7587,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.9", ngImpor
7587
7587
  args: ['class.visible']
7588
7588
  }] } });
7589
7589
 
7590
+ const DEFAULT_MAX_MESSAGES = 2000;
7591
+ const DEFAULT_MAX_VISIBLE_MESSAGES = 200;
7590
7592
  class CommentViewComponent {
7591
7593
  constructor(backend, elementRef) {
7592
7594
  this.backend = backend;
@@ -7606,7 +7608,7 @@ class CommentViewComponent {
7606
7608
  * While this is called "new" messages, it really represents the messages that would be visible *at the beginning
7607
7609
  * of the sort order*, which can be flipped by the newestLast feature (used for replies mode).
7608
7610
  *
7609
- * So, when newestLast is false, regardless of the current sortOrder, newMessages are conceptually
7611
+ * So, when newestLast is false (top-level comments), regardless of the current sortOrder, newMessages are conceptually
7610
7612
  * *above* the visible set of messages.
7611
7613
  *
7612
7614
  * When newestLast is true (as in replies mode), regardless of the current sortOrder, newMessages are conceptually
@@ -7624,10 +7626,6 @@ class CommentViewComponent {
7624
7626
  * *above* the visible set of messages.
7625
7627
  */
7626
7628
  this.olderMessages = [];
7627
- //#endregion
7628
- //#region Inputs
7629
- this.maxMessages = 2000;
7630
- this.maxVisibleMessages = 200;
7631
7629
  this.newestLast = false;
7632
7630
  this.holdNewMessages = false;
7633
7631
  this.showEmptyState = true;
@@ -7667,6 +7665,10 @@ class CommentViewComponent {
7667
7665
  set source(value) { this.setSource(value); }
7668
7666
  get previousMessages() { return this.newestLast ? this.olderMessages : this.newMessages; }
7669
7667
  get nextMessages() { return this.newestLast ? this.newMessages : this.olderMessages; }
7668
+ set maxMessages(value) { this._maxMessages = value; }
7669
+ get maxMessages() { return this._maxMessages ?? DEFAULT_MAX_MESSAGES; }
7670
+ set maxVisibleMessages(value) { this._maxVisibleMessages = value; }
7671
+ get maxVisibleMessages() { return this._maxVisibleMessages ?? DEFAULT_MAX_VISIBLE_MESSAGES; }
7670
7672
  get comments() { return Array.from(this.commentsQuery); }
7671
7673
  //#endregion
7672
7674
  /**
@@ -7689,16 +7691,15 @@ class CommentViewComponent {
7689
7691
  console.error(`Error while loading message in context: Failed to find message ${message.id}, maybe it was deleted!`);
7690
7692
  return false;
7691
7693
  }
7692
- let pageSize = this.maxVisibleMessages;
7693
7694
  let items = [].concat(this.olderMessages, this.messages, this.newMessages);
7694
7695
  let index = items.findIndex(x => x.id === message.id);
7695
7696
  if (index < 0) {
7696
7697
  console.error(`Error while loading message in context: Message was not present in message list!`);
7697
7698
  return false;
7698
7699
  }
7699
- let startIndex = Math.max(0, index - pageSize / 2);
7700
+ let startIndex = Math.max(0, index - this.maxVisibleMessages / 2);
7700
7701
  this.newMessages = items.splice(0, startIndex);
7701
- this.messages = items.splice(0, pageSize);
7702
+ this.messages = items.splice(0, this.maxVisibleMessages);
7702
7703
  this.olderMessages = items;
7703
7704
  this.isViewingMore = true;
7704
7705
  }
@@ -7936,12 +7937,14 @@ class CommentViewComponent {
7936
7937
  return this.previousMessages.length > 0;
7937
7938
  }
7938
7939
  get pageSize() {
7939
- return Math.min(20, this.maxVisibleMessages);
7940
+ return Math.min(20, this.maxVisibleMessages || 20);
7940
7941
  }
7941
7942
  async showPrevious() {
7942
7943
  this.isViewingMore = true;
7943
7944
  let nextPageSize = this.pageSize;
7944
7945
  this.isLoadingMore = false;
7946
+ if (isNaN(nextPageSize))
7947
+ throw new Error(`Not safe to load more with NaN page size`);
7945
7948
  if (this.previousMessages.length > 0) {
7946
7949
  const storedMessages = this.previousMessages.splice(Math.max(0, this.previousMessages.length - nextPageSize), nextPageSize);
7947
7950
  this.messages = [...storedMessages, ...this.messages];
@@ -8009,6 +8012,8 @@ class CommentViewComponent {
8009
8012
  async showNext() {
8010
8013
  this.isViewingMore = true;
8011
8014
  let nextPageSize = this.pageSize;
8015
+ if (isNaN(nextPageSize))
8016
+ throw new Error(`Not safe to load more with NaN page size`);
8012
8017
  this.isLoadingMore = false;
8013
8018
  if (this.nextMessages.length > 0) {
8014
8019
  const storedMessages = this.nextMessages.splice(0, nextPageSize);
@@ -8049,6 +8054,8 @@ class CommentViewComponent {
8049
8054
  async showMore() {
8050
8055
  this.isViewingMore = true;
8051
8056
  let nextPageSize = this.pageSize;
8057
+ if (isNaN(nextPageSize))
8058
+ throw new Error(`Not safe to load more with NaN page size`);
8052
8059
  this.isLoadingMore = false;
8053
8060
  if (this.olderMessages.length > 0) {
8054
8061
  const storedMessages = this.olderMessages.splice(0, nextPageSize);
@@ -8092,14 +8099,20 @@ class CommentViewComponent {
8092
8099
  // Extract the messages that do not fit in the maxVisibleMessages buffer.
8093
8100
  if (this.messages.length > this.maxVisibleMessages) {
8094
8101
  let overflow = [];
8095
- if (this.newestLast)
8102
+ // Move overflowing messages into newMessages.
8103
+ // Regardless of the order (newestLast), newMessages represents the direction that is being loaded,
8104
+ // since it's definition depends on that order.
8105
+ if (this.newestLast) {
8096
8106
  overflow = this.messages.splice(this.maxVisibleMessages, this.messages.length);
8097
- else
8107
+ this.newMessages = overflow.concat(this.newMessages);
8108
+ this.newMessages.splice(this.maxMessages - this.maxVisibleMessages, this.newMessages.length);
8109
+ }
8110
+ else {
8098
8111
  overflow = this.messages.splice(0, this.messages.length - this.maxVisibleMessages);
8099
- // Regardless of the order (newestLast), newMessages represents the direction that is being pushed, since it's definition
8100
- // depends on that order. Move overflowing messages into newMessages.
8101
- this.newMessages = overflow.concat(this.newMessages);
8102
- this.newMessages.splice(this.maxMessages - this.maxVisibleMessages, this.newMessages.length);
8112
+ this.newMessages.push(...overflow);
8113
+ if (this.newMessages.length > this.maxMessages - this.maxVisibleMessages)
8114
+ this.newMessages.splice(0, this.newMessages.length - (this.maxMessages - this.maxVisibleMessages));
8115
+ }
8103
8116
  }
8104
8117
  }
8105
8118
  addMessage(message) {
@@ -9440,7 +9453,9 @@ class BantaCommentsComponent {
9440
9453
  }
9441
9454
  this._selected.next(message);
9442
9455
  console.log(`[Banta] Opening thread for ${this.topicID}/${message.id}...`);
9443
- let selectedMessageThread = await this.backend.getSourceForThread(this.topicID, message.id);
9456
+ let selectedMessageThread = await this.backend.getSourceForThread(this.topicID, message.id, {
9457
+ metadata: this.metadata
9458
+ });
9444
9459
  if (!selectedMessageThread) {
9445
9460
  console.warn(`Failed to locate thread for message ${this.topicID}/${message.id}!`);
9446
9461
  return null;