ハッシュタグでユーザー検索できるように (#4298)
* ハッシュタグでユーザー検索できるように
* 🎨
* Increase limit
* リモートユーザーも表示
* Fix bug
* Fix bug
* Improve performance
This commit is contained in:
parent
03e2c7eec6
commit
1d5a54ff6f
22 changed files with 366 additions and 56 deletions
|
|
@ -19,7 +19,7 @@ import UserList from '../../models/user-list';
|
|||
import resolveUser from '../../remote/resolve-user';
|
||||
import Meta from '../../models/meta';
|
||||
import config from '../../config';
|
||||
import registerHashtag from '../register-hashtag';
|
||||
import { updateHashtag } from '../update-hashtag';
|
||||
import isQuote from '../../misc/is-quote';
|
||||
import notesChart from '../../services/chart/notes';
|
||||
import perUserNotesChart from '../../services/chart/per-user-notes';
|
||||
|
|
@ -235,7 +235,7 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
|
|||
}
|
||||
|
||||
// ハッシュタグ登録
|
||||
for (const tag of tags) registerHashtag(user, tag);
|
||||
for (const tag of tags) updateHashtag(user, tag);
|
||||
|
||||
// ファイルが添付されていた場合ドライブのファイルの「このファイルが添付された投稿一覧」プロパティにこの投稿を追加
|
||||
if (data.files) {
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
import { IUser } from '../models/user';
|
||||
import Hashtag from '../models/hashtag';
|
||||
import hashtagChart from '../services/chart/hashtag';
|
||||
|
||||
export default async function(user: IUser, tag: string) {
|
||||
tag = tag.toLowerCase();
|
||||
|
||||
const index = await Hashtag.findOne({ tag });
|
||||
|
||||
if (index != null) {
|
||||
// 自分が初めてこのタグを使ったなら
|
||||
if (!index.mentionedUserIds.some(id => id.equals(user._id))) {
|
||||
Hashtag.update({ tag }, {
|
||||
$push: {
|
||||
mentionedUserIds: user._id
|
||||
},
|
||||
$inc: {
|
||||
mentionedUserIdsCount: 1
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Hashtag.insert({
|
||||
tag,
|
||||
mentionedUserIds: [user._id],
|
||||
mentionedUserIdsCount: 1
|
||||
});
|
||||
}
|
||||
|
||||
hashtagChart.update(tag, user);
|
||||
}
|
||||
86
src/services/update-hashtag.ts
Normal file
86
src/services/update-hashtag.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import { IUser, isLocalUser } from '../models/user';
|
||||
import Hashtag from '../models/hashtag';
|
||||
import hashtagChart from './chart/hashtag';
|
||||
|
||||
export async function updateHashtag(user: IUser, tag: string, isUserAttached = false, inc = true) {
|
||||
tag = tag.toLowerCase();
|
||||
|
||||
const index = await Hashtag.findOne({ tag });
|
||||
|
||||
if (index == null && !inc) return;
|
||||
|
||||
if (index != null) {
|
||||
const $push = {} as any;
|
||||
const $pull = {} as any;
|
||||
const $inc = {} as any;
|
||||
|
||||
if (isUserAttached) {
|
||||
if (inc) {
|
||||
// 自分が初めてこのタグを使ったなら
|
||||
if (!index.attachedUserIds.some(id => id.equals(user._id))) {
|
||||
$push.attachedUserIds = user._id;
|
||||
$inc.attachedUsersCount = 1;
|
||||
}
|
||||
// 自分が(ローカル内で)初めてこのタグを使ったなら
|
||||
if (isLocalUser(user) && !index.attachedLocalUserIds.some(id => id.equals(user._id))) {
|
||||
$push.attachedLocalUserIds = user._id;
|
||||
$inc.attachedLocalUsersCount = 1;
|
||||
}
|
||||
} else {
|
||||
$pull.attachedUserIds = user._id;
|
||||
$inc.attachedUsersCount = -1;
|
||||
if (isLocalUser(user)) {
|
||||
$pull.attachedLocalUserIds = user._id;
|
||||
$inc.attachedLocalUsersCount = -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 自分が初めてこのタグを使ったなら
|
||||
if (!index.mentionedUserIds.some(id => id.equals(user._id))) {
|
||||
$push.mentionedUserIds = user._id;
|
||||
$inc.mentionedUsersCount = 1;
|
||||
}
|
||||
// 自分が(ローカル内で)初めてこのタグを使ったなら
|
||||
if (isLocalUser(user) && !index.mentionedLocalUserIds.some(id => id.equals(user._id))) {
|
||||
$push.mentionedLocalUserIds = user._id;
|
||||
$inc.mentionedLocalUsersCount = 1;
|
||||
}
|
||||
}
|
||||
|
||||
const q = {} as any;
|
||||
if (Object.keys($push).length > 0) q.$push = $push;
|
||||
if (Object.keys($pull).length > 0) q.$pull = $pull;
|
||||
if (Object.keys($inc).length > 0) q.$inc = $inc;
|
||||
if (Object.keys(q).length > 0) Hashtag.update({ tag }, q);
|
||||
} else {
|
||||
if (isUserAttached) {
|
||||
Hashtag.insert({
|
||||
tag,
|
||||
mentionedUserIds: [],
|
||||
mentionedUsersCount: 0,
|
||||
mentionedLocalUserIds: [],
|
||||
mentionedLocalUsersCount: 0,
|
||||
attachedUserIds: [user._id],
|
||||
attachedUsersCount: 1,
|
||||
attachedLocalUserIds: isLocalUser(user) ? [user._id] : [],
|
||||
attachedLocalUsersCount: isLocalUser(user) ? 1 : 0
|
||||
});
|
||||
} else {
|
||||
Hashtag.insert({
|
||||
tag,
|
||||
mentionedUserIds: [user._id],
|
||||
mentionedUsersCount: 1,
|
||||
mentionedLocalUserIds: isLocalUser(user) ? [user._id] : [],
|
||||
mentionedLocalUsersCount: isLocalUser(user) ? 1 : 0,
|
||||
attachedUserIds: [],
|
||||
attachedUsersCount: 0,
|
||||
attachedLocalUserIds: [],
|
||||
attachedLocalUsersCount: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!isUserAttached) {
|
||||
hashtagChart.update(tag, user);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue