summaryrefslogtreecommitdiff
path: root/src/client/app/common/scripts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-25 07:46:39 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-25 07:46:39 +0900
commit0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d (patch)
tree38d3d6b2112326bb1a03a8732cd8969e24d693de /src/client/app/common/scripts
parentFix #4793 (diff)
downloadsharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.tar.gz
sharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.tar.bz2
sharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.zip
Resolve #3119
Diffstat (limited to 'src/client/app/common/scripts')
-rw-r--r--src/client/app/common/scripts/gen-search-query.ts31
-rw-r--r--src/client/app/common/scripts/search.ts2
2 files changed, 32 insertions, 1 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;
}