summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-12-19 11:16:29 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-12-19 11:16:29 +0900
commit00f979f0e65d92d4ad522146e5543a651485933c (patch)
tree37581222706f296b2b13860315eb52143a553e46
parentRefactor (diff)
downloadmisskey-00f979f0e65d92d4ad522146e5543a651485933c.tar.gz
misskey-00f979f0e65d92d4ad522146e5543a651485933c.tar.bz2
misskey-00f979f0e65d92d4ad522146e5543a651485933c.zip
Fix bug
-rw-r--r--src/client/app/desktop/views/components/post-form.vue4
-rw-r--r--src/client/app/mobile/views/components/post-form.vue3
-rw-r--r--src/mfm/parser.ts9
-rw-r--r--src/misc/extract-mentions.ts19
-rw-r--r--src/services/note/create.ts15
5 files changed, 34 insertions, 16 deletions
diff --git a/src/client/app/desktop/views/components/post-form.vue b/src/client/app/desktop/views/components/post-form.vue
index 0e86bbf9f8..de3e815b8e 100644
--- a/src/client/app/desktop/views/components/post-form.vue
+++ b/src/client/app/desktop/views/components/post-form.vue
@@ -74,6 +74,7 @@ import { host } from '../../../config';
import { erase, unique } from '../../../../../prelude/array';
import { length } from 'stringz';
import { toASCII } from 'punycode';
+import extractMentions from '../../../../../misc/extract-mentions';
export default Vue.extend({
i18n: i18n('desktop/views/components/post-form.vue'),
@@ -184,8 +185,7 @@ export default Vue.extend({
if (this.reply && this.reply.text != null) {
const ast = parse(this.reply.text);
- // TODO: 新しいMFMパーサに対応
- for (const x of ast.filter(t => t.type == 'mention')) {
+ for (const x of extractMentions(ast)) {
const mention = x.host ? `@${x.username}@${toASCII(x.host)}` : `@${x.username}`;
// 自分は除外
diff --git a/src/client/app/mobile/views/components/post-form.vue b/src/client/app/mobile/views/components/post-form.vue
index d9cf1471c5..e35a647640 100644
--- a/src/client/app/mobile/views/components/post-form.vue
+++ b/src/client/app/mobile/views/components/post-form.vue
@@ -66,6 +66,7 @@ import { host } from '../../../config';
import { erase, unique } from '../../../../../prelude/array';
import { length } from 'stringz';
import { toASCII } from 'punycode';
+import extractMentions from '../../../../../misc/extract-mentions';
export default Vue.extend({
i18n: i18n('mobile/views/components/post-form.vue'),
@@ -174,7 +175,7 @@ export default Vue.extend({
if (this.reply && this.reply.text != null) {
const ast = parse(this.reply.text);
- for (const x of ast.filter(t => t.type == 'mention')) {
+ for (const x of extractMentions(ast)) {
const mention = x.host ? `@${x.username}@${toASCII(x.host)}` : `@${x.username}`;
// 自分は除外
diff --git a/src/mfm/parser.ts b/src/mfm/parser.ts
index 6980b36ea0..56c49ba3fa 100644
--- a/src/mfm/parser.ts
+++ b/src/mfm/parser.ts
@@ -11,6 +11,15 @@ export type Node = {
props?: any;
};
+export interface IMentionNode extends Node {
+ props: {
+ canonical: string;
+ username: string;
+ host: string;
+ acct: string;
+ };
+}
+
function _makeNode(name: string, children?: Node[], props?: any): Node {
return children ? {
name,
diff --git a/src/misc/extract-mentions.ts b/src/misc/extract-mentions.ts
new file mode 100644
index 0000000000..1d844211c0
--- /dev/null
+++ b/src/misc/extract-mentions.ts
@@ -0,0 +1,19 @@
+import parse from '../mfm/parse';
+import { Node, IMentionNode } from '../mfm/parser';
+
+export default function(tokens: ReturnType<typeof parse>): IMentionNode['props'][] {
+ const mentions: IMentionNode['props'][] = [];
+
+ const extract = (tokens: Node[]) => {
+ for (const x of tokens.filter(x => x.name === 'mention')) {
+ mentions.push(x.props);
+ }
+ for (const x of tokens.filter(x => x.children)) {
+ extract(x.children);
+ }
+ };
+
+ extract(tokens);
+
+ return mentions;
+}
diff --git a/src/services/note/create.ts b/src/services/note/create.ts
index eef36505ab..75d9521bd7 100644
--- a/src/services/note/create.ts
+++ b/src/services/note/create.ts
@@ -29,6 +29,7 @@ import insertNoteUnread from './unread';
import registerInstance from '../register-instance';
import Instance from '../../models/instance';
import { Node } from '../../mfm/parser';
+import extractMentions from '../../misc/extract-mentions';
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';
@@ -665,19 +666,7 @@ function incNotesCount(user: IUser) {
async function extractMentionedUsers(user: IUser, tokens: ReturnType<typeof parse>): Promise<IUser[]> {
if (tokens == null) return [];
- const mentions: any[] = [];
-
- const extract = (tokens: Node[]) => {
- for (const x of tokens.filter(x => x.name === 'mention')) {
- mentions.push(x.props);
- }
- for (const x of tokens.filter(x => x.children)) {
- extract(x.children);
- }
- };
-
- // Extract hashtags
- extract(tokens);
+ const mentions = extractMentions(tokens);
let mentionedUsers =
erase(null, await Promise.all(mentions.map(async m => {