Skip to content

Commit

Permalink
feat(channel): チャンネル一覧を表示できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
nafu-at committed Oct 7, 2024
1 parent 5a43f4b commit 7b417b0
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/backend/src/server/api/EndpointsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ import * as ep___channels_featured from './endpoints/channels/featured.js';
import * as ep___channels_featured_games from './endpoints/channels/featured-games.js';
import * as ep___channels_follow from './endpoints/channels/follow.js';
import * as ep___channels_followed from './endpoints/channels/followed.js';
import * as ep___channels_list from './endpoints/channels/list.js'

Check failure on line 127 in packages/backend/src/server/api/EndpointsModule.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Missing semicolon
import * as ep___channels_owned from './endpoints/channels/owned.js';
import * as ep___channels_recommended from './endpoints/channels/recommended.js';
import * as ep___channels_show from './endpoints/channels/show.js';
Expand Down Expand Up @@ -525,6 +526,7 @@ const $channels_featured: Provider = { provide: 'ep:channels/featured', useClass
const $channels_featured_games: Provider = { provide: 'ep:channels/featured-games', useClass: ep___channels_featured_games.default };
const $channels_follow: Provider = { provide: 'ep:channels/follow', useClass: ep___channels_follow.default };
const $channels_followed: Provider = { provide: 'ep:channels/followed', useClass: ep___channels_followed.default };
const $channels_list: Provider = { provide: 'ep:channels/list', useClass: ep___channels_list.default };
const $channels_owned: Provider = { provide: 'ep:channels/owned', useClass: ep___channels_owned.default };
const $channels_recommended: Provider = { provide: 'ep:channels/recommended', useClass: ep___channels_recommended.default };
const $channels_show: Provider = { provide: 'ep:channels/show', useClass: ep___channels_show.default };
Expand Down Expand Up @@ -930,6 +932,7 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__
$channels_featured_games,
$channels_follow,
$channels_followed,
$channels_list,
$channels_owned,
$channels_recommended,
$channels_show,
Expand Down Expand Up @@ -1329,6 +1332,7 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__
$channels_featured_games,
$channels_follow,
$channels_followed,
$channels_list,
$channels_owned,
$channels_recommended,
$channels_show,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ import * as ep___channels_featured from './endpoints/channels/featured.js';
import * as ep___channels_featured_games from './endpoints/channels/featured-games.js';
import * as ep___channels_follow from './endpoints/channels/follow.js';
import * as ep___channels_followed from './endpoints/channels/followed.js';
import * as ep___channels_list from './endpoints/channels/list.js'

Check failure on line 127 in packages/backend/src/server/api/endpoints.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Missing semicolon
import * as ep___channels_owned from './endpoints/channels/owned.js';
import * as ep___channels_recommended from './endpoints/channels/recommended.js';
import * as ep___channels_show from './endpoints/channels/show.js';
Expand Down Expand Up @@ -523,6 +524,7 @@ const eps = [
['channels/featured-games', ep___channels_featured_games],
['channels/follow', ep___channels_follow],
['channels/followed', ep___channels_followed],
['channels/list', ep___channels_list],
['channels/owned', ep___channels_owned],
['channels/recommended', ep___channels_recommended],
['channels/show', ep___channels_show],
Expand Down
61 changes: 61 additions & 0 deletions packages/backend/src/server/api/endpoints/channels/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { ChannelsRepository } from '@/models/_.js';
import { QueryService } from '@/core/QueryService.js';
import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js';
import { DI } from '@/di-symbols.js';

export const meta = {
tags: ['channels', 'account'],

requireCredential: true,

kind: 'read:channels',

res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'Channel',
},
},
} as const;

export const paramDef = {
type: 'object',
properties: {
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 5 },
},
required: [],
} as const;

@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
@Inject(DI.channelsRepository)
private channelsRepository: ChannelsRepository,

private channelEntityService: ChannelEntityService,
private queryService: QueryService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.channelsRepository.createQueryBuilder('channel'), ps.sinceId, ps.untilId)
.andWhere('channel.isArchived = FALSE');

const channels = await query
.limit(ps.limit)
.getMany();

return await this.channelEntityService.packMany(channels, me);
});
}
}
13 changes: 13 additions & 0 deletions packages/frontend/src/pages/channels.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_margin" :channel="channel"/>
</MkPagination>
</div>
<div v-else-if="tab === 'list'" key="list">
<MkPagination v-slot="{items}" :pagination="listPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_margin" :channel="channel"/>
</MkPagination>
</div>
<div v-else-if="tab === 'favorites'" key="favorites">
<MkPagination v-slot="{items}" :pagination="favoritesPagination">
<MkChannelPreview v-for="channel in items" :key="channel.id" class="_margin" :channel="channel"/>
Expand Down Expand Up @@ -83,6 +88,10 @@ onMounted(() => {
searchType.value = props.type ?? 'nameAndDescription';
});

const listPagination = {
endpoint: 'channels/list' as const,
limit: 10,
};
const featuredPagination = {
endpoint: 'channels/featured' as const,
noPaging: true,
Expand Down Expand Up @@ -134,6 +143,10 @@ const headerTabs = computed(() => [{
key: 'search',
title: i18n.ts.search,
icon: 'ti ti-search',
}, {
key: 'list',
title: i18n.ts.lists,
icon: 'ti ti-list',
}, {
key: 'featured',
title: i18n.ts._channel.featured,
Expand Down
8 changes: 8 additions & 0 deletions packages/misskey-js/etc/misskey-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,12 @@ type ChannelsFollowedResponse = operations['channels___followed']['responses']['
// @public (undocumented)
type ChannelsFollowRequest = operations['channels___follow']['requestBody']['content']['application/json'];

// @public (undocumented)
type ChannelsListRequest = operations['channels___list']['requestBody']['content']['application/json'];

// @public (undocumented)
type ChannelsListResponse = operations['channels___list']['responses']['200']['content']['application/json'];

// @public (undocumented)
type ChannelsMyFavoritesResponse = operations['channels___my-favorites']['responses']['200']['content']['application/json'];

Expand Down Expand Up @@ -1387,6 +1393,8 @@ declare namespace entities {
ChannelsFollowRequest,
ChannelsFollowedRequest,
ChannelsFollowedResponse,
ChannelsListRequest,
ChannelsListResponse,
ChannelsOwnedRequest,
ChannelsOwnedResponse,
ChannelsRecommendedResponse,
Expand Down
11 changes: 11 additions & 0 deletions packages/misskey-js/src/autogen/apiClientJSDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,17 @@ declare module '../api.js' {
credential?: string | null,
): Promise<SwitchCaseResponseType<E, P>>;

/**
* No description provided.
*
* **Credential required**: *Yes* / **Permission**: *read:channels*
*/
request<E extends 'channels/list', P extends Endpoints[E]['req']>(
endpoint: E,
params: P,
credential?: string | null,
): Promise<SwitchCaseResponseType<E, P>>;

/**
* No description provided.
*
Expand Down
3 changes: 3 additions & 0 deletions packages/misskey-js/src/autogen/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ import type {
ChannelsFollowRequest,
ChannelsFollowedRequest,
ChannelsFollowedResponse,
ChannelsListRequest,
ChannelsListResponse,
ChannelsOwnedRequest,
ChannelsOwnedResponse,
ChannelsRecommendedResponse,
Expand Down Expand Up @@ -713,6 +715,7 @@ export type Endpoints = {
'channels/featured-games': { req: EmptyRequest; res: ChannelsFeaturedGamesResponse };
'channels/follow': { req: ChannelsFollowRequest; res: EmptyResponse };
'channels/followed': { req: ChannelsFollowedRequest; res: ChannelsFollowedResponse };
'channels/list': { req: ChannelsListRequest; res: ChannelsListResponse };
'channels/owned': { req: ChannelsOwnedRequest; res: ChannelsOwnedResponse };
'channels/recommended': { req: EmptyRequest; res: ChannelsRecommendedResponse };
'channels/show': { req: ChannelsShowRequest; res: ChannelsShowResponse };
Expand Down
2 changes: 2 additions & 0 deletions packages/misskey-js/src/autogen/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export type ChannelsFeaturedGamesResponse = operations['channels___featured-game
export type ChannelsFollowRequest = operations['channels___follow']['requestBody']['content']['application/json'];
export type ChannelsFollowedRequest = operations['channels___followed']['requestBody']['content']['application/json'];
export type ChannelsFollowedResponse = operations['channels___followed']['responses']['200']['content']['application/json'];
export type ChannelsListRequest = operations['channels___list']['requestBody']['content']['application/json'];
export type ChannelsListResponse = operations['channels___list']['responses']['200']['content']['application/json'];
export type ChannelsOwnedRequest = operations['channels___owned']['requestBody']['content']['application/json'];
export type ChannelsOwnedResponse = operations['channels___owned']['responses']['200']['content']['application/json'];
export type ChannelsRecommendedResponse = operations['channels___recommended']['responses']['200']['content']['application/json'];
Expand Down
67 changes: 67 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,15 @@ export type paths = {
*/
post: operations['channels___followed'];
};
'/channels/list': {
/**
* channels/list
* @description No description provided.
*
* **Credential required**: *Yes* / **Permission**: *read:channels*
*/
post: operations['channels___list'];
};
'/channels/owned': {
/**
* channels/owned
Expand Down Expand Up @@ -12572,6 +12581,64 @@ export type operations = {
};
};
};
/**
* channels/list
* @description No description provided.
*
* **Credential required**: *Yes* / **Permission**: *read:channels*
*/
channels___list: {
requestBody: {
content: {
'application/json': {
/** Format: misskey:id */
sinceId?: string;
/** Format: misskey:id */
untilId?: string;
/** @default 5 */
limit?: number;
};
};
};
responses: {
/** @description OK (with results) */
200: {
content: {
'application/json': components['schemas']['Channel'][];
};
};
/** @description Client error */
400: {
content: {
'application/json': components['schemas']['Error'];
};
};
/** @description Authentication error */
401: {
content: {
'application/json': components['schemas']['Error'];
};
};
/** @description Forbidden error */
403: {
content: {
'application/json': components['schemas']['Error'];
};
};
/** @description I'm Ai */
418: {
content: {
'application/json': components['schemas']['Error'];
};
};
/** @description Internal server error */
500: {
content: {
'application/json': components['schemas']['Error'];
};
};
};
};
/**
* channels/owned
* @description No description provided.
Expand Down

0 comments on commit 7b417b0

Please sign in to comment.