Skip to content

Commit

Permalink
HF 30 - Private groups - Fix websocket, small fixes, memo key not req…
Browse files Browse the repository at this point in the history
…uired
  • Loading branch information
1aerostorm committed Oct 2, 2024
1 parent c85c9b4 commit 0097f95
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 22 deletions.
18 changes: 18 additions & 0 deletions src/components/elements/messages/Compose/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand Down
26 changes: 21 additions & 5 deletions src/components/modules/Modals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 (
<div>
{show_login_modal && <Reveal revealStyle={{ ...modalStyle, }} onBackdropClick={this.onLoginBackdropClick}
onHide={hideLogin} show={show_login_modal}>
<LoginForm onCancel={hideLogin} />
onHide={doHideLogin} show={show_login_modal}>
<LoginForm onCancel={doHideLogin} />
</Reveal>}
{show_donate_modal && <Reveal revealStyle={{ ...modalStyle, }}
onHide={hideDonate} show={show_donate_modal}>
Expand Down Expand Up @@ -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');
Expand All @@ -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 => {
Expand Down Expand Up @@ -187,4 +203,4 @@ export default connect(
removeNotification: (key) => dispatch({type: 'REMOVE_NOTIFICATION', payload: {key}}),

})
)(Modals)
)(Modals))
41 changes: 24 additions & 17 deletions src/components/pages/Messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class Messages extends React.Component {
setTimeout(ping, 10000)
}
ping(true)
this.watchGroup(this.props.to)
}

componentDidMount() {
Expand All @@ -288,12 +289,15 @@ class Messages extends React.Component {
document.addEventListener('resume', this.onResume)
}
this.props.loginUser()
this.checkUserAuth(true)
}

checkUserAuth = (initial) => {
const memoNeed = this.props.to && this.props.to.startsWith('@')
const checkAuth = () => {
if (!this.props.username) {
this.props.checkMemo(this.props.currentUser);
}
this.props.checkAuth(this.props.currentUser, memoNeed)
}
if (!localStorage.getItem('msgr_auth')) {
if (!initial || !localStorage.getItem('msgr_auth')) {
checkAuth()
} else {
setTimeout(() => {
Expand All @@ -303,6 +307,9 @@ class Messages extends React.Component {
}

componentDidUpdate(prevProps) {
if (this.props.to !== prevProps.to) {
this.checkUserAuth()
}
if (this.props.username !== prevProps.username && this.props.username) {
this.props.fetchState(this.props.to);
this.setCallback(this.props.username)
Expand All @@ -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;
Expand All @@ -344,9 +351,7 @@ class Messages extends React.Component {
if (added)
this.markMessages2();
setTimeout(() => {
if (anotherChat || anotherKey) {
this.focusInput();
}
this.focusInput();
}, focusTimeout);
})
}
Expand Down Expand Up @@ -1112,21 +1117,23 @@ export default withRouter(connect(
dispatch => ({
loginUser: () => dispatch(user.actions.usernamePasswordLogin()),

checkMemo: (currentUser) => {
checkAuth: (currentUser, memoNeed) => {
if (!currentUser) {
hideSplash()
dispatch(user.actions.showLogin({
loginDefault: { cancelIsRegister: true, unclosable: true }
}));
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;
},
Expand Down

0 comments on commit 0097f95

Please sign in to comment.