fix: check friendship
This commit is contained in:
parent
f011adddfb
commit
5de08cf49d
|
@ -1,5 +1,6 @@
|
|||
import './index.scss';
|
||||
|
||||
import {push} from 'connected-react-router';
|
||||
import React, {useRef} from 'react';
|
||||
import {useDispatch, useSelector} from 'react-redux';
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
|
@ -10,7 +11,12 @@ import {
|
|||
inputText,
|
||||
submitMessage,
|
||||
} from '@reddichat/chat/client';
|
||||
import {userSelector} from '@reddichat/user/client';
|
||||
import {
|
||||
friendshipSelector,
|
||||
userSelector,
|
||||
redditUsernameSelector,
|
||||
usernamesSelector,
|
||||
} from '@reddichat/user/client';
|
||||
|
||||
import useChannel from 'hooks/useChannel';
|
||||
|
||||
|
@ -18,9 +24,29 @@ export default function ChatSubmitMessage() {
|
|||
const channel = useChannel();
|
||||
const dispatch = useDispatch();
|
||||
const $form = useRef(null);
|
||||
const redditUsername = useSelector(redditUsernameSelector);
|
||||
const user = useSelector(userSelector);
|
||||
const usernames = useSelector(usernamesSelector);
|
||||
const text = useSelector((state) => inputChannelSelector(state, channel));
|
||||
const setText = (text) => dispatch(inputText({channel, text}));
|
||||
const friendship = useSelector(friendshipSelector);
|
||||
const areNotFriends = 'r' !== channel.type && !friendship.find(({addeeId, adderId, status}) => {
|
||||
const addeeName = usernames[addeeId];
|
||||
const adderName = usernames[adderId];
|
||||
if (
|
||||
(redditUsername === addeeName && channel.name === adderName)
|
||||
|| (redditUsername === adderName && channel.name === addeeName)
|
||||
) {
|
||||
if ('active' === status) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (areNotFriends) {
|
||||
dispatch(push('/chat'));
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div className="chat--messageSubmit">
|
||||
<form
|
||||
|
|
Loading…
Reference in New Issue
Block a user