Просмотр исходного кода

Fixed chat(not requests)

bugfix/app-changes
Djordje Mitrovic 3 лет назад
Родитель
Сommit
c58f8d5158
32 измененных файлов: 62 добавлений и 86 удалений
  1. 1
    0
      src/components/Admin/Sidebar/MarketplaceButton/MarketplaceButton.js
  2. 0
    2
      src/components/Cards/ChatCard/ChatCard.js
  3. 0
    2
      src/components/Cards/FilterCard/Choser/CategoryChoser/CategoryChoser.js
  4. 0
    2
      src/components/Cards/FilterCard/Choser/LocationChoser/LocationChoser.js
  5. 0
    1
      src/components/Cards/FilterCard/Choser/SubcategoryChoser/SubcategoryChoser.js
  6. 0
    1
      src/components/Cards/FilterCard/FilterDropdown/Checkbox/CheckboxDropdownList/CheckboxDropdownList.js
  7. 0
    2
      src/components/Cards/FilterCard/FilterDropdown/Checkbox/FilterCheckboxDropdown.js
  8. 0
    1
      src/components/Cards/FilterCard/FilterDropdown/Checkbox/FilterSubDropdown/FilterSmallDropdown/FilterSmallDropdown.js
  9. 0
    3
      src/components/Cards/ItemDetailsCard/OfferDetails/OfferDetails.js
  10. 14
    4
      src/components/Cards/RequestExchangeCard/RequestExchangeMessage/RequestExchangeMessage.js
  11. 2
    0
      src/components/ChatColumn/ChatColumn.js
  12. 6
    4
      src/components/DirectChat/DirectChat.js
  13. 2
    3
      src/components/DirectChat/DirectChatContent/DirectChatContent.js
  14. 0
    2
      src/components/DirectChat/DirectChatContent/DirectChatContentHeader/DirectChatContentHeader.js
  15. 4
    5
      src/components/DirectChat/DirectChatNewMessage/DirectChatNewMessage.js
  16. 0
    1
      src/components/ItemDetails/ItemDetailsHeaderCard/ItemDetailsHeaderCard.js
  17. 0
    2
      src/components/MarketPlace/Header/TooltipHeader/TooltipHeader.js
  18. 2
    0
      src/components/Modals/EditCategory/EditCategory.js
  19. 0
    1
      src/components/Popovers/MyMessages/MyMessages.js
  20. 0
    2
      src/components/TextFields/SearchField/SearchField.js
  21. 1
    7
      src/components/UserReviews/UserReviews.js
  22. 0
    1
      src/hooks/useOffers/useCategoryFilter.js
  23. 0
    1
      src/hooks/useOffers/useFilters.js
  24. 0
    1
      src/hooks/useOffers/useMyOffers.js
  25. 0
    11
      src/hooks/useOffers/useOffers.js
  26. 0
    1
      src/hooks/useOffers/usePaging.js
  27. 0
    3
      src/hooks/useOffers/useQueryString.js
  28. 0
    5
      src/hooks/useOffers/useSubcategoryFilter.js
  29. 0
    1
      src/pages/HomePage/HomePage.js
  30. 15
    6
      src/socket/socket.js
  31. 9
    8
      src/store/reducers/chat/chatReducer.js
  32. 6
    3
      src/store/saga/chatSaga.js

+ 1
- 0
src/components/Admin/Sidebar/MarketplaceButton/MarketplaceButton.js Просмотреть файл

@@ -7,6 +7,7 @@ import {
MarketplaceIcon,
} from "./MarketplaceButton.styled";
import { useTranslation } from "react-i18next";
import history from "../../../../store/utils/history";

const MarketplaceButton = () => {
const { t } = useTranslation();

+ 0
- 2
src/components/Cards/ChatCard/ChatCard.js Просмотреть файл

@@ -27,8 +27,6 @@ const ChatCard = (props) => {
const routeToItem = () => {
props.navigateToChat(chat?._id);
};
console.log(chat)

const interlocutor = useMemo(() => {
return userId === chat?.participants[0]._id ? 1 : 0;
}, [userId, chat]);

+ 0
- 2
src/components/Cards/FilterCard/Choser/CategoryChoser/CategoryChoser.js Просмотреть файл

@@ -21,10 +21,8 @@ const CategoryChoser = forwardRef((props, ref) => {
const handleSelectCategory = (category) => {
filters.category.setSelectedCategory(category);
filters.subcategory.setSelectedSubcategory({});
console.log("category 1")
props.offers.applyFilters();
};
console.log(props);
useImperativeHandle(ref, () => ({
closeSection: () => {
setIsOpened(false);

+ 0
- 2
src/components/Cards/FilterCard/Choser/LocationChoser/LocationChoser.js Просмотреть файл

@@ -15,8 +15,6 @@ const LocationChoser = forwardRef((props, ref) => {
const [isOpened, setIsOpened] = useState(false);
const filters = props.filters;

console.log(props);

const allLocations = useMemo(
() => filters.locations.allLocations || [],
[filters.locations]

+ 0
- 1
src/components/Cards/FilterCard/Choser/SubcategoryChoser/SubcategoryChoser.js Просмотреть файл

@@ -34,7 +34,6 @@ const SubcategoryChoser = forwardRef((props, ref) => {

const handleSelectSubcategory = (subcategory) => {
filters.subcategory.setSelectedSubcategory(subcategory, !props.myOffers);
console.log("props.offers")
// if (props.myOffers) props.offers?.applyFilters();
};


+ 0
- 1
src/components/Cards/FilterCard/FilterDropdown/Checkbox/CheckboxDropdownList/CheckboxDropdownList.js Просмотреть файл

@@ -17,7 +17,6 @@ const CheckboxDropdownList = (props) => {
const [isOpened, setIsOpened] = useState(false);
const handleDelete = (item) => {
props.setItemsSelected([...props.filters.filter((p) => p !== item)]);
console.log("dropdown 1")
props.offers.applyFilters();
};
const handleOpen = () => {

+ 0
- 2
src/components/Cards/FilterCard/FilterDropdown/Checkbox/FilterCheckboxDropdown.js Просмотреть файл

@@ -9,7 +9,6 @@ const FilterCheckboxDropdown = (props) => {
const [isOpened, setIsOpened] = useState(false);
const [toSearch, setToSearch] = useState("");
const { data } = props;
console.log(props);

useEffect(() => {
setDataToShow([...data]);
@@ -55,7 +54,6 @@ const FilterCheckboxDropdown = (props) => {
props.setItemsSelected([...props.filters, item]);
props.offers.applyFilters();
}
console.log("filter checkbox 1");
}
};
const handleOpen = () => {

+ 0
- 1
src/components/Cards/FilterCard/FilterDropdown/Checkbox/FilterSubDropdown/FilterSmallDropdown/FilterSmallDropdown.js Просмотреть файл

@@ -55,7 +55,6 @@ const FilterSmallDropdown = (props) => {
props.offers.applyFilters();
}
}
console.log("dropdown 2")
};

const setDropdownHandler = () => {

+ 0
- 3
src/components/Cards/ItemDetailsCard/OfferDetails/OfferDetails.js Просмотреть файл

@@ -27,7 +27,6 @@ const OfferDetails = (props) => {
const [images, setImages] = useState([]);
const [imagesCarouselModal, setImagesCarouselModal] = useState(false);

console.log(offer);

useEffect(() => {
if (props?.offer?.images) {
@@ -49,12 +48,10 @@ const OfferDetails = (props) => {
});
}
}, [props?.offer?.images]);
console.log(images);
const date = formatDateLocale(new Date(offer?._created));
const onModalClose = () => {
setImagesCarouselModal(false);
};
console.log(props);
return (
<>
<Details

+ 14
- 4
src/components/Cards/RequestExchangeCard/RequestExchangeMessage/RequestExchangeMessage.js Просмотреть файл

@@ -9,8 +9,14 @@ import {
import { useTranslation } from "react-i18next";
import { acceptExchangeSocket } from "../../../../socket/socket";
import { useDispatch, useSelector } from "react-redux";
import { selectExchange, selectRequester } from "../../../../store/selectors/exchangeSelector";
import { acceptExchange, setRequester } from "../../../../store/actions/exchange/exchangeActions";
import {
selectExchange,
selectRequester,
} from "../../../../store/selectors/exchangeSelector";
import {
acceptExchange,
setRequester,
} from "../../../../store/actions/exchange/exchangeActions";
import { addNewMessage } from "../../../../store/actions/chat/chatActions";
import { convertLocalDateToUTCDate } from "../../../../util/helpers/dateHelpers";
import requesterStatus from "../../../../constants/requesterStatus";
@@ -36,7 +42,9 @@ const RequestExchangeMessage = (props) => {
addNewMessage({
_id: props.chatId,
message: {
userId: props.userId,
user: {
_id: props.userId,
},
text: "",
isAcceptRequest: true,
_created: convertLocalDateToUTCDate(new Date()),
@@ -65,7 +73,9 @@ const RequestExchangeMessage = (props) => {
onClick={handleAcceptExchange}
disabled={props.haveIAccepted}
>
{props.haveIAccepted ? t("messages.acceptedRequest") : t("messages.acceptRequest")}
{props.haveIAccepted
? t("messages.acceptedRequest")
: t("messages.acceptRequest")}
</RequestExchangeMessageButton>
</RequestExchangeMessageButtonsContainer>
</RequestExchangeMessageContainer>

+ 2
- 0
src/components/ChatColumn/ChatColumn.js Просмотреть файл

@@ -61,6 +61,8 @@ export const ChatColumn = (props) => {
return;
}
addMessageListener(({ succeed, data }) => {
console.log(data);

if (succeed) {
dispatch(
addNewMessage({

+ 6
- 4
src/components/DirectChat/DirectChat.js Просмотреть файл

@@ -109,7 +109,6 @@ const DirectChat = () => {
}, [exchange, amIBuyer]);

const interlocutorObject = useMemo(() => {
console.log(offer);
if (location?.state?.offerId) {
return offer?.user;
}
@@ -131,6 +130,7 @@ const DirectChat = () => {
// Listener to socket.IO chat
useEffect(() => {
addMessageListener(({ succeed, data }) => {
console.log(data);
if (succeed) {
if (
[...allChats].find((item) => {
@@ -170,11 +170,11 @@ const DirectChat = () => {
}
};
const handleAcceptExchange = () => {
console.log(chat)
let interlocutor = userId === chat?.participants[0]._id ? 1 : 0;
acceptExchangeSocket(
chat?._id,
userId,
chat?.interlocutor?._id,
chat?.participants[interlocutor]._id,
() => {
dispatch(
acceptExchange({
@@ -185,7 +185,9 @@ const DirectChat = () => {
addNewMessage({
_id: chat?._id,
message: {
userId,
user: {
_id: userId
},
isAcceptRequest: true,
text: "",
_created: convertLocalDateToUTCDate(new Date()),

+ 2
- 3
src/components/DirectChat/DirectChatContent/DirectChatContent.js Просмотреть файл

@@ -34,12 +34,11 @@ const DirectChatContent = (props) => {
behaviour: "smooth",
});
window.scrollTo({ top: document.body.scrollHeight, behavior: "smooth" });
}, [props?.chat?.chat?.messages, messagesRef, isLoadingChatContent]);
}, [props?.chat?.messages, messagesRef, isLoadingChatContent]);

const handleRefresh = () => {
props.refreshChat();
};
console.log(props);
return (
<>
{isLoadingChatContent || isLoadingChatContent === undefined ? (
@@ -52,7 +51,7 @@ const DirectChatContent = (props) => {
/>
<MessagesList ref={messagesRef} exchangeState={props?.exchangeState}>
{messages?.map((item) => {
const isMyMessage = userId === item.userId;
const isMyMessage = userId === item.user?._id;
const image = isMyMessage
? myProfileImage
: interlocutorProfileImage;

+ 0
- 2
src/components/DirectChat/DirectChatContent/DirectChatContentHeader/DirectChatContentHeader.js Просмотреть файл

@@ -32,7 +32,6 @@ const DirectChatContentHeader = (props) => {
const [phonePopoverAnchorEl, setPhonePopoverAnchorEl] = useState(null);
const { isMobile } = useIsMobile();
const mineProfileBlocked = useSelector(selectAmIBlocked);
console.log(props)
const togglePhonePopover = (event) => {
if (props.interlocutor?.company?.contacts?.telephone) {
setShowPhonePopover((prevState) => !prevState);
@@ -50,7 +49,6 @@ const DirectChatContentHeader = (props) => {
})
);
};
console.log("in", props);
return (
<>
<DirectChatContentHeaderContainer>

+ 4
- 5
src/components/DirectChat/DirectChatNewMessage/DirectChatNewMessage.js Просмотреть файл

@@ -32,10 +32,8 @@ const DirectChatNewMessage = (props) => {
const location = useLocation();
const history = useHistory();
const userId = useSelector(selectUserId);
console.log(props)
const handleSend = useCallback(
(newChatId = undefined) => {
console.log(props?.chat?._id);
if (typedValue?.length === 0) return;
if (props?.chat?._id) {
const chatId = props.chat?._id || newChatId;
@@ -44,7 +42,9 @@ const DirectChatNewMessage = (props) => {
addNewMessage({
_id: chatId,
message: {
userId,
user: {
_id: userId,
},
text: typedValue,
_created: convertLocalDateToUTCDate(new Date()),
},
@@ -62,7 +62,6 @@ const DirectChatNewMessage = (props) => {
},
[typedValue, props.chat?._id, userId, props.interlocutor]
);
console.log(exchange);
const handleMessageSendSuccess = (newChatId) => {
history.replace(`${newChatId}`);
};
@@ -86,7 +85,7 @@ const DirectChatNewMessage = (props) => {
startNewChat({
offerId,
message: typedValue,
interlocutorUserId: props.interlocutor.userId,
interlocutorUserId: props.interlocutor._id,
handleMessageSendSuccess,
})
);

+ 0
- 1
src/components/ItemDetails/ItemDetailsHeaderCard/ItemDetailsHeaderCard.js Просмотреть файл

@@ -35,7 +35,6 @@ const ItemDetailsHeaderCard = (props) => {
const { t } = useTranslation();
const offer = useMemo(() => {
if (props.offer) {
console.log("itemDetailsHeader: ", props.offer)
if (props.offer._id === routeMatch.params.offerId) {
return props.offer;
}

+ 0
- 2
src/components/MarketPlace/Header/TooltipHeader/TooltipHeader.js Просмотреть файл

@@ -31,12 +31,10 @@ const TooltipHeader = (props) => {
const handleClickCategory = () => {
props?.offers?.filters?.locations.clear();
props?.offers?.filters?.subcategory.clear();
console.log("tooltip 1")
props?.offers?.applyFilters();
};
const handleClickSubcategory = () => {
props?.offers?.filters?.locations.clear();
console.log("tooltip 2")
props?.offers?.applyFilters();
};
const goBack = () => {

+ 2
- 0
src/components/Modals/EditCategory/EditCategory.js Просмотреть файл

@@ -52,10 +52,12 @@ const EditCategory = (props) => {
// };

const closeModalHandler = () => {
console.log("closed")
dispatch(closeModal());
};

const handleApiResponseSuccess = () => {
console.log("succes")
if (clickedOnNext) {
formik.resetForm();
inputRef.current.focus();

+ 0
- 1
src/components/Popovers/MyMessages/MyMessages.js Просмотреть файл

@@ -41,7 +41,6 @@ export const MyMessages = (props) => {
}
}, [userId]);
useEffect(() => {
console.log(chats);
if (chats?.length > 0) {
setLastChats([...convertMessages(chats)]);
}

+ 0
- 2
src/components/TextFields/SearchField/SearchField.js Просмотреть файл

@@ -11,7 +11,6 @@ const SearchField = (props) => {
// Event keycode 13 = ENTER keycode
if (event.keyCode === 13) {
event.preventDefault();
console.log("iz search1")
handleSearch();
}
},
@@ -27,7 +26,6 @@ const SearchField = (props) => {
searchRef.current.removeEventListener("keyup", listener);
};
const handleSearch = () => {
console.log("iz search 2")
if (props.isAdmin) {
if (props.handleSearch) props.handleSearch(searchRef.current.value);
else search.searchOffersImmediately(searchRef.current.value);

+ 1
- 7
src/components/UserReviews/UserReviews.js Просмотреть файл

@@ -20,7 +20,6 @@ import { useRouteMatch } from "react-router-dom";
import {
fetchReviews,
setReviews,
fetchReviewsAsAdmin,
} from "../../store/actions/review/reviewActions";
import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors";
import SkeletonUserReviews from "./SkeletonUserReviews/SkeletonUserReviews";
@@ -54,15 +53,10 @@ const UserReviews = (props) => {
)
);


useEffect(() => {
let idProfile = routeMatch.params?.profileId;
if (idProfile) {
if (props.isAdmin) {
dispatch(fetchReviewsAsAdmin(idProfile));
} else {
dispatch(fetchReviews(idProfile));
}
dispatch(fetchReviews(idProfile));
}

// if (props.profileReviews && routeMatch.params?.profileId) {

+ 0
- 1
src/hooks/useOffers/useCategoryFilter.js Просмотреть файл

@@ -17,7 +17,6 @@ const useCategoryFilter = () => {

useEffect(() => {
setSelectedCategoryLocally(selectedCategory);
console.log("sleectedCat")
}, [selectedCategory]);

// Set selected category locally in state

+ 0
- 1
src/hooks/useOffers/useFilters.js Просмотреть файл

@@ -21,7 +21,6 @@ const useFilters = (clearAll = false, applyFilters = () => {}) => {
if (category.selectedCategoryLocally?._id) sumOfFiltersChosen++;
if (subcategory.selectedSubcategoryLocally?._id) sumOfFiltersChosen++;
sumOfFiltersChosen += locations.selectedLocationsLocally.length;
console.log("numOfFiltersChosen");
return sumOfFiltersChosen;
}, [
category.selectedCategoryLocally,

+ 0
- 1
src/hooks/useOffers/useMyOffers.js Просмотреть файл

@@ -39,7 +39,6 @@ const useMyOffers = () => {
// Filter, search and sort all mine offers
const allOffersToShow = useMemo(() => {
let mineOffersFiltered = [...mineOffers];
console.log(filters)
// Filter mine offers by category
if (filters.category.selectedCategoryLocally?.name)
mineOffersFiltered = mineOffersFiltered.filter(

+ 0
- 11
src/hooks/useOffers/useOffers.js Просмотреть файл

@@ -46,7 +46,6 @@ const useOffers = () => {
sorting
);
dispatch(setQueryString(convertQueryStringForBackend(newQueryString)));
console.log("useoff apply")
};

const filters = useFilters(false, apply);
@@ -71,7 +70,6 @@ const useOffers = () => {
dispatch(setHeaderString(makeHeaderStringHelper({})));
history.location.state = {};
}
console.log("history.log");
}, [history.location]);

// On every change of query string, new header string should be created
@@ -79,12 +77,10 @@ const useOffers = () => {
useEffect(() => {
const headerStringLocal = makeHeaderStringHelper(filters);
dispatch(setHeaderString(headerStringLocal));
console.log("queryStringHook.queryString, filtersCleared")
}, [queryStringHook.queryString, filtersCleared]);

// Initially set category, location and subcategory based on query string
useEffect(() => {
console.log("!!!!!!!!!!queryStringHook.isInitiallyLoaded")
if (queryStringHook.isInitiallyLoaded) {
const queryObject = queryStringHook.queryObject;
if (KEY_CATEGORY in queryObject) {
@@ -139,28 +135,23 @@ const useOffers = () => {
setFiltersCleared(false);
apply();
}
console.log("filtersCleared")
}, [filtersCleared]);

const applyFilters = () => {
console.log("applyfilters")
setFiltersCleared(true);
};
const clearFiltersAndApply = () => {
console.log("applyfilters")
clear();
setFiltersCleared(true);
};
const applySorting = () => {
console.log("applyfilters")
paging.changePage(1);
setFiltersCleared(true);
};
const applySearch = () => {
console.log("applyfilters")
paging.changePage(1);
setFiltersCleared(true);
};
@@ -175,7 +166,6 @@ const useOffers = () => {
if (queryStringHook.isInitiallyLoaded) {
search.searchOffers(search.searchString);
}
console.log("search log")
}, [search.searchString]);

// Clears only filters(does not clear sorting and search)
@@ -183,7 +173,6 @@ const useOffers = () => {
filters.clear();
paging.changePage(1);
setFiltersCleared(true);
console.log("clear log")
};

const clear = () => {

+ 0
- 1
src/hooks/useOffers/usePaging.js Просмотреть файл

@@ -8,7 +8,6 @@ const usePaging = (applyAllFilters, disableScroll) => {
// except on initial load
useEffect(() => {
if (isInitallyLoaded && applyAllFilters) {
console.log("paging apply")
applyAllFilters();
}
if (!disableScroll) {

+ 0
- 3
src/hooks/useOffers/useQueryString.js Просмотреть файл

@@ -33,7 +33,6 @@ const useQueryString = () => {
} else {
setHistoryStateCleared(true);
}
console.log("history location querystr")
}, [history.location]);

// Set initially loaded to true on initial load
@@ -45,7 +44,6 @@ const useQueryString = () => {
) {
setIsInitallyLoaded(true);
}
console.log("querystr")
}, [queryString]);

// Updating offers on query string change
@@ -59,7 +57,6 @@ const useQueryString = () => {
search: convertQueryStringForFrontend(queryString),
});
}
console.log("querystr, isinit")
}, [queryString, isInitiallyLoaded]);

return {

+ 0
- 5
src/hooks/useOffers/useSubcategoryFilter.js Просмотреть файл

@@ -33,13 +33,9 @@ const useSubcategoryFilter = (applyFilters = () => {}) => {
// if (immediateApply) {
dispatch(setFilteredSubcategory(subcategory));
// }
console.log("funk");
};

const apply = () => {
console.log("apply");
console.log("SELECTED SUB", selectedSubcategory);
console.log("SELECTED SUBLOCALLY", selectedSubcategoryLocally);
if (
Number(selectedSubcategory?._id) !==
Number(selectedSubcategoryLocally?._id)
@@ -48,7 +44,6 @@ const useSubcategoryFilter = (applyFilters = () => {}) => {
};

const clear = () => {
console.log("clear");
setSelectedSubcategoryLocally(initialOption);
dispatch(setFilteredSubcategory(initialOption));
};

+ 0
- 1
src/pages/HomePage/HomePage.js Просмотреть файл

@@ -17,7 +17,6 @@ const HomePage = () => {
const toggleFilters = () => {
setFiltersOpened((prevFiltersOpened) => !prevFiltersOpened);
};
console.log("rerender")
return (
<HomePageContainer>
<MainLayout

+ 15
- 6
src/socket/socket.js Просмотреть файл

@@ -1,8 +1,8 @@
import io from "socket.io-client";

export const socket = io("https://trampa-api-test.dilig.net/", {
// export const socket = io("http://localhost:3001/", {
// export const socket = io(process.env.REACT_APP_BASE_API_URL, {
// export const socket = io("http://localhost:3001/", {
// export const socket = io(process.env.REACT_APP_BASE_API_URL, {
transports: ["websocket"],
reconnectionAttempts: 5,
});
@@ -20,19 +20,28 @@ export const sendMessage = (chatId, userId, text, receiverUserId) => {
chatId,
receiverUserId,
message: {
userId,
user: {
_id: userId,
},
text,
},
});
};
export const acceptExchangeSocket = (chatId, userId, receiverUserId, callbackFn) => {
export const acceptExchangeSocket = (
chatId,
userId,
receiverUserId,
callbackFn
) => {
socket.emit("private_message", {
chatId,
receiverUserId,
message: {
userId,
user: {
_id: userId
},
isAcceptRequest: true,
text: ""
text: "",
},
});
callbackFn();

+ 9
- 8
src/store/reducers/chat/chatReducer.js Просмотреть файл

@@ -47,24 +47,25 @@ function clearChats() {
}
function addNewMessage(state, { payload }) {
let allChats = [...state.latestChats];
console.log(state);
console.log("state", state);
let chat = allChats.find((item) => item._id === payload._id);
console.log("chat: ", chat);
if (chat) {
chat = {
...chat,
messages: [...chat.messages, payload.message],
};
console.log("newchat: ", chat);
allChats = allChats.filter((item) => item._id !== chat._id);
console.log("allchats1: ", allChats);
allChats = [chat, ...allChats];
console.log("allchats2: ", allChats);
}
let newSelectedChat = {};
if (state.selectedChat.chat) {
newSelectedChat = { ...state.selectedChat };
if (newSelectedChat._id === chat._id)
newSelectedChat = { ...newSelectedChat, chat: chat };
} else {
newSelectedChat = { ...chat };
}
if (state.selectedChat.chat) newSelectedChat = { ...state.selectedChat };
console.log("newSelectedChat1: ", newSelectedChat);
newSelectedChat = { ...chat };
console.log("newSelectedChat2: ", newSelectedChat);
return {
...state,
latestChats: [...allChats],

+ 6
- 3
src/store/saga/chatSaga.js Просмотреть файл

@@ -91,7 +91,7 @@ function* fetchOneChat(payload) {
chatData.data.messages.forEach((item) => {
if (requester !== requesterStatus.NOONE) return;
if (item.isAcceptRequest) {
if (item.userId === userId) requester = requesterStatus.ME;
if (item.user._id === userId) requester = requesterStatus.ME;
else requester = requesterStatus.interlocutor;
}
});
@@ -113,7 +113,7 @@ function* sendMessage(payload) {
const exchange = yield select(selectExchange);
const userId = yield select(selectUserId);
yield call(attemptSendMessage, payload.payload.chatId, messageObject);
if (chat?.offer?.offer?.userId === userId && exchange.valid === false) {
if (chat?.offer?.user._id === userId && exchange.valid === false) {
yield put(validateExchange(exchange._id));
}
yield call(fetchChats);
@@ -128,6 +128,7 @@ function* sendMessage(payload) {
}
function* startNewChat(payload) {
try {
console.log(payload)
const userId = yield select(selectUserId);
const newChatData = yield call(attemptCreateNewChat, {
offerId: payload.payload.offerId,
@@ -150,7 +151,9 @@ function* startNewChat(payload) {
addNewMessage({
_id: newChatId,
message: {
userId,
user: {
_id: userId
},
text: payload.payload.message,
_created: new Date().toISOString(),
},

Загрузка…
Отмена
Сохранить