<commit_before>import React, { Component } from 'react'
import moment from 'moment';

import { Sigil } from '/components/lib/icons/sigil';
import { Route, Link } from 'react-router-dom';
import { base64urlEncode } from '../../lib/util';

export class LinkItem extends Component {
  constructor(props) {
    super(props);
    this.state = {
      timeSinceLinkPost: this.getTimeSinceLinkPost()
    };
    this.markPostAsSeen = this.markPostAsSeen.bind(this);
  }

  componentDidMount() {
    this.updateTimeSinceNewestMessageInterval = setInterval( () => {
      this.setState({timeSinceLinkPost: this.getTimeSinceLinkPost()});
    }, 60000);
  }

  componentWillUnmount() {
    if (this.updateTimeSinceNewestMessageInterval) {
      clearInterval(this.updateTimeSinceNewestMessageInterval);
      this.updateTimeSinceNewestMessageInterval = null;
    }
  }

  getTimeSinceLinkPost() {
    return !!this.props.timestamp ?
      moment.unix(this.props.timestamp / 1000).from(moment.utc())
      : '';
  }

  markPostAsSeen() {
    api.seenLink(this.props.groupPath, this.props.url);
  }

  render() {

    let props = this.props;

    let mono = (props.nickname) ? "inter white-d" : "mono white-d";

    let URLparser = new RegExp(/((?:([\w\d\.-]+)\:\/\/?){1}(?:(www)\.?){0,1}(((?:[\w\d-]+\.)*)([\w\d-]+\.[\w\d]+))){1}(?:\:(\d+)){0,1}((\/(?:(?:[^\/\s\?]+\/)*))(?:([^\?\/\s#]+?(?:.[^\?\s]+){0,1}){0,1}(?:\?([^\s#]+)){0,1})){0,1}(?:#([^#\s]+)){0,1}/);

    let hostname = URLparser.exec(props.url);

    const seenState = props.seen
      ? "grey2"
      : "green2 pointer";
    const seenAction = props.seen
      ? ()=>{}
      : this.markPostAsSeen

    if (hostname) {
      hostname = hostname[4];
    }

    let encodedUrl = base64urlEncode(props.url);

    let comments = props.comments + " comment" + ((props.comments === 1) ? "" : "s");

    return (
      <div className="w-100 pv3 flex">
        <Sigil
          ship={"~" + props.ship}
          size={36}
          color={"#" + props.color}
            />
        <div className="flex flex-column ml2">
          <a href={props.url}
          className="w-100 flex"
          target="_blank"
          onClick={this.markPostAsSeen}>
            <p className="f8 truncate">{props.title}
              <span className="gray2 dib truncate-m mw4-m v-btm ml2">{hostname} ↗</span><commit_msg>link: correct unread color class<commit_after>import React, { Component } from 'react'
import moment from 'moment';

import { Sigil } from '/components/lib/icons/sigil';
import { Route, Link } from 'react-router-dom';
import { base64urlEncode } from '../../lib/util';

export class LinkItem extends Component {
  constructor(props) {
    super(props);
    this.state = {
      timeSinceLinkPost: this.getTimeSinceLinkPost()
    };
    this.markPostAsSeen = this.markPostAsSeen.bind(this);
  }

  componentDidMount() {
    this.updateTimeSinceNewestMessageInterval = setInterval( () => {
      this.setState({timeSinceLinkPost: this.getTimeSinceLinkPost()});
    }, 60000);
  }

  componentWillUnmount() {
    if (this.updateTimeSinceNewestMessageInterval) {
      clearInterval(this.updateTimeSinceNewestMessageInterval);
      this.updateTimeSinceNewestMessageInterval = null;
    }
  }

  getTimeSinceLinkPost() {
    return !!this.props.timestamp ?
      moment.unix(this.props.timestamp / 1000).from(moment.utc())
      : '';
  }

  markPostAsSeen() {
    api.seenLink(this.props.groupPath, this.props.url);
  }

  render() {

    let props = this.props;

    let mono = (props.nickname) ? "inter white-d" : "mono white-d";

    let URLparser = new RegExp(/((?:([\w\d\.-]+)\:\/\/?){1}(?:(www)\.?){0,1}(((?:[\w\d-]+\.)*)([\w\d-]+\.[\w\d]+))){1}(?:\:(\d+)){0,1}((\/(?:(?:[^\/\s\?]+\/)*))(?:([^\?\/\s#]+?(?:.[^\?\s]+){0,1}){0,1}(?:\?([^\s#]+)){0,1})){0,1}(?:#([^#\s]+)){0,1}/);

    let hostname = URLparser.exec(props.url);

    const seenState = props.seen
      ? "gray2"
      : "green2 pointer";
    const seenAction = props.seen
      ? ()=>{}
      : this.markPostAsSeen

    if (hostname) {
      hostname = hostname[4];
    }

    let encodedUrl = base64urlEncode(props.url);

    let comments = props.comments + " comment" + ((props.comments === 1) ? "" : "s");

    return (
      <div className="w-100 pv3 flex">
        <Sigil
          ship={"~" + props.ship}
          size={36}
          color={"#" + props.color}
            />
        <div className="flex flex-column ml2">
          <a href={props.url}
          className="w-100 flex"
          target="_blank"
          onClick={this.markPostAsSeen}>
            <p className="f8 truncate">{props.title}
              <span className="gray2 dib truncate-m mw4-m v-btm ml2">{hostname} ↗</span>
{'fraction_non_alphanumeric': 0.20577617328519857, 'fraction_numerical': 0.01996177532384795, 'mean_word_length': 2.7953263497179694, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6099373', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1637, 'n_words': 259}