Skip to content

Commit

Permalink
メディアタイムライン追加
Browse files Browse the repository at this point in the history
  • Loading branch information
terman0407 committed May 14, 2023
1 parent c4f0473 commit c01be0d
Show file tree
Hide file tree
Showing 28 changed files with 302 additions and 1 deletion.
1 change: 1 addition & 0 deletions locales/de-DE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,7 @@ _instanceCharts:
_timelines:
home: "Startseite"
local: "Lokal"
media: "Medien"
social: "Sozial"
global: "Global"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,7 @@ _instanceCharts:
_timelines:
home: "Home"
local: "Local"
media: "Media"
social: "Social"
global: "Global"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/es-ES.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,7 @@ _instanceCharts:
_timelines:
home: "Inicio"
local: "Local"
media: "Media"
social: "Social"
global: "Global"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/fr-FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ _instanceCharts:
_timelines:
home: "Principal"
local: "Local"
media: "Média"
social: "Social"
global: "Global"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/id-ID.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,7 @@ _instanceCharts:
_timelines:
home: "Beranda"
local: "Lokal"
media: "Media"
social: "Sosial"
global: "Global"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/it-IT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,7 @@ _instanceCharts:
_timelines:
home: "Home"
local: "Locale"
media: "Contenuti multimediali"
social: "Sociale"
global: "Federata"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,7 @@ _instanceCharts:
_timelines:
home: "ホーム"
local: "ローカル"
media: "メディア"
social: "ソーシャル"
global: "グローバル"

Expand Down
1 change: 1 addition & 0 deletions locales/ja-KS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,7 @@ _instanceCharts:
_timelines:
home: "ホーム"
local: "ローカル"
media: "メディア"
social: "ソーシャル"
global: "グローバル"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/ko-KR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ _instanceCharts:
_timelines:
home: ""
local: "로컬"
media: "미디어"
social: "소셜"
global: "글로벌"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/ru-RU.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,7 @@ _instanceCharts:
_timelines:
home: "Персональная"
local: "Местная"
media: "Медиа"
social: "Социальная"
global: "Всеобщая"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/sk-SK.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@ _instanceCharts:
_timelines:
home: "Domov"
local: "Lokálne"
media: "Médiá"
social: "Sociálne"
global: "Globálne"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/th-TH.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,7 @@ _instanceCharts:
_timelines:
home: "หน้าแรก"
local: "ในพื้นที่"
media: "สื่อ"
social: "โซเชี่ยล"
global: "ทั่วโลก"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/uk-UA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,7 @@ _instanceCharts:
_timelines:
home: "Домівка"
local: "Локальна"
media: "Медіафайли"
social: "Соціальна"
global: "Глобальна"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/vi-VN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,7 @@ _instanceCharts:
_timelines:
home: "Trang chính"
local: "Máy chủ này"
media: "Phương tiện"
social: "Xã hội"
global: "Liên hợp"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,7 @@ _instanceCharts:
_timelines:
home: "首页"
local: "本地"
media: "媒体"
social: "社交"
global: "全局"
_play:
Expand Down
1 change: 1 addition & 0 deletions locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,7 @@ _instanceCharts:
_timelines:
home: "首頁"
local: "本地"
media: "媒體"
social: "社交"
global: "公開"
_play:
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/ServerModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { HashtagChannelService } from './api/stream/channels/hashtag.js';
import { HomeTimelineChannelService } from './api/stream/channels/home-timeline.js';
import { HybridTimelineChannelService } from './api/stream/channels/hybrid-timeline.js';
import { LocalTimelineChannelService } from './api/stream/channels/local-timeline.js';
import { MediaTimelineChannelService } from './api/stream/channels/media-timeline.js';
import { QueueStatsChannelService } from './api/stream/channels/queue-stats.js';
import { ServerStatsChannelService } from './api/stream/channels/server-stats.js';
import { UserListChannelService } from './api/stream/channels/user-list.js';
Expand Down Expand Up @@ -74,6 +75,7 @@ import { RoleTimelineChannelService } from './api/stream/channels/role-timeline.
HomeTimelineChannelService,
HybridTimelineChannelService,
LocalTimelineChannelService,
MediaTimelineChannelService,
QueueStatsChannelService,
ServerStatsChannelService,
UserListChannelService,
Expand Down
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 @@ -251,6 +251,7 @@ import * as ep___notes_featured from './endpoints/notes/featured.js';
import * as ep___notes_globalTimeline from './endpoints/notes/global-timeline.js';
import * as ep___notes_hybridTimeline from './endpoints/notes/hybrid-timeline.js';
import * as ep___notes_localTimeline from './endpoints/notes/local-timeline.js';
import * as ep___notes_mediaTimeline from './endpoints/notes/media-timeline.js';
import * as ep___notes_mentions from './endpoints/notes/mentions.js';
import * as ep___notes_polls_recommendation from './endpoints/notes/polls/recommendation.js';
import * as ep___notes_polls_vote from './endpoints/notes/polls/vote.js';
Expand Down Expand Up @@ -586,6 +587,7 @@ const $notes_featured: Provider = { provide: 'ep:notes/featured', useClass: ep__
const $notes_globalTimeline: Provider = { provide: 'ep:notes/global-timeline', useClass: ep___notes_globalTimeline.default };
const $notes_hybridTimeline: Provider = { provide: 'ep:notes/hybrid-timeline', useClass: ep___notes_hybridTimeline.default };
const $notes_localTimeline: Provider = { provide: 'ep:notes/local-timeline', useClass: ep___notes_localTimeline.default };
const $notes_mediaTimeline: Provider = { provide: 'ep:notes/media-timeline', useClass: ep___notes_mediaTimeline.default };
const $notes_mentions: Provider = { provide: 'ep:notes/mentions', useClass: ep___notes_mentions.default };
const $notes_polls_recommendation: Provider = { provide: 'ep:notes/polls/recommendation', useClass: ep___notes_polls_recommendation.default };
const $notes_polls_vote: Provider = { provide: 'ep:notes/polls/vote', useClass: ep___notes_polls_vote.default };
Expand Down Expand Up @@ -925,6 +927,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention
$notes_globalTimeline,
$notes_hybridTimeline,
$notes_localTimeline,
$notes_mediaTimeline,
$notes_mentions,
$notes_polls_recommendation,
$notes_polls_vote,
Expand Down Expand Up @@ -1258,6 +1261,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention
$notes_globalTimeline,
$notes_hybridTimeline,
$notes_localTimeline,
$notes_mediaTimeline,
$notes_mentions,
$notes_polls_recommendation,
$notes_polls_vote,
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 @@ -251,6 +251,7 @@ import * as ep___notes_featured from './endpoints/notes/featured.js';
import * as ep___notes_globalTimeline from './endpoints/notes/global-timeline.js';
import * as ep___notes_hybridTimeline from './endpoints/notes/hybrid-timeline.js';
import * as ep___notes_localTimeline from './endpoints/notes/local-timeline.js';
import * as ep___notes_mediaTimeline from './endpoints/notes/media-timeline.js';
import * as ep___notes_mentions from './endpoints/notes/mentions.js';
import * as ep___notes_polls_recommendation from './endpoints/notes/polls/recommendation.js';
import * as ep___notes_polls_vote from './endpoints/notes/polls/vote.js';
Expand Down Expand Up @@ -584,6 +585,7 @@ const eps = [
['notes/global-timeline', ep___notes_globalTimeline],
['notes/hybrid-timeline', ep___notes_hybridTimeline],
['notes/local-timeline', ep___notes_localTimeline],
['notes/media-timeline', ep___notes_mediaTimeline],
['notes/mentions', ep___notes_mentions],
['notes/polls/recommendation', ep___notes_polls_recommendation],
['notes/polls/vote', ep___notes_polls_vote],
Expand Down
128 changes: 128 additions & 0 deletions packages/backend/src/server/api/endpoints/notes/media-timeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common';
import type { NotesRepository } from '@/models/index.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { MetaService } from '@/core/MetaService.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
import { IdService } from '@/core/IdService.js';
import { ApiError } from '../../error.js';

export const meta = {
tags: ['notes'],

res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'Note',
},
},

errors: {
ltlDisabled: {
message: 'Media timeline has been disabled.',
code: 'MTL_DISABLED',
id: '45a6eb02-7695-4393-b023-dd4be9aaaefd',
},
},
} as const;

export const paramDef = {
type: 'object',
properties: {
withFiles: {
type: 'boolean',
default: false,
description: 'Only show notes that have attached files.',
},
fileType: { type: 'array', items: {
type: 'string',
} },
excludeNsfw: { type: 'boolean', default: false },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
},
required: [],
} as const;

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

private noteEntityService: NoteEntityService,
private queryService: QueryService,
private metaService: MetaService,
private roleService: RoleService,
private activeUsersChart: ActiveUsersChart,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const policies = await this.roleService.getUserPolicies(me ? me.id : null);
if (!policies.ltlAvailable) {
throw new ApiError(meta.errors.ltlDisabled);
}

//#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
.andWhere('note.id > :minId', { minId: this.idService.genId(new Date(Date.now() - (1000 * 60 * 60 * 24 * 10))) }) // 10日前まで
.andWhere('(note.visibility = \'public\') AND (note.userHost IS NULL)')
.andWhere('note.fileIds != \'{}\'')
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
.leftJoinAndSelect('renote.user', 'renoteUser');

this.queryService.generateChannelQuery(query, me);
this.queryService.generateRepliesQuery(query, me);
this.queryService.generateVisibilityQuery(query, me);
if (me) this.queryService.generateMutedUserQuery(query, me);
if (me) this.queryService.generateMutedNoteQuery(query, me);
if (me) this.queryService.generateBlockedUserQuery(query, me);
if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);

if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}

if (ps.fileType != null) {
query.andWhere('note.fileIds != \'{}\'');
query.andWhere(new Brackets(qb => {
for (const type of ps.fileType!) {
const i = ps.fileType!.indexOf(type);
qb.orWhere(`:type${i} = ANY(note.attachedFileTypes)`, { [`type${i}`]: type });
}
}));

if (ps.excludeNsfw) {
query.andWhere('note.cw IS NULL');
query.andWhere('0 = (SELECT COUNT(*) FROM drive_file df WHERE df.id = ANY(note."fileIds") AND df."isSensitive" = TRUE)');
}
}
//#endregion

const timeline = await query.take(ps.limit).getMany();

process.nextTick(() => {
if (me) {
this.activeUsersChart.read(me);
}
});

return await this.noteEntityService.packMany(timeline, me);
});
}
}
3 changes: 3 additions & 0 deletions packages/backend/src/server/api/stream/ChannelsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import { HybridTimelineChannelService } from './channels/hybrid-timeline.js';
import { LocalTimelineChannelService } from './channels/local-timeline.js';
import { MediaTimelineChannelService } from './channels/media-timeline.js';
import { HomeTimelineChannelService } from './channels/home-timeline.js';
import { GlobalTimelineChannelService } from './channels/global-timeline.js';
import { MainChannelService } from './channels/main.js';
Expand All @@ -21,6 +22,7 @@ export class ChannelsService {
private mainChannelService: MainChannelService,
private homeTimelineChannelService: HomeTimelineChannelService,
private localTimelineChannelService: LocalTimelineChannelService,
private mediaTimelineChannelService: MediaTimelineChannelService,
private hybridTimelineChannelService: HybridTimelineChannelService,
private globalTimelineChannelService: GlobalTimelineChannelService,
private userListChannelService: UserListChannelService,
Expand All @@ -41,6 +43,7 @@ export class ChannelsService {
case 'main': return this.mainChannelService;
case 'homeTimeline': return this.homeTimelineChannelService;
case 'localTimeline': return this.localTimelineChannelService;
case 'mediaTimeline': return this.mediaTimelineChannelService;
case 'hybridTimeline': return this.hybridTimelineChannelService;
case 'globalTimeline': return this.globalTimelineChannelService;
case 'userList': return this.userListChannelService;
Expand Down
Loading

0 comments on commit c01be0d

Please sign in to comment.