diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-04-25 13:25:10 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-04-25 13:25:10 +0900 |
| commit | 6721d27e3f085a2335485eed0eb90409240539c1 (patch) | |
| tree | 9cfebab85e7cd4651f2d2dac9929a21d7d21e6da /src/models | |
| parent | Improve API definition (diff) | |
| download | sharkey-6721d27e3f085a2335485eed0eb90409240539c1.tar.gz sharkey-6721d27e3f085a2335485eed0eb90409240539c1.tar.bz2 sharkey-6721d27e3f085a2335485eed0eb90409240539c1.zip | |
Improve hashtag API
Diffstat (limited to 'src/models')
| -rw-r--r-- | src/models/index.ts | 4 | ||||
| -rw-r--r-- | src/models/repositories/hashtag.ts | 71 |
2 files changed, 73 insertions, 2 deletions
diff --git a/src/models/index.ts b/src/models/index.ts index d66e4e710a..826044e7a5 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -7,7 +7,6 @@ import { Meta } from './entities/meta'; import { SwSubscription } from './entities/sw-subscription'; import { NoteWatching } from './entities/note-watching'; import { UserListJoining } from './entities/user-list-joining'; -import { Hashtag } from './entities/hashtag'; import { NoteUnread } from './entities/note-unread'; import { RegistrationTicket } from './entities/registration-tickets'; import { UserRepository } from './repositories/user'; @@ -35,6 +34,7 @@ import { FollowingRepository } from './repositories/following'; import { AbuseUserReportRepository } from './repositories/abuse-user-report'; import { AuthSessionRepository } from './repositories/auth-session'; import { UserProfile } from './entities/user-profile'; +import { HashtagRepository } from './repositories/hashtag'; export const Apps = getCustomRepository(AppRepository); export const Notes = getCustomRepository(NoteRepository); @@ -62,7 +62,7 @@ export const Metas = getRepository(Meta); export const Mutings = getCustomRepository(MutingRepository); export const Blockings = getCustomRepository(BlockingRepository); export const SwSubscriptions = getRepository(SwSubscription); -export const Hashtags = getRepository(Hashtag); +export const Hashtags = getCustomRepository(HashtagRepository); export const AbuseUserReports = getCustomRepository(AbuseUserReportRepository); export const RegistrationTickets = getRepository(RegistrationTicket); export const AuthSessions = getCustomRepository(AuthSessionRepository); diff --git a/src/models/repositories/hashtag.ts b/src/models/repositories/hashtag.ts new file mode 100644 index 0000000000..22321fca80 --- /dev/null +++ b/src/models/repositories/hashtag.ts @@ -0,0 +1,71 @@ +import { EntityRepository, Repository } from 'typeorm'; +import { Hashtag } from '../entities/hashtag'; +import { SchemaType, types, bool } from '../../misc/schema'; + +export type PackedHashtag = SchemaType<typeof packedHashtagSchema>; + +@EntityRepository(Hashtag) +export class HashtagRepository extends Repository<Hashtag> { + public packMany( + hashtags: Hashtag[], + ) { + return Promise.all(hashtags.map(x => this.pack(x))); + } + + public async pack( + src: Hashtag, + ): Promise<PackedHashtag> { + return { + tag: src.name, + mentionedUsersCount: src.mentionedUsersCount, + mentionedLocalUsersCount: src.mentionedLocalUsersCount, + mentionedRemoteUsersCount: src.mentionedRemoteUsersCount, + attachedUsersCount: src.attachedUsersCount, + attachedLocalUsersCount: src.attachedLocalUsersCount, + attachedRemoteUsersCount: src.attachedRemoteUsersCount, + }; + } +} + +export const packedHashtagSchema = { + type: types.object, + optional: bool.false, nullable: bool.false, + properties: { + tag: { + type: types.string, + optional: bool.false, nullable: bool.false, + description: 'The hashtag name. No # prefixed.', + example: 'misskey', + }, + mentionedUsersCount: { + type: types.number, + optional: bool.false, nullable: bool.false, + description: 'Number of all users using this hashtag.' + }, + mentionedLocalUsersCount: { + type: types.number, + optional: bool.false, nullable: bool.false, + description: 'Number of local users using this hashtag.' + }, + mentionedRemoteUsersCount: { + type: types.number, + optional: bool.false, nullable: bool.false, + description: 'Number of remote users using this hashtag.' + }, + attachedUsersCount: { + type: types.number, + optional: bool.false, nullable: bool.false, + description: 'Number of all users who attached this hashtag to profile.' + }, + attachedLocalUsersCount: { + type: types.number, + optional: bool.false, nullable: bool.false, + description: 'Number of local users who attached this hashtag to profile.' + }, + attachedRemoteUsersCount: { + type: types.number, + optional: bool.false, nullable: bool.false, + description: 'Number of remote users who attached this hashtag to profile.' + }, + } +}; |