Skip to content

Commit

Permalink
Merge pull request #98 from anatawa12/user-note-for-featured
Browse files Browse the repository at this point in the history
User note for featured
  • Loading branch information
anatawa12 authored Nov 27, 2023
2 parents 9766dde + 4be04ad commit 3f2e395
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
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

0 comments on commit 3f2e395

Please sign in to comment.