add unescape function without jQuery

This commit is contained in:
Yamagishi Kazutoshi 2017-04-29 20:13:06 +09:00
parent 7d6d918f69
commit a373e0f908
1 changed files with 7 additions and 1 deletions

View File

@ -25,6 +25,12 @@ const fetchRelatedRelationships = (dispatch, notifications) => {
}
};
const unescapeHTML = (html) => {
const wrapper = document.createElement('p');
wrapper.innerHTML = html;
return wrapper.textContent;
}
export function updateNotifications(notification, intlMessages, intlLocale) {
return (dispatch, getState) => {
const showAlert = getState().getIn(['settings', 'notifications', 'alerts', notification.type], true);
@ -43,7 +49,7 @@ export function updateNotifications(notification, intlMessages, intlLocale) {
// Desktop notifications
if (typeof window.Notification !== 'undefined' && showAlert) {
const title = new IntlMessageFormat(intlMessages[`notification.${notification.type}`], intlLocale).format({ name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username });
const body = (notification.status && notification.status.spoiler_text.length > 0) ? notification.status.spoiler_text : $('<p>').html(notification.status ? notification.status.content : '').text();
const body = (notification.status && notification.status.spoiler_text.length > 0) ? notification.status.spoiler_text : notification.status ? unescapeHTML(notification.status.content) : '';
new Notification(title, { body, icon: notification.account.avatar, tag: notification.id });
}