新規投稿のMFMをHTMLに変換する際、リモートユーザーへのメンションのリンク先を(できれば)urlに (#5562)
* 新規投稿のMFMをHTMLに変換する際、リモートユーザーへのメンションのリンク先を(できれば)urlに Fix #2467 Related #5560 * remove unnecessary import * Update src/services/note/create.ts Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com> * Apply suggestions from code review Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
parent
e1cf090440
commit
0c1d3e186b
|
@ -135,7 +135,7 @@ export function toHtml(tokens: MfmForest | null, mentionedRemoteUsers: IMentione
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
const remoteUserInfo = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
|
const remoteUserInfo = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
|
||||||
a.href = remoteUserInfo ? remoteUserInfo.uri : `${config.url}/${acct}`;
|
a.href = remoteUserInfo ? (remoteUserInfo.url ? remoteUserInfo.url : remoteUserInfo.uri) : `${config.url}/${acct}`;
|
||||||
a.className = 'u-url mention';
|
a.className = 'u-url mention';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,6 +228,7 @@ export class Note {
|
||||||
|
|
||||||
export type IMentionedRemoteUsers = {
|
export type IMentionedRemoteUsers = {
|
||||||
uri: string;
|
uri: string;
|
||||||
|
url?: string;
|
||||||
username: string;
|
username: string;
|
||||||
host: string;
|
host: string;
|
||||||
}[];
|
}[];
|
||||||
|
|
|
@ -16,11 +16,11 @@ import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc';
|
||||||
import extractMentions from '../../misc/extract-mentions';
|
import extractMentions from '../../misc/extract-mentions';
|
||||||
import extractEmojis from '../../misc/extract-emojis';
|
import extractEmojis from '../../misc/extract-emojis';
|
||||||
import extractHashtags from '../../misc/extract-hashtags';
|
import extractHashtags from '../../misc/extract-hashtags';
|
||||||
import { Note } from '../../models/entities/note';
|
import { Note, IMentionedRemoteUsers } from '../../models/entities/note';
|
||||||
import { Mutings, Users, NoteWatchings, Followings, Notes, Instances, UserProfiles } from '../../models';
|
import { Mutings, Users, NoteWatchings, Followings, Notes, Instances, UserProfiles } from '../../models';
|
||||||
import { DriveFile } from '../../models/entities/drive-file';
|
import { DriveFile } from '../../models/entities/drive-file';
|
||||||
import { App } from '../../models/entities/app';
|
import { App } from '../../models/entities/app';
|
||||||
import { Not, getConnection } from 'typeorm';
|
import { Not, getConnection, In } from 'typeorm';
|
||||||
import { User, ILocalUser, IRemoteUser } from '../../models/entities/user';
|
import { User, ILocalUser, IRemoteUser } from '../../models/entities/user';
|
||||||
import { genId } from '../../misc/gen-id';
|
import { genId } from '../../misc/gen-id';
|
||||||
import { notesChart, perUserNotesChart, activeUsersChart, instanceChart } from '../chart';
|
import { notesChart, perUserNotesChart, activeUsersChart, instanceChart } from '../chart';
|
||||||
|
@ -383,11 +383,17 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
|
||||||
// Append mentions data
|
// Append mentions data
|
||||||
if (mentionedUsers.length > 0) {
|
if (mentionedUsers.length > 0) {
|
||||||
insert.mentions = mentionedUsers.map(u => u.id);
|
insert.mentions = mentionedUsers.map(u => u.id);
|
||||||
insert.mentionedRemoteUsers = JSON.stringify(mentionedUsers.filter(u => Users.isRemoteUser(u)).map(u => ({
|
const profiles = await UserProfiles.find({ userId: In(insert.mentions) });
|
||||||
uri: (u as IRemoteUser).uri,
|
insert.mentionedRemoteUsers = JSON.stringify(mentionedUsers.filter(u => Users.isRemoteUser(u)).map(u => {
|
||||||
|
const profile = profiles.find(p => p.userId == u.id);
|
||||||
|
const url = profile != null ? profile.url : null;
|
||||||
|
return {
|
||||||
|
uri: u.uri,
|
||||||
|
url: url == null ? undefined : url,
|
||||||
username: u.username,
|
username: u.username,
|
||||||
host: u.host
|
host: u.host
|
||||||
})));
|
} as IMentionedRemoteUsers[0];
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 投稿を作成
|
// 投稿を作成
|
||||||
|
|
Loading…
Reference in New Issue