Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User note for featured #98

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### General
- こんにりらみすきー部がハイライトから除外されるようになりました
- モデレーターがユーザーのアイコンもしくはバナー画像を未設定状態にできる機能を追加
- Fix: ハイライトでユーザミュートが機能しない問題

### Client
- リアクションの横幅を150pxに制限するかどうかユーザーが選べるように
Expand Down
25 changes: 22 additions & 3 deletions packages/backend/src/server/api/endpoints/notes/featured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
import { FeaturedService } from '@/core/FeaturedService.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { CacheService } from '@/core/CacheService.js';

export const meta = {
tags: ['notes'],
Expand Down Expand Up @@ -50,6 +52,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

private noteEntityService: NoteEntityService,
private featuredService: FeaturedService,
private cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
let noteIds: string[];
Expand Down Expand Up @@ -84,10 +87,26 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('renote.user', 'renoteUser')
.leftJoinAndSelect('note.channel', 'channel');

const notes = await query.getMany();
notes.sort((a, b) => a.id > b.id ? -1 : 1);
let notes = await query.getMany();

if (me != null) {
// user mute and blocking
const [
userIdsWhoMeMuting,
] = await Promise.all([
this.cacheService.userMutingsCache.fetch(me.id),
]);

notes = notes.filter(note => {
if (isUserRelated(note, userIdsWhoMeMuting, true)) return false;

return true;
});

// TODO: ミュート等考慮
// TODO: フィルタで件数が減った場合の埋め合わせ処理
}

notes.sort((a, b) => a.id > b.id ? -1 : 1);

return await this.noteEntityService.packMany(notes, me);
});
Expand Down
31 changes: 28 additions & 3 deletions packages/backend/src/server/api/endpoints/users/featured-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
import { FeaturedService } from '@/core/FeaturedService.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { CacheService } from '@/core/CacheService.js';

export const meta = {
tags: ['notes'],
Expand Down Expand Up @@ -46,6 +48,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

private noteEntityService: NoteEntityService,
private featuredService: FeaturedService,
private cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
let noteIds = await this.featuredService.getPerUserNotesRanking(ps.userId, 50);
Expand All @@ -69,10 +72,32 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('renote.user', 'renoteUser')
.leftJoinAndSelect('note.channel', 'channel');

const notes = await query.getMany();
notes.sort((a, b) => a.id > b.id ? -1 : 1);
let notes = await query.getMany();

if (me != null) {
// user mute and blocking
const [
userIdsWhoMeMuting,
userIdsWhoBlockingMe,
] = await Promise.all([
this.cacheService.userMutingsCache.fetch(me.id),
this.cacheService.userBlockedCache.fetch(me.id),
]);

notes = notes.filter(note => {
if (note.userId === me.id) {
return true;
}
if (isUserRelated(note, userIdsWhoBlockingMe, true)) return false;
if (isUserRelated(note, userIdsWhoMeMuting, true)) return false;

return true;
});

// TODO: ミュート等考慮
// Get next page if notes is empty?
}

notes.sort((a, b) => a.id > b.id ? -1 : 1);

return await this.noteEntityService.packMany(notes, me);
});
Expand Down
Loading