forked from FoundKeyGang/FoundKey
server: refactor note/renote rendering to separate file
This commit is contained in:
parent
a8c0e1f827
commit
9458045c8f
4 changed files with 24 additions and 18 deletions
|
@ -0,0 +1,17 @@
|
||||||
|
import config from '@/config/index.js';
|
||||||
|
import { Notes } from '@/models/index.js';
|
||||||
|
import { Note } from '@/models/entities/note.js';
|
||||||
|
import { isPureRenote } from '@/misc/renote.js';
|
||||||
|
import { IActivity } from '@/remote/activitypub/types.js';
|
||||||
|
import renderNote from '@/remote/activitypub/renderer/note.js';
|
||||||
|
import renderCreate from '@/remote/activitypub/renderer/create.js';
|
||||||
|
import renderAnnounce from '@/remote/activitypub/renderer/announce.js';
|
||||||
|
|
||||||
|
export async function renderNoteOrRenoteActivity(note: Note): Promise<IActivity> {
|
||||||
|
if (isPureRenote(note)) {
|
||||||
|
const renote = await Notes.findOneByOrFail({ id: note.renoteId });
|
||||||
|
return renderAnnounce(renote.uri ?? `${config.url}/notes/${renote.id}`, note);
|
||||||
|
} else {
|
||||||
|
return renderCreate(await renderNote(note, false), note);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,8 @@ import { ILocalUser, User } from '@/models/entities/user.js';
|
||||||
import { renderLike } from '@/remote/activitypub/renderer/like.js';
|
import { renderLike } from '@/remote/activitypub/renderer/like.js';
|
||||||
import { getUserKeypair } from '@/misc/keypair-store.js';
|
import { getUserKeypair } from '@/misc/keypair-store.js';
|
||||||
import renderFollow from '@/remote/activitypub/renderer/follow.js';
|
import renderFollow from '@/remote/activitypub/renderer/follow.js';
|
||||||
import Outbox, { packActivity } from './activitypub/outbox.js';
|
import { renderNoteOrRenoteActivity } from '@/remote/activitypub/renderer/note-or-renote.js';
|
||||||
|
import Outbox from './activitypub/outbox.js';
|
||||||
import Followers from './activitypub/followers.js';
|
import Followers from './activitypub/followers.js';
|
||||||
import Following from './activitypub/following.js';
|
import Following from './activitypub/following.js';
|
||||||
import Featured from './activitypub/featured.js';
|
import Featured from './activitypub/featured.js';
|
||||||
|
@ -115,7 +116,7 @@ router.get('/notes/:note/activity', async ctx => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.body = renderActivity(await packActivity(note));
|
ctx.body = renderActivity(await renderNoteOrRenoteActivity(note));
|
||||||
ctx.set('Cache-Control', 'public, max-age=180');
|
ctx.set('Cache-Control', 'public, max-age=180');
|
||||||
setResponseType(ctx);
|
setResponseType(ctx);
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@ import renderOrderedCollectionPage from '@/remote/activitypub/renderer/ordered-c
|
||||||
import renderNote from '@/remote/activitypub/renderer/note.js';
|
import renderNote from '@/remote/activitypub/renderer/note.js';
|
||||||
import renderCreate from '@/remote/activitypub/renderer/create.js';
|
import renderCreate from '@/remote/activitypub/renderer/create.js';
|
||||||
import renderAnnounce from '@/remote/activitypub/renderer/announce.js';
|
import renderAnnounce from '@/remote/activitypub/renderer/announce.js';
|
||||||
|
import { renderNoteOrRenoteActivity } from '@/remote/activitypub/renderer/note-or-renote.js';
|
||||||
import { countIf } from '@/prelude/array.js';
|
import { countIf } from '@/prelude/array.js';
|
||||||
import * as url from '@/prelude/url.js';
|
import * as url from '@/prelude/url.js';
|
||||||
import { Users, Notes } from '@/models/index.js';
|
import { Users, Notes } from '@/models/index.js';
|
||||||
|
@ -63,7 +64,7 @@ export default async (ctx: Router.RouterContext) => {
|
||||||
|
|
||||||
if (sinceId) notes.reverse();
|
if (sinceId) notes.reverse();
|
||||||
|
|
||||||
const activities = await Promise.all(notes.map(note => packActivity(note)));
|
const activities = await Promise.all(notes.map(note => renderNoteOrRenoteActivity(note)));
|
||||||
const rendered = renderOrderedCollectionPage(
|
const rendered = renderOrderedCollectionPage(
|
||||||
`${partOf}?${url.query({
|
`${partOf}?${url.query({
|
||||||
page: 'true',
|
page: 'true',
|
||||||
|
@ -94,16 +95,3 @@ export default async (ctx: Router.RouterContext) => {
|
||||||
setResponseType(ctx);
|
setResponseType(ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Pack Create<Note> or Announce Activity
|
|
||||||
* @param note Note
|
|
||||||
*/
|
|
||||||
export async function packActivity(note: Note): Promise<any> {
|
|
||||||
if (isPureRenote(note)) {
|
|
||||||
const renote = await Notes.findOneByOrFail({ id: note.renoteId });
|
|
||||||
return renderAnnounce(renote.uri ?? `${config.url}/notes/${renote.id}`, note);
|
|
||||||
} else {
|
|
||||||
return renderCreate(await renderNote(note, false), note);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ import { Cache } from '@/misc/cache.js';
|
||||||
import { UserProfile } from '@/models/entities/user-profile.js';
|
import { UserProfile } from '@/models/entities/user-profile.js';
|
||||||
import { getActiveWebhooks } from '@/misc/webhook-cache.js';
|
import { getActiveWebhooks } from '@/misc/webhook-cache.js';
|
||||||
import { IActivity } from '@/remote/activitypub/type.js';
|
import { IActivity } from '@/remote/activitypub/type.js';
|
||||||
import { packActivity } from '@/server/activitypub/outbox.js';
|
import { renderNoteOrRenoteActivity } from '@/remote/activitypub/renderer/note-or-renote.js';
|
||||||
import { MINUTE } from '@/const.js';
|
import { MINUTE } from '@/const.js';
|
||||||
import { updateHashtags } from '../update-hashtag.js';
|
import { updateHashtags } from '../update-hashtag.js';
|
||||||
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js';
|
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js';
|
||||||
|
@ -431,7 +431,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
|
||||||
//#region AP deliver
|
//#region AP deliver
|
||||||
if (Users.isLocalUser(user) && !data.localOnly) {
|
if (Users.isLocalUser(user) && !data.localOnly) {
|
||||||
(async () => {
|
(async () => {
|
||||||
const noteActivity = renderActivity(await packActivity(note));
|
const noteActivity = renderActivity(await renderNoteOrRenoteActivity(note));
|
||||||
const dm = new DeliverManager(user, noteActivity);
|
const dm = new DeliverManager(user, noteActivity);
|
||||||
|
|
||||||
// Delivered to remote users who have been mentioned
|
// Delivered to remote users who have been mentioned
|
||||||
|
|
Loading…
Reference in a new issue