Browse Source

fix chat-reducer

Vitalii Polishchuk 3 years ago
parent
commit
c6cd65ef3a
2 changed files with 2 additions and 3 deletions
  1. 0 1
      src/components/chatsList.js
  2. 2 2
      src/reducers/chat.js

+ 0 - 1
src/components/chatsList.js

@@ -15,7 +15,6 @@ const ChatItem = ({ id, chat }) => {
                 <div className="aside-chat-info">
 
                     <h5>{chat.title}</h5>
-                    {/* {chat.messages && chat.messages.length ? <span>{chat.messages[chat.messages.length - 1].owner.login + ": " + chat.messages[chat.messages.length - 1].text}</span> : <span>Пусто</span>} */}
                     <span>Последнее обновление: </span>
                     {chat.lastModified && <ReactTimeAgo date={+(chat.lastModified)} locale="ru" timeStyle="round" />}
                 </div>

+ 2 - 2
src/reducers/chat.js

@@ -37,7 +37,7 @@ function chatReducer(state = {}, { type, chat_id, title, createdAt, lastModified
                 [chat_id]: {
                     title: state[chat_id].title,
                     createdAt: state[chat_id].createdAt,
-                    lastModified: msg_createdAt,
+                    lastModified: state[chat_id].lastModified > msg_createdAt ? state[chat_id].lastModified : msg_createdAt,
                     avatar: state[chat_id].avatar,
                     messages: socket ? [...state[chat_id].messages, { _id: msg_id, text: msg_text, createdAt: msg_createdAt, owner: msg_owner, media: msg_media, replyTo: msg_replyTo }] : [{ _id: msg_id, text: msg_text, createdAt: msg_createdAt, owner: msg_owner, media: msg_media, replyTo: msg_replyTo }, ...state[chat_id].messages],
                     members: state[chat_id].members
@@ -63,7 +63,7 @@ function chatReducer(state = {}, { type, chat_id, title, createdAt, lastModified
                 [chat_id]: {
                     title: state[chat_id].title,
                     createdAt: state[chat_id].createdAt,
-                    lastModified: state[chat_id.createdAt],
+                    lastModified: state[chat_id].lastModified,
                     avatar: state[chat_id].avatar,
                     messages: newMessages,
                     members: state[chat_id].members