diff --git a/src/main/account.js b/src/main/account.js index b7b8179c..c9358e84 100644 --- a/src/main/account.js +++ b/src/main/account.js @@ -36,6 +36,21 @@ export default class Account { ) }) } + + getAccount (id) { + return new Promise((resolve, reject) => { + this.db.findOne( + { + _id: id + }, + (err, doc) => { + if (err) return reject(err) + if (empty(doc)) return reject(new EmptyRecordError('empty')) + resolve(doc) + } + ) + }) + } } class EmptyRecordError { diff --git a/src/main/index.js b/src/main/index.js index 69ea92ad..b68a02b5 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -125,6 +125,17 @@ ipcMain.on('get-instance', (event, id) => { }) }) +ipcMain.on('get-local-account', (event, id) => { + const account = new Account(db) + account.getAccount(id) + .catch((err) => { + event.sender.send('error-get-local-account', err) + }) + .then((token) => { + event.sender.send('response-get-local-account', token) + }) +}) + /** * Auto Updater * diff --git a/src/renderer/components/TimelineSpace.vue b/src/renderer/components/TimelineSpace.vue index aef7beb1..69dbe096 100644 --- a/src/renderer/components/TimelineSpace.vue +++ b/src/renderer/components/TimelineSpace.vue @@ -22,6 +22,6 @@ export default { diff --git a/src/renderer/components/TimelineSpace/SideMenu.vue b/src/renderer/components/TimelineSpace/SideMenu.vue index dc251261..c2d4a7d8 100644 --- a/src/renderer/components/TimelineSpace/SideMenu.vue +++ b/src/renderer/components/TimelineSpace/SideMenu.vue @@ -2,7 +2,8 @@
- {{ instance.baseURL }} + @{{ username }} + {{ instance.baseURL }}
state.TimelineSpace.SideMenu.instance + instance: state => state.TimelineSpace.SideMenu.instance, + username: state => state.TimelineSpace.SideMenu.username }) }, created () { this.$store.dispatch('TimelineSpace/SideMenu/fetchInstance', this.$route.params.id) + this.$store.dispatch('TimelineSpace/SideMenu/username', this.$route.params.id) }, methods: { id () { @@ -64,8 +67,8 @@ export default { position: fixed; top: 0; left: 65px; - width: 144px; - height: 40px; + width: 180px; + height: 60px; .profile { color: #ffffff; @@ -76,10 +79,10 @@ export default { .timeline-menu { position: fixed; - top: 40px; + top: 60px; left: 65px; height: 100%; - width: 144px; + width: 180px; } } diff --git a/src/renderer/store/TimelineSpace/SideMenu.js b/src/renderer/store/TimelineSpace/SideMenu.js index 46bfe918..371971e6 100644 --- a/src/renderer/store/TimelineSpace/SideMenu.js +++ b/src/renderer/store/TimelineSpace/SideMenu.js @@ -1,4 +1,5 @@ import { ipcRenderer } from 'electron' +import Mastodon from 'mastodon-api' const SideMenu = { namespaced: true, @@ -6,11 +7,15 @@ const SideMenu = { instance: { baseURL: '', id: '' - } + }, + username: '' }, mutations: { updateInstance (state, instance) { state.instance = instance + }, + updateUsername (state, body) { + state.username = body.username } }, actions: { @@ -23,6 +28,27 @@ const SideMenu = { ipcRenderer.on('response-get-instance', (event, instance) => { commit('updateInstance', instance) }) + }, + username ({ commit }, id) { + return new Promise((resolve, reject) => { + ipcRenderer.send('get-local-account', id) + ipcRenderer.on('error-get-local-account', (event, err) => { + reject(err) + }) + ipcRenderer.on('response-get-local-account', (event, account) => { + const client = new Mastodon( + { + access_token: account.accessToken, + api_url: account.baseURL + '/api/v1' + + }) + client.get('/accounts/verify_credentials', {}) + .then((res) => { + commit('updateUsername', res.data) + resolve(res) + }) + }) + }) } } }