mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-02 21:24:23 +01:00
renderStatus: don't fetch the author, expect it to be passed in
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { type AppController } from '@/app.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
import { insertUser } from '@/db/users.ts';
|
||||
import { type Filter, findReplyTag, nip19, z } from '@/deps.ts';
|
||||
import { findReplyTag, nip19, z } from '@/deps.ts';
|
||||
import { type DittoFilter } from '@/filter.ts';
|
||||
import * as mixer from '@/mixer.ts';
|
||||
import { getAuthor, getFollowedPubkeys, getFollows } from '@/queries.ts';
|
||||
import { booleanParamSchema, fileSchema } from '@/schema.ts';
|
||||
@@ -137,7 +138,7 @@ const accountStatusesController: AppController = async (c) => {
|
||||
return c.json([]);
|
||||
}
|
||||
|
||||
const filter: Filter<1> = { authors: [pubkey], kinds: [1], since, until, limit };
|
||||
const filter: DittoFilter<1> = { authors: [pubkey], kinds: [1], relations: ['author'], since, until, limit };
|
||||
if (tagged) {
|
||||
filter['#t'] = [tagged];
|
||||
}
|
||||
@@ -256,7 +257,7 @@ const favouritesController: AppController = async (c) => {
|
||||
.map((event) => event.tags.find((tag) => tag[0] === 'e')?.[1])
|
||||
.filter((id): id is string => !!id);
|
||||
|
||||
const events1 = await mixer.getFilters([{ kinds: [1], ids }], { timeout: Time.seconds(1) });
|
||||
const events1 = await mixer.getFilters([{ kinds: [1], ids, relations: ['author'] }], { timeout: Time.seconds(1) });
|
||||
|
||||
const statuses = await Promise.all(events1.map((event) => renderStatus(event, c.get('pubkey'))));
|
||||
return paginated(c, events1, statuses);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { AppController } from '@/app.ts';
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { type Event, type Filter, nip19, z } from '@/deps.ts';
|
||||
import { type Event, nip19, z } from '@/deps.ts';
|
||||
import { type DittoFilter } from '@/filter.ts';
|
||||
import * as mixer from '@/mixer.ts';
|
||||
import { booleanParamSchema } from '@/schema.ts';
|
||||
import { nostrIdSchema } from '@/schemas/nostr.ts';
|
||||
@@ -65,9 +66,10 @@ const searchController: AppController = async (c) => {
|
||||
function searchEvents({ q, type, limit, account_id }: SearchQuery): Promise<Event[]> {
|
||||
if (type === 'hashtags') return Promise.resolve([]);
|
||||
|
||||
const filter: Filter = {
|
||||
const filter: DittoFilter = {
|
||||
kinds: typeToKinds(type),
|
||||
search: q,
|
||||
relations: ['author'],
|
||||
limit,
|
||||
};
|
||||
|
||||
@@ -98,8 +100,8 @@ async function lookupEvent(query: SearchQuery): Promise<Event | undefined> {
|
||||
}
|
||||
|
||||
/** Get filters to lookup the input value. */
|
||||
async function getLookupFilters({ q, type, resolve }: SearchQuery): Promise<Filter[]> {
|
||||
const filters: Filter[] = [];
|
||||
async function getLookupFilters({ q, type, resolve }: SearchQuery): Promise<DittoFilter[]> {
|
||||
const filters: DittoFilter[] = [];
|
||||
|
||||
const accounts = !type || type === 'accounts';
|
||||
const statuses = !type || type === 'statuses';
|
||||
@@ -138,7 +140,7 @@ async function getLookupFilters({ q, type, resolve }: SearchQuery): Promise<Filt
|
||||
}
|
||||
}
|
||||
|
||||
return filters;
|
||||
return filters.map((filter) => ({ ...filter, relations: ['author'] }));
|
||||
}
|
||||
|
||||
export { searchController };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { type AppController } from '@/app.ts';
|
||||
import { getUnattachedMediaByIds } from '@/db/unattached-media.ts';
|
||||
import { type Event, ISO6391, z } from '@/deps.ts';
|
||||
import { getAncestors, getDescendants, getEvent } from '@/queries.ts';
|
||||
import { getAncestors, getAuthor, getDescendants, getEvent } from '@/queries.ts';
|
||||
import { createEvent, paginationSchema, parseBody } from '@/utils/web.ts';
|
||||
import { renderEventAccounts } from '@/views.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
@@ -29,7 +29,7 @@ const createStatusSchema = z.object({
|
||||
const statusController: AppController = async (c) => {
|
||||
const id = c.req.param('id');
|
||||
|
||||
const event = await getEvent(id, { kind: 1 });
|
||||
const event = await getEvent(id, { kind: 1, relations: ['author'] });
|
||||
if (event) {
|
||||
return c.json(await renderStatus(event, c.get('pubkey')));
|
||||
}
|
||||
@@ -83,12 +83,13 @@ const createStatusController: AppController = async (c) => {
|
||||
tags,
|
||||
}, c);
|
||||
|
||||
return c.json(await renderStatus(event, c.get('pubkey')));
|
||||
const author = await getAuthor(event.pubkey);
|
||||
return c.json(await renderStatus({ ...event, author }, c.get('pubkey')));
|
||||
};
|
||||
|
||||
const contextController: AppController = async (c) => {
|
||||
const id = c.req.param('id');
|
||||
const event = await getEvent(id, { kind: 1 });
|
||||
const event = await getEvent(id, { kind: 1, relations: ['author'] });
|
||||
|
||||
async function renderStatuses(events: Event<1>[]) {
|
||||
const statuses = await Promise.all(events.map((event) => renderStatus(event, c.get('pubkey'))));
|
||||
@@ -109,7 +110,7 @@ const contextController: AppController = async (c) => {
|
||||
|
||||
const favouriteController: AppController = async (c) => {
|
||||
const id = c.req.param('id');
|
||||
const target = await getEvent(id, { kind: 1 });
|
||||
const target = await getEvent(id, { kind: 1, relations: ['author'] });
|
||||
|
||||
if (target) {
|
||||
await createEvent({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { type AppController } from '@/app.ts';
|
||||
import { z } from '@/deps.ts';
|
||||
import { type DittoFilter } from '@/filter.ts';
|
||||
import { getFeedPubkeys } from '@/queries.ts';
|
||||
import { getAuthor, getFeedPubkeys } from '@/queries.ts';
|
||||
import { Sub } from '@/subs.ts';
|
||||
import { bech32ToPubkey } from '@/utils.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
@@ -63,7 +63,8 @@ const streamingController: AppController = (c) => {
|
||||
|
||||
if (filter) {
|
||||
for await (const event of Sub.sub(socket, '1', [filter])) {
|
||||
const status = await renderStatus(event, pubkey);
|
||||
const author = await getAuthor(event.pubkey);
|
||||
const status = await renderStatus({ ...event, author }, pubkey);
|
||||
if (status) {
|
||||
send('update', status);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,10 @@ const hashtagTimelineController: AppController = (c) => {
|
||||
|
||||
/** Render statuses for timelines. */
|
||||
async function renderStatuses(c: AppContext, filters: DittoFilter<1>[]) {
|
||||
const events = await mixer.getFilters(filters, { timeout: Time.seconds(1) });
|
||||
const events = await mixer.getFilters(
|
||||
filters.map((filter) => ({ ...filter, relations: ['author'] })),
|
||||
{ timeout: Time.seconds(1) },
|
||||
);
|
||||
|
||||
if (!events.length) {
|
||||
return c.json([]);
|
||||
|
||||
Reference in New Issue
Block a user