This commit is contained in:
syuilo 2018-12-19 11:16:29 +09:00
parent 556677be7a
commit 00f979f0e6
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
5 changed files with 34 additions and 16 deletions

View file

@ -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}`;
//

View file

@ -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}`;
//

View file

@ -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,

View file

@ -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;
}

View file

@ -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 => {