Make author_stats and event_stats two separate keys on an event
This commit is contained in:
parent
a48c1e51e1
commit
5415656b4d
|
@ -224,8 +224,9 @@ type AuthorStats = Omit<DittoDB['pubkey_stats'], 'pubkey'>;
|
||||||
type EventStats = Omit<DittoDB['event_stats'], 'event_id'>;
|
type EventStats = Omit<DittoDB['event_stats'], 'event_id'>;
|
||||||
|
|
||||||
interface DittoEvent<K extends number = number> extends Event<K> {
|
interface DittoEvent<K extends number = number> extends Event<K> {
|
||||||
author?: Event<0> & { stats?: AuthorStats };
|
author?: DittoEvent<0>;
|
||||||
stats?: EventStats;
|
author_stats?: AuthorStats;
|
||||||
|
event_stats?: EventStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get events for filters from the database. */
|
/** Get events for filters from the database. */
|
||||||
|
@ -263,7 +264,7 @@ async function getFilters<K extends number>(
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof row.author_stats_followers_count === 'number') {
|
if (typeof row.author_stats_followers_count === 'number') {
|
||||||
event.author.stats = {
|
event.author.author_stats = {
|
||||||
followers_count: row.author_stats_followers_count,
|
followers_count: row.author_stats_followers_count,
|
||||||
following_count: row.author_stats_following_count!,
|
following_count: row.author_stats_following_count!,
|
||||||
notes_count: row.author_stats_notes_count!,
|
notes_count: row.author_stats_notes_count!,
|
||||||
|
@ -272,7 +273,7 @@ async function getFilters<K extends number>(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof row.stats_replies_count === 'number') {
|
if (typeof row.stats_replies_count === 'number') {
|
||||||
event.stats = {
|
event.event_stats = {
|
||||||
replies_count: row.stats_replies_count,
|
replies_count: row.stats_replies_count,
|
||||||
reposts_count: row.stats_reposts_count!,
|
reposts_count: row.stats_reposts_count!,
|
||||||
reactions_count: row.stats_reactions_count!,
|
reactions_count: row.stats_reactions_count!,
|
||||||
|
|
|
@ -45,8 +45,8 @@ async function renderAccount(
|
||||||
emojis: renderEmojis(event),
|
emojis: renderEmojis(event),
|
||||||
fields: [],
|
fields: [],
|
||||||
follow_requests_count: 0,
|
follow_requests_count: 0,
|
||||||
followers_count: event.stats?.followers_count ?? 0,
|
followers_count: event.author_stats?.followers_count ?? 0,
|
||||||
following_count: event.stats?.following_count ?? 0,
|
following_count: event.author_stats?.following_count ?? 0,
|
||||||
fqn: parsed05?.handle || npub,
|
fqn: parsed05?.handle || npub,
|
||||||
header: banner,
|
header: banner,
|
||||||
header_static: banner,
|
header_static: banner,
|
||||||
|
@ -64,7 +64,7 @@ async function renderAccount(
|
||||||
follow_requests_count: 0,
|
follow_requests_count: 0,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
statuses_count: event.stats?.notes_count ?? 0,
|
statuses_count: event.author_stats?.notes_count ?? 0,
|
||||||
url: Conf.local(`/users/${pubkey}`),
|
url: Conf.local(`/users/${pubkey}`),
|
||||||
username: parsed05?.nickname || npub.substring(0, 8),
|
username: parsed05?.nickname || npub.substring(0, 8),
|
||||||
pleroma: {
|
pleroma: {
|
||||||
|
|
|
@ -63,9 +63,9 @@ async function renderStatus(event: eventsDB.DittoEvent<1>, viewerPubkey?: string
|
||||||
spoiler_text: (cw ? cw[1] : subject?.[1]) || '',
|
spoiler_text: (cw ? cw[1] : subject?.[1]) || '',
|
||||||
visibility: 'public',
|
visibility: 'public',
|
||||||
language: event.tags.find((tag) => tag[0] === 'lang')?.[1] || null,
|
language: event.tags.find((tag) => tag[0] === 'lang')?.[1] || null,
|
||||||
replies_count: event.stats?.replies_count ?? 0,
|
replies_count: event.event_stats?.replies_count ?? 0,
|
||||||
reblogs_count: event.stats?.reposts_count ?? 0,
|
reblogs_count: event.event_stats?.reposts_count ?? 0,
|
||||||
favourites_count: event.stats?.reactions_count ?? 0,
|
favourites_count: event.event_stats?.reactions_count ?? 0,
|
||||||
favourited: reactionEvent?.content === '+',
|
favourited: reactionEvent?.content === '+',
|
||||||
reblogged: Boolean(repostEvent),
|
reblogged: Boolean(repostEvent),
|
||||||
muted: false,
|
muted: false,
|
||||||
|
|
Loading…
Reference in New Issue