<commit_before>import store from '../store';
import { mapState } from 'vuex';
import Vue from 'vue';
import PerfectScrollbar from '../components/perfect-scrollbar';
import VuePm from '../components/pm/message.vue';
import VueAutosave from '../plugins/autosave';
import VuePrompt from '../components/forms/prompt.vue';
import VueMarkdown from '../components/forms/markdown.vue';
import VueButton from '../components/forms/button.vue';
import VueError from '../components/forms/error.vue';
import {default as ws} from '../libs/realtime.ts';
import VuePaste from '../plugins/paste.js';
import VueModal from '../components/modal.vue';
import VuePagination from '../components/pagination.vue';
import VueAutocomplete from '../components/forms/autocomplete.vue';
import differenceInMinutes from 'date-fns/differenceInMinutes';
import parseISO from 'date-fns/parseISO';
import {default as axiosErrorHandler} from "@/libs/axios-error-handler";
import VueNotifications from "vue-notification";

Vue.use(VueAutosave);
Vue.use(VueNotifications, {componentName: 'vue-notifications'});
Vue.use(VuePaste, {url: '/assets'});

axiosErrorHandler(message => Vue.notify({type: 'error', text: message}));

const DRAFT_KEY = 'pm';
const INBOX = 1;

new Vue({
  el: '#app-pm',
  delimiters: ['${', '}'],
  components: {
    'perfect-scrollbar': PerfectScrollbar,
    'vue-pm': VuePm,
    'vue-prompt': VuePrompt,
    'vue-button': VueButton,
    'vue-modal': VueModal,
    'vue-markdown': VueMarkdown,
    'vue-pagination': VuePagination,
    'vue-autocomplete': VueAutocomplete,
    'vue-error': VueError
  },
  data() {
    return {
      recipient: window.data.recipient,
      sender: window.data.sender,
      text: '',
      isProcessing: false,
      errors: {},
      items: [],
      assets: [],
      tab: 'body',
      isTyping: false
    };
  },
  store,
  created() {
    // fill vuex with data passed from controller to view
    store.commit('messages/init', {messages: window.data.messages, total: window.data.total, perPage: window.data.per_page, currentPage: window.data.current_page});

    this.text = this.$loadDraft(DRAFT_KEY);
    this.$watch('text', newValue => this.$saveDraft(DRAFT_KEY, newValue));
  },
  mounted() {
    this.listenForMessage();
    this.listenForTyping();
    this.scrollToBottom();
    this.addScrollbarEvent();
    this.markAllAsRead();
  },
  methods: {
    addScrollbarEvent() {
      if ('scrollbar' in this.$refs) {
        this.$refs.scrollbar.$refs.container.addEventListener('ps-y-reach-start', this.loadMore);
      }
    },

    removeScrollbarEvent() {
      if ('scrollbar' in this.$refs) {
        this.$refs.scrollbar.$refs.container.removeEventListener('ps-y-reach-start', this.loadMore);
      }
    },

    scrollToBottom() {
      const overview = document.getElementById('overview');

      if (overview) {
        document.getElementById('wrap').scrollTop = overview.clientHeight;
      }
    },

    sendMessage() {
      this.isProcessing = true;

      store.dispatch('messages/add', {recipient: this.recipient.name, text: this.text, assets: this.assets})
        .then(() => {
          this.errors = {};
          this.assets = [];
          this.text = null;

          this.$nextTick(() => this.scrollToBottom());
          this.tab = 'body';

          this.$removeDraft(DRAFT_KEY);
        })
        .catch(err => this.errors = err.response.data.errors)
        .finally(() => this.isProcessing = false);
    },

    typing() {
      ws.subscribe(this.privateChannel).whisper('pm-typing', {recipient: this.sender});
    },

    listenForMessage() {
      this.channel().on('PmCreated', ({ data }) => {
        if (data.user.id === this.recipient.id) {
          store.commit('messages/add', data);

          this.$nextTick(() => {
            this.scrollToBottom();
            this.markAllAsRead();
          });
        }
      });

      // message was read by recipient
      this.channel().on('PmRead', data => {
        const message = this.messages.find(item => item.text_id === data.text_id);

        if (message) {
          store.commit('messages/mark', message);
        }
      });
    },

    listenForTyping() {
      this.timer = null;

      ws.subscribe(this.privateChannel).on('pm-typing', data => {
        if (this.recipient.id !== data.recipient.id) {
          return;
        }

        this.isTyping = true;

        clearTimeout(this.timer);

        this.timer = setTimeout(() => this.isTyping = false, 1000);<commit_msg>bugfix<commit_after>import store from '../store';
import { mapState } from 'vuex';
import Vue from 'vue';
import PerfectScrollbar from '../components/perfect-scrollbar';
import VuePm from '../components/pm/message.vue';
import VueAutosave from '../plugins/autosave';
import VuePrompt from '../components/forms/prompt.vue';
import VueMarkdown from '../components/forms/markdown.vue';
import VueButton from '../components/forms/button.vue';
import VueError from '../components/forms/error.vue';
import {default as ws} from '../libs/realtime.ts';
import VuePaste from '../plugins/paste.js';
import VueModal from '../components/modal.vue';
import VuePagination from '../components/pagination.vue';
import VueAutocomplete from '../components/forms/autocomplete.vue';
import differenceInMinutes from 'date-fns/differenceInMinutes';
import parseISO from 'date-fns/parseISO';
import {default as axiosErrorHandler} from "@/libs/axios-error-handler";
import VueNotifications from "vue-notification";

Vue.use(VueAutosave);
Vue.use(VueNotifications, {componentName: 'vue-notifications'});
Vue.use(VuePaste, {url: '/assets'});

axiosErrorHandler(message => Vue.notify({type: 'error', text: message}));

const DRAFT_KEY = 'pm';
const INBOX = 1;

new Vue({
  el: '#app-pm',
  delimiters: ['${', '}'],
  components: {
    'perfect-scrollbar': PerfectScrollbar,
    'vue-pm': VuePm,
    'vue-prompt': VuePrompt,
    'vue-button': VueButton,
    'vue-modal': VueModal,
    'vue-markdown': VueMarkdown,
    'vue-pagination': VuePagination,
    'vue-autocomplete': VueAutocomplete,
    'vue-error': VueError
  },
  data() {
    return {
      recipient: window.data.recipient,
      sender: window.data.sender,
      text: '',
      isProcessing: false,
      errors: {},
      items: [],
      assets: [],
      tab: 'body',
      isTyping: false
    };
  },
  store,
  created() {
    // fill vuex with data passed from controller to view
    store.commit('messages/init', {messages: window.data.messages, total: window.data.total, perPage: window.data.per_page, currentPage: window.data.current_page});

    this.text = this.$loadDraft(DRAFT_KEY);
    this.$watch('text', newValue => this.$saveDraft(DRAFT_KEY, newValue));
  },
  mounted() {
    this.listenForMessage();
    this.listenForTyping();
    this.scrollToBottom();
    this.addScrollbarEvent();
    this.markAllAsRead();
  },
  methods: {
    addScrollbarEvent() {
      if ('scrollbar' in this.$refs) {
        this.$refs.scrollbar.$refs.container.addEventListener('ps-y-reach-start', this.loadMore);
      }
    },

    removeScrollbarEvent() {
      if ('scrollbar' in this.$refs) {
        this.$refs.scrollbar.$refs.container.removeEventListener('ps-y-reach-start', this.loadMore);
      }
    },

    scrollToBottom() {
      const overview = document.getElementById('overview');

      if (overview) {
        document.getElementById('wrap').scrollTop = overview.clientHeight;
      }
    },

    sendMessage() {
      this.isProcessing = true;

      store.dispatch('messages/add', {recipient: this.recipient.name, text: this.text, assets: this.assets})
        .then(() => {
          this.errors = {};
          this.assets = [];
          this.text = null;

          this.$nextTick(() => this.scrollToBottom());
          this.tab = 'body';

          this.$removeDraft(DRAFT_KEY);
        })
        .catch(err => this.errors = err.response.data.errors)
        .finally(() => this.isProcessing = false);
    },

    typing() {
      ws.subscribe(this.privateChannel).whisper('pm-typing', {recipient: this.sender});
    },

    listenForMessage() {
      this.channel().on('PmCreated', ({ data }) => {
        if (data.user.id === this.recipient.id) {
          store.commit('messages/add', data);

          this.$nextTick(() => {
            this.scrollToBottom();
            this.markAllAsRead();
          });
        }
      });

      // message was read by recipient
      this.channel().on('PmRead', data => {
        const message = this.messages.find(item => item.text_id === data.text_id);

        if (message) {
          store.commit('messages/mark', message);
        }
      });
    },

    listenForTyping() {
      if (!('editor' in this.$refs)) {
        return;
      }

      this.timer = null;

      ws.subscribe(this.privateChannel).on('pm-typing', data => {
        if (this.recipient.id !== data.recipient.id) {
          return;
        }

        this.isTyping = true;

        clearTimeout(this.timer);

        this.timer = setTimeout(() => this.isTyping = false, 1000);
{'fraction_non_alphanumeric': 0.1620130228451606, 'fraction_numerical': 0.0011036309458117206, 'mean_word_length': 2.8430873621713317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '5142910', 'n_tokens_mistral': 2900, 'n_tokens_neox': 2797, 'n_words': 538}