improve emoji rendering
Some checks failed
Lint / pnpm_install (push) Successful in 2m13s
Publish Docker image / Build (push) Successful in 5m17s
Test (production install and build) / production (22.11.0) (push) Successful in 1m11s
Lint / lint (backend) (push) Successful in 2m24s
Lint / lint (frontend) (push) Successful in 2m20s
Test (backend) / unit (22.11.0) (push) Successful in 9m10s
Lint / lint (frontend-embed) (push) Successful in 2m43s
Lint / lint (frontend-shared) (push) Successful in 2m40s
Lint / lint (misskey-bubble-game) (push) Successful in 2m40s
Lint / lint (misskey-js) (push) Successful in 2m40s
Test (backend) / e2e (22.11.0) (push) Successful in 12m53s
Lint / lint (misskey-reversi) (push) Successful in 3m10s
Lint / lint (sw) (push) Successful in 2m57s
Lint / typecheck (backend) (push) Successful in 2m45s
Lint / typecheck (sw) (push) Has been cancelled
Lint / typecheck (misskey-js) (push) Has been cancelled
Publish Docker image / Build (pull_request) Has been cancelled
Lint / pnpm_install (pull_request) Successful in 1m53s
Lint / lint (backend) (pull_request) Has been cancelled
Lint / lint (frontend) (pull_request) Has been cancelled
Lint / lint (frontend-embed) (pull_request) Has been cancelled
Lint / lint (frontend-shared) (pull_request) Has been cancelled
Lint / lint (misskey-bubble-game) (pull_request) Has been cancelled
Lint / lint (misskey-js) (pull_request) Has been cancelled
Lint / lint (misskey-reversi) (pull_request) Has been cancelled
Lint / lint (sw) (pull_request) Has been cancelled
Lint / typecheck (backend) (pull_request) Has been cancelled
Lint / typecheck (misskey-js) (pull_request) Has been cancelled
Lint / typecheck (sw) (pull_request) Has been cancelled
Test (backend) / unit (22.11.0) (pull_request) Has been cancelled
Test (backend) / e2e (22.11.0) (pull_request) Has been cancelled
Test (production install and build) / production (22.11.0) (pull_request) Has been cancelled
Some checks failed
Lint / pnpm_install (push) Successful in 2m13s
Publish Docker image / Build (push) Successful in 5m17s
Test (production install and build) / production (22.11.0) (push) Successful in 1m11s
Lint / lint (backend) (push) Successful in 2m24s
Lint / lint (frontend) (push) Successful in 2m20s
Test (backend) / unit (22.11.0) (push) Successful in 9m10s
Lint / lint (frontend-embed) (push) Successful in 2m43s
Lint / lint (frontend-shared) (push) Successful in 2m40s
Lint / lint (misskey-bubble-game) (push) Successful in 2m40s
Lint / lint (misskey-js) (push) Successful in 2m40s
Test (backend) / e2e (22.11.0) (push) Successful in 12m53s
Lint / lint (misskey-reversi) (push) Successful in 3m10s
Lint / lint (sw) (push) Successful in 2m57s
Lint / typecheck (backend) (push) Successful in 2m45s
Lint / typecheck (sw) (push) Has been cancelled
Lint / typecheck (misskey-js) (push) Has been cancelled
Publish Docker image / Build (pull_request) Has been cancelled
Lint / pnpm_install (pull_request) Successful in 1m53s
Lint / lint (backend) (pull_request) Has been cancelled
Lint / lint (frontend) (pull_request) Has been cancelled
Lint / lint (frontend-embed) (pull_request) Has been cancelled
Lint / lint (frontend-shared) (pull_request) Has been cancelled
Lint / lint (misskey-bubble-game) (pull_request) Has been cancelled
Lint / lint (misskey-js) (pull_request) Has been cancelled
Lint / lint (misskey-reversi) (pull_request) Has been cancelled
Lint / lint (sw) (pull_request) Has been cancelled
Lint / typecheck (backend) (pull_request) Has been cancelled
Lint / typecheck (misskey-js) (pull_request) Has been cancelled
Lint / typecheck (sw) (pull_request) Has been cancelled
Test (backend) / unit (22.11.0) (pull_request) Has been cancelled
Test (backend) / e2e (22.11.0) (pull_request) Has been cancelled
Test (production install and build) / production (22.11.0) (pull_request) Has been cancelled
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
a236bbb8d4
commit
249cc63da1
2 changed files with 54 additions and 25 deletions
|
@ -10,6 +10,7 @@ import type { Packed } from '@/misc/json-schema.js';
|
|||
import type { } from '@/models/Blocking.js';
|
||||
import type { MiEmoji } from '@/models/Emoji.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { In } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class EmojiEntityService {
|
||||
|
@ -20,11 +21,9 @@ export class EmojiEntityService {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public async packSimple(
|
||||
src: MiEmoji['id'] | MiEmoji,
|
||||
): Promise<Packed<'EmojiSimple'>> {
|
||||
const emoji = typeof src === 'object' ? src : await this.emojisRepository.findOneByOrFail({ id: src });
|
||||
|
||||
public packSimpleNoQuery(
|
||||
emoji: MiEmoji,
|
||||
): Packed<'EmojiSimple'> {
|
||||
return {
|
||||
aliases: emoji.aliases,
|
||||
name: emoji.name,
|
||||
|
@ -38,18 +37,34 @@ export class EmojiEntityService {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public packSimpleMany(
|
||||
emojis: any[],
|
||||
) {
|
||||
return Promise.all(emojis.map(x => this.packSimple(x)));
|
||||
public async packSimple(
|
||||
src: MiEmoji['id'] | MiEmoji,
|
||||
): Promise<Packed<'EmojiSimple'>> {
|
||||
const emoji = typeof src === 'object' ? src : await this.emojisRepository.findOneByOrFail({ id: src });
|
||||
|
||||
return this.packSimpleNoQuery(emoji);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async packDetailed(
|
||||
src: MiEmoji['id'] | MiEmoji,
|
||||
): Promise<Packed<'EmojiDetailed'>> {
|
||||
const emoji = typeof src === 'object' ? src : await this.emojisRepository.findOneByOrFail({ id: src });
|
||||
public async packSimpleMany(
|
||||
emojis: MiEmoji['id'][] | MiEmoji[],
|
||||
): Promise<Packed<'EmojiSimple'>[]> {
|
||||
if (emojis.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (typeof emojis[0] === 'string') {
|
||||
const res = await this.emojisRepository.findBy({ id: In(emojis as MiEmoji['id'][]) });
|
||||
return res.map(this.packSimpleNoQuery);
|
||||
}
|
||||
|
||||
return (emojis as MiEmoji[]).map(this.packSimpleNoQuery);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public packDetailedNoQuery(
|
||||
emoji: MiEmoji,
|
||||
): Packed<'EmojiDetailed'> {
|
||||
return {
|
||||
id: emoji.id,
|
||||
aliases: emoji.aliases,
|
||||
|
@ -65,11 +80,28 @@ export class EmojiEntityService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async packDetailed(
|
||||
src: MiEmoji['id'] | MiEmoji,
|
||||
): Promise<Packed<'EmojiDetailed'>> {
|
||||
const emoji = typeof src === 'object' ? src : await this.emojisRepository.findOneByOrFail({ id: src });
|
||||
|
||||
return this.packDetailedNoQuery(emoji);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public packDetailedMany(
|
||||
emojis: any[],
|
||||
emojis: MiEmoji['id'][] | MiEmoji[],
|
||||
) {
|
||||
return Promise.all(emojis.map(x => this.packDetailed(x)));
|
||||
if (emojis.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (typeof emojis[0] === 'string') {
|
||||
return this.emojisRepository.findBy({ id: In(emojis as MiEmoji['id'][]) }).then(res => res.map(this.packDetailedNoQuery));
|
||||
}
|
||||
|
||||
return (emojis as MiEmoji[]).map(this.packDetailedNoQuery);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,18 +50,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
private emojiEntityService: EmojiEntityService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const emojis = await this.emojisRepository.find({
|
||||
where: {
|
||||
host: IsNull(),
|
||||
},
|
||||
order: {
|
||||
category: 'ASC',
|
||||
name: 'ASC',
|
||||
},
|
||||
});
|
||||
const emojis = await this.emojisRepository
|
||||
.createQueryBuilder()
|
||||
.where({ host: IsNull() })
|
||||
.orderBy('LOWER(category)', 'ASC')
|
||||
.addOrderBy('LOWER(name)', 'ASC')
|
||||
.getMany();
|
||||
|
||||
return {
|
||||
emojis: await this.emojiEntityService.packSimpleMany(emojis),
|
||||
emojis: emojis.map(this.emojiEntityService.packSimpleNoQuery),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue