ハッシュタグでユーザー検索できるように (#4298)
* ハッシュタグでユーザー検索できるように
* 🎨
* Increase limit
* リモートユーザーも表示
* Fix bug
* Fix bug
* Improve performance
This commit is contained in:
55
src/server/api/endpoints/hashtags/list.ts
Normal file
55
src/server/api/endpoints/hashtags/list.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import $ from 'cafy';
|
||||
import define from '../../define';
|
||||
import Hashtag from '../../../../models/hashtag';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
|
||||
params: {
|
||||
limit: {
|
||||
validator: $.optional.num.range(1, 100),
|
||||
default: 10
|
||||
},
|
||||
|
||||
sort: {
|
||||
validator: $.str.or([
|
||||
'+mentionedUsers',
|
||||
'-mentionedUsers',
|
||||
'+mentionedLocalUsers',
|
||||
'-mentionedLocalUsers',
|
||||
'+attachedUsers',
|
||||
'-attachedUsers',
|
||||
'+attachedLocalUsers',
|
||||
'-attachedLocalUsers',
|
||||
]),
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
const sort: any = {
|
||||
'+mentionedUsers': { mentionedUsersCount: -1 },
|
||||
'-mentionedUsers': { mentionedUsersCount: 1 },
|
||||
'+mentionedLocalUsers': { mentionedLocalUsersCount: -1 },
|
||||
'-mentionedLocalUsers': { mentionedLocalUsersCount: 1 },
|
||||
'+attachedUsers': { attachedUsersCount: -1 },
|
||||
'-attachedUsers': { attachedUsersCount: 1 },
|
||||
'+attachedLocalUsers': { attachedLocalUsersCount: -1 },
|
||||
'-attachedLocalUsers': { attachedLocalUsersCount: 1 },
|
||||
};
|
||||
|
||||
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||
const tags = await Hashtag
|
||||
.find({}, {
|
||||
limit: ps.limit,
|
||||
sort: sort[ps.sort],
|
||||
fields: {
|
||||
tag: true,
|
||||
mentionedUsersCount: true,
|
||||
mentionedLocalUsersCount: true,
|
||||
attachedUsersCount: true,
|
||||
attachedLocalUsersCount: true
|
||||
}
|
||||
});
|
||||
|
||||
res(tags);
|
||||
}));
|
83
src/server/api/endpoints/hashtags/users.ts
Normal file
83
src/server/api/endpoints/hashtags/users.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import $ from 'cafy';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
|
||||
params: {
|
||||
tag: {
|
||||
validator: $.str,
|
||||
},
|
||||
|
||||
limit: {
|
||||
validator: $.optional.num.range(1, 100),
|
||||
default: 10
|
||||
},
|
||||
|
||||
sort: {
|
||||
validator: $.str.or([
|
||||
'+follower',
|
||||
'-follower',
|
||||
'+createdAt',
|
||||
'-createdAt',
|
||||
'+updatedAt',
|
||||
'-updatedAt',
|
||||
]),
|
||||
},
|
||||
|
||||
state: {
|
||||
validator: $.optional.str.or([
|
||||
'all',
|
||||
'alive'
|
||||
]),
|
||||
default: 'all'
|
||||
},
|
||||
|
||||
origin: {
|
||||
validator: $.optional.str.or([
|
||||
'combined',
|
||||
'local',
|
||||
'remote',
|
||||
]),
|
||||
default: 'local'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const sort: any = {
|
||||
'+follower': { followersCount: -1 },
|
||||
'-follower': { followersCount: 1 },
|
||||
'+createdAt': { createdAt: -1 },
|
||||
'-createdAt': { createdAt: 1 },
|
||||
'+updatedAt': { updatedAt: -1 },
|
||||
'-updatedAt': { updatedAt: 1 },
|
||||
};
|
||||
|
||||
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||
const q = {
|
||||
tags: ps.tag,
|
||||
$and: []
|
||||
} as any;
|
||||
|
||||
// state
|
||||
q.$and.push(
|
||||
ps.state == 'alive' ? { updatedAt: { $gt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 5)) } } :
|
||||
{}
|
||||
);
|
||||
|
||||
// origin
|
||||
q.$and.push(
|
||||
ps.origin == 'local' ? { host: null } :
|
||||
ps.origin == 'remote' ? { host: { $ne: null } } :
|
||||
{}
|
||||
);
|
||||
|
||||
const users = await User
|
||||
.find(q, {
|
||||
limit: ps.limit,
|
||||
sort: sort[ps.sort],
|
||||
});
|
||||
|
||||
res(await Promise.all(users.map(user => pack(user, me, { detail: true }))));
|
||||
}));
|
@ -11,6 +11,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';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -221,6 +222,10 @@ export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
|
||||
|
||||
updates.emojis = emojis;
|
||||
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);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
Reference in New Issue
Block a user