diff --git a/src/components/elements/messages/Compose/index.jsx b/src/components/elements/messages/Compose/index.jsx index d7b20c90..0be80a77 100644 --- a/src/components/elements/messages/Compose/index.jsx +++ b/src/components/elements/messages/Compose/index.jsx @@ -8,6 +8,18 @@ import Icon from 'app/components/elements/Icon'; import { displayQuoteMsg } from 'app/utils/MessageUtils'; import './Compose.css'; +const fixComposeSize = () => { + const sb = document.getElementsByClassName('msgs-sidebar')[0] + let cw = '100%' + if (sb) { + cw = 'calc(100% - ' + sb.offsetWidth + 'px)' + } + const compose = document.getElementsByClassName('msgs-compose')[0] + if (compose) { + compose.style.width = cw + } +} + export default class Compose extends React.Component { onKeyDown = (e) => { if (!window.IS_MOBILE_DEVICE && e.keyCode === 13) { @@ -57,12 +69,18 @@ export default class Compose extends React.Component { componentDidMount() { this.init(); + fixComposeSize() + window.addEventListener('resize', fixComposeSize) } componentDidUpdate() { this.init(); } + componentWillUnmount() { + window.removeEventListener('resize', fixComposeSize) + } + onEmojiClick = (event) => { event.stopPropagation(); diff --git a/src/components/modules/Modals.jsx b/src/components/modules/Modals.jsx index 9a370990..f4bbcba8 100644 --- a/src/components/modules/Modals.jsx +++ b/src/components/modules/Modals.jsx @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types' import {NotificationStack} from 'react-notification' import { connect } from 'react-redux'; +import { withRouter } from 'react-router' import CloseButton from 'react-foundation-components/lib/global/close-button'; import Reveal from 'react-foundation-components/lib/global/reveal'; @@ -81,11 +82,23 @@ class Modals extends React.Component { overflow: 'hidden', } + const doHideLogin = (e) => { + const goBack = () => { + const { history, } = this.props + if (history.action !== 'POP') { + history.goBack() + } else { + history.push('/') + } + } + hideLogin(e, goBack) + } + return (
{show_login_modal && - + onHide={doHideLogin} show={show_login_modal}> + } {show_donate_modal && @@ -132,7 +145,7 @@ class Modals extends React.Component { } } -export default connect( +export default withRouter(connect( state => { const loginDefault = state.user.get('loginDefault'); const loginUnclosable = loginDefault && loginDefault.get('unclosable'); @@ -150,8 +163,11 @@ export default connect( } }, dispatch => ({ - hideLogin: e => { + hideLogin: (e, goBack) => { if (e) e.preventDefault(); + if (goBack) { + goBack() + } dispatch(user.actions.hideLogin()) }, hideDonate: e => { @@ -187,4 +203,4 @@ export default connect( removeNotification: (key) => dispatch({type: 'REMOVE_NOTIFICATION', payload: {key}}), }) -)(Modals) +)(Modals)) diff --git a/src/components/pages/Messages.jsx b/src/components/pages/Messages.jsx index 23f8af5a..3abcf53c 100644 --- a/src/components/pages/Messages.jsx +++ b/src/components/pages/Messages.jsx @@ -273,6 +273,7 @@ class Messages extends React.Component { setTimeout(ping, 10000) } ping(true) + this.watchGroup(this.props.to) } componentDidMount() { @@ -288,12 +289,14 @@ class Messages extends React.Component { document.addEventListener('resume', this.onResume) } this.props.loginUser() + this.checkUserAuth(true) + } + + checkUserAuth = (initial) => { const checkAuth = () => { - if (!this.props.username) { - this.props.checkMemo(this.props.currentUser); - } + this.props.checkAuth(this.props.currentUser, this.isChat()) } - if (!localStorage.getItem('msgr_auth')) { + if (!initial || !localStorage.getItem('msgr_auth')) { checkAuth() } else { setTimeout(() => { @@ -303,7 +306,11 @@ class Messages extends React.Component { } componentDidUpdate(prevProps) { - if (this.props.username !== prevProps.username && this.props.username) { + const loggedNow = this.props.username !== prevProps.username && this.props.username + if (this.props.to !== prevProps.to || (this.isChat() && loggedNow)) { + this.checkUserAuth() + } + if (loggedNow) { this.props.fetchState(this.props.to); this.setCallback(this.props.username) } else if (this.props.to !== this.state.to) { @@ -323,9 +330,9 @@ class Messages extends React.Component { this.setState({ to: this.props.to, // protects from infinity loop }); - if (!this.props.checkMemo(currentUser)) { + /*if (!this.props.checkMemo(currentUser)) { return; - } + }*/ const anotherKey = this.props.memo_private !== prevProps.memo_private; const added = this.props.messages.size > this.state.messagesCount; let focusTimeout = prevProps.messages.size ? 100 : 1000; @@ -344,9 +351,7 @@ class Messages extends React.Component { if (added) this.markMessages2(); setTimeout(() => { - if (anotherChat || anotherKey) { - this.focusInput(); - } + this.focusInput(); }, focusTimeout); }) } @@ -911,6 +916,11 @@ class Messages extends React.Component { ); }; + isChat = () => { + const { to } = this.props + return to && to.startsWith('@') + } + isGroup = () => { const { to } = this.props return to && !to.startsWith('@') @@ -1112,7 +1122,7 @@ export default withRouter(connect( dispatch => ({ loginUser: () => dispatch(user.actions.usernamePasswordLogin()), - checkMemo: (currentUser) => { + checkAuth: (currentUser, memoNeed) => { if (!currentUser) { hideSplash() dispatch(user.actions.showLogin({ @@ -1120,13 +1130,15 @@ export default withRouter(connect( })); return false; } - const private_key = currentUser.getIn(['private_keys', 'memo_private']); - if (!private_key) { - hideSplash() - dispatch(user.actions.showLogin({ - loginDefault: { username: currentUser.get('username'), authType: 'memo', unclosable: true } - })); - return false; + if (memoNeed) { + const private_key = currentUser.getIn(['private_keys', 'memo_private']) + if (!private_key) { + hideSplash() + dispatch(user.actions.showLogin({ + loginDefault: { username: currentUser.get('username'), authType: 'memo', } + })); + return false + } } return true; },