Merge pull request #410 from h3poteto/iss-409

closes #409 Fix findLink method to detect link, tag, and account
This commit is contained in:
AkiraFukushima 2018-06-20 22:04:10 +09:00 committed by GitHub
commit f229144f25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 5 deletions

View File

@ -36,7 +36,7 @@
<script>
import moment from 'moment'
import { shell } from 'electron'
import { findLink, isTag } from '../../../../utils/link'
import { findAccount, findLink, isTag } from '../../../../utils/link'
export default {
name: 'favourite',
@ -58,6 +58,23 @@ export default {
this.$router.push({ path: tag })
return tag
}
const accountURL = findAccount(e.target)
if (accountURL !== null) {
this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', true)
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/searchAccount', accountURL)
.then((account) => {
this.$store.dispatch('TimelineSpace/Contents/SideBar/openAccountComponent')
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account)
})
.catch(() => {
this.$message({
message: 'Account not found',
type: 'error'
})
this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', false)
})
return accountURL
}
const link = findLink(e.target)
if (link !== null) {
return shell.openExternal(link)

View File

@ -36,7 +36,7 @@
<script>
import moment from 'moment'
import { shell } from 'electron'
import { findLink, isTag } from '../../../../utils/link'
import { findAccount, findLink, isTag } from '../../../../utils/link'
export default {
name: 'reblog',
@ -58,6 +58,23 @@ export default {
this.$router.push({ path: tag })
return tag
}
const accountURL = findAccount(e.target)
if (accountURL !== null) {
this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', true)
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/searchAccount', accountURL)
.then((account) => {
this.$store.dispatch('TimelineSpace/Contents/SideBar/openAccountComponent')
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account)
})
.catch(() => {
this.$message({
message: 'Account not found',
type: 'error'
})
this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', false)
})
return accountURL
}
const link = findLink(e.target)
if (link !== null) {
return shell.openExternal(link)

View File

@ -5,7 +5,9 @@ export function findLink (target) {
if (target.parentNode === undefined || target.parentNode === null) {
return null
}
if (target.parentNode.getAttribute('class') === 'toot') {
if ((target.parentNode.getAttribute('class') === 'toot') ||
(target.parentNode.getAttribute('class') === 'favourite') ||
(target.parentNode.getAttribute('class') === 'reblog')) {
return null
}
return findLink(target.parentNode)
@ -18,7 +20,9 @@ export function isTag (target) {
if (target.parentNode === undefined || target.parentNode === null) {
return false
}
if (target.parentNode.getAttribute('class') === 'toot') {
if ((target.parentNode.getAttribute('class') === 'toot') ||
(target.parentNode.getAttribute('class') === 'favourite') ||
(target.parentNode.getAttribute('class') === 'reblog')) {
return false
}
return isTag(target.parentNode)
@ -31,7 +35,9 @@ export function findAccount (target) {
if (target.parentNode === undefined || target.parentNode === null) {
return null
}
if (target.parentNode.getAttribute('class') === 'toot') {
if ((target.parentNode.getAttribute('class') === 'toot') ||
(target.parentNode.getAttribute('class') === 'favourite') ||
(target.parentNode.getAttribute('class') === 'reblog')) {
return null
}
return findAccount(target.parentNode)