<commit_before>import config from 'config'
import ajax from '../utils/ajax.js'
import MapStore from './mapStore'
import auth from './auth'
import {registerSignals} from '../utils/helpers'

var api = config.apiurl_comments


function commentCompare(a, b) {return a.created > b.created ? 1 : -1}

function orderComments(comments) {
    comments.sort(commentCompare)
    for (let com of comments) {
        if (com.replies) orderComments(com.replies)
    }
    return comments
}


class Comments extends MapStore {
    constructor(signal) {
        super(signal)
        registerSignals(this,
            'sendComment sendDelete sendReport sendReply sendEdit sendVote'
        )
    }
    ajaxParams(key) {
        let url = `${api}/thread/${key}`,
            method = 'get'
        return {url, method}
    }
    processResponse(json) {
        orderComments(json.comments)
        return json
    }<commit_msg>strings -> dates in comments<commit_after>import config from 'config'
import ajax from '../utils/ajax.js'
import MapStore from './mapStore'
import auth from './auth'
import {registerSignals} from '../utils/helpers'

var api = config.apiurl_comments


function commentCompare(a, b) {return a.created > b.created ? 1 : -1}

function orderComments(comments) {
    // Substitute strings for Dates
    for (let comment of comments) {
        comment.created = new Date(comment.created)
        comment.modified = new Date(comment.modified)
    }
    comments.sort(commentCompare)
    for (let com of comments) {
        if (com.replies) orderComments(com.replies)
    }
    return comments
}


class Comments extends MapStore {
    constructor(signal) {
        super(signal)
        registerSignals(this,
            'sendComment sendDelete sendReport sendReply sendEdit sendVote'
        )
    }
    ajaxParams(key) {
        let url = `${api}/thread/${key}`,
            method = 'get'
        return {url, method}
    }
    processResponse(json) {
        orderComments(json.comments)
        return json
    }
{'fraction_non_alphanumeric': 0.10698365527488855, 'fraction_numerical': 0.001981178801386825, 'mean_word_length': 2.6861313868613137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3268452', 'n_tokens_mistral': 588, 'n_tokens_neox': 579, 'n_words': 158}