diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-04-25 07:46:39 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-04-25 07:46:39 +0900 |
| commit | 0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d (patch) | |
| tree | 38d3d6b2112326bb1a03a8732cd8969e24d693de /src/client/app | |
| parent | Fix #4793 (diff) | |
| download | sharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.tar.gz sharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.tar.bz2 sharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.zip | |
Resolve #3119
Diffstat (limited to 'src/client/app')
| -rw-r--r-- | src/client/app/common/scripts/gen-search-query.ts | 31 | ||||
| -rw-r--r-- | src/client/app/common/scripts/search.ts | 2 | ||||
| -rw-r--r-- | src/client/app/common/views/components/user-list.vue | 8 | ||||
| -rw-r--r-- | src/client/app/common/views/deck/deck.notes.vue | 8 | ||||
| -rw-r--r-- | src/client/app/common/views/deck/deck.search-column.vue | 5 | ||||
| -rw-r--r-- | src/client/app/desktop/views/components/notes.vue | 6 | ||||
| -rw-r--r-- | src/client/app/desktop/views/home/search.vue | 5 | ||||
| -rw-r--r-- | src/client/app/mobile/views/components/notes.vue | 8 | ||||
| -rw-r--r-- | src/client/app/mobile/views/pages/search.vue | 5 |
9 files changed, 56 insertions, 22 deletions
diff --git a/src/client/app/common/scripts/gen-search-query.ts b/src/client/app/common/scripts/gen-search-query.ts new file mode 100644 index 0000000000..fc26cb7f78 --- /dev/null +++ b/src/client/app/common/scripts/gen-search-query.ts @@ -0,0 +1,31 @@ +import parseAcct from '../../../../misc/acct/parse'; +import { host as localHost } from '../../config'; + +export async function genSearchQuery(v: any, q: string) { + let host: string; + let userId: string; + if (q.split(' ').some(x => x.startsWith('@'))) { + for (const at of q.split(' ').filter(x => x.startsWith('@')).map(x => x.substr(1))) { + if (at.includes('.')) { + if (at === localHost || at === '.') { + host = null; + } else { + host = at; + } + } else { + const user = await v.$root.api('users/show', parseAcct(at)).catch(x => null); + if (user) { + userId = user.id; + } else { + // todo: show error + } + } + } + + } + return { + query: q.split(' ').filter(x => !x.startsWith('/') && !x.startsWith('@')).join(' '), + host: host, + userId: userId + }; +} diff --git a/src/client/app/common/scripts/search.ts b/src/client/app/common/scripts/search.ts index c44581817b..2897ed6318 100644 --- a/src/client/app/common/scripts/search.ts +++ b/src/client/app/common/scripts/search.ts @@ -3,7 +3,7 @@ import { faHistory } from '@fortawesome/free-solid-svg-icons'; export async function search(v: any, q: string) { q = q.trim(); - if (q.startsWith('@')) { + if (q.startsWith('@') && !q.includes(' ')) { v.$router.push(`/${q}`); return; } diff --git a/src/client/app/common/views/components/user-list.vue b/src/client/app/common/views/components/user-list.vue index b8bcc35d82..53577bad00 100644 --- a/src/client/app/common/views/components/user-list.vue +++ b/src/client/app/common/views/components/user-list.vue @@ -60,9 +60,9 @@ export default Vue.extend({ }, methods: { - init() { + async init() { this.fetching = true; - this.makePromise().then(x => { + await (this.makePromise()).then(x => { if (Array.isArray(x)) { this.us = x; } else { @@ -76,9 +76,9 @@ export default Vue.extend({ }); }, - fetchMoreUsers() { + async fetchMoreUsers() { this.fetchingMoreUsers = true; - this.makePromise(this.cursor).then(x => { + await (this.makePromise(this.cursor)).then(x => { this.us = this.us.concat(x.users); this.cursor = x.cursor; this.fetchingMoreUsers = false; diff --git a/src/client/app/common/views/deck/deck.notes.vue b/src/client/app/common/views/deck/deck.notes.vue index bc67f4911c..680b44bc81 100644 --- a/src/client/app/common/views/deck/deck.notes.vue +++ b/src/client/app/common/views/deck/deck.notes.vue @@ -110,11 +110,11 @@ export default Vue.extend({ this.init(); }, - init() { + async init() { this.queue = []; this.notes = []; this.fetching = true; - this.makePromise().then(x => { + await (this.makePromise()).then(x => { if (Array.isArray(x)) { this.notes = x; } else { @@ -129,10 +129,10 @@ export default Vue.extend({ }); }, - fetchMore() { + async fetchMore() { if (!this.more || this.moreFetching) return; this.moreFetching = true; - this.makePromise(this.notes[this.notes.length - 1].id).then(x => { + await (this.makePromise(this.notes[this.notes.length - 1].id)).then(x => { this.notes = this.notes.concat(x.notes); this.more = x.more; this.moreFetching = false; diff --git a/src/client/app/common/views/deck/deck.search-column.vue b/src/client/app/common/views/deck/deck.search-column.vue index ab19bdaab6..17ee2ef454 100644 --- a/src/client/app/common/views/deck/deck.search-column.vue +++ b/src/client/app/common/views/deck/deck.search-column.vue @@ -14,6 +14,7 @@ import Vue from 'vue'; import XColumn from './deck.column.vue'; import XNotes from './deck.notes.vue'; +import { genSearchQuery } from '../../../common/scripts/gen-search-query'; const limit = 20; @@ -25,10 +26,10 @@ export default Vue.extend({ data() { return { - makePromise: cursor => this.$root.api('notes/search', { + makePromise: async cursor => this.$root.api('notes/search', { limit: limit + 1, offset: cursor ? cursor : undefined, - query: this.q + ...(await genSearchQuery(this, this.q)) }).then(notes => { if (notes.length == limit + 1) { notes.pop(); diff --git a/src/client/app/desktop/views/components/notes.vue b/src/client/app/desktop/views/components/notes.vue index 9044ad3478..87fdc749de 100644 --- a/src/client/app/desktop/views/components/notes.vue +++ b/src/client/app/desktop/views/components/notes.vue @@ -105,9 +105,9 @@ export default Vue.extend({ this.init(); }, - init() { + async init() { this.fetching = true; - this.makePromise().then(x => { + await (this.makePromise()).then(x => { if (Array.isArray(x)) { this.notes = x; } else { @@ -122,7 +122,7 @@ export default Vue.extend({ }); }, - fetchMore() { + async fetchMore() { if (!this.more || this.moreFetching || this.notes.length === 0) return; this.moreFetching = true; this.makePromise(this.notes[this.notes.length - 1].id).then(x => { diff --git a/src/client/app/desktop/views/home/search.vue b/src/client/app/desktop/views/home/search.vue index 84153d18c4..50c6456158 100644 --- a/src/client/app/desktop/views/home/search.vue +++ b/src/client/app/desktop/views/home/search.vue @@ -14,6 +14,7 @@ import Vue from 'vue'; import i18n from '../../../i18n'; import Progress from '../../../common/scripts/loading'; +import { genSearchQuery } from '../../../common/scripts/gen-search-query'; const limit = 20; @@ -21,10 +22,10 @@ export default Vue.extend({ i18n: i18n('desktop/views/pages/search.vue'), data() { return { - makePromise: cursor => this.$root.api('notes/search', { + makePromise: async cursor => this.$root.api('notes/search', { limit: limit + 1, offset: cursor ? cursor : undefined, - query: this.q + ...(await genSearchQuery(this, this.q)) }).then(notes => { if (notes.length == limit + 1) { notes.pop(); diff --git a/src/client/app/mobile/views/components/notes.vue b/src/client/app/mobile/views/components/notes.vue index 2e42300717..5ad80c286d 100644 --- a/src/client/app/mobile/views/components/notes.vue +++ b/src/client/app/mobile/views/components/notes.vue @@ -106,9 +106,9 @@ export default Vue.extend({ this.init(); }, - init() { + async init() { this.fetching = true; - this.makePromise().then(x => { + await (this.makePromise()).then(x => { if (Array.isArray(x)) { this.notes = x; } else { @@ -123,10 +123,10 @@ export default Vue.extend({ }); }, - fetchMore() { + async fetchMore() { if (!this.more || this.moreFetching || this.notes.length === 0) return; this.moreFetching = true; - this.makePromise(this.notes[this.notes.length - 1].id).then(x => { + await (this.makePromise(this.notes[this.notes.length - 1].id)).then(x => { this.notes = this.notes.concat(x.notes); this.more = x.more; this.moreFetching = false; diff --git a/src/client/app/mobile/views/pages/search.vue b/src/client/app/mobile/views/pages/search.vue index 0225dd9e9f..45f3837907 100644 --- a/src/client/app/mobile/views/pages/search.vue +++ b/src/client/app/mobile/views/pages/search.vue @@ -12,6 +12,7 @@ import Vue from 'vue'; import i18n from '../../../i18n'; import Progress from '../../../common/scripts/loading'; +import { genSearchQuery } from '../../../common/scripts/gen-search-query'; const limit = 20; @@ -19,10 +20,10 @@ export default Vue.extend({ i18n: i18n('mobile/views/pages/search.vue'), data() { return { - makePromise: cursor => this.$root.api('notes/search', { + makePromise: async cursor => this.$root.api('notes/search', { limit: limit + 1, untilId: cursor ? cursor : undefined, - query: this.q + ...(await genSearchQuery(this, this.q)) }).then(notes => { if (notes.length == limit + 1) { notes.pop(); |