From 7ecfc007a99d1df6d65b5f227a49d295e3df5913 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sun, 18 Aug 2019 12:47:45 +0900 Subject: [PATCH] =?UTF-8?q?updateHashtag=E3=82=92=E4=B8=A6=E5=88=97?= =?UTF-8?q?=E3=81=A7=E8=A1=8C=E3=82=8F=E3=81=AA=E3=81=84=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=20(#5284)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/remote/activitypub/models/person.ts | 8 +++----- src/server/api/endpoints/i/update.ts | 5 ++--- src/services/note/create.ts | 4 ++-- src/services/update-hashtag.ts | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index bfcad100f..b09446d69 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -12,7 +12,7 @@ import { ITag, extractHashtags } from './tag'; import { IIdentifier } from './identifier'; import { apLogger } from '../logger'; import { Note } from '../../../models/entities/note'; -import { updateHashtag } from '../../../services/update-hashtag'; +import { updateUsertags } from '../../../services/update-hashtag'; import { Users, UserNotePinings, Instances, DriveFiles, Followings, UserProfiles, UserPublickeys } from '../../../models'; import { User, IRemoteUser } from '../../../models/entities/user'; import { Emoji } from '../../../models/entities/emoji'; @@ -194,8 +194,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise !tags.includes(x))) updateHashtag(user!, tag, true, false); + updateUsertags(user!, tags); //#region アイコンとヘッダー画像をフェッチ const [avatar, banner] = (await Promise.all([ @@ -355,8 +354,7 @@ export async function updatePerson(uri: string, resolver?: Resolver | null, hint }); // ハッシュタグ更新 - for (const tag of tags) updateHashtag(exist, tag, true, true); - for (const tag of (exist.tags || []).filter(x => !tags.includes(x))) updateHashtag(exist, tag, true, false); + updateUsertags(exist, tags); // 該当ユーザーが既にフォロワーになっていた場合はFollowingもアップデートする await Followings.update({ diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index 149081e50..1ea2c2da3 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -8,7 +8,7 @@ import { parse, parsePlain } from '../../../../mfm/parse'; import extractEmojis from '../../../../misc/extract-emojis'; import extractHashtags from '../../../../misc/extract-hashtags'; import * as langmap from 'langmap'; -import { updateHashtag } from '../../../../services/update-hashtag'; +import { updateUsertags } from '../../../../services/update-hashtag'; import { ApiError } from '../../error'; import { Users, DriveFiles, UserProfiles, Pages } from '../../../../models'; import { User } from '../../../../models/entities/user'; @@ -264,8 +264,7 @@ export default define(meta, async (ps, user, app) => { updates.tags = tags; // ハッシュタグ更新 - for (const tag of tags) updateHashtag(user, tag, true, true); - for (const tag of user.tags.filter(x => !tags.includes(x))) updateHashtag(user, tag, true, false); + updateUsertags(user, tags); //#endregion if (Object.keys(updates).length > 0) await Users.update(user.id, updates); diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 48d867022..0dd0e1962 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -9,7 +9,7 @@ import watch from './watch'; import { parse } from '../../mfm/parse'; import { resolveUser } from '../../remote/resolve-user'; import config from '../../config'; -import { updateHashtag } from '../update-hashtag'; +import { updateHashtags } from '../update-hashtag'; import { concat } from '../../prelude/array'; import insertNoteUnread from './unread'; import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc'; @@ -202,7 +202,7 @@ export default async (user: User, data: Option, silent = false) => new Promise !tags.includes(x))) { + await updateHashtag(user, tag, true, false); + } +} + export async function updateHashtag(user: User, tag: string, isUserAttached = false, inc = true) { tag = tag.toLowerCase();