Support account subscriptions on Mastodon

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
improve-ci
marcin mikołajczak 2021-12-30 16:13:45 +01:00
rodzic ab886e647c
commit fc3b9d62a6
6 zmienionych plików z 52 dodań i 10 usunięć

Wyświetl plik

@ -203,7 +203,7 @@ export function fetchAccountFail(id, error) {
}; };
} }
export function followAccount(id, reblogs = true) { export function followAccount(id, options = { reblogs: true }) {
return (dispatch, getState) => { return (dispatch, getState) => {
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
@ -212,7 +212,7 @@ export function followAccount(id, reblogs = true) {
dispatch(followAccountRequest(id, locked)); dispatch(followAccountRequest(id, locked));
api(getState).post(`/api/v1/accounts/${id}/follow`, { reblogs }).then(response => { api(getState).post(`/api/v1/accounts/${id}/follow`, options).then(response => {
dispatch(followAccountSuccess(response.data, alreadyFollowing)); dispatch(followAccountSuccess(response.data, alreadyFollowing));
}).catch(error => { }).catch(error => {
dispatch(followAccountFail(error, locked)); dispatch(followAccountFail(error, locked));

Wyświetl plik

@ -256,7 +256,21 @@ class Header extends ImmutablePureComponent {
}); });
} }
if (features.accountSubscriptions) { if (features.accountNotifies) {
if (account.getIn(['relationship', 'notifying'])) {
menu.push({
text: intl.formatMessage(messages.unsubscribe, { name: account.get('username') }),
action: this.props.onNotifyToggle,
icon: require('@tabler/icons/icons/bell.svg'),
});
} else {
menu.push({
text: intl.formatMessage(messages.subscribe, { name: account.get('username') }),
action: this.props.onNotifyToggle,
icon: require('@tabler/icons/icons/bell-off.svg'),
});
}
} else if (features.accountSubscriptions) {
if (account.getIn(['relationship', 'subscribing'])) { if (account.getIn(['relationship', 'subscribing'])) {
menu.push({ menu.push({
text: intl.formatMessage(messages.unsubscribe, { name: account.get('username') }), text: intl.formatMessage(messages.unsubscribe, { name: account.get('username') }),
@ -550,8 +564,8 @@ class Header extends ImmutablePureComponent {
<StillImage src={account.get('header')} alt='' className='parallax' /> <StillImage src={account.get('header')} alt='' className='parallax' />
</a>} </a>}
{features.accountSubscriptions && <div className='account__header__subscribe'> {(features.accountNotifies || features.accountSubscriptions) && <div className='account__header__subscribe'>
<SubscriptionButton account={account} /> <SubscriptionButton account={account} features={features} />
</div>} </div>}
</div> </div>

Wyświetl plik

@ -57,6 +57,10 @@ export default class Header extends ImmutablePureComponent {
this.props.onSubscriptionToggle(this.props.account); this.props.onSubscriptionToggle(this.props.account);
} }
handleNotifyToggle = () => {
this.props.onNotifyToggle(this.props.account);
}
handleMute = () => { handleMute = () => {
this.props.onMute(this.props.account); this.props.onMute(this.props.account);
} }
@ -143,6 +147,7 @@ export default class Header extends ImmutablePureComponent {
onChat={this.handleChat} onChat={this.handleChat}
onReblogToggle={this.handleReblogToggle} onReblogToggle={this.handleReblogToggle}
onSubscriptionToggle={this.handleSubscriptionToggle} onSubscriptionToggle={this.handleSubscriptionToggle}
onNotifyToggle={this.handleNotifyToggle}
onReport={this.handleReport} onReport={this.handleReport}
onMute={this.handleMute} onMute={this.handleMute}
onBlockDomain={this.handleBlockDomain} onBlockDomain={this.handleBlockDomain}

Wyświetl plik

@ -112,9 +112,9 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onReblogToggle(account) { onReblogToggle(account) {
if (account.getIn(['relationship', 'showing_reblogs'])) { if (account.getIn(['relationship', 'showing_reblogs'])) {
dispatch(followAccount(account.get('id'), false)); dispatch(followAccount(account.get('id'), { reblogs: false }));
} else { } else {
dispatch(followAccount(account.get('id'), true)); dispatch(followAccount(account.get('id'), { reblogs: true }));
} }
}, },
@ -126,6 +126,14 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
} }
}, },
onNotifyToggle(account) {
if (account.getIn(['relationship', 'notifying'])) {
dispatch(followAccount(account.get('id'), { notify: false }));
} else {
dispatch(followAccount(account.get('id'), { notify: true }));
}
},
// onEndorseToggle(account) { // onEndorseToggle(account) {
// if (account.getIn(['relationship', 'endorsed'])) { // if (account.getIn(['relationship', 'endorsed'])) {
// dispatch(unpinAccount(account.get('id'))); // dispatch(unpinAccount(account.get('id')));

Wyświetl plik

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import { defineMessages, injectIntl } from 'react-intl'; import { defineMessages, injectIntl } from 'react-intl';
import classNames from 'classnames'; import classNames from 'classnames';
@ -7,6 +8,7 @@ import Button from 'soapbox/components/button';
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import { import {
followAccount,
subscribeAccount, subscribeAccount,
unsubscribeAccount, unsubscribeAccount,
} from 'soapbox/actions/accounts'; } from 'soapbox/actions/accounts';
@ -32,6 +34,13 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(subscribeAccount(account.get('id'))); dispatch(subscribeAccount(account.get('id')));
} }
}, },
onNotifyToggle(account) {
if (account.getIn(['relationship', 'notifying'])) {
dispatch(followAccount(account.get('id'), { notify: false }));
} else {
dispatch(followAccount(account.get('id'), { notify: true }));
}
},
}); });
export default @connect(mapStateToProps, mapDispatchToProps) export default @connect(mapStateToProps, mapDispatchToProps)
@ -40,15 +49,17 @@ class SubscriptionButton extends ImmutablePureComponent {
static propTypes = { static propTypes = {
account: ImmutablePropTypes.map, account: ImmutablePropTypes.map,
features: PropTypes.object.isRequired,
}; };
handleSubscriptionToggle = () => { handleSubscriptionToggle = () => {
this.props.onSubscriptionToggle(this.props.account); if (this.props.features.accountNotifies) this.props.onNotifyToggle(this.props.account);
else this.props.onSubscriptionToggle(this.props.account);
} }
render() { render() {
const { account, intl } = this.props; const { account, intl, features } = this.props;
const subscribing = account.getIn(['relationship', 'subscribing']); const subscribing = features.accountNotifies ? account.getIn(['relationship', 'notifying']) : account.getIn(['relationship', 'subscribing']);
const following = account.getIn(['relationship', 'following']); const following = account.getIn(['relationship', 'following']);
const requested = account.getIn(['relationship', 'requested']); const requested = account.getIn(['relationship', 'requested']);

Wyświetl plik

@ -64,6 +64,10 @@ export const getFeatures = createSelector([
resetPasswordAPI: v.software === PLEROMA, resetPasswordAPI: v.software === PLEROMA,
exposableReactions: features.includes('exposable_reactions'), exposableReactions: features.includes('exposable_reactions'),
accountSubscriptions: v.software === PLEROMA && gte(v.version, '1.0.0'), accountSubscriptions: v.software === PLEROMA && gte(v.version, '1.0.0'),
accountNotifies: any([
v.software === MASTODON && gte(v.compatVersion, '3.3.0'),
v.software === PLEROMA && gte(v.version, '2.4.50'),
]),
unrestrictedLists: v.software === PLEROMA, unrestrictedLists: v.software === PLEROMA,
accountByUsername: v.software === PLEROMA, accountByUsername: v.software === PLEROMA,
profileDirectory: any([ profileDirectory: any([