<commit_before>import { createAction } from 'redux-actions';
import SteemConnect from 'sc2-sdk';
import { createCommentPermlink } from '../helpers/steemitHelpers';

const version = require('../../package.json').version;

export const GET_COMMENTS = 'GET_COMMENTS';
export const GET_COMMENTS_START = 'GET_COMMENTS_START';
export const GET_COMMENTS_SUCCESS = 'GET_COMMENTS_SUCCESS';
export const GET_COMMENTS_ERROR = 'GET_COMMENTS_ERROR';

export const SHOW_MORE_COMMENTS = 'SHOW_MORE_COMMENTS';

export const SEND_COMMENT = 'SEND_COMMENT';
export const SEND_COMMENT_START = 'SEND_COMMENT_START';
export const SEND_COMMENT_SUCCESS = 'SEND_COMMENT_SUCCESS';
export const SEND_COMMENT_ERROR = 'SEND_COMMENT_ERROR';

export const OPEN_COMMENTING_DRAFT = 'OPEN_COMMENTING_DRAFT';
export const UPDATE_COMMENTING_DRAFT = 'UPDATE_COMMENTING_DRAFT';
export const CLOSE_COMMENTING_DRAFT = 'CLOSE_COMMENTING_DRAFT';


export const openCommentingDraft = createAction(OPEN_COMMENTING_DRAFT);
export const updateCommentingDraft = createAction(UPDATE_COMMENTING_DRAFT);
export const closeCommentingDraft = createAction(CLOSE_COMMENTING_DRAFT);

export const LIKE_COMMENT = '@comments/LIKE_COMMENT';
export const LIKE_COMMENT_START = '@comments/LIKE_COMMENT_START';
export const LIKE_COMMENT_SUCCESS = '@comments/LIKE_COMMENT_SUCCESS';
export const LIKE_COMMENT_ERROR = '@comments/LIKE_COMMENT_ERROR';

export const showMoreComments = createAction(
  SHOW_MORE_COMMENTS,
  () => null,
  meta => ({ id: meta })
);

export const RELOAD_EXISTING_COMMENT = '@comments/RELOAD_EXISTING_COMMENT';
export const reloadExistingComment = createAction(RELOAD_EXISTING_COMMENT);

const getRootCommentsList = (apiRes) => {
  return Object.keys(apiRes.content).filter((commentKey) => {
    return apiRes.content[commentKey].depth === 1;
  }).map(commentKey => apiRes.content[commentKey].id);
};


const getCommentsChildrenLists = (apiRes) => {
  let listsById = {};
  Object.keys(apiRes.content).forEach((commentKey) => {
    listsById[apiRes.content[commentKey].id] = apiRes.content[commentKey].replies.map(
      childKey => apiRes.content[childKey].id
    );
  });

  return listsById;
};

export const getComments = (postId, isFromAnotherComment = false) => {
  return (dispatch, getState, { steemAPI }) => {
    const { posts, comments } = getState();

    let content;
    if (isFromAnotherComment) {
      content = comments.comments[postId];
    } else {
      content = posts[postId];
    }

    const { category, author, permlink } = content;

    dispatch({
      type: GET_COMMENTS,
      payload: {
        promise: steemAPI.getStateAsync(`/${category}/@${author}/${permlink}`).then((apiRes) => {
          return {
            rootCommentsList: getRootCommentsList(apiRes),
            commentsChildrenList: getCommentsChildrenLists(apiRes),
            content: apiRes.content,
          };
        }),
      },
      meta: {
        id: postId,
        isReplyToComment: isFromAnotherComment,
      },
    });
  };
};

export const sendCommentV2 = (parentPost, body) =>
  (dispatch, getState) => {
    const { parent_author, parent_permlink, category, root_comment } = parentPost;
    const { auth } = getState();

    if (!auth.isAuthenticated) {
      // dispatch error
      return;
    }

    if (!body || !body.length) {
      // dispatch error
      return;
    }

    const author = auth.user.name;
    const permlink = createCommentPermlink(parent_author, parent_permlink);
    const jsonMetadata = { tags: [category], app: `busy/${version}` };

    return dispatch({
      type: SEND_COMMENT,
      payload: {
        promise: SteemConnect.comment(
          parent_author,
          parent_permlink,
          author,<commit_msg>Updated commentActions to correctly identify parent post<commit_after>import { createAction } from 'redux-actions';
import SteemConnect from 'sc2-sdk';
import { createCommentPermlink } from '../helpers/steemitHelpers';

const version = require('../../package.json').version;

export const GET_COMMENTS = 'GET_COMMENTS';
export const GET_COMMENTS_START = 'GET_COMMENTS_START';
export const GET_COMMENTS_SUCCESS = 'GET_COMMENTS_SUCCESS';
export const GET_COMMENTS_ERROR = 'GET_COMMENTS_ERROR';

export const SHOW_MORE_COMMENTS = 'SHOW_MORE_COMMENTS';

export const SEND_COMMENT = 'SEND_COMMENT';
export const SEND_COMMENT_START = 'SEND_COMMENT_START';
export const SEND_COMMENT_SUCCESS = 'SEND_COMMENT_SUCCESS';
export const SEND_COMMENT_ERROR = 'SEND_COMMENT_ERROR';

export const OPEN_COMMENTING_DRAFT = 'OPEN_COMMENTING_DRAFT';
export const UPDATE_COMMENTING_DRAFT = 'UPDATE_COMMENTING_DRAFT';
export const CLOSE_COMMENTING_DRAFT = 'CLOSE_COMMENTING_DRAFT';


export const openCommentingDraft = createAction(OPEN_COMMENTING_DRAFT);
export const updateCommentingDraft = createAction(UPDATE_COMMENTING_DRAFT);
export const closeCommentingDraft = createAction(CLOSE_COMMENTING_DRAFT);

export const LIKE_COMMENT = '@comments/LIKE_COMMENT';
export const LIKE_COMMENT_START = '@comments/LIKE_COMMENT_START';
export const LIKE_COMMENT_SUCCESS = '@comments/LIKE_COMMENT_SUCCESS';
export const LIKE_COMMENT_ERROR = '@comments/LIKE_COMMENT_ERROR';

export const showMoreComments = createAction(
  SHOW_MORE_COMMENTS,
  () => null,
  meta => ({ id: meta })
);

export const RELOAD_EXISTING_COMMENT = '@comments/RELOAD_EXISTING_COMMENT';
export const reloadExistingComment = createAction(RELOAD_EXISTING_COMMENT);

const getRootCommentsList = (apiRes) => {
  return Object.keys(apiRes.content).filter((commentKey) => {
    return apiRes.content[commentKey].depth === 1;
  }).map(commentKey => apiRes.content[commentKey].id);
};


const getCommentsChildrenLists = (apiRes) => {
  let listsById = {};
  Object.keys(apiRes.content).forEach((commentKey) => {
    listsById[apiRes.content[commentKey].id] = apiRes.content[commentKey].replies.map(
      childKey => apiRes.content[childKey].id
    );
  });

  return listsById;
};

export const getComments = (postId, isFromAnotherComment = false) => {
  return (dispatch, getState, { steemAPI }) => {
    const { posts, comments } = getState();

    let content;
    if (isFromAnotherComment) {
      content = comments.comments[postId];
    } else {
      content = posts[postId];
    }

    const { category, author, permlink } = content;

    dispatch({
      type: GET_COMMENTS,
      payload: {
        promise: steemAPI.getStateAsync(`/${category}/@${author}/${permlink}`).then((apiRes) => {
          return {
            rootCommentsList: getRootCommentsList(apiRes),
            commentsChildrenList: getCommentsChildrenLists(apiRes),
            content: apiRes.content,
          };
        }),
      },
      meta: {
        id: postId,
        isReplyToComment: isFromAnotherComment,
      },
    });
  };
};

export const sendCommentV2 = (parentPost, body) =>
  (dispatch, getState) => {
    const { category, root_comment } = parentPost;
    const parent_permlink = parentPost.permlink;
    const parent_author = parentPost.author;
    const { auth } = getState();

    if (!auth.isAuthenticated) {
      // dispatch error
      return;
    }

    if (!body || !body.length) {
      // dispatch error
      return;
    }
    debugger;
    const author = auth.user.name;
    const permlink = createCommentPermlink(parent_author, parent_permlink);
    const jsonMetadata = { tags: [category], app: `busy/${version}` };

    return dispatch({
      type: SEND_COMMENT,
      payload: {
        promise: SteemConnect.comment(
          parent_author,
          parent_permlink,
          author,
{'fraction_non_alphanumeric': 0.11382866208355367, 'fraction_numerical': 0.0007932310946589106, 'mean_word_length': 4.101146325016858, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '5028236', 'n_tokens_mistral': 2432, 'n_tokens_neox': 2360, 'n_words': 462}