Skip to content

Commit ebf9082

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Implement missing hotkeys for notifications (mastodon#9927)
1 parent c2d7649 commit ebf9082

2 files changed

Lines changed: 79 additions & 8 deletions

File tree

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class Notification extends ImmutablePureComponent {
2929
onMoveUp: PropTypes.func.isRequired,
3030
onMoveDown: PropTypes.func.isRequired,
3131
onMention: PropTypes.func.isRequired,
32+
onFavourite: PropTypes.func.isRequired,
33+
onReblog: PropTypes.func.isRequired,
34+
onToggleHidden: PropTypes.func.isRequired,
35+
status: PropTypes.option,
3236
intl: PropTypes.object.isRequired,
3337
};
3438

@@ -64,14 +68,32 @@ class Notification extends ImmutablePureComponent {
6468
onMention(notification.get('account'), this.context.router.history);
6569
}
6670

71+
handleHotkeyFavourite = () => {
72+
const { status } = this.props;
73+
if (status) this.props.onFavourite(status);
74+
}
75+
76+
handleHotkeyBoost = e => {
77+
const { status } = this.props;
78+
if (status) this.props.onReblog(status, e);
79+
}
80+
81+
handleHotkeyToggleHidden = () => {
82+
const { status } = this.props;
83+
if (status) this.props.onToggleHidden(status);
84+
}
85+
6786
getHandlers () {
6887
return {
69-
moveUp: this.handleMoveUp,
70-
moveDown: this.handleMoveDown,
88+
reply: this.handleMention,
89+
favourite: this.handleHotkeyFavourite,
90+
boost: this.handleHotkeyBoost,
91+
mention: this.handleMention,
7192
open: this.handleOpen,
7293
openProfile: this.handleOpenProfile,
73-
mention: this.handleMention,
74-
reply: this.handleMention,
94+
moveUp: this.handleMoveUp,
95+
moveDown: this.handleMoveDown,
96+
toggleHidden: this.handleHotkeyToggleHidden,
7597
};
7698
}
7799

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
import { connect } from 'react-redux';
2-
import { makeGetNotification } from '../../../selectors';
2+
import { makeGetNotification, makeGetStatus } from '../../../selectors';
33
import Notification from '../components/notification';
4+
import { openModal } from '../../../actions/modal';
45
import { mentionCompose } from '../../../actions/compose';
6+
import {
7+
reblog,
8+
favourite,
9+
unreblog,
10+
unfavourite,
11+
} from '../../../actions/interactions';
12+
import {
13+
hideStatus,
14+
revealStatus,
15+
} from '../../../actions/statuses';
16+
import { boostModal } from '../../../initial_state';
517

618
const makeMapStateToProps = () => {
719
const getNotification = makeGetNotification();
20+
const getStatus = makeGetStatus();
821

9-
const mapStateToProps = (state, props) => ({
10-
notification: getNotification(state, props.notification, props.accountId),
11-
});
22+
const mapStateToProps = (state, props) => {
23+
const notification = getNotification(state, props.notification, props.accountId);
24+
return {
25+
notification: notification,
26+
status: notification.get('status') ? getStatus(state, { id: notification.get('status') }) : null,
27+
};
28+
};
1229

1330
return mapStateToProps;
1431
};
@@ -17,6 +34,38 @@ const mapDispatchToProps = dispatch => ({
1734
onMention: (account, router) => {
1835
dispatch(mentionCompose(account, router));
1936
},
37+
38+
onModalReblog (status) {
39+
dispatch(reblog(status));
40+
},
41+
42+
onReblog (status, e) {
43+
if (status.get('reblogged')) {
44+
dispatch(unreblog(status));
45+
} else {
46+
if (e.shiftKey || !boostModal) {
47+
this.onModalReblog(status);
48+
} else {
49+
dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
50+
}
51+
}
52+
},
53+
54+
onFavourite (status) {
55+
if (status.get('favourited')) {
56+
dispatch(unfavourite(status));
57+
} else {
58+
dispatch(favourite(status));
59+
}
60+
},
61+
62+
onToggleHidden (status) {
63+
if (status.get('hidden')) {
64+
dispatch(revealStatus(status.get('id')));
65+
} else {
66+
dispatch(hideStatus(status.get('id')));
67+
}
68+
},
2069
});
2170

2271
export default connect(makeMapStateToProps, mapDispatchToProps)(Notification);

0 commit comments

Comments
 (0)