add new featured tab for "users popular locally"

This commit is contained in:
Hazelnoot 2025-05-09 22:33:08 -04:00
parent 2e4ec0dd9e
commit 81910cf725
5 changed files with 40 additions and 4 deletions

8
locales/index.d.ts vendored
View file

@ -13049,6 +13049,14 @@ export interface Locale extends ILocale {
* Note: the bubble timeline is hidden by default, and must be enabled via roles. * Note: the bubble timeline is hidden by default, and must be enabled via roles.
*/ */
"bubbleTimelineMustBeEnabled": string; "bubbleTimelineMustBeEnabled": string;
/**
* Users popular on the global network
*/
"popularUsersGlobal": string;
/**
* Users popular on {host}
*/
"popularUsersLocal": ParameterizedString<"host">;
/** /**
* Translation timeout * Translation timeout
*/ */

View file

@ -4,11 +4,13 @@
*/ */
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import type { UsersRepository } from '@/models/_.js'; import { MiFollowing } from '@/models/_.js';
import type { MiUser, UsersRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js'; import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js'; import { QueryService } from '@/core/QueryService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import type { SelectQueryBuilder } from 'typeorm';
export const meta = { export const meta = {
tags: ['users'], tags: ['users'],
@ -38,7 +40,7 @@ export const paramDef = {
properties: { properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
offset: { type: 'integer', default: 0 }, offset: { type: 'integer', default: 0 },
sort: { type: 'string', enum: ['+follower', '-follower', '+createdAt', '-createdAt', '+updatedAt', '-updatedAt'] }, sort: { type: 'string', enum: ['+follower', '-follower', '+localFollower', '-localFollower', '+createdAt', '-createdAt', '+updatedAt', '-updatedAt'] },
state: { type: 'string', enum: ['all', 'alive'], default: 'all' }, state: { type: 'string', enum: ['all', 'alive'], default: 'all' },
origin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'local' }, origin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'local' },
hostname: { hostname: {
@ -81,6 +83,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
switch (ps.sort) { switch (ps.sort) {
case '+follower': query.orderBy('user.followersCount', 'DESC'); break; case '+follower': query.orderBy('user.followersCount', 'DESC'); break;
case '-follower': query.orderBy('user.followersCount', 'ASC'); break; case '-follower': query.orderBy('user.followersCount', 'ASC'); break;
case '+localFollower': this.addLocalFollowers(query); query.orderBy('f."localFollowers"', 'DESC'); break;
case '-localFollower': this.addLocalFollowers(query); query.orderBy('f."localFollowers"', 'ASC'); break;
case '+createdAt': query.orderBy('user.id', 'DESC'); break; case '+createdAt': query.orderBy('user.id', 'DESC'); break;
case '-createdAt': query.orderBy('user.id', 'ASC'); break; case '-createdAt': query.orderBy('user.id', 'ASC'); break;
case '+updatedAt': query.andWhere('user.updatedAt IS NOT NULL').orderBy('user.updatedAt', 'DESC'); break; case '+updatedAt': query.andWhere('user.updatedAt IS NOT NULL').orderBy('user.updatedAt', 'DESC'); break;
@ -99,4 +103,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return await this.userEntityService.packMany(users, me, { schema: 'UserDetailed' }); return await this.userEntityService.packMany(users, me, { schema: 'UserDetailed' });
}); });
} }
private addLocalFollowers(query: SelectQueryBuilder<MiUser>) {
query.innerJoin(qb => {
return qb
.from(MiFollowing, 'f')
.addSelect('f."followeeId"')
.addSelect('COUNT(*) FILTER (where f."followerHost" IS NULL)', 'localFollowers')
.addSelect('COUNT(*) FILTER (where f."followeeHost" IS NOT NULL)', 'remoteFollowers')
.groupBy('"followeeId"');
}, 'f', 'user.id = f."followeeId"');
}
} }

View file

@ -46,7 +46,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<template v-if="tag == null"> <template v-if="tag == null">
<MkFoldableSection class="_margin"> <MkFoldableSection class="_margin">
<template #header><i class="ti ti-chart-line ti-fw" style="margin-right: 0.5em;"></i>{{ i18n.ts.popularUsers }}</template> <template #header><i class="ti ti-chart-line ti-fw" style="margin-right: 0.5em;"></i>{{ i18n.tsx.popularUsersLocal({ host: instance.name ?? host }) }}</template>
<MkUserList :pagination="popularUsersLocalF"/>
</MkFoldableSection>
<MkFoldableSection class="_margin">
<template #header><i class="ti ti-chart-line ti-fw" style="margin-right: 0.5em;"></i>{{ i18n.ts.popularUsersGlobal }}</template>
<MkUserList :pagination="popularUsersF"/> <MkUserList :pagination="popularUsersF"/>
</MkFoldableSection> </MkFoldableSection>
<MkFoldableSection class="_margin"> <MkFoldableSection class="_margin">
@ -71,6 +75,7 @@ import MkTab from '@/components/MkTab.vue';
import { misskeyApi } from '@/utility/misskey-api.js'; import { misskeyApi } from '@/utility/misskey-api.js';
import { instance } from '@/instance.js'; import { instance } from '@/instance.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { host } from '@@/js/config';
const props = defineProps<{ const props = defineProps<{
tag?: string; tag?: string;
@ -115,6 +120,11 @@ const popularUsersF = { endpoint: 'users', limit: 10, noPaging: true, params: {
origin: 'remote', origin: 'remote',
sort: '+follower', sort: '+follower',
} }; } };
const popularUsersLocalF = { endpoint: 'users', limit: 10, noPaging: true, params: {
state: 'alive',
origin: 'remote',
sort: '+localFollower',
} };
const recentlyUpdatedUsersF = { endpoint: 'users', limit: 10, noPaging: true, params: { const recentlyUpdatedUsersF = { endpoint: 'users', limit: 10, noPaging: true, params: {
origin: 'combined', origin: 'combined',
sort: '+updatedAt', sort: '+updatedAt',

View file

@ -31523,7 +31523,7 @@ export type operations = {
/** @default 0 */ /** @default 0 */
offset?: number; offset?: number;
/** @enum {string} */ /** @enum {string} */
sort?: '+follower' | '-follower' | '+createdAt' | '-createdAt' | '+updatedAt' | '-updatedAt'; sort?: '+follower' | '-follower' | '+localFollower' | '-localFollower' | '+createdAt' | '-createdAt' | '+updatedAt' | '-updatedAt';
/** /**
* @default all * @default all
* @enum {string} * @enum {string}

View file

@ -566,5 +566,8 @@ bubbleTimeline: "Bubble timeline"
bubbleTimelineDescription: "Choose which instances should be displayed in the bubble." bubbleTimelineDescription: "Choose which instances should be displayed in the bubble."
bubbleTimelineMustBeEnabled: "Note: the bubble timeline is hidden by default, and must be enabled via roles." bubbleTimelineMustBeEnabled: "Note: the bubble timeline is hidden by default, and must be enabled via roles."
popularUsersGlobal: "Users popular on the global network"
popularUsersLocal: "Users popular on {host}"
translationTimeoutLabel: "Translation timeout" translationTimeoutLabel: "Translation timeout"
translationTimeoutCaption: "Timeout in milliseconds for translation API requests." translationTimeoutCaption: "Timeout in milliseconds for translation API requests."