1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-06 04:13:36 +01:00

refs #26 Add desktop notification when get notification in user streaming

This commit is contained in:
AkiraFukushima 2018-03-13 14:52:13 +09:00
parent a0c01f1313
commit 2ef6a65aae
2 changed files with 28 additions and 4 deletions

View File

@ -10,7 +10,7 @@
background-color="#4a5664" background-color="#4a5664"
text-color="#909399" text-color="#909399"
active-text-color="#ffffff"> active-text-color="#ffffff">
<el-menu-item :index="index.toString()" v-for="(account, index) in accounts" v-bind:key="account.id" :route="{path: `/${account.id}/home`}"> <el-menu-item :index="index.toString()" v-for="(account, index) in accounts" v-bind:key="account._id" :route="{path: `/${account._id}/home`}">
<i class="el-icon-menu"></i> <i class="el-icon-menu"></i>
<span slot="title">{{ account.domain }}</span> <span slot="title">{{ account.domain }}</span>
</el-menu-item> </el-menu-item>

View File

@ -1,6 +1,7 @@
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
import Mastodon from 'mastodon-api' import Mastodon from 'mastodon-api'
import SideMenu from './TimelineSpace/SideMenu' import SideMenu from './TimelineSpace/SideMenu'
import router from '../router'
const TimelineSpace = { const TimelineSpace = {
namespaced: true, namespaced: true,
@ -10,7 +11,7 @@ const TimelineSpace = {
state: { state: {
account: { account: {
domain: '', domain: '',
id: '' _id: ''
}, },
username: '', username: '',
homeTimeline: [], homeTimeline: [],
@ -61,7 +62,6 @@ const TimelineSpace = {
{ {
access_token: account.accessToken, access_token: account.accessToken,
api_url: account.baseURL + '/api/v1' api_url: account.baseURL + '/api/v1'
}) })
client.get('/accounts/verify_credentials', {}) client.get('/accounts/verify_credentials', {})
.then((res) => { .then((res) => {
@ -72,7 +72,6 @@ const TimelineSpace = {
}, },
startUserStreaming ({ commit }, account) { startUserStreaming ({ commit }, account) {
ipcRenderer.send('start-user-streaming', account) ipcRenderer.send('start-user-streaming', account)
// TODO: when get notification, create notify and display badge in sidemenu
ipcRenderer.once('error-start-userstreaming', (event, err) => { ipcRenderer.once('error-start-userstreaming', (event, err) => {
console.log(err) console.log(err)
}) })
@ -80,6 +79,10 @@ const TimelineSpace = {
commit('appendHomeTimeline', update) commit('appendHomeTimeline', update)
}) })
ipcRenderer.on('notification-start-user-streaming', (event, notification) => { ipcRenderer.on('notification-start-user-streaming', (event, notification) => {
let notify = buildNotification(notification)
notify.onclick = () => {
router.push(`/${account._id}/notifications`)
}
commit('appendNotifications', notification) commit('appendNotifications', notification)
}) })
}, },
@ -160,3 +163,24 @@ export default TimelineSpace
class AuthenticationError { class AuthenticationError {
} }
function buildNotification (notification) {
switch (notification.type) {
case 'favourite':
return new Notification('Favourite', {
body: `${notification.account.display_name} favourited your status`
})
case 'follow':
return new Notification('Follow', {
body: `${notification.account.display_name} is now following you`
})
case 'mention':
return new Notification(`${notification.status.account.display_name}`, {
body: `${notification.status.content}`
})
case 'reblog':
return new Notification('Reblog', {
body: `${notification.account.display_name} boosted your status`
})
}
}