refs #517 Update instance custom emoji and apply to suggest

This commit is contained in:
AkiraFukushima 2018-08-19 14:42:20 +09:00
parent d8b81281d6
commit 810a0660aa
4 changed files with 29 additions and 12 deletions

View File

@ -120,6 +120,7 @@ export default {
})
})
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
this.$store.dispatch('TimelineSpace/fetchEmojis', account)
},
handleDrop (e) {
e.preventDefault()

View File

@ -22,7 +22,7 @@
@shortkey="insertItem(item)"
@mouseover="highlightedIndex = index"
:class="{'highlighted': highlightedIndex === index}">
{{ item }}
{{ item.name }}
</li>
</ul>
</el-popover>
@ -50,17 +50,13 @@ export default {
highlightedIndex: 0,
startIndex: null,
matchWord: null,
filteredSuggestion: [],
emojis: [
':python:',
':slack:',
':nodejs'
]
filteredSuggestion: []
}
},
computed: {
...mapState({
filteredAccounts: state => state.TimelineSpace.Modals.NewToot.Status.filteredAccounts
filteredAccounts: state => state.TimelineSpace.Modals.NewToot.Status.filteredAccounts,
emojis: state => state.TimelineSpace.emojis
}),
status: {
get: function () {
@ -126,7 +122,7 @@ export default {
this.closeSuggest()
return false
}
const filtered = this.emojis.filter(emoji => emoji.includes(word))
const filtered = this.emojis.filter(emoji => emoji.name.includes(word))
if (filtered.length > 0) {
this.openSuggest = true
this.startIndex = start
@ -155,7 +151,7 @@ export default {
}
},
insertItem (item) {
const str = `${this.status.slice(0, this.startIndex)}${item} ${this.status.slice(this.startIndex + this.matchWord.length)}`
const str = `${this.status.slice(0, this.startIndex - 1)}${item.name} ${this.status.slice(this.startIndex + this.matchWord.length)}`
this.status = str
this.closeSuggest()
},

View File

@ -1,4 +1,5 @@
import { ipcRenderer } from 'electron'
import Mastodon from 'megalodon'
import SideMenu from './TimelineSpace/SideMenu'
import HeaderMenu from './TimelineSpace/HeaderMenu'
import Modals from './TimelineSpace/Modals'
@ -19,7 +20,8 @@ const TimelineSpace = {
_id: '',
username: ''
},
loading: false
loading: false,
emojis: []
},
mutations: {
updateAccount (state, account) {
@ -27,6 +29,14 @@ const TimelineSpace = {
},
changeLoading (state, value) {
state.loading = value
},
updateEmojis (state, emojis) {
state.emojis = emojis.map((e) => {
return {
name: `:${e.shortcode}:`,
image: e.url
}
})
}
},
actions: {
@ -151,6 +161,11 @@ const TimelineSpace = {
},
async clearUnread ({ dispatch }) {
dispatch('TimelineSpace/SideMenu/clearUnread', {}, { root: true })
},
async fetchEmojis ({ commit }, account) {
const data = await Mastodon.get('/custom_emojis', {}, account.baseURL + '/api/v1')
commit('updateEmojis', data)
return data
}
}
}

View File

@ -7,7 +7,12 @@ const Status = {
},
mutations: {
updateFilteredAccounts (state, accounts) {
state.filteredAccounts = accounts.map(a => a.acct)
state.filteredAccounts = accounts.map((a) => {
return {
name: `@${a.acct}`,
image: null
}
})
},
clearFilteredAccounts (state) {
state.filteredAccounts = []