<commit_before><dom-module id="ghvz-chat-page">
  <script>
    // Not sure why this HTMLImports.whenReady is really needed.
    // Something about polymer initialization order.
    // I think we're not supposed to need this.
    HTMLImports.whenReady(() => {
      Polymer({
        is: 'ghvz-chat-page',

        properties: {
          bridge: Object,
          database: Object,
          user: String,
          game: String,
          player: Object,
          page: String,

          currentChatRoom: {
            type: Object,
            value: null,
          },
        },

        observers: [
          'onPageChanged_(page, game.chatRooms.*)',
        ],

        onPageChanged_() {
          if (this.page == "chat" || this.page.startsWith('chat/')) {
            let chatRoomId;
            if (this.page.includes('/')) {
              chatRoomId = this.page.split('/')[1];
            }
            if (chatRoomId) {
              this.$.chatRoomSelector.select(
                  this.game.chatRooms.find(chatRoom => chatRoom.id == chatRoomId));
            } else {
              if (this.game.chatRooms.length > 0) {
                this.async(() => {
                  chatRoomId = this.game.chatRooms[0].id;
                  var page = "chat/" + chatRoomId;
                  this.fire('ghvz-open-page', {
                    page: page,
                  });
                });
              }
            }
          }
        },

        extractChatRoomIdFromUrl_() {
          let initialUrl = window.location.pathname;
          let match = /(?:\w+\/\w+\/)([\w/-]+)?/.exec(initialUrl);
          if (!match) {
            return null;
          }<commit_msg>make chat page redirect to a valid chat if chat id in url doesnt exist anymore<commit_after><dom-module id="ghvz-chat-page">
  <script>
    // Not sure why this HTMLImports.whenReady is really needed.
    // Something about polymer initialization order.
    // I think we're not supposed to need this.
    HTMLImports.whenReady(() => {
      Polymer({
        is: 'ghvz-chat-page',

        properties: {
          bridge: Object,
          database: Object,
          user: String,
          game: String,
          player: Object,
          page: String,

          currentChatRoom: {
            type: Object,
            value: null,
          },
        },

        observers: [
          'onPageChanged_(page, game.chatRooms.*)',
        ],

        onPageChanged_() {
          if (this.page == "chat" || this.page.startsWith('chat/')) {
            var chatRoomId = this.page.includes('/') ? this.page.split('/')[1] : "";
            if (chatRoomId) {
              this.$.chatRoomSelector.select(
                  this.game.chatRooms.find(chatRoom => chatRoom.id == chatRoomId));
              if (this.$.chatRoomSelector.selected != null) {
                return;
              }
            }
            if (this.game.chatRooms.length > 0) {
              this.async(() => {
                chatRoomId = this.game.chatRooms[0].id;
                var page = "chat/" + chatRoomId;
                this.fire('ghvz-open-page', {
                  page: page,
                });
              });
            }
          }
        },

        extractChatRoomIdFromUrl_() {
          let initialUrl = window.location.pathname;
          let match = /(?:\w+\/\w+\/)([\w/-]+)?/.exec(initialUrl);
          if (!match) {
            return null;
          }
{'fraction_non_alphanumeric': 0.13557358053302435, 'fraction_numerical': 0.0017381228273464658, 'mean_word_length': 1.3331081081081082, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '5753131', 'n_tokens_mistral': 985, 'n_tokens_neox': 953, 'n_words': 198}