<commit_before>/**
 * Created by quasarchimaere on 30.07.2019.
 */
import React from "react";
import PropTypes from "prop-types";
import { relativeTime } from "../../won-label-utils.js";
import { useSelector } from "react-redux";
import { selectLastUpdateTime } from "../../redux/selectors/general-selectors.js";
import * as messageUtils from "../../redux/utils/message-utils.js";

import "~/style/_connection-message-status.scss";
import ico16_indicator_warning from "~/images/won-icons/ico16_indicator_warning.svg";
import ico36_added_circle from "~/images/won-icons/ico36_added_circle.svg";

export default function WonConnectionMessageStatus({ message }) {
  const lastUpdateTime = useSelector(selectLastUpdateTime);

  const isOutgoingMessage = messageUtils.isOutgoingMessage(message);
  const isFailedToSend = messageUtils.hasFailedToSend(message);
  const isReceivedByOwn = messageUtils.isReceivedByOwn(message);
  const isReceivedByRemote = messageUtils.isReceivedByRemote(message);

  let statusIcons;

  if (isOutgoingMessage) {
    let icons;
    if (isFailedToSend) {
      icons = (
        <svg
          className="msgstatus__icons__icon"
          style={{ "--local-primary": "red" }}
        >
          <use
            xlinkHref={ico16_indicator_warning}
            href={ico16_indicator_warning}
          />
        </svg>
      );
    } else {
      icons = (
        <React.Fragment>
          <svg
            className={
              "msgstatus__icons__icon " + (isReceivedByOwn ? " received " : "")
            }
          >
            <use xlinkHref={ico36_added_circle} href={ico36_added_circle} />
          </svg>
          <svg
            className={
              "msgstatus__icons__icon " +
              (isReceivedByRemote ? " received " : "")
            }
          >
            <use xlinkHref={ico36_added_circle} href={ico36_added_circle} />
          </svg>
        </React.Fragment>
      );
    }

    statusIcons = <div className="msgstatus__icons">{icons}</div>;
  }

  let timeStampLabel;
  let failedLabel;
  let sendingLabel;

  if (
    !isOutgoingMessage ||
    (!isFailedToSend && (isReceivedByRemote && isReceivedByOwn))
  ) {
    timeStampLabel = (
      <div className="msgstatus__time">
        {relativeTime(lastUpdateTime, messageUtils.getDate(message))}
      </div>
    );
  }

  if (
    isOutgoingMessage &&
    !isFailedToSend &&
    (!isReceivedByRemote || !isReceivedByOwn)
  ) {
    sendingLabel = (
      <div className="msgstatus__time--pending">Sending&nbsp;&hellip;</div>
    );
  }

  if (isOutgoingMessage && isFailedToSend) {
    failedLabel = (
      <div className="msgstatus__time--failure">Sending failed</div>
    );
  }

  return (
    <won-connection-message-status>
      {statusIcons}
      {timeStampLabel}
      {sendingLabel}
      {failedLabel}
    </won-connection-message-status>
  );
}
WonConnectionMessageStatus.propTypes = {
  message: PropTypes.object.isRequired,
};<commit_msg>Refactor connection-message-status -> less vars for outgoingMessages<commit_after>/**
 * Created by quasarchimaere on 30.07.2019.
 */
import React from "react";
import PropTypes from "prop-types";
import { relativeTime } from "../../won-label-utils.js";
import { useSelector } from "react-redux";
import { selectLastUpdateTime } from "../../redux/selectors/general-selectors.js";
import * as messageUtils from "../../redux/utils/message-utils.js";

import "~/style/_connection-message-status.scss";
import ico16_indicator_warning from "~/images/won-icons/ico16_indicator_warning.svg";
import ico36_added_circle from "~/images/won-icons/ico36_added_circle.svg";

export default function WonConnectionMessageStatus({ message }) {
  const lastUpdateTime = useSelector(selectLastUpdateTime);

  const isOutgoingMessage = messageUtils.isOutgoingMessage(message);

  if (isOutgoingMessage) {
    const isFailedToSend = messageUtils.hasFailedToSend(message);

    let icons;
    let label;

    if (isFailedToSend) {
      icons = (
        <svg
          className="msgstatus__icons__icon"
          style={{ "--local-primary": "red" }}
        >
          <use
            xlinkHref={ico16_indicator_warning}
            href={ico16_indicator_warning}
          />
        </svg>
      );
      label = <div className="msgstatus__time--failure">Sending failed</div>;
    } else {
      const isReceivedByOwn = messageUtils.isReceivedByOwn(message);
      const isReceivedByRemote = messageUtils.isReceivedByRemote(message);

      icons = (
        <React.Fragment>
          <svg
            className={
              "msgstatus__icons__icon " + (isReceivedByOwn ? " received " : "")
            }
          >
            <use xlinkHref={ico36_added_circle} href={ico36_added_circle} />
          </svg>
          <svg
            className={
              "msgstatus__icons__icon " +
              (isReceivedByRemote ? " received " : "")
            }
          >
            <use xlinkHref={ico36_added_circle} href={ico36_added_circle} />
          </svg>
        </React.Fragment>
      );

      label =
        isReceivedByRemote && isReceivedByOwn ? (
          <div className="msgstatus__time">
            {relativeTime(lastUpdateTime, messageUtils.getDate(message))}
          </div>
        ) : (
          <div className="msgstatus__time--pending">Sending&nbsp;&hellip;</div>
        );
    }

    return (
      <won-connection-message-status>
        <div className="msgstatus__icons">{icons}</div>
        {label}
      </won-connection-message-status>
    );
  } else {
    return (
      <won-connection-message-status>
        <div className="msgstatus__time">
          {relativeTime(lastUpdateTime, messageUtils.getDate(message))}
        </div>
      </won-connection-message-status>
    );
  }
}
WonConnectionMessageStatus.propTypes = {
  message: PropTypes.object.isRequired,
};
{'fraction_non_alphanumeric': 0.12502129109180718, 'fraction_numerical': 0.009538409129620166, 'mean_word_length': 2.6024539877300614, 'pattern_counts': {'":': 2, '<': 49, '<?xml version=': 0, '>': 50, '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': '3115365', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1731, 'n_words': 284}