v12 (#5712)
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
This commit is contained in:
58
src/models/repositories/antenna.ts
Normal file
58
src/models/repositories/antenna.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { EntityRepository, Repository } from 'typeorm';
|
||||
import { Antenna } from '../entities/antenna';
|
||||
import { ensure } from '../../prelude/ensure';
|
||||
import { SchemaType } from '../../misc/schema';
|
||||
import { AntennaNotes } from '..';
|
||||
|
||||
export type PackedAntenna = SchemaType<typeof packedAntennaSchema>;
|
||||
|
||||
@EntityRepository(Antenna)
|
||||
export class AntennaRepository extends Repository<Antenna> {
|
||||
public async pack(
|
||||
src: Antenna['id'] | Antenna,
|
||||
): Promise<PackedAntenna> {
|
||||
const antenna = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
||||
|
||||
const hasUnreadNote = (await AntennaNotes.findOne({ antennaId: antenna.id, read: false })) != null;
|
||||
|
||||
return {
|
||||
id: antenna.id,
|
||||
createdAt: antenna.createdAt.toISOString(),
|
||||
name: antenna.name,
|
||||
keywords: antenna.keywords,
|
||||
src: antenna.src,
|
||||
userListId: antenna.userListId,
|
||||
users: antenna.users,
|
||||
caseSensitive: antenna.caseSensitive,
|
||||
notify: antenna.notify,
|
||||
withReplies: antenna.withReplies,
|
||||
withFile: antenna.withFile,
|
||||
hasUnreadNote
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const packedAntennaSchema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
format: 'id',
|
||||
description: 'The unique identifier for this Antenna.',
|
||||
example: 'xxxxxxxxxx',
|
||||
},
|
||||
createdAt: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
format: 'date-time',
|
||||
description: 'The date that the Antenna was created.'
|
||||
},
|
||||
name: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
description: 'The name of the Antenna.'
|
||||
},
|
||||
},
|
||||
};
|
||||
46
src/models/repositories/clip.ts
Normal file
46
src/models/repositories/clip.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { EntityRepository, Repository } from 'typeorm';
|
||||
import { Clip } from '../entities/clip';
|
||||
import { ensure } from '../../prelude/ensure';
|
||||
import { SchemaType } from '../../misc/schema';
|
||||
|
||||
export type PackedClip = SchemaType<typeof packedClipSchema>;
|
||||
|
||||
@EntityRepository(Clip)
|
||||
export class ClipRepository extends Repository<Clip> {
|
||||
public async pack(
|
||||
src: Clip['id'] | Clip,
|
||||
): Promise<PackedClip> {
|
||||
const clip = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
||||
|
||||
return {
|
||||
id: clip.id,
|
||||
createdAt: clip.createdAt.toISOString(),
|
||||
name: clip.name,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const packedClipSchema = {
|
||||
type: 'object' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
format: 'id',
|
||||
description: 'The unique identifier for this Clip.',
|
||||
example: 'xxxxxxxxxx',
|
||||
},
|
||||
createdAt: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
format: 'date-time',
|
||||
description: 'The date that the Clip was created.'
|
||||
},
|
||||
name: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
description: 'The name of the Clip.'
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import { NoteReaction } from '../entities/note-reaction';
|
||||
import { Users } from '..';
|
||||
import { ensure } from '../../prelude/ensure';
|
||||
import { SchemaType } from '../../misc/schema';
|
||||
import { convertLegacyReaction } from '../../misc/reaction-lib';
|
||||
|
||||
export type PackedNoteReaction = SchemaType<typeof packedNoteReactionSchema>;
|
||||
|
||||
@@ -18,7 +19,7 @@ export class NoteReactionRepository extends Repository<NoteReaction> {
|
||||
id: reaction.id,
|
||||
createdAt: reaction.createdAt.toISOString(),
|
||||
user: await Users.pack(reaction.userId, me),
|
||||
type: reaction.reaction,
|
||||
type: convertLegacyReaction(reaction.reaction),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Emojis, Users, Apps, PollVotes, DriveFiles, NoteReactions, Followings,
|
||||
import { ensure } from '../../prelude/ensure';
|
||||
import { SchemaType } from '../../misc/schema';
|
||||
import { awaitAll } from '../../prelude/await-all';
|
||||
import { convertLegacyReaction } from '../../misc/reaction-lib';
|
||||
|
||||
export type PackedNote = SchemaType<typeof packedNoteSchema>;
|
||||
|
||||
@@ -71,7 +72,6 @@ export class NoteRepository extends Repository<Note> {
|
||||
packedNote.text = null;
|
||||
packedNote.poll = undefined;
|
||||
packedNote.cw = null;
|
||||
packedNote.geo = undefined;
|
||||
packedNote.isHidden = true;
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ export class NoteRepository extends Repository<Note> {
|
||||
});
|
||||
|
||||
if (reaction) {
|
||||
return reaction.reaction;
|
||||
return convertLegacyReaction(reaction.reaction);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@@ -178,7 +178,6 @@ export class NoteRepository extends Repository<Note> {
|
||||
const packed = await awaitAll({
|
||||
id: note.id,
|
||||
createdAt: note.createdAt.toISOString(),
|
||||
app: note.appId ? Apps.pack(note.appId) : undefined,
|
||||
userId: note.userId,
|
||||
user: Users.pack(note.user || note.userId, meId),
|
||||
text: text,
|
||||
@@ -189,7 +188,7 @@ export class NoteRepository extends Repository<Note> {
|
||||
viaMobile: note.viaMobile || undefined,
|
||||
renoteCount: note.renoteCount,
|
||||
repliesCount: note.repliesCount,
|
||||
reactions: note.reactions,
|
||||
reactions: note.reactions, // v12 TODO: convert legacy reaction
|
||||
tags: note.tags.length > 0 ? note.tags : undefined,
|
||||
emojis: populateEmojis(note.emojis, host, Object.keys(note.reactions)),
|
||||
fileIds: note.fileIds,
|
||||
@@ -356,9 +355,6 @@ export const packedNoteSchema = {
|
||||
type: 'object' as const,
|
||||
optional: true as const, nullable: true as const,
|
||||
},
|
||||
geo: {
|
||||
type: 'object' as const,
|
||||
optional: true as const, nullable: true as const,
|
||||
},
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
@@ -70,7 +70,7 @@ export const packedNotificationSchema = {
|
||||
type: {
|
||||
type: 'string' as const,
|
||||
optional: false as const, nullable: false as const,
|
||||
enum: ['follow', 'receiveFollowRequest', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote'],
|
||||
enum: ['follow', 'followRequestAccepted', 'receiveFollowRequest', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote'],
|
||||
description: 'The type of the notification.'
|
||||
},
|
||||
userId: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import { EntityRepository, Repository, In, Not } from 'typeorm';
|
||||
import { User, ILocalUser, IRemoteUser } from '../entities/user';
|
||||
import { Emojis, Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages } from '..';
|
||||
import { Emojis, Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages, Announcements, AnnouncementReads, Antennas, AntennaNotes } from '..';
|
||||
import { ensure } from '../../prelude/ensure';
|
||||
import config from '../../config';
|
||||
import { SchemaType } from '../../misc/schema';
|
||||
@@ -84,6 +84,47 @@ export class UserRepository extends Repository<User> {
|
||||
return withUser || withGroups.some(x => x);
|
||||
}
|
||||
|
||||
public async getHasUnreadAnnouncement(userId: User['id']): Promise<boolean> {
|
||||
const reads = await AnnouncementReads.find({
|
||||
userId: userId
|
||||
});
|
||||
|
||||
const count = await Announcements.count(reads.length > 0 ? {
|
||||
id: Not(In(reads.map(read => read.announcementId)))
|
||||
} : {});
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
public async getHasUnreadAntenna(userId: User['id']): Promise<boolean> {
|
||||
const antennas = await Antennas.find({ userId });
|
||||
|
||||
const unread = antennas.length > 0 ? await AntennaNotes.findOne({
|
||||
antennaId: In(antennas.map(x => x.id)),
|
||||
read: false
|
||||
}) : null;
|
||||
|
||||
return unread != null;
|
||||
}
|
||||
|
||||
public async getHasUnreadNotification(userId: User['id']): Promise<boolean> {
|
||||
const mute = await Mutings.find({
|
||||
muterId: userId
|
||||
});
|
||||
const mutedUserIds = mute.map(m => m.muteeId);
|
||||
|
||||
const count = await Notifications.count({
|
||||
where: {
|
||||
notifieeId: userId,
|
||||
...(mutedUserIds.length > 0 ? { notifierId: Not(In(mutedUserIds)) } : {}),
|
||||
isRead: false
|
||||
},
|
||||
take: 1
|
||||
});
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: User['id'] | User,
|
||||
me?: User['id'] | User | null | undefined,
|
||||
@@ -193,14 +234,10 @@ export class UserRepository extends Repository<User> {
|
||||
alwaysMarkNsfw: profile!.alwaysMarkNsfw,
|
||||
carefulBot: profile!.carefulBot,
|
||||
autoAcceptFollowed: profile!.autoAcceptFollowed,
|
||||
hasUnreadAnnouncement: this.getHasUnreadAnnouncement(user.id),
|
||||
hasUnreadAntenna: this.getHasUnreadAntenna(user.id),
|
||||
hasUnreadMessagingMessage: this.getHasUnreadMessagingMessage(user.id),
|
||||
hasUnreadNotification: Notifications.count({
|
||||
where: {
|
||||
notifieeId: user.id,
|
||||
isRead: false
|
||||
},
|
||||
take: 1
|
||||
}).then(count => count > 0),
|
||||
hasUnreadNotification: this.getHasUnreadNotification(user.id),
|
||||
pendingReceivedFollowRequestsCount: FollowRequests.count({
|
||||
followeeId: user.id
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user