import history from "../../store/utils/history";

export const startChat = (chats, offer, userId) => {
  const chatItem = chats.find(
    (item) => item.chat.offerId === offer?._id && offer?.userId !== userId
  );
  if (chatItem !== undefined) {
    history.push(`/messages/${chatItem.chat._id}`);
  } else {
    if (offer?.userId !== userId) {
      history.push(`/messages/newMessage`, {
        offerId: offer?._id,
      });
    }
  }
};
