mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-12-12 13:48:28 +09:00
Add Event to create api
This commit is contained in:
parent
173a901eee
commit
453d25ff37
@ -8,6 +8,7 @@ import { extractCustomEmojisFromMfm } from '@/misc/extract-custom-emojis-from-mf
|
|||||||
import { extractHashtags } from '@/misc/extract-hashtags.js';
|
import { extractHashtags } from '@/misc/extract-hashtags.js';
|
||||||
import type { IMentionedRemoteUsers } from '@/models/entities/Note.js';
|
import type { IMentionedRemoteUsers } from '@/models/entities/Note.js';
|
||||||
import { Note } from '@/models/entities/Note.js';
|
import { Note } from '@/models/entities/Note.js';
|
||||||
|
import { Event, IEvent } from '@/models/entities/Event.js';
|
||||||
import type { ChannelFollowingsRepository, ChannelsRepository, InstancesRepository, MutedNotesRepository, MutingsRepository, NotesRepository, NoteThreadMutingsRepository, UserProfilesRepository, UsersRepository } from '@/models/index.js';
|
import type { ChannelFollowingsRepository, ChannelsRepository, InstancesRepository, MutedNotesRepository, MutingsRepository, NotesRepository, NoteThreadMutingsRepository, UserProfilesRepository, UsersRepository } from '@/models/index.js';
|
||||||
import type { DriveFile } from '@/models/entities/DriveFile.js';
|
import type { DriveFile } from '@/models/entities/DriveFile.js';
|
||||||
import type { App } from '@/models/entities/App.js';
|
import type { App } from '@/models/entities/App.js';
|
||||||
@ -126,6 +127,7 @@ type Option = {
|
|||||||
renote?: Note | null;
|
renote?: Note | null;
|
||||||
files?: DriveFile[] | null;
|
files?: DriveFile[] | null;
|
||||||
poll?: IPoll | null;
|
poll?: IPoll | null;
|
||||||
|
event?: IEvent | null;
|
||||||
localOnly?: boolean | null;
|
localOnly?: boolean | null;
|
||||||
reactionAcceptance?: Note['reactionAcceptance'];
|
reactionAcceptance?: Note['reactionAcceptance'];
|
||||||
cw?: string | null;
|
cw?: string | null;
|
||||||
@ -358,6 +360,7 @@ export class NoteCreateService implements OnApplicationShutdown {
|
|||||||
name: data.name,
|
name: data.name,
|
||||||
text: data.text,
|
text: data.text,
|
||||||
hasPoll: data.poll != null,
|
hasPoll: data.poll != null,
|
||||||
|
hasEvent: data.event != null,
|
||||||
cw: data.cw == null ? null : data.cw,
|
cw: data.cw == null ? null : data.cw,
|
||||||
tags: tags.map(tag => normalizeForSearch(tag)),
|
tags: tags.map(tag => normalizeForSearch(tag)),
|
||||||
emojis,
|
emojis,
|
||||||
@ -402,23 +405,40 @@ export class NoteCreateService implements OnApplicationShutdown {
|
|||||||
|
|
||||||
// 投稿を作成
|
// 投稿を作成
|
||||||
try {
|
try {
|
||||||
if (insert.hasPoll) {
|
if (insert.hasPoll || insert.hasEvent) {
|
||||||
// Start transaction
|
// Start transaction
|
||||||
await this.db.transaction(async transactionalEntityManager => {
|
await this.db.transaction(async transactionalEntityManager => {
|
||||||
await transactionalEntityManager.insert(Note, insert);
|
await transactionalEntityManager.insert(Note, insert);
|
||||||
|
|
||||||
const poll = new Poll({
|
if (insert.hasPoll) {
|
||||||
noteId: insert.id,
|
const poll = new Poll({
|
||||||
choices: data.poll!.choices,
|
noteId: insert.id,
|
||||||
expiresAt: data.poll!.expiresAt,
|
choices: data.poll!.choices,
|
||||||
multiple: data.poll!.multiple,
|
expiresAt: data.poll!.expiresAt,
|
||||||
votes: new Array(data.poll!.choices.length).fill(0),
|
multiple: data.poll!.multiple,
|
||||||
noteVisibility: insert.visibility,
|
votes: new Array(data.poll!.choices.length).fill(0),
|
||||||
userId: user.id,
|
noteVisibility: insert.visibility,
|
||||||
userHost: user.host,
|
userId: user.id,
|
||||||
});
|
userHost: user.host,
|
||||||
|
});
|
||||||
|
|
||||||
await transactionalEntityManager.insert(Poll, poll);
|
await transactionalEntityManager.insert(Poll, poll);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (insert.hasEvent) {
|
||||||
|
const event = new Event({
|
||||||
|
noteId: insert.id,
|
||||||
|
start: data.event!.start,
|
||||||
|
end: data.event!.end ?? undefined,
|
||||||
|
title: data.event!.title,
|
||||||
|
metadata: data.event!.metadata,
|
||||||
|
noteVisibility: insert.visibility,
|
||||||
|
userId: user.id,
|
||||||
|
userHost: user.host,
|
||||||
|
});
|
||||||
|
|
||||||
|
await transactionalEntityManager.insert(Event, event);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await this.notesRepository.insert(insert);
|
await this.notesRepository.insert(insert);
|
||||||
|
@ -144,6 +144,16 @@ export const paramDef = {
|
|||||||
},
|
},
|
||||||
required: ['choices'],
|
required: ['choices'],
|
||||||
},
|
},
|
||||||
|
event: {
|
||||||
|
type: 'object',
|
||||||
|
nullable: true,
|
||||||
|
properties: {
|
||||||
|
title: { type: 'string', minLength: 1, maxLength: 128, nullable: false },
|
||||||
|
start: { type: 'integer', nullable: false },
|
||||||
|
end: { type: 'integer', nullable: true },
|
||||||
|
metadata: { type: 'object' },
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// (re)note with text, files and poll are optional
|
// (re)note with text, files and poll are optional
|
||||||
anyOf: [
|
anyOf: [
|
||||||
@ -279,6 +289,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||||||
text: ps.text ?? undefined,
|
text: ps.text ?? undefined,
|
||||||
reply,
|
reply,
|
||||||
renote,
|
renote,
|
||||||
|
event: ps.event ? {
|
||||||
|
start: new Date(ps.event.start!),
|
||||||
|
end: ps.event.end ? new Date(ps.event.end) : null,
|
||||||
|
title: ps.event.title!,
|
||||||
|
metadata: ps.event.metadata ?? {},
|
||||||
|
} : undefined,
|
||||||
cw: ps.cw,
|
cw: ps.cw,
|
||||||
localOnly: ps.localOnly,
|
localOnly: ps.localOnly,
|
||||||
reactionAcceptance: ps.reactionAcceptance,
|
reactionAcceptance: ps.reactionAcceptance,
|
||||||
|
Loading…
Reference in New Issue
Block a user