|
3 | 3 | * SPDX-License-Identifier: AGPL-3.0-only |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { IsNull } from 'typeorm'; |
7 | | -import { Inject, Injectable } from '@nestjs/common'; |
8 | | -import type { EmojisRepository } from '@/models/_.js'; |
| 6 | +import { Injectable } from '@nestjs/common'; |
9 | 7 | import { Endpoint } from '@/server/api/endpoint-base.js'; |
| 8 | +import { CustomEmojiService } from '@/core/CustomEmojiService.js'; |
10 | 9 | import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js'; |
11 | | -import { DI } from '@/di-symbols.js'; |
12 | 10 |
|
13 | 11 | export const meta = { |
14 | 12 | tags: ['meta'], |
@@ -44,21 +42,23 @@ export const paramDef = { |
44 | 42 | @Injectable() |
45 | 43 | export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export |
46 | 44 | constructor( |
47 | | - @Inject(DI.emojisRepository) |
48 | | - private emojisRepository: EmojisRepository, |
49 | | - |
| 45 | + private customEmojiService: CustomEmojiService, |
50 | 46 | private emojiEntityService: EmojiEntityService, |
51 | 47 | ) { |
52 | 48 | super(meta, paramDef, async (ps, me) => { |
53 | | - const emojis = await this.emojisRepository.find({ |
54 | | - where: { |
55 | | - host: IsNull(), |
56 | | - }, |
57 | | - order: { |
58 | | - category: 'ASC', |
59 | | - name: 'ASC', |
60 | | - }, |
61 | | - }); |
| 49 | + const emojis = Array.from((await this.customEmojiService.localEmojisCache.fetch()).values()) |
| 50 | + .sort((a, b) => { |
| 51 | + if (a.category === null && b.category !== null) return 1; |
| 52 | + if (a.category !== null && b.category === null) return -1; |
| 53 | + if (a.category !== null && b.category !== null) { |
| 54 | + if (a.category < b.category) return -1; |
| 55 | + if (a.category > b.category) return 1; |
| 56 | + } |
| 57 | + |
| 58 | + if (a.name < b.name) return -1; |
| 59 | + if (a.name > b.name) return 1; |
| 60 | + return 0; |
| 61 | + }); |
62 | 62 |
|
63 | 63 | return { |
64 | 64 | emojis: await this.emojiEntityService.packSimpleMany(emojis), |
|
0 commit comments