<commit_before>/** File: chat.js
 * Candy - Chats are not dead yet.
 *
 * Authors:
 *   - <NAME> <<EMAIL>>
 *   - <NAME> <<EMAIL>>
 *
 * Copyright:
 *   (c) 2011 Amiado Group AG. All rights reserved.
 *   (c) 2012-2014 <NAME> & <NAME>. All rights reserved.
 */
'use strict';

/* global Candy, document, Mustache, Strophe, Audio, jQuery */

/** Class: Candy.View.Pane
 * Candy view pane handles everything regarding DOM updates etc.
 *
 * Parameters:
 *   (Candy.View.Pane) self - itself
 *   (jQuery) $ - jQuery
 */
Candy.View.Pane = (function(self, $) {

  /** Class: Candy.View.Pane.Chat
   * Chat-View related view updates
   */
  self.Chat = {
    /** Variable: rooms
     * Contains opened room elements
     */
    rooms: [],

    /** Function: addTab
     * Add a tab to the chat pane.
     *
     * Parameters:
     *   (String) roomJid - JID of room
     *   (String) roomName - Tab label
     *   (String) roomType - Type of room: `groupchat` or `chat`
     */
    addTab: function(roomJid, roomName, roomType) {
      var roomId = Candy.Util.jidToId(roomJid),
        html = Mustache.to_html(Candy.View.Template.Chat.tab, {
          roomJid: roomJid,
          roomId: roomId,
          name: roomName || Strophe.getNodeFromJid(roomJid),
          privateUserChat: function() {return roomType === 'chat';},
          roomType: roomType
        }),
        tab = $(html).appendTo('#chat-tabs');

      tab.click(self.Chat.tabClick);
      // TODO: maybe we find a better way to get the close element.
      $('a.close', tab).click(self.Chat.tabClose);

      self.Chat.fitTabs();
    },

    /** Function: getTab
     * Get tab by JID.
     *
     * Parameters:
     *   (String) roomJid - JID of room
     *
     * Returns:
     *   (jQuery object) - Tab element
     */
    getTab: function(roomJid) {
      return $('#chat-tabs').children('li[data-roomjid="' + roomJid + '"]');
    },

    /** Function: removeTab
     * Remove tab element.
     *<commit_msg>Add an event before adding the tab.<commit_after>/** File: chat.js
 * Candy - Chats are not dead yet.
 *
 * Authors:
 *   - <NAME> <<EMAIL>>
 *   - <NAME> <<EMAIL>>
 *
 * Copyright:
 *   (c) 2011 Amiado Group AG. All rights reserved.
 *   (c) 2012-2014 <NAME> & <NAME>. All rights reserved.
 */
'use strict';

/* global Candy, document, Mustache, Strophe, Audio, jQuery */

/** Class: Candy.View.Pane
 * Candy view pane handles everything regarding DOM updates etc.
 *
 * Parameters:
 *   (Candy.View.Pane) self - itself
 *   (jQuery) $ - jQuery
 */
Candy.View.Pane = (function(self, $) {

  /** Class: Candy.View.Pane.Chat
   * Chat-View related view updates
   */
  self.Chat = {
    /** Variable: rooms
     * Contains opened room elements
     */
    rooms: [],

    /** Function: addTab
     * Add a tab to the chat pane.
     *
     * Parameters:
     *   (String) roomJid - JID of room
     *   (String) roomName - Tab label
     *   (String) roomType - Type of room: `groupchat` or `chat`
     */
    addTab: function(roomJid, roomName, roomType) {
      var roomId = Candy.Util.jidToId(roomJid);

      var evtData = {
        roomJid: roomJid,
        roomName: roomName,
        roomType: roomType,
        roomId: roomId
      };

      /** Event: candy:view.pane.before-tab
       * Before sending a message
       *
       * Parameters:
       *   (String) roomJid - JID of the room the tab is for.
       *   (String) roomName - Name of the room.
       *   (String) roomType - What type of room: `groupchat` or `chat`
       *
       * Returns:
       *   Boolean|undefined - If you want to handle displaying the tab on your own, return false.
       */
      if ($(Candy).triggerHandler('candy:view.pane.before-tab', evtData) === false) {
        event.preventDefault();
        return;
      }

      var html = Mustache.to_html(Candy.View.Template.Chat.tab, {
          roomJid: roomJid,
          roomId: roomId,
          name: roomName || Strophe.getNodeFromJid(roomJid),
          privateUserChat: function() {return roomType === 'chat';},
          roomType: roomType
        }),
        tab = $(html).appendTo('#chat-tabs');

      tab.click(self.Chat.tabClick);
      // TODO: maybe we find a better way to get the close element.
      $('a.close', tab).click(self.Chat.tabClose);

      self.Chat.fitTabs();
    },

    /** Function: getTab
     * Get tab by JID.
     *
     * Parameters:
     *   (String) roomJid - JID of room
     *
     * Returns:
     *   (jQuery object) - Tab element
     */
    getTab: function(roomJid) {
      return $('#chat-tabs').children('li[data-roomjid="' + roomJid + '"]');
    },

    /** Function: removeTab
     * Remove tab element.
     *
{'fraction_non_alphanumeric': 0.14365113296280463, 'fraction_numerical': 0.005130397605814451, 'mean_word_length': 2.133958472873409, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4188599', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1512, 'n_words': 404}