mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-01 01:32:09 +01:00
✌️
This commit is contained in:
parent
856737c112
commit
47e9e88816
1 changed files with 6 additions and 2 deletions
|
@ -11,6 +11,10 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid user_id param');
|
||||||
|
|
||||||
|
// Get 'limit' parameter
|
||||||
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Lookup user
|
// Lookup user
|
||||||
const user = await User.findOne({
|
const user = await User.findOne({
|
||||||
_id: userId
|
_id: userId
|
||||||
|
@ -82,8 +86,8 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
// Sort replies by frequency
|
// Sort replies by frequency
|
||||||
const repliedUsersSorted = Object.keys(repliedUsers).sort((a, b) => repliedUsers[b] - repliedUsers[a]);
|
const repliedUsersSorted = Object.keys(repliedUsers).sort((a, b) => repliedUsers[b] - repliedUsers[a]);
|
||||||
|
|
||||||
// Lookup top 10 replies
|
// Extract top replied users
|
||||||
const topRepliedUsers = repliedUsersSorted.slice(0, 10);
|
const topRepliedUsers = repliedUsersSorted.slice(0, limit);
|
||||||
|
|
||||||
// Make replies object (includes weights)
|
// Make replies object (includes weights)
|
||||||
const repliesObj = await Promise.all(topRepliedUsers.map(async (user) => ({
|
const repliesObj = await Promise.all(topRepliedUsers.map(async (user) => ({
|
||||||
|
|
Loading…
Reference in a new issue