mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-23 04:33:50 +01:00
Fix bug
This commit is contained in:
parent
8a97bd63c7
commit
4d17f35730
@ -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}`;
|
||||
|
||||
// 自分は除外
|
||||
|
@ -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}`;
|
||||
|
||||
// 自分は除外
|
||||
|
@ -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,
|
||||
|
19
src/misc/extract-mentions.ts
Normal file
19
src/misc/extract-mentions.ts
Normal 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;
|
||||
}
|
@ -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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user