From 0c1d3e186b7b1b3d19ed6580decbbbab7e30ecd9 Mon Sep 17 00:00:00 2001 From: rinsuki <428rinsuki+git@gmail.com> Date: Fri, 1 Nov 2019 05:43:54 +0900 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E8=A6=8F=E6=8A=95=E7=A8=BF=E3=81=AEMF?= =?UTF-8?q?M=E3=82=92HTML=E3=81=AB=E5=A4=89=E6=8F=9B=E3=81=99=E3=82=8B?= =?UTF-8?q?=E9=9A=9B=E3=80=81=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=B8=E3=81=AE=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=AE=E3=83=AA=E3=83=B3=E3=82=AF?= =?UTF-8?q?=E5=85=88=E3=82=92(=E3=81=A7=E3=81=8D=E3=82=8C=E3=81=B0)url?= =?UTF-8?q?=E3=81=AB=20(#5562)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 新規投稿のMFMをHTMLに変換する際、リモートユーザーへのメンションのリンク先を(できれば)urlに Fix #2467 Related #5560 * remove unnecessary import * Update src/services/note/create.ts Co-Authored-By: Acid Chicken (硫酸鶏) * Apply suggestions from code review Co-Authored-By: Acid Chicken (硫酸鶏) --- src/mfm/toHtml.ts | 2 +- src/models/entities/note.ts | 1 + src/services/note/create.ts | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/mfm/toHtml.ts b/src/mfm/toHtml.ts index 8289288d3b..a44e70830c 100644 --- a/src/mfm/toHtml.ts +++ b/src/mfm/toHtml.ts @@ -135,7 +135,7 @@ export function toHtml(tokens: MfmForest | null, mentionedRemoteUsers: IMentione break; default: 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'; break; } diff --git a/src/models/entities/note.ts b/src/models/entities/note.ts index 33a6d2bc27..d67faae829 100644 --- a/src/models/entities/note.ts +++ b/src/models/entities/note.ts @@ -228,6 +228,7 @@ export class Note { export type IMentionedRemoteUsers = { uri: string; + url?: string; username: string; host: string; }[]; diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 9d5c0a58d5..5d9492e6ab 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -16,11 +16,11 @@ import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc'; import extractMentions from '../../misc/extract-mentions'; import extractEmojis from '../../misc/extract-emojis'; 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 { DriveFile } from '../../models/entities/drive-file'; 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 { genId } from '../../misc/gen-id'; 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 if (mentionedUsers.length > 0) { insert.mentions = mentionedUsers.map(u => u.id); - insert.mentionedRemoteUsers = JSON.stringify(mentionedUsers.filter(u => Users.isRemoteUser(u)).map(u => ({ - uri: (u as IRemoteUser).uri, - username: u.username, - host: u.host - }))); + const profiles = await UserProfiles.find({ userId: In(insert.mentions) }); + 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, + host: u.host + } as IMentionedRemoteUsers[0]; + })); } // 投稿を作成