Skip to content

Commit

Permalink
refactor: isPureRenotePackedを他のところでも使う
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Apr 12, 2024
1 parent 1a63a91 commit b047271
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/backend/src/misc/is-pure-renote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function isPureRenote(note: MiNote): note is MiNote & { renoteId: NonNull
return true;
}

export function isPureRenotePacked(note: Packed<'Note'>): note is Packed<'Note'> & { renote: NonNullable<Packed<'Note'>['renote']>, renoteId: NonNullable<Packed<'Note'>['renoteId']> } {
if (!note.renote) return false;
export function isPureRenotePacked(note: Packed<'Note'>): note is Packed<'Note'> & { renoteId: NonNullable<Packed<'Note'>['renoteId']> } {
if (!note.renoteId) return false;

if (note.text) return false; // it's quoted with text
if (note.fileIds != null && note.fileIds.length !== 0) return false; // it's quoted with files
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/server/api/stream/channels/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Injectable } from '@nestjs/common';
import type { Packed } from '@/misc/json-schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { isPureRenotePacked } from '@/misc/is-pure-renote.js';
import Channel, { type MiChannelService } from '../channel.js';

class ChannelChannel extends Channel {
Expand Down Expand Up @@ -39,7 +40,7 @@ class ChannelChannel extends Channel {

if (this.isNoteMutedOrBlocked(note)) return;

if (this.user && note.renoteId && !note.text) {
if (this.user && isPureRenotePacked(note)) {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
note.renote.myReaction = myRenoteReaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*/

import { Injectable } from '@nestjs/common';
import { isUserRelated } from '@/misc/is-user-related.js';
import type { Packed } from '@/misc/json-schema.js';
import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
import { isPureRenotePacked } from '@/misc/is-pure-renote.js';
import Channel, { type MiChannelService } from '../channel.js';

class GlobalTimelineChannel extends Channel {
Expand Down Expand Up @@ -50,11 +50,11 @@ class GlobalTimelineChannel extends Channel {
if (note.visibility !== 'public') return;
if (note.channelId != null) return;

if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;
if (isPureRenotePacked(note) && !this.withRenotes) return;

if (this.isNoteMutedOrBlocked(note)) return;

if (this.user && note.renoteId && !note.text) {
if (this.user && isPureRenotePacked(note)) {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
note.renote.myReaction = myRenoteReaction;
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/server/api/stream/channels/hashtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { normalizeForSearch } from '@/misc/normalize-for-search.js';
import type { Packed } from '@/misc/json-schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { isPureRenotePacked } from '@/misc/is-pure-renote.js';
import Channel, { type MiChannelService } from '../channel.js';

class HashtagChannel extends Channel {
Expand Down Expand Up @@ -44,7 +45,7 @@ class HashtagChannel extends Channel {

if (this.isNoteMutedOrBlocked(note)) return;

if (this.user && note.renoteId && !note.text) {
if (this.user && isPureRenotePacked(note)) {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
note.renote.myReaction = myRenoteReaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Injectable } from '@nestjs/common';
import type { Packed } from '@/misc/json-schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { isPureRenotePacked } from '@/misc/is-pure-renote.js';
import Channel, { type MiChannelService } from '../channel.js';

class HomeTimelineChannel extends Channel {
Expand Down Expand Up @@ -66,7 +67,7 @@ class HomeTimelineChannel extends Channel {
}

// 純粋なリノート(引用リノートでないリノート)の場合
if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && note.poll == null) {
if (isPureRenotePacked(note) && note.renote) {
if (!this.withRenotes) return;
if (note.renote.reply) {
const reply = note.renote.reply;
Expand All @@ -77,7 +78,7 @@ class HomeTimelineChannel extends Channel {

if (this.isNoteMutedOrBlocked(note)) return;

if (this.user && note.renoteId && !note.text) {
if (this.user && isPureRenotePacked(note)) {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
note.renote.myReaction = myRenoteReaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
import { isPureRenotePacked } from '@/misc/is-pure-renote.js';
import Channel, { type MiChannelService } from '../channel.js';

class HybridTimelineChannel extends Channel {
Expand Down Expand Up @@ -81,7 +82,7 @@ class HybridTimelineChannel extends Channel {
}
}

if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;
if (isPureRenotePacked(note) && !this.withRenotes) return;

if (this.user && note.renoteId && !note.text) {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
import { isPureRenotePacked } from '@/misc/is-pure-renote.js';
import Channel, { type MiChannelService } from '../channel.js';

class LocalTimelineChannel extends Channel {
Expand Down Expand Up @@ -59,11 +60,11 @@ class LocalTimelineChannel extends Channel {
if (reply.userId !== this.user.id && note.userId !== this.user.id && reply.userId !== note.userId) return;
}

if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;
if (isPureRenotePacked(note) && !this.withRenotes) return;

if (this.isNoteMutedOrBlocked(note)) return;

if (this.user && note.renoteId && !note.text) {
if (this.user && isPureRenotePacked(note)) {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
note.renote.myReaction = myRenoteReaction;
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/server/api/stream/channels/user-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Packed } from '@/misc/json-schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { isPureRenotePacked } from '@/misc/is-pure-renote.js';
import Channel, { type MiChannelService } from '../channel.js';

class UserListChannel extends Channel {
Expand Down Expand Up @@ -104,11 +105,11 @@ class UserListChannel extends Channel {
}
}

if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;
if (isPureRenotePacked(note) && !this.withRenotes) return;

if (this.isNoteMutedOrBlocked(note)) return;

if (this.user && note.renoteId && !note.text) {
if (this.user && isPureRenotePacked(note)) {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
note.renote.myReaction = myRenoteReaction;
Expand Down

0 comments on commit b047271

Please sign in to comment.