Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit 79efcf8

Browse files
Change notification permission handling (mastodon#15176)
* Change notification permission handling - allow changing individual alert settings even if permission is not explicitly enabled (asks for permission on toggle) - persist permission request banner dismissal across sessions through settings * Add additional, more discrete message to grant permissions * Change permission granting button design according to reviews Co-authored-by: Claire <[email protected]>
1 parent 8357969 commit 79efcf8

File tree

8 files changed

+51
-22
lines changed

8 files changed

+51
-22
lines changed

app/javascript/mastodon/actions/notifications.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ export const NOTIFICATIONS_UNMOUNT = 'NOTIFICATIONS_UNMOUNT';
3737

3838
export const NOTIFICATIONS_MARK_AS_READ = 'NOTIFICATIONS_MARK_AS_READ';
3939

40-
export const NOTIFICATIONS_SET_BROWSER_SUPPORT = 'NOTIFICATIONS_SET_BROWSER_SUPPORT';
41-
export const NOTIFICATIONS_SET_BROWSER_PERMISSION = 'NOTIFICATIONS_SET_BROWSER_PERMISSION';
42-
export const NOTIFICATIONS_DISMISS_BROWSER_PERMISSION = 'NOTIFICATIONS_DISMISS_BROWSER_PERMISSION';
40+
export const NOTIFICATIONS_SET_BROWSER_SUPPORT = 'NOTIFICATIONS_SET_BROWSER_SUPPORT';
41+
export const NOTIFICATIONS_SET_BROWSER_PERMISSION = 'NOTIFICATIONS_SET_BROWSER_PERMISSION';
4342

4443
defineMessages({
4544
mention: { id: 'notification.mention', defaultMessage: '{name} mentioned you' },
@@ -284,7 +283,3 @@ export function setBrowserPermission (value) {
284283
value,
285284
};
286285
}
287-
288-
export const dismissBrowserPermission = () => ({
289-
type: NOTIFICATIONS_DISMISS_BROWSER_PERMISSION,
290-
});

app/javascript/mastodon/features/notifications/components/column_settings.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import ImmutablePropTypes from 'react-immutable-proptypes';
44
import { FormattedMessage } from 'react-intl';
55
import ClearColumnButton from './clear_column_button';
6+
import GrantPermissionButton from './grant_permission_button';
67
import SettingToggle from './setting_toggle';
78

89
export default class ColumnSettings extends React.PureComponent {
@@ -23,7 +24,7 @@ export default class ColumnSettings extends React.PureComponent {
2324
}
2425

2526
render () {
26-
const { settings, pushSettings, onChange, onClear, alertsEnabled, browserSupport, browserPermission } = this.props;
27+
const { settings, pushSettings, onChange, onClear, alertsEnabled, browserSupport, browserPermission, onRequestNotificationPermission } = this.props;
2728

2829
const filterShowStr = <FormattedMessage id='notifications.column_settings.filter_bar.show' defaultMessage='Show' />;
2930
const filterAdvancedStr = <FormattedMessage id='notifications.column_settings.filter_bar.advanced' defaultMessage='Display all categories' />;
@@ -42,6 +43,14 @@ export default class ColumnSettings extends React.PureComponent {
4243
</div>
4344
)}
4445

46+
{alertsEnabled && browserSupport && browserPermission === 'default' && (
47+
<div className='column-settings__row column-settings__row--with-margin'>
48+
<span className='warning-hint'>
49+
<FormattedMessage id='notifications.permission_required' defaultMessage='Desktop notifications are unavailable because the required permission has not been granted.' /> <GrantPermissionButton onClick={onRequestNotificationPermission} />
50+
</span>
51+
</div>
52+
)}
53+
4554
<div className='column-settings__row'>
4655
<ClearColumnButton onClick={onClear} />
4756
</div>
@@ -61,7 +70,7 @@ export default class ColumnSettings extends React.PureComponent {
6170
<span id='notifications-follow' className='column-settings__section'><FormattedMessage id='notifications.column_settings.follow' defaultMessage='New followers:' /></span>
6271

6372
<div className='column-settings__row'>
64-
<SettingToggle disabled={browserPermission !== 'granted'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'follow']} onChange={onChange} label={alertStr} />
73+
<SettingToggle disabled={browserPermission === 'denied'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'follow']} onChange={onChange} label={alertStr} />
6574
{showPushSettings && <SettingToggle prefix='notifications_push' settings={pushSettings} settingPath={['alerts', 'follow']} onChange={this.onPushChange} label={pushStr} />}
6675
<SettingToggle prefix='notifications' settings={settings} settingPath={['shows', 'follow']} onChange={onChange} label={showStr} />
6776
<SettingToggle prefix='notifications' settings={settings} settingPath={['sounds', 'follow']} onChange={onChange} label={soundStr} />
@@ -72,7 +81,7 @@ export default class ColumnSettings extends React.PureComponent {
7281
<span id='notifications-follow-request' className='column-settings__section'><FormattedMessage id='notifications.column_settings.follow_request' defaultMessage='New follow requests:' /></span>
7382

7483
<div className='column-settings__row'>
75-
<SettingToggle disabled={browserPermission !== 'granted'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'follow_request']} onChange={onChange} label={alertStr} />
84+
<SettingToggle disabled={browserPermission === 'denied'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'follow_request']} onChange={onChange} label={alertStr} />
7685
{showPushSettings && <SettingToggle prefix='notifications_push' settings={pushSettings} settingPath={['alerts', 'follow_request']} onChange={this.onPushChange} label={pushStr} />}
7786
<SettingToggle prefix='notifications' settings={settings} settingPath={['shows', 'follow_request']} onChange={onChange} label={showStr} />
7887
<SettingToggle prefix='notifications' settings={settings} settingPath={['sounds', 'follow_request']} onChange={onChange} label={soundStr} />
@@ -83,7 +92,7 @@ export default class ColumnSettings extends React.PureComponent {
8392
<span id='notifications-favourite' className='column-settings__section'><FormattedMessage id='notifications.column_settings.favourite' defaultMessage='Favourites:' /></span>
8493

8594
<div className='column-settings__row'>
86-
<SettingToggle disabled={browserPermission !== 'granted'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'favourite']} onChange={onChange} label={alertStr} />
95+
<SettingToggle disabled={browserPermission === 'denied'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'favourite']} onChange={onChange} label={alertStr} />
8796
{showPushSettings && <SettingToggle prefix='notifications_push' settings={pushSettings} settingPath={['alerts', 'favourite']} onChange={this.onPushChange} label={pushStr} />}
8897
<SettingToggle prefix='notifications' settings={settings} settingPath={['shows', 'favourite']} onChange={onChange} label={showStr} />
8998
<SettingToggle prefix='notifications' settings={settings} settingPath={['sounds', 'favourite']} onChange={onChange} label={soundStr} />
@@ -94,7 +103,7 @@ export default class ColumnSettings extends React.PureComponent {
94103
<span id='notifications-mention' className='column-settings__section'><FormattedMessage id='notifications.column_settings.mention' defaultMessage='Mentions:' /></span>
95104

96105
<div className='column-settings__row'>
97-
<SettingToggle disabled={browserPermission !== 'granted'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'mention']} onChange={onChange} label={alertStr} />
106+
<SettingToggle disabled={browserPermission === 'denied'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'mention']} onChange={onChange} label={alertStr} />
98107
{showPushSettings && <SettingToggle prefix='notifications_push' settings={pushSettings} settingPath={['alerts', 'mention']} onChange={this.onPushChange} label={pushStr} />}
99108
<SettingToggle prefix='notifications' settings={settings} settingPath={['shows', 'mention']} onChange={onChange} label={showStr} />
100109
<SettingToggle prefix='notifications' settings={settings} settingPath={['sounds', 'mention']} onChange={onChange} label={soundStr} />
@@ -105,7 +114,7 @@ export default class ColumnSettings extends React.PureComponent {
105114
<span id='notifications-reblog' className='column-settings__section'><FormattedMessage id='notifications.column_settings.reblog' defaultMessage='Boosts:' /></span>
106115

107116
<div className='column-settings__row'>
108-
<SettingToggle disabled={browserPermission !== 'granted'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'reblog']} onChange={onChange} label={alertStr} />
117+
<SettingToggle disabled={browserPermission === 'denied'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'reblog']} onChange={onChange} label={alertStr} />
109118
{showPushSettings && <SettingToggle prefix='notifications_push' settings={pushSettings} settingPath={['alerts', 'reblog']} onChange={this.onPushChange} label={pushStr} />}
110119
<SettingToggle prefix='notifications' settings={settings} settingPath={['shows', 'reblog']} onChange={onChange} label={showStr} />
111120
<SettingToggle prefix='notifications' settings={settings} settingPath={['sounds', 'reblog']} onChange={onChange} label={soundStr} />
@@ -116,7 +125,7 @@ export default class ColumnSettings extends React.PureComponent {
116125
<span id='notifications-poll' className='column-settings__section'><FormattedMessage id='notifications.column_settings.poll' defaultMessage='Poll results:' /></span>
117126

118127
<div className='column-settings__row'>
119-
<SettingToggle disabled={browserPermission !== 'granted'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'poll']} onChange={onChange} label={alertStr} />
128+
<SettingToggle disabled={browserPermission === 'denied'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'poll']} onChange={onChange} label={alertStr} />
120129
{showPushSettings && <SettingToggle prefix='notifications_push' settings={pushSettings} settingPath={['alerts', 'poll']} onChange={this.onPushChange} label={pushStr} />}
121130
<SettingToggle prefix='notifications' settings={settings} settingPath={['shows', 'poll']} onChange={onChange} label={showStr} />
122131
<SettingToggle prefix='notifications' settings={settings} settingPath={['sounds', 'poll']} onChange={onChange} label={soundStr} />
@@ -127,7 +136,7 @@ export default class ColumnSettings extends React.PureComponent {
127136
<span id='notifications-status' className='column-settings__section'><FormattedMessage id='notifications.column_settings.status' defaultMessage='New toots:' /></span>
128137

129138
<div className='column-settings__row'>
130-
<SettingToggle disabled={browserPermission !== 'granted'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'status']} onChange={onChange} label={alertStr} />
139+
<SettingToggle disabled={browserPermission === 'denied'} prefix='notifications_desktop' settings={settings} settingPath={['alerts', 'status']} onChange={onChange} label={alertStr} />
131140
{showPushSettings && <SettingToggle prefix='notifications_push' settings={pushSettings} settingPath={['alerts', 'status']} onChange={this.onPushChange} label={pushStr} />}
132141
<SettingToggle prefix='notifications' settings={settings} settingPath={['shows', 'status']} onChange={onChange} label={showStr} />
133142
<SettingToggle prefix='notifications' settings={settings} settingPath={['sounds', 'status']} onChange={onChange} label={soundStr} />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { FormattedMessage } from 'react-intl';
4+
5+
export default class GrantPermissionButton extends React.PureComponent {
6+
7+
static propTypes = {
8+
onClick: PropTypes.func.isRequired,
9+
};
10+
11+
render () {
12+
return (
13+
<button className='text-btn column-header__permission-btn' tabIndex='0' onClick={this.props.onClick}>
14+
<FormattedMessage id='notifications.grant_permission' defaultMessage='Grant permission.' />
15+
</button>
16+
);
17+
}
18+
19+
}

app/javascript/mastodon/features/notifications/components/notifications_permission_banner.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from 'react';
22
import Icon from 'mastodon/components/icon';
33
import Button from 'mastodon/components/button';
44
import IconButton from 'mastodon/components/icon_button';
5-
import { requestBrowserPermission, dismissBrowserPermission } from 'mastodon/actions/notifications';
5+
import { requestBrowserPermission } from 'mastodon/actions/notifications';
6+
import { changeSetting } from 'mastodon/actions/settings';
67
import { connect } from 'react-redux';
78
import PropTypes from 'prop-types';
89
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
@@ -25,7 +26,7 @@ class NotificationsPermissionBanner extends React.PureComponent {
2526
}
2627

2728
handleClose = () => {
28-
this.props.dispatch(dismissBrowserPermission());
29+
this.props.dispatch(changeSetting(['notifications', 'dismissPermissionBanner'], true));
2930
}
3031

3132
render () {

app/javascript/mastodon/features/notifications/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const mapStateToProps = state => ({
6262
numPending: state.getIn(['notifications', 'pendingItems'], ImmutableList()).size,
6363
lastReadId: state.getIn(['notifications', 'readMarkerId']),
6464
canMarkAsRead: state.getIn(['notifications', 'readMarkerId']) !== '0' && getNotifications(state).some(item => item !== null && compareId(item.get('id'), state.getIn(['notifications', 'readMarkerId'])) > 0),
65-
needsNotificationPermission: state.getIn(['settings', 'notifications', 'alerts']).includes(true) && state.getIn(['notifications', 'browserSupport']) && state.getIn(['notifications', 'browserPermission']) === 'default',
65+
needsNotificationPermission: state.getIn(['settings', 'notifications', 'alerts']).includes(true) && state.getIn(['notifications', 'browserSupport']) && state.getIn(['notifications', 'browserPermission']) === 'default' && !state.getIn(['settings', 'notifications', 'dismissPermissionBanner']),
6666
});
6767

6868
export default @connect(mapStateToProps)

app/javascript/mastodon/reducers/notifications.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
NOTIFICATIONS_MARK_AS_READ,
1313
NOTIFICATIONS_SET_BROWSER_SUPPORT,
1414
NOTIFICATIONS_SET_BROWSER_PERMISSION,
15-
NOTIFICATIONS_DISMISS_BROWSER_PERMISSION,
1615
} from '../actions/notifications';
1716
import {
1817
ACCOUNT_BLOCK_SUCCESS,
@@ -251,8 +250,6 @@ export default function notifications(state = initialState, action) {
251250
return state.set('browserSupport', action.value);
252251
case NOTIFICATIONS_SET_BROWSER_PERMISSION:
253252
return state.set('browserPermission', action.value);
254-
case NOTIFICATIONS_DISMISS_BROWSER_PERMISSION:
255-
return state.set('browserPermission', 'denied');
256253
default:
257254
return state;
258255
}

app/javascript/mastodon/reducers/settings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const initialState = ImmutableMap({
4444
advanced: false,
4545
}),
4646

47+
dismissPermissionBanner: false,
48+
4749
shows: ImmutableMap({
4850
follow: true,
4951
follow_request: false,

app/javascript/styles/mastodon/components.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3459,6 +3459,12 @@ a.status-card.compact:hover {
34593459
}
34603460
}
34613461

3462+
.column-header__permission-btn {
3463+
display: inline;
3464+
font-weight: inherit;
3465+
text-decoration: underline;
3466+
}
3467+
34623468
.column-header__setting-arrows {
34633469
float: right;
34643470

@@ -3857,7 +3863,7 @@ a.status-card.compact:hover {
38573863
}
38583864

38593865
.column-settings__row {
3860-
.text-btn {
3866+
.text-btn:not(.column-header__permission-btn) {
38613867
margin-bottom: 15px;
38623868
}
38633869
}

0 commit comments

Comments
 (0)