|
@@ -32,7 +32,6 @@ const MessageItem = ({
|
|
// date.getSeconds().toString().padStart(2, 0);
|
|
// date.getSeconds().toString().padStart(2, 0);
|
|
|
|
|
|
return (
|
|
return (
|
|
- // <div className="list-group-item list-group-item-success m-2 gradient shadow-sm border-2">
|
|
|
|
<div
|
|
<div
|
|
className={`messageItem list-group-item m-2 gradient shadow-sm border-2 ${
|
|
className={`messageItem list-group-item m-2 gradient shadow-sm border-2 ${
|
|
myId === ownerId ? "start-right list-group-item-success text-success" : " list-group-item-light"
|
|
myId === ownerId ? "start-right list-group-item-success text-success" : " list-group-item-light"
|
|
@@ -77,9 +76,11 @@ const MessageItem = ({
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
|
|
-const MessagesList = ({ arrayOfMessages, myId }) => {
|
|
|
|
|
|
+const MessagesList = ({ messages, myId, chatId }) => {
|
|
const messagesEndRef = useRef(null); // указатель на пустой div в коце сообщений для перемотки
|
|
const messagesEndRef = useRef(null); // указатель на пустой div в коце сообщений для перемотки
|
|
|
|
|
|
|
|
+ let arrayOfMessages = messages[chatId];
|
|
|
|
+
|
|
// скролл в самый низ при приходе новых сообщений
|
|
// скролл в самый низ при приходе новых сообщений
|
|
const scrollToBottom = () => messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
const scrollToBottom = () => messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
|
|
|
|
@@ -106,18 +107,26 @@ const MessagesList = ({ arrayOfMessages, myId }) => {
|
|
|
|
|
|
const CMessagesList = connect(
|
|
const CMessagesList = connect(
|
|
(s) => ({
|
|
(s) => ({
|
|
- arrayOfMessages:
|
|
|
|
|
|
+ //FIXME: приконнектить массив сообщений
|
|
|
|
+ chatId:
|
|
s.promise.MessageFind &&
|
|
s.promise.MessageFind &&
|
|
s.promise.MessageFind.payload &&
|
|
s.promise.MessageFind.payload &&
|
|
s.promise.MessageFind.payload.data &&
|
|
s.promise.MessageFind.payload.data &&
|
|
- s.promise.MessageFind.payload.data.MessageFind,
|
|
|
|
|
|
+ s.promise.MessageFind.payload.data.MessageFind &&
|
|
|
|
+ s.promise.MessageFind.payload.data.MessageFind[0] &&
|
|
|
|
+ s.promise.MessageFind.payload.data.MessageFind[0].chat &&
|
|
|
|
+ s.promise.MessageFind.payload.data.MessageFind[0].chat._id,
|
|
|
|
+ messages: s.msg,
|
|
myId: s.auth && s.auth.payloadId,
|
|
myId: s.auth && s.auth.payloadId,
|
|
}),
|
|
}),
|
|
{}
|
|
{}
|
|
)(MessagesList);
|
|
)(MessagesList);
|
|
|
|
|
|
-const Messages = ({ avatar, _id = "", title = "No Title", getMsg }) => {
|
|
|
|
- // id чата, аватар чата
|
|
|
|
|
|
+const Messages = ({ _id = "", messages, getMsg }) => {
|
|
|
|
+ // id чата,
|
|
|
|
+
|
|
|
|
+ let avatar = messages && messages[_id] && messages[_id][0] && messages[_id][0].chat && messages[_id][0].chat.avatar;
|
|
|
|
+ let title = messages && messages[_id] && messages[_id][0] && messages[_id][0].chat && messages[_id][0].chat.title;
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (typeof doSearchMsg === "function") getMsg(_id);
|
|
if (typeof doSearchMsg === "function") getMsg(_id);
|
|
@@ -172,29 +181,34 @@ const CMessages = connect(
|
|
(s) => ({
|
|
(s) => ({
|
|
//id чата
|
|
//id чата
|
|
_id:
|
|
_id:
|
|
- s.promise.chatFindOne &&
|
|
|
|
- s.promise.chatFindOne.payload &&
|
|
|
|
- s.promise.chatFindOne.payload.data &&
|
|
|
|
- s.promise.chatFindOne.payload.data.ChatFindOne &&
|
|
|
|
- s.promise.chatFindOne.payload.data.ChatFindOne._id,
|
|
|
|
- arrayOfMessages:
|
|
|
|
- s.promise.chatFindOne &&
|
|
|
|
- s.promise.chatFindOne.payload &&
|
|
|
|
- s.promise.chatFindOne.payload.data &&
|
|
|
|
- s.promise.chatFindOne.payload.data.ChatFindOne &&
|
|
|
|
- s.promise.chatFindOne.payload.data.ChatFindOne.messages,
|
|
|
|
- avatar:
|
|
|
|
- s.promise.chatFindOne &&
|
|
|
|
- s.promise.chatFindOne.payload &&
|
|
|
|
- s.promise.chatFindOne.payload.data &&
|
|
|
|
- s.promise.chatFindOne.payload.data.ChatFindOne &&
|
|
|
|
- s.promise.chatFindOne.payload.data.ChatFindOne.avatar,
|
|
|
|
- title:
|
|
|
|
- s.promise.chatFindOne &&
|
|
|
|
- s.promise.chatFindOne.payload &&
|
|
|
|
- s.promise.chatFindOne.payload.data &&
|
|
|
|
- s.promise.chatFindOne.payload.data.ChatFindOne &&
|
|
|
|
- s.promise.chatFindOne.payload.data.ChatFindOne.title,
|
|
|
|
|
|
+ s.promise.MessageFind &&
|
|
|
|
+ s.promise.MessageFind.payload &&
|
|
|
|
+ s.promise.MessageFind.payload.data &&
|
|
|
|
+ s.promise.MessageFind.payload.data.MessageFind &&
|
|
|
|
+ s.promise.MessageFind.payload.data.MessageFind[0] &&
|
|
|
|
+ s.promise.MessageFind.payload.data.MessageFind[0].chat &&
|
|
|
|
+ s.promise.MessageFind.payload.data.MessageFind[0].chat._id,
|
|
|
|
+ messages: s.msg,
|
|
|
|
+ // s.promise.chatFindOne.payload &&
|
|
|
|
+ // s.promise.chatFindOne.payload.data &&
|
|
|
|
+ // s.promise.chatFindOne.payload.data.ChatFindOne &&
|
|
|
|
+ // s.promise.chatFindOne.payload.data.ChatFindOne.messages,
|
|
|
|
+ // avatar:
|
|
|
|
+ // s.promise.MessageFind &&
|
|
|
|
+ // s.promise.MessageFind.payload &&
|
|
|
|
+ // s.promise.MessageFind.payload.data &&
|
|
|
|
+ // s.promise.MessageFind.payload.data.MessageFind &&
|
|
|
|
+ // s.promise.MessageFind.payload.data.MessageFind[0] &&
|
|
|
|
+ // s.promise.MessageFind.payload.data.MessageFind[0].chat &&
|
|
|
|
+ // s.promise.MessageFind.payload.data.MessageFind[0].chat.avatar,
|
|
|
|
+ // title:
|
|
|
|
+ // s.promise.MessageFind &&
|
|
|
|
+ // s.promise.MessageFind.payload &&
|
|
|
|
+ // s.promise.MessageFind.payload.data &&
|
|
|
|
+ // s.promise.MessageFind.payload.data.MessageFind &&
|
|
|
|
+ // s.promise.MessageFind.payload.data.MessageFind[0] &&
|
|
|
|
+ // s.promise.MessageFind.payload.data.MessageFind[0].chat &&
|
|
|
|
+ // s.promise.MessageFind.payload.data.MessageFind[0].chat.title,
|
|
}),
|
|
}),
|
|
{ getMsg: actionGetMessagesByChatId }
|
|
{ getMsg: actionGetMessagesByChatId }
|
|
)(Messages);
|
|
)(Messages);
|