Bladeren bron

added chat exit

ivar_n 3 jaren geleden
bovenliggende
commit
b4efd0e14d

+ 12 - 6
src/actions/authActions.js

@@ -114,10 +114,7 @@ import {
    )
 
 
-
-
-   // так же нужен setUserChats
-      // дописать
+   
    // происходит когда юзер уходит сам, иначе в чат добавляются юзер, а не наоборот
    const actionUpdateUserCahts = (userId, newChats) => (
       actionPromise('updateUser', gql(`mutation updateUser($user:UserInput) {
@@ -126,10 +123,19 @@ import {
             login  
             nick
          }
-      }`, { user: {_id: userId, } }))
+      }`, { user: {_id: userId, chats: newChats } }))
    )
 
-
+   export const setUserChats = (chatId) => (
+      async (dispatch, getState) => {
+         let { promise } = getState()
+         let userId = promise.myProfile.payload._id
+         let oldChats = promise.myProfile.payload.chats
+         let newChats = oldChats.filter((chat) => chat._id !== chatId)
+         await dispatch(actionUpdateUserCahts(userId, newChats))
+         await dispatch(actionAboutMe()) 
+      }
+   )
 
 
       // не работает

+ 2 - 0
src/actions/index.js

@@ -5,6 +5,7 @@ import {
    actionFullRegister, 
    actionSetUserInfo,
    actionSetUserPass,
+   setUserChats
 } from './authActions'
 import {
    actionGetChatsByUser,
@@ -38,6 +39,7 @@ export {
    actionFullRegister, 
    actionSetUserInfo,
    actionSetUserPass,
+   setUserChats
 } 
 export {
    actionGetChatsByUser,

+ 1 - 1
src/actions/msgActions.js

@@ -53,7 +53,7 @@ export const actionGetMsgsByChat = (chatId, skipCount=0, limitCount=50) => (
          }
       }     
    }`, { 
-         q: JSON.stringify([  { "chat._id": chatId },
+         q: JSON.stringify([  { "chat._id": {$in: [chatId]} },
                               { 
                                  sort: [{_id: -1}],  
                                  skip: [skipCount], 

+ 1 - 1
src/components/Msg.jsx

@@ -219,7 +219,7 @@ const Msg = ({ msg, prevOwner, prevTime, myProfile, onEvent }) => {
                                                                               <a 
                                                                                  key={mediaObj.url} 
                                                                                  href={backURL + mediaObj.url}
-                                                                                 download    
+                                                                                 download={mediaObj.originalFileName} 
                                                                                  style={downloadStyle}                                                                       
                                                                               >
                                                                                  <div 

src/reducers/contactsReduser.js → src/reducers/contactsReducer.js


+ 3 - 0
src/reducers/findUserActions.js

@@ -17,6 +17,9 @@ export const actionUserFindOne = (userId, name='findUserOne') => (
             _id
             url
          }
+         chats {
+            _id
+         }
       }     
    }`, { 
          q: JSON.stringify([  {_id: userId}  ])