diff --git a/src/app/organisms/profile-viewer/ProfileViewer.jsx b/src/app/organisms/profile-viewer/ProfileViewer.jsx index 17405e9..6705b29 100644 --- a/src/app/organisms/profile-viewer/ProfileViewer.jsx +++ b/src/app/organisms/profile-viewer/ProfileViewer.jsx @@ -78,19 +78,27 @@ SessionInfo.propTypes = { userId: PropTypes.string.isRequired, }; -function ProfileFooter({ userId, onRequestClose }) { +function ProfileFooter({ roomId, userId, onRequestClose }) { const [isCreatingDM, setIsCreatingDM] = useState(false); const [isIgnoring, setIsIgnoring] = useState(false); const [isUserIgnored, setIsUserIgnored] = useState(initMatrix.matrixClient.isUserIgnored(userId)); - const mx = initMatrix.matrixClient; const isMountedRef = useRef(true); + const mx = initMatrix.matrixClient; + const room = mx.getRoom(roomId); + const member = room.getMember(userId); + const isInvitable = member?.membership !== 'join' && member?.membership !== 'ban'; + + const [isInviting, setIsInviting] = useState(false); + const [isInvited, setIsInvited] = useState(member?.membership === 'invite'); useEffect(() => () => { isMountedRef.current = false; }, []); useEffect(() => { setIsUserIgnored(initMatrix.matrixClient.isUserIgnored(userId)); + setIsIgnoring(false); + setIsInviting(false); }, [userId]); async function openDM() { @@ -144,6 +152,24 @@ function ProfileFooter({ userId, onRequestClose }) { setIsIgnoring(false); } } + + async function toggleInvite() { + try { + setIsInviting(true); + let isInviteSent = false; + if (isInvited) await roomActions.kick(roomId, userId); + else { + await roomActions.invite(roomId, userId); + isInviteSent = true; + } + if (isMountedRef.current === false) return; + setIsInvited(isInviteSent); + setIsInviting(false); + } catch { + setIsInviting(false); + } + } + return (