kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Mastodon: conditionally disable chats
rodzic
a3f06badcf
commit
893c903d71
|
@ -15,6 +15,7 @@ import Icon from '../../../components/icon';
|
||||||
import ThemeToggle from '../../ui/components/theme_toggle_container';
|
import ThemeToggle from '../../ui/components/theme_toggle_container';
|
||||||
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
import { isStaff } from 'soapbox/utils/accounts';
|
import { isStaff } from 'soapbox/utils/accounts';
|
||||||
|
import { getFeatures } from 'soapbox/utils/features';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
post: { id: 'tabs_bar.post', defaultMessage: 'Post' },
|
post: { id: 'tabs_bar.post', defaultMessage: 'Post' },
|
||||||
|
@ -32,6 +33,7 @@ class TabsBar extends React.PureComponent {
|
||||||
dashboardCount: PropTypes.number,
|
dashboardCount: PropTypes.number,
|
||||||
notificationCount: PropTypes.number,
|
notificationCount: PropTypes.number,
|
||||||
chatsCount: PropTypes.number,
|
chatsCount: PropTypes.number,
|
||||||
|
features: PropTypes.object.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
|
@ -52,7 +54,7 @@ class TabsBar extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
getNavLinks() {
|
getNavLinks() {
|
||||||
const { intl: { formatMessage }, logo, account, dashboardCount, notificationCount, chatsCount } = this.props;
|
const { intl: { formatMessage }, logo, account, dashboardCount, notificationCount, chatsCount, features } = this.props;
|
||||||
const links = [];
|
const links = [];
|
||||||
if (logo) {
|
if (logo) {
|
||||||
links.push(
|
links.push(
|
||||||
|
@ -73,7 +75,7 @@ class TabsBar extends React.PureComponent {
|
||||||
<span><FormattedMessage id='tabs_bar.notifications' defaultMessage='Notifications' /></span>
|
<span><FormattedMessage id='tabs_bar.notifications' defaultMessage='Notifications' /></span>
|
||||||
</NavLink>);
|
</NavLink>);
|
||||||
}
|
}
|
||||||
if (account) {
|
if (features.chats && account) {
|
||||||
links.push(
|
links.push(
|
||||||
<NavLink key='chats' className='tabs-bar__link tabs-bar__link--chats' to='/chats' data-preview-title-id='column.chats'>
|
<NavLink key='chats' className='tabs-bar__link tabs-bar__link--chats' to='/chats' data-preview-title-id='column.chats'>
|
||||||
<IconWithCounter icon='comment' count={chatsCount} />
|
<IconWithCounter icon='comment' count={chatsCount} />
|
||||||
|
@ -155,12 +157,15 @@ const mapStateToProps = state => {
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
const reportsCount = state.getIn(['admin', 'openReports']).count();
|
const reportsCount = state.getIn(['admin', 'openReports']).count();
|
||||||
const approvalCount = state.getIn(['admin', 'awaitingApproval']).count();
|
const approvalCount = state.getIn(['admin', 'awaitingApproval']).count();
|
||||||
|
const instance = state.get('instance');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
account: state.getIn(['accounts', me]),
|
account: state.getIn(['accounts', me]),
|
||||||
logo: getSoapboxConfig(state).get('logo'),
|
logo: getSoapboxConfig(state).get('logo'),
|
||||||
notificationCount: state.getIn(['notifications', 'unread']),
|
notificationCount: state.getIn(['notifications', 'unread']),
|
||||||
chatsCount: state.get('chats').reduce((acc, curr) => acc + Math.min(curr.get('unread', 0), 1), 0),
|
chatsCount: state.get('chats').reduce((acc, curr) => acc + Math.min(curr.get('unread', 0), 1), 0),
|
||||||
dashboardCount: reportsCount + approvalCount,
|
dashboardCount: reportsCount + approvalCount,
|
||||||
|
features: getFeatures(instance),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ import Icon from 'soapbox/components/icon';
|
||||||
import { isStaff, isAdmin } from 'soapbox/utils/accounts';
|
import { isStaff, isAdmin } from 'soapbox/utils/accounts';
|
||||||
import ProfileHoverCard from 'soapbox/components/profile_hover_card';
|
import ProfileHoverCard from 'soapbox/components/profile_hover_card';
|
||||||
import { getAccessToken } from 'soapbox/utils/auth';
|
import { getAccessToken } from 'soapbox/utils/auth';
|
||||||
|
import { getFeatures } from 'soapbox/utils/features';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Status,
|
Status,
|
||||||
|
@ -115,6 +116,7 @@ const messages = defineMessages({
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
const account = state.getIn(['accounts', me]);
|
const account = state.getIn(['accounts', me]);
|
||||||
|
const instance = state.get('instance');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null,
|
dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null,
|
||||||
|
@ -122,6 +124,7 @@ const mapStateToProps = state => {
|
||||||
streamingUrl: state.getIn(['instance', 'urls', 'streaming_api']),
|
streamingUrl: state.getIn(['instance', 'urls', 'streaming_api']),
|
||||||
me,
|
me,
|
||||||
account,
|
account,
|
||||||
|
features: getFeatures(instance),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -158,6 +161,7 @@ class SwitchingColumnsArea extends React.PureComponent {
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
location: PropTypes.object,
|
location: PropTypes.object,
|
||||||
onLayoutChange: PropTypes.func.isRequired,
|
onLayoutChange: PropTypes.func.isRequired,
|
||||||
|
features: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
|
@ -186,7 +190,7 @@ class SwitchingColumnsArea extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children } = this.props;
|
const { children, features } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
|
@ -236,8 +240,10 @@ class SwitchingColumnsArea extends React.PureComponent {
|
||||||
|
|
||||||
<WrappedRoute path='/search' publicRoute page={DefaultPage} component={Search} content={children} />
|
<WrappedRoute path='/search' publicRoute page={DefaultPage} component={Search} content={children} />
|
||||||
|
|
||||||
<WrappedRoute path='/chats' exact page={DefaultPage} component={ChatIndex} content={children} />
|
{features.chats && <>
|
||||||
<WrappedRoute path='/chats/:chatId' page={DefaultPage} component={ChatRoom} content={children} />
|
<WrappedRoute path='/chats' exact page={DefaultPage} component={ChatIndex} content={children} />
|
||||||
|
<WrappedRoute path='/chats/:chatId' page={DefaultPage} component={ChatRoom} content={children} />
|
||||||
|
</>}
|
||||||
|
|
||||||
<WrappedRoute path='/follow_requests' page={DefaultPage} component={FollowRequests} content={children} />
|
<WrappedRoute path='/follow_requests' page={DefaultPage} component={FollowRequests} content={children} />
|
||||||
<WrappedRoute path='/blocks' page={DefaultPage} component={Blocks} content={children} />
|
<WrappedRoute path='/blocks' page={DefaultPage} component={Blocks} content={children} />
|
||||||
|
@ -302,6 +308,7 @@ class UI extends React.PureComponent {
|
||||||
me: SoapboxPropTypes.me,
|
me: SoapboxPropTypes.me,
|
||||||
streamingUrl: PropTypes.string,
|
streamingUrl: PropTypes.string,
|
||||||
account: PropTypes.object,
|
account: PropTypes.object,
|
||||||
|
features: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
|
@ -411,7 +418,7 @@ class UI extends React.PureComponent {
|
||||||
});
|
});
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { account } = this.props;
|
const { account, features } = this.props;
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
|
|
||||||
window.addEventListener('resize', this.handleResize, { passive: true });
|
window.addEventListener('resize', this.handleResize, { passive: true });
|
||||||
|
@ -432,7 +439,10 @@ class UI extends React.PureComponent {
|
||||||
if (account) {
|
if (account) {
|
||||||
this.props.dispatch(expandHomeTimeline());
|
this.props.dispatch(expandHomeTimeline());
|
||||||
this.props.dispatch(expandNotifications());
|
this.props.dispatch(expandNotifications());
|
||||||
this.props.dispatch(fetchChats());
|
|
||||||
|
if (features.chats) {
|
||||||
|
this.props.dispatch(fetchChats());
|
||||||
|
}
|
||||||
|
|
||||||
if (isStaff(account)) {
|
if (isStaff(account)) {
|
||||||
this.props.dispatch(fetchReports({ state: 'open' }));
|
this.props.dispatch(fetchReports({ state: 'open' }));
|
||||||
|
@ -577,7 +587,7 @@ class UI extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { streamingUrl } = this.props;
|
const { streamingUrl, features } = this.props;
|
||||||
const { draggingOver, mobile } = this.state;
|
const { draggingOver, mobile } = this.state;
|
||||||
const { intl, children, location, dropdownMenuIsOpen, me } = this.props;
|
const { intl, children, location, dropdownMenuIsOpen, me } = this.props;
|
||||||
|
|
||||||
|
@ -624,7 +634,7 @@ class UI extends React.PureComponent {
|
||||||
<HotKeys keyMap={keyMap} handlers={handlers} ref={this.setHotkeysRef} attach={window} focused>
|
<HotKeys keyMap={keyMap} handlers={handlers} ref={this.setHotkeysRef} attach={window} focused>
|
||||||
<div className={classnames} ref={this.setRef} style={style}>
|
<div className={classnames} ref={this.setRef} style={style}>
|
||||||
<TabsBar />
|
<TabsBar />
|
||||||
<SwitchingColumnsArea location={location} onLayoutChange={this.handleLayoutChange}>
|
<SwitchingColumnsArea location={location} onLayoutChange={this.handleLayoutChange} features={features}>
|
||||||
{children}
|
{children}
|
||||||
</SwitchingColumnsArea>
|
</SwitchingColumnsArea>
|
||||||
|
|
||||||
|
@ -635,7 +645,7 @@ class UI extends React.PureComponent {
|
||||||
<ModalContainer />
|
<ModalContainer />
|
||||||
<UploadArea active={draggingOver} onClose={this.closeUploadModal} />
|
<UploadArea active={draggingOver} onClose={this.closeUploadModal} />
|
||||||
{me && <SidebarMenu />}
|
{me && <SidebarMenu />}
|
||||||
{me && !mobile && (
|
{me && features.chats && !mobile && (
|
||||||
<BundleContainer fetchComponent={ChatPanes}>
|
<BundleContainer fetchComponent={ChatPanes}>
|
||||||
{Component => <Component />}
|
{Component => <Component />}
|
||||||
</BundleContainer>
|
</BundleContainer>
|
||||||
|
|
|
@ -16,6 +16,7 @@ export const getFeatures = createSelector([
|
||||||
focalPoint: v.software === 'Mastodon' && gte(v.compatVersion, '2.3.0'),
|
focalPoint: v.software === 'Mastodon' && gte(v.compatVersion, '2.3.0'),
|
||||||
importMutes: v.software === 'Pleroma' && gte(v.version, '2.2.0'),
|
importMutes: v.software === 'Pleroma' && gte(v.version, '2.2.0'),
|
||||||
emailList: f.includes('email_list'),
|
emailList: f.includes('email_list'),
|
||||||
|
chats: v.software === 'Pleroma' && gte(v.version, '2.1.0'),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue