{"size": 575, "ext": "js", "max_stars_repo_path": "src/store/middlewares.js", "max_stars_repo_name": "alex-l-morozov/gb-reactjs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/store/middlewares.js", "max_issues_repo_name": "alex-l-morozov/gb-reactjs", "max_issues_repo_issues_event_min_datetime": "2021-08-02T07:35:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-02T07:35:22.000Z", "max_forks_repo_path": "src/store/middlewares.js", "max_forks_repo_name": "alex-l-morozov/gb-reactjs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 23.9583333333, "max_line_length": 61, "alphanum_fraction": 0.5930434783}
import { ADD_CHAT, SEND_MESSAGE } from "./chats/actionTypes";
import { addChat, sendMessage } from "./chats/actions";
import { AUTHORS } from "../constants/authors";

export const middleware = (store) => (next) => (action) => {
  console.log(action.type);

  if (
    action.type === SEND_MESSAGE &&
    action.payload.message.author !== AUTHORS.robot
  ) {
    setTimeout(() => {
      store.dispatch(
        sendMessage(action.payload.chatId, {
          text: "generated",
          author: AUTHORS.robot,
        })
      );
    }, 1000);
  }

  return next(action);
};
