Support `pinned` param in accountStatusesController
This commit is contained in:
parent
3341d6aedd
commit
57d7f7ff40
|
@ -7,12 +7,12 @@ import { type DittoFilter } from '@/filter.ts';
|
||||||
import { getAuthor, getFollowedPubkeys } from '@/queries.ts';
|
import { getAuthor, getFollowedPubkeys } from '@/queries.ts';
|
||||||
import { booleanParamSchema, fileSchema } from '@/schema.ts';
|
import { booleanParamSchema, fileSchema } from '@/schema.ts';
|
||||||
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
|
||||||
import { addTag, deleteTag } from '@/tags.ts';
|
import { addTag, deleteTag, getTagSet } from '@/tags.ts';
|
||||||
import { uploadFile } from '@/upload.ts';
|
import { uploadFile } from '@/upload.ts';
|
||||||
import { lookupAccount, nostrNow } from '@/utils.ts';
|
import { lookupAccount, nostrNow } from '@/utils.ts';
|
||||||
import { paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts';
|
import { paginated, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts';
|
||||||
import { createEvent } from '@/utils/web.ts';
|
import { createEvent } from '@/utils/web.ts';
|
||||||
import { renderAccounts, renderEventAccounts } from '@/views.ts';
|
import { renderAccounts, renderEventAccounts, renderStatuses } from '@/views.ts';
|
||||||
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
||||||
import { renderRelationship } from '@/views/mastodon/relationships.ts';
|
import { renderRelationship } from '@/views/mastodon/relationships.ts';
|
||||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||||
|
@ -134,9 +134,14 @@ const accountStatusesController: AppController = async (c) => {
|
||||||
const { since, until } = paginationSchema.parse(c.req.query());
|
const { since, until } = paginationSchema.parse(c.req.query());
|
||||||
const { pinned, limit, exclude_replies, tagged } = accountStatusesQuerySchema.parse(c.req.query());
|
const { pinned, limit, exclude_replies, tagged } = accountStatusesQuerySchema.parse(c.req.query());
|
||||||
|
|
||||||
// Nostr doesn't support pinned statuses.
|
|
||||||
if (pinned) {
|
if (pinned) {
|
||||||
return c.json([]);
|
const [pinEvent] = await eventsDB.getEvents([{ kinds: [10001], authors: [pubkey], limit: 1 }]);
|
||||||
|
if (pinEvent) {
|
||||||
|
const pinnedEventIds = getTagSet(pinEvent.tags, 'e');
|
||||||
|
return renderStatuses(c, [...pinnedEventIds].reverse());
|
||||||
|
} else {
|
||||||
|
return c.json([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const filter: DittoFilter<1> = {
|
const filter: DittoFilter<1> = {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { type Event, findReplyTag } from '@/deps.ts';
|
||||||
import { type AuthorMicrofilter, type DittoFilter, type IdMicrofilter, type Relation } from '@/filter.ts';
|
import { type AuthorMicrofilter, type DittoFilter, type IdMicrofilter, type Relation } from '@/filter.ts';
|
||||||
import { reqmeister } from '@/reqmeister.ts';
|
import { reqmeister } from '@/reqmeister.ts';
|
||||||
import { type DittoEvent } from '@/store.ts';
|
import { type DittoEvent } from '@/store.ts';
|
||||||
|
import { getTagSet } from '@/tags.ts';
|
||||||
|
|
||||||
interface GetEventOpts<K extends number> {
|
interface GetEventOpts<K extends number> {
|
||||||
/** Signal to abort the request. */
|
/** Signal to abort the request. */
|
||||||
|
@ -87,10 +88,7 @@ const getFollows = async (pubkey: string, signal?: AbortSignal): Promise<Event<3
|
||||||
async function getFollowedPubkeys(pubkey: string, signal?: AbortSignal): Promise<string[]> {
|
async function getFollowedPubkeys(pubkey: string, signal?: AbortSignal): Promise<string[]> {
|
||||||
const event = await getFollows(pubkey, signal);
|
const event = await getFollows(pubkey, signal);
|
||||||
if (!event) return [];
|
if (!event) return [];
|
||||||
|
return [...getTagSet(event.tags, 'p')];
|
||||||
return event.tags
|
|
||||||
.filter((tag) => tag[0] === 'p')
|
|
||||||
.map((tag) => tag[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get pubkeys the user follows, including the user's own pubkey. */
|
/** Get pubkeys the user follows, including the user's own pubkey. */
|
||||||
|
|
|
@ -47,6 +47,10 @@ async function renderAccounts(c: AppContext, authors: string[], signal = AbortSi
|
||||||
|
|
||||||
/** Render statuses by event IDs. */
|
/** Render statuses by event IDs. */
|
||||||
async function renderStatuses(c: AppContext, ids: string[], signal = AbortSignal.timeout(1000)) {
|
async function renderStatuses(c: AppContext, ids: string[], signal = AbortSignal.timeout(1000)) {
|
||||||
|
if (!ids.length) {
|
||||||
|
return c.json([]);
|
||||||
|
}
|
||||||
|
|
||||||
const { limit } = paginationSchema.parse(c.req.query());
|
const { limit } = paginationSchema.parse(c.req.query());
|
||||||
|
|
||||||
const events = await eventsDB.getEvents(
|
const events = await eventsDB.getEvents(
|
||||||
|
|
Loading…
Reference in New Issue