ivar_n před 2 roky
rodič
revize
8735d92eaf

+ 1 - 1
src/App.js

@@ -79,7 +79,7 @@ const history = createHistory()
 
 function App() {
 
-  window.addEventListener("contextmenu", e => e.preventDefault());
+  // window.addEventListener("contextmenu", e => e.preventDefault());
 
   return (
     <Router history={history}>

+ 7 - 2
src/actions/msgActions.js

@@ -177,7 +177,7 @@ export const actionGetMsgById = (msgId) => (
 
 
 
-const actionUpdateMsg = (chatId, text, media, msgId) => (
+const actionUpdateMsg = (chatId, text, media, replyedMsg, msgId) => (
    actionPromise('updateMsg', gql(`mutation updateMsg($msg: MessageInput) {
       MessageUpsert(message: $msg) {
          _id
@@ -216,7 +216,12 @@ const actionUpdateMsg = (chatId, text, media, msgId) => (
             _id
          }
       }
-   }`, { msg: { _id: msgId, text, chat: {_id: chatId}, media } }
+   }`, { msg: {_id: msgId, 
+               text, 
+               chat: {_id: chatId}, 
+               media, 
+               replyTo: {_id: replyedMsg}  
+            } }
    ))
 )
 

+ 12 - 10
src/components/Msg.jsx

@@ -194,9 +194,7 @@ const Msg = ({ msg, myProfile, onEdit }) => {
             //    left: 300
             // }}
          >
-
-
-                                    
+              
          <List sx={{ width: '100%', maxWidth: 300, bgcolor: 'background.paper' }}>
 
             <ListItemButton onClick={() => {
@@ -205,19 +203,23 @@ const Msg = ({ msg, myProfile, onEdit }) => {
                Ответить
             </ListItemButton>
 
-            <ListItemButton onClick={() => {
-               onEdit(msg);
-               handleClose()
-            }} >
-               Редактировать
-            </ListItemButton>
+            {  (myId === owner._id) && 
+
+               <ListItemButton onClick={() => {
+                  onEdit(msg);
+                  handleClose()
+               }} >
+                  Редактировать
+               </ListItemButton>
+            }
+
 
          </List>
 
 
        </Popover>
 
-         <div onContextMenu={handleClick}
+         <div onClick={handleClick}
 
             style={  (myId === owner._id) ? 
                         ( (nextOwner === owner._id) ? 

+ 9 - 8
src/components/SendingField.jsx

@@ -236,16 +236,16 @@ const MsgDropZone = ({ setText, setFiles, setMsgId, files, text, onEnter }) => {
 }
 
 
-const SendingField = ({ chatId, onSend, msg }) => {
+const SendingField = ({ chatId, onSend, msg, myId }) => {
 
-   const [text, setText] = useState(msg?.text || '')
-   const [files, setFiles] = useState(msg?.media.map(mediaFile =>( {...mediaFile, url: backURL +  mediaFile.url} )) || [])
-   const [msgId, setMsgId] = useState(msg?._id)
+   const [text, setText] = useState( (myId === msg?.owner._id && msg?.text) || '')
+   const [files, setFiles] = useState( (myId === msg?.owner._id && msg?.media.map(mediaFile =>( {...mediaFile, url: backURL +  mediaFile.url} )) ) || [])
+   const [msgId, setMsgId] = useState( (myId === msg?.owner._id && msg?._id) || undefined  )
 
    useEffect(() => {
-      setText(msg?.text || '')
-      setFiles(msg?.media.map(mediaFile =>( {...mediaFile, url: backURL +  mediaFile.url} )) || [])
-      setMsgId(msg?._id)
+      setText( (myId === msg?.owner._id && msg?.text) || '')
+      setFiles( (myId === msg?.owner._id && msg?.media.map(mediaFile =>( {...mediaFile, url: backURL +  mediaFile.url} )) ) || [])
+      setMsgId( (myId === msg?.owner._id && msg?._id) || undefined )
    },[msg])
 
    return (
@@ -299,4 +299,5 @@ const SendingField = ({ chatId, onSend, msg }) => {
       </Box>
    )
 }
-export const CSendingField= connect( null, {onSend: actionSendMsg})(SendingField)
+export const CSendingField= connect( state => ({ myId: state.promise.myProfile?.payload?._id || null}),
+                           {onSend: actionSendMsg})(SendingField)

+ 1 - 1
src/reducers/chatsReducer.js

@@ -15,7 +15,7 @@
 // }
 
 // payload - или массив чатов или массив сообщений или 1 чат
- export function chatsReducer (state={}, {type, payload}) {
+ export function chatsReducer (state, {type, payload}) {
     if (!state) {
         return {}
     }