refs #581 Control notification using preferences

This commit is contained in:
AkiraFukushima 2018-08-30 08:34:11 +09:00
parent 5b43b606d5
commit 2de06a9776
4 changed files with 67 additions and 19 deletions

View File

@ -91,6 +91,15 @@ export default {
})
}
}
},
created () {
this.$store.dispatch('Preferences/Notification/loadNotification')
.catch(() => {
this.$message({
message: this.$t('message.preferences_load_error'),
type: 'error'
})
})
}
}
</script>

View File

@ -11,7 +11,13 @@ const App = {
theme: LightTheme,
fontSize: 14,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
tootVisibility: Visibility.Public.value
tootVisibility: Visibility.Public.value,
notify: {
reply: true,
reblog: true,
favourite: true,
follow: true
}
},
mutations: {
updateTheme (state, themeKey) {
@ -35,6 +41,9 @@ const App = {
},
updateTootVisibility (state, value) {
state.tootVisibility = value
},
updateNotify (state, notify) {
state.notify = notify
}
},
actions: {
@ -59,6 +68,7 @@ const App = {
commit('updateDisplayNameStyle', conf.general.displayNameStyle)
commit('updateFontSize', conf.general.fontSize)
commit('updateTootVisibility', conf.general.tootVisibility)
commit('updateNotify', conf.notification.notify)
resolve(conf)
})
})

View File

@ -18,7 +18,21 @@ export default {
}
},
actions: {
updateNotify ({ commit, state }, notify) {
loadNotification ({ commit }) {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-preferences')
ipcRenderer.once('error-get-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-get-preferences')
reject(err)
})
ipcRenderer.once('response-get-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-get-preferences')
commit('updateNotification', conf.notification)
resolve(conf)
})
})
},
updateNotify ({ commit, state, dispatch }, notify) {
const newNotify = Object.assign({}, state.notification.notify, notify)
const newNotification = Object.assign({}, state.notification, {
notify: newNotify
@ -29,6 +43,7 @@ export default {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('response-update-preferences', (event, conf) => {
commit('updateNotification', conf.notification)
dispatch('App/loadPreferences', null, { root: true })
})
}
}

View File

@ -89,9 +89,11 @@ const TimelineSpace = {
commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', true, { root: true })
})
ipcRenderer.on('notification-start-user-streaming', (event, notification) => {
let notify = buildNotification(notification)
notify.onclick = () => {
router.push(`/${account._id}/notifications`)
let notify = createNotification(notification, rootState.App.notify)
if (notify) {
notify.onclick = () => {
router.push(`/${account._id}/notifications`)
}
}
commit('TimelineSpace/Contents/Notifications/appendNotifications', notification, { root: true })
if (rootState.TimelineSpace.Contents.Notifications.heading && Math.random() > 0.8) {
@ -172,25 +174,37 @@ const TimelineSpace = {
export default TimelineSpace
function buildNotification (notification) {
function createNotification (notification, notifyConfig) {
switch (notification.type) {
case 'favourite':
return new Notification('Favourite', {
body: `${username(notification.account)} favourited your status`
})
if (notifyConfig.favourite) {
return new Notification('Favourite', {
body: `${username(notification.account)} favourited your status`
})
}
break
case 'follow':
return new Notification('Follow', {
body: `${username(notification.account)} is now following you`
})
if (notifyConfig.follow) {
return new Notification('Follow', {
body: `${username(notification.account)} is now following you`
})
}
break
case 'mention':
// Clean html tags
return new Notification(`${notification.status.account.display_name}`, {
body: `${notification.status.content.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g, '')}`
})
if (notifyConfig.reply) {
// Clean html tags
return new Notification(`${notification.status.account.display_name}`, {
body: `${notification.status.content.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g, '')}`
})
}
break
case 'reblog':
return new Notification('Reblog', {
body: `${username(notification.account)} boosted your status`
})
if (notifyConfig.reblog) {
return new Notification('Reblog', {
body: `${username(notification.account)} boosted your status`
})
}
break
}
}