From b22b2cbfacdaef2441d14f401c95863d8ca2e66c Mon Sep 17 00:00:00 2001 From: Eugen Date: Tue, 11 Apr 2017 22:53:58 +0200 Subject: Fix #1491 - Fix broken notifications, broken Link header parsing for exclude_types (#1548) --- .../components/actions/notifications.jsx | 6 ++-- app/assets/javascripts/components/api.jsx | 2 +- .../javascripts/components/components/account.jsx | 2 +- .../compose/components/autosuggest_account.jsx | 2 +- .../components/account_authorize.jsx | 2 +- .../notifications/components/notification.jsx | 16 +++++------ app/assets/javascripts/components/link_header.jsx | 33 ++++++++++++++++++++++ 7 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 app/assets/javascripts/components/link_header.jsx (limited to 'app/assets') diff --git a/app/assets/javascripts/components/actions/notifications.jsx b/app/assets/javascripts/components/actions/notifications.jsx index 11e814e1f..b09ca0854 100644 --- a/app/assets/javascripts/components/actions/notifications.jsx +++ b/app/assets/javascripts/components/actions/notifications.jsx @@ -50,6 +50,8 @@ export function updateNotifications(notification, intlMessages, intlLocale) { }; }; +const excludeTypesFromSettings = state => state.getIn(['settings', 'notifications', 'shows']).filter(enabled => !enabled).keySeq().toJS(); + export function refreshNotifications() { return (dispatch, getState) => { dispatch(refreshNotificationsRequest()); @@ -61,7 +63,7 @@ export function refreshNotifications() { params.since_id = ids.first().get('id'); } - params.exclude_types = getState().getIn(['settings', 'notifications', 'shows']).filter(enabled => !enabled).keySeq().toJS(); + params.exclude_types = excludeTypesFromSettings(getState()); api(getState).get('/api/v1/notifications', { params }).then(response => { const next = getLinks(response).refs.find(link => link.rel === 'next'); @@ -109,7 +111,7 @@ export function expandNotifications() { const params = {}; - params.exclude_types = getState().getIn(['settings', 'notifications', 'shows']).filter(enabled => !enabled).keySeq().toJS(); + params.exclude_types = excludeTypesFromSettings(getState()); api(getState).get(url, params).then(response => { const next = getLinks(response).refs.find(link => link.rel === 'next'); diff --git a/app/assets/javascripts/components/api.jsx b/app/assets/javascripts/components/api.jsx index 93cfc8046..185729ce0 100644 --- a/app/assets/javascripts/components/api.jsx +++ b/app/assets/javascripts/components/api.jsx @@ -1,5 +1,5 @@ import axios from 'axios'; -import LinkHeader from 'http-link-header'; +import LinkHeader from './link_header'; export const getLinks = response => { const value = response.headers.link; diff --git a/app/assets/javascripts/components/components/account.jsx b/app/assets/javascripts/components/components/account.jsx index 782cf382d..8ce9b1929 100644 --- a/app/assets/javascripts/components/components/account.jsx +++ b/app/assets/javascripts/components/components/account.jsx @@ -65,7 +65,7 @@ const Account = React.createClass({
-
+
diff --git a/app/assets/javascripts/components/features/compose/components/autosuggest_account.jsx b/app/assets/javascripts/components/features/compose/components/autosuggest_account.jsx index 9e05193fb..2d21f3437 100644 --- a/app/assets/javascripts/components/features/compose/components/autosuggest_account.jsx +++ b/app/assets/javascripts/components/features/compose/components/autosuggest_account.jsx @@ -4,7 +4,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; const AutosuggestAccount = ({ account }) => (
-
+
); diff --git a/app/assets/javascripts/components/features/follow_requests/components/account_authorize.jsx b/app/assets/javascripts/components/features/follow_requests/components/account_authorize.jsx index 9c713287c..1939eba65 100644 --- a/app/assets/javascripts/components/features/follow_requests/components/account_authorize.jsx +++ b/app/assets/javascripts/components/features/follow_requests/components/account_authorize.jsx @@ -33,7 +33,7 @@ const AccountAuthorize = ({ intl, account, onAuthorize, onReject }) => {
-
+
diff --git a/app/assets/javascripts/components/features/notifications/components/notification.jsx b/app/assets/javascripts/components/features/notifications/components/notification.jsx index 0607466d0..fdebe4bb5 100644 --- a/app/assets/javascripts/components/features/notifications/components/notification.jsx +++ b/app/assets/javascripts/components/features/notifications/components/notification.jsx @@ -79,14 +79,14 @@ const Notification = React.createClass({ const link = ; switch(notification.get('type')) { - case 'follow': - return this.renderFollow(account, link); - case 'mention': - return this.renderMention(notification); - case 'favourite': - return this.renderFavourite(notification, link); - case 'reblog': - return this.renderReblog(notification, link); + case 'follow': + return this.renderFollow(account, link); + case 'mention': + return this.renderMention(notification); + case 'favourite': + return this.renderFavourite(notification, link); + case 'reblog': + return this.renderReblog(notification, link); } } diff --git a/app/assets/javascripts/components/link_header.jsx b/app/assets/javascripts/components/link_header.jsx new file mode 100644 index 000000000..9a9ff7e7a --- /dev/null +++ b/app/assets/javascripts/components/link_header.jsx @@ -0,0 +1,33 @@ +import Link from 'http-link-header'; +import querystring from 'querystring'; + +Link.parseAttrs = (link, parts) => { + let match = null + let attr = '' + let value = '' + let attrs = '' + + let uriAttrs = /<(.*)>;\s*(.*)/gi.exec(parts) + + if(uriAttrs) { + attrs = uriAttrs[2] + link = Link.parseParams(link, uriAttrs[1]) + } + + while(match = Link.attrPattern.exec(attrs)) { + attr = match[1].toLowerCase() + value = match[4] || match[3] || match[2] + + if( /\*$/.test(attr)) { + Link.setAttr(link, attr, Link.parseExtendedValue(value)) + } else if(/%/.test(value)) { + Link.setAttr(link, attr, querystring.decode(value)) + } else { + Link.setAttr(link, attr, value) + } + } + + return link +}; + +export default Link; -- cgit