All files conversation.js

100% Statements 41/41
100% Branches 6/6
100% Functions 3/3
100% Lines 41/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 421x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 28x 28x 28x 1x 1x 1x 1x 1x 1x 1x 19x 19x 1x 1x 1x 1x 1x 1x 1x 43x 43x 5x 5x 43x 1x 1x 1x  
"use strict";
 
/**
 * Conversation history for a single player.
 *
 * @class
 */
class Conversation {
  /**
   * Initializes a new Conversation instance.
   *
   * @param {number} [limit=20] - Maximum number of messages to keep.
   */
  constructor(limit) {
    this.messages = [];
    this.limit = limit || 20;
  }
 
  /**
   * Retrieve the list of messages in the conversation.
   *
   * @returns {Message[]} Conversation messages.
   */
  getMessages() {
    return this.messages;
  }
 
  /**
   * Add a new message to the conversation.
   *
   * @param {Message} message - Message to append.
   */
  addMessage(message) {
    this.messages.push(message);
    if (this.messages.length > this.limit) {
      this.messages.shift();
    }
  }
}
 
export { Conversation as default };