Skip to content

Commit

Permalink
enhance(backend): use ❤️ for reaction fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Mar 24, 2023
1 parent 4edc7d8 commit 09a846a
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

### General
- コンディショナルロールの条件に「投稿数が~以下」「投稿数が~以上」を追加
- リアクション非対応AP実装からのLikeアクティビティの解釈を👍から♥に

### Client
- クリップボタンをノートアクションに追加できるように
Expand Down
1 change: 0 additions & 1 deletion locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ tokenRequested: "アカウントへのアクセス許可"
pluginTokenRequestedDescription: "このプラグインはここで設定した権限を行使できるようになります。"
notificationType: "通知の種類"
edit: "編集"
useStarForReactionFallback: "リアクション絵文字が不明な場合、代わりに★を使う"
emailServer: "メールサーバー"
enableEmail: "メール配信機能を有効化する"
emailConfigInfo: "メールアドレスの確認やパスワードリセットの際に使います"
Expand Down
11 changes: 11 additions & 0 deletions packages/backend/migration/1679651580149-cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class cleanup1679651580149 {
name = 'cleanup1679651580149'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "useStarForReactionFallback"`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "useStarForReactionFallback" boolean NOT NULL DEFAULT false`);
}
}
12 changes: 4 additions & 8 deletions packages/backend/src/core/ReactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { bindThis } from '@/decorators.js';
import { UtilityService } from '@/core/UtilityService.js';
import { UserBlockingService } from '@/core/UserBlockingService.js';

const FALLBACK = '❤';

const legacies: Record<string, string> = {
'like': '👍',
'love': '❤', // ここに記述する場合は異体字セレクタを入れない
Expand Down Expand Up @@ -255,12 +257,6 @@ export class ReactionService {
//#endregion
}

@bindThis
public async getFallbackReaction(): Promise<string> {
const meta = await this.metaService.fetch();
return meta.useStarForReactionFallback ? '⭐' : '👍';
}

@bindThis
public convertLegacyReactions(reactions: Record<string, number>) {
const _reactions = {} as Record<string, number>;
Expand Down Expand Up @@ -294,7 +290,7 @@ export class ReactionService {

@bindThis
public async toDbReaction(reaction?: string | null, reacterHost?: string | null): Promise<string> {
if (reaction == null) return await this.getFallbackReaction();
if (reaction == null) return FALLBACK;

reacterHost = this.utilityService.toPunyNullable(reacterHost);

Expand Down Expand Up @@ -322,7 +318,7 @@ export class ReactionService {
if (emoji) return reacterHost ? `:${name}@${reacterHost}:` : `:${name}:`;
}

return await this.getFallbackReaction();
return FALLBACK;
}

@bindThis
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/models/entities/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ export class Meta {
})
public disableRegistration: boolean;

@Column('boolean', {
default: false,
})
public useStarForReactionFallback: boolean;

@Column('varchar', {
length: 1024, array: true, default: '{}',
})
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
enableServiceWorker: instance.enableServiceWorker,
translatorAvailable: instance.deeplAuthKey != null,
cacheRemoteFiles: instance.cacheRemoteFiles,
useStarForReactionFallback: instance.useStarForReactionFallback,
pinnedUsers: instance.pinnedUsers,
hiddenTags: instance.hiddenTags,
blockedHosts: instance.blockedHosts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const paramDef = {
type: 'object',
properties: {
disableRegistration: { type: 'boolean', nullable: true },
useStarForReactionFallback: { type: 'boolean', nullable: true },
pinnedUsers: { type: 'array', nullable: true, items: {
type: 'string',
} },
Expand Down Expand Up @@ -115,10 +114,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
set.disableRegistration = ps.disableRegistration;
}

if (typeof ps.useStarForReactionFallback === 'boolean') {
set.useStarForReactionFallback = ps.useStarForReactionFallback;
}

if (Array.isArray(ps.pinnedUsers)) {
set.pinnedUsers = ps.pinnedUsers.filter(Boolean);
}
Expand Down

0 comments on commit 09a846a

Please sign in to comment.