Merge branch 'develop' of https://github.com/syuilo/misskey into develop

This commit is contained in:
syuilo
2019-02-14 01:13:28 +09:00
7 changed files with 53 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import $ from 'cafy';
import ID, { transform } from '../../misc/cafy-id';
import User from '../../models/user';
import Following from '../../models/following';
import * as url from '../../prelude/url';
import { renderActivity } from '../../remote/activitypub/renderer';
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
import renderOrderedCollectionPage from '../../remote/activitypub/renderer/ordered-collection-page';
@ -20,7 +21,7 @@ export default async (ctx: Router.IRouterContext) => {
const userId = new ObjectID(ctx.params.user);
// Get 'cursor' parameter
const [cursor = null, cursorErr] = $.optional.type(ID).get(ctx.request.query.cursor);
const [cursor, cursorErr] = $.optional.type(ID).get(ctx.request.query.cursor);
// Get 'page' parameter
const pageErr = !$.optional.str.or(['true', 'false']).ok(ctx.request.query.page);
@ -72,10 +73,16 @@ export default async (ctx: Router.IRouterContext) => {
const renderedFollowers = await Promise.all(followings.map(following => renderFollowUser(following.followerId)));
const rendered = renderOrderedCollectionPage(
`${partOf}?page=true${cursor ? `&cursor=${cursor}` : ''}`,
`${partOf}?${url.query({
page: 'true',
cursor
})}`,
user.followersCount, renderedFollowers, partOf,
null,
inStock ? `${partOf}?page=true&cursor=${followings[followings.length - 1]._id}` : null
inStock ? `${partOf}?${url.query({
page: 'true',
cursor: followings[followings.length - 1]._id.toHexString()
})}` : null
);
ctx.body = renderActivity(rendered);

View File

@ -5,6 +5,7 @@ import $ from 'cafy';
import ID, { transform } from '../../misc/cafy-id';
import User from '../../models/user';
import Following from '../../models/following';
import * as url from '../../prelude/url';
import { renderActivity } from '../../remote/activitypub/renderer';
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
import renderOrderedCollectionPage from '../../remote/activitypub/renderer/ordered-collection-page';
@ -20,7 +21,7 @@ export default async (ctx: Router.IRouterContext) => {
const userId = new ObjectID(ctx.params.user);
// Get 'cursor' parameter
const [cursor = null, cursorErr] = $.optional.type(ID).get(ctx.request.query.cursor);
const [cursor, cursorErr] = $.optional.type(ID).get(ctx.request.query.cursor);
// Get 'page' parameter
const pageErr = !$.optional.str.or(['true', 'false']).ok(ctx.request.query.page);
@ -72,10 +73,16 @@ export default async (ctx: Router.IRouterContext) => {
const renderedFollowees = await Promise.all(followings.map(following => renderFollowUser(following.followeeId)));
const rendered = renderOrderedCollectionPage(
`${partOf}?page=true${cursor ? `&cursor=${cursor}` : ''}`,
`${partOf}?${url.query({
page: 'true',
cursor
})}`,
user.followingCount, renderedFollowees, partOf,
null,
inStock ? `${partOf}?page=true&cursor=${followings[followings.length - 1]._id}` : null
inStock ? `${partOf}?${url.query({
page: 'true',
cursor: followings[followings.length - 1]._id.toHexString()
})}` : null
);
ctx.body = renderActivity(rendered);

View File

@ -14,6 +14,7 @@ import renderNote from '../../remote/activitypub/renderer/note';
import renderCreate from '../../remote/activitypub/renderer/create';
import renderAnnounce from '../../remote/activitypub/renderer/announce';
import { countIf } from '../../prelude/array';
import * as url from '../../prelude/url';
export default async (ctx: Router.IRouterContext) => {
if (!ObjectID.isValid(ctx.params.user)) {
@ -88,10 +89,20 @@ export default async (ctx: Router.IRouterContext) => {
const activities = await Promise.all(notes.map(note => packActivity(note)));
const rendered = renderOrderedCollectionPage(
`${partOf}?page=true${sinceId ? `&since_id=${sinceId}` : ''}${untilId ? `&until_id=${untilId}` : ''}`,
`${partOf}?${url.query({
page: 'true',
since_id: sinceId,
until_id: untilId
})}`,
user.notesCount, activities, partOf,
notes.length > 0 ? `${partOf}?page=true&since_id=${notes[0]._id}` : null,
notes.length > 0 ? `${partOf}?page=true&until_id=${notes[notes.length - 1]._id}` : null
notes.length ? `${partOf}?${url.query({
page: 'true',
since_id: notes[0]._id.toHexString()
})}` : null,
notes.length ? `${partOf}?${url.query({
page: 'true',
until_id: notes[notes.length - 1]._id.toHexString()
})}` : null
);
ctx.body = renderActivity(rendered);