Skip to content

Commit

Permalink
fix: adapt tocha list subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
KarasuShin committed Sep 25, 2024
1 parent f9e891b commit 8f7bdaa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 23 deletions.
28 changes: 20 additions & 8 deletions lib/routes/follow/profile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ViewType, type Data, type Route } from '@/types';
import type { Context } from 'hono';
import ofetch from '@/utils/ofetch';
import type { FollowResponse, Profile, Subscription } from './types';
import type { FollowResponse, ListSubscription, Profile, Subscription } from './types';
import { parse } from 'tldts';

export const route: Route = {
Expand All @@ -26,6 +26,8 @@ export const route: Route = {
view: ViewType.Notifications,
};

const isList = (subscription: Subscription): subscription is ListSubscription => 'lists' in subscription;

async function handler(ctx: Context): Promise<Data> {
const uid = ctx.req.param('uid');
const host = 'https://api.follow.is';
Expand All @@ -35,13 +37,23 @@ async function handler(ctx: Context): Promise<Data> {

return {
title: `${profile.data.name}'s subscriptions`,
item: subscriptions.data.map((subscription) => ({
title: subscription.feeds.title,
description: subscription.feeds.description,
link: `https://app.follow.is/feed/${subscription.feedId}`,
image: getUrlIcon(subscription.feeds.siteUrl).src,
category: [subscription.category],
})),
item: subscriptions.data.map((subscription) => {
if (isList(subscription)) {
return {
title: subscription.lists.title,
description: subscription.lists.description,
link: `https://app.follow.is/list/${subscription.listId}`,
image: subscription.lists.image,
};
}
return {
title: subscription.feeds.title,
description: subscription.feeds.description,
link: `https://app.follow.is/feed/${subscription.feedId}`,
image: getUrlIcon(subscription.feeds.siteUrl).src,
category: subscription.category ? [subscription.category] : undefined,
};
}),
link: `https://app.follow.is/profile/${uid}`,
image: profile.data.image,
};
Expand Down
60 changes: 45 additions & 15 deletions lib/routes/follow/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@ export interface FollowResponse<T> {
data: T;
}

export interface Subscription {
category: string;
export type Subscription = FeedSubscription | ListSubscription;

export interface Profile {
id: string;
name: string;
email: string;
emailVerified: unknown;
image: string;
handle: unknown;
createdAt: string;
}

export interface BaseSubscription {
feedId: string;
isPrivate: boolean;
title: string | null;
userId: string;
view: number;
}

export interface FeedSubscription extends BaseSubscription {
category: string | null;
feeds: {
checkAt: string;
description: string;
Expand All @@ -18,21 +37,32 @@ export interface Subscription {
ownerUserId: string | null;
siteUrl: string;
title: string;
ttl: number;
type: 'feed';
url: string;
};
isPrivate: boolean;
title: string | null;
userId: string;
view: number;
}

export interface Profile {
id: string;
name: string;
email: string;
emailVerified: unknown;
image: string;
handle: unknown;
createdAt: string;
export interface ListSubscription extends BaseSubscription {
lastViewedAt: string;
listId: string;
lists: {
description: string;
fee: number;
feedIds: string[];
id: string;
image: string;
owner: {
createdAt: string;
emailVerified: unknown;
handle: string | null;
id: string;
image: string;
name: string;
};
ownerUserId: string;
timelineUpdatedAt: string;
title: string;
type: 'list';
view: number;
};
}

0 comments on commit 8f7bdaa

Please sign in to comment.