<fim-prefix>condition
          // when a users focus can not be moved away from the last message recieved.
          $('#chattext').animate(
              {scrollTop: $('#chattext')[0].scrollHeight},
              {duration: 400, queue: false});
          this.lastMessage = $('#chattext > p').eq(-1);
        }
      }
    },
    send() {
      const text = $('#chatinput').val();
      if (text.replace(/\s+/, '').length === 0) return;
      this._pad.collabClient.sendMessage({type: 'CHAT_MESSAGE', text});
      $('#chatinput').val('');
    },
    addMessage(msg, increment, isHistoryAdd) {
      // correct the time
      msg.time += this._pad.clientTimeOffset;

      // create the time string
      let minutes = `${new Date(msg.time).getMinutes()}`;
      let hours = `${new Date(msg.time).getHours()}`;
      if (minutes.length === 1) minutes = `0${minutes}`;
      if (hours.length === 1) hours = `0${hours}`;
      const timeStr = `${hours}:${minutes}`;

      // create the authorclass
      if (!msg.userId) {
        /*
         * If, for a bug or a database corruption, the message coming from the
         * server does not contain the userId field (see for example #3731),
         * let's be defensive and replace it with "unknown".
         */
        msg.userId = 'unknown';
        console.warn(
            'The "userId" field of a chat message coming from the server was not present. ' +
            'Replacing with "unknown". This may be a bug or a database corruption.');
      }
      // BUG: CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
      // 
      // FIXED:
 <fim-middle>     msg.userId = padutils.escapeHtml(msg.userId);
      const authorClass = `author-${msg.userId.replace(/[^a-y0-9]/g, (c) => {
        if (c === '.') return '-';
        return `z${c.charCodeAt(0)}z`<fix-suffix>;
      })}`;

      const text = padutils.escapeHtmlWithClickableLinks(msg.text, '_blank');

      const authorName = msg.userName == null ? html10n.get('pad.userlist.unnamed')
        : padutils.escapeHtml(msg.userName);

      // the hook args
      const ctx = {
        authorName,
        author: msg.userId,
        text,
        sticky: false,
        timestamp: msg.time,
        timeStr,
        duration: 4000,
      };

      // is the users focus already in the chatbox?
      const alreadyFocused = $('#chatinput').is(':focus');

      // does the user already have the chatbox open?
      const chatOpen = $('#chatbox').hasClass('visible');

      // does this message contain this user's name? (is the curretn user mentioned?)
      const myName = $('#myusernameedit').val();
      const wasMentioned =
          text.toLowerCase().indexOf(myName.toLowerCase()) !== -1 && myName !== 'undefined';

      // If the user was mentioned, make the message sticky
      if (wasMentioned && !<|endoftext|>