From 2f4408582bf27a83ba8d22605077d067f8433d7c Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 18 May 2023 15:06:32 -0500 Subject: Set default feeds --- src/lib/constants.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/lib/constants.ts') diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 6d0d4797b..88e429d83 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -94,6 +94,49 @@ export function SUGGESTED_FOLLOWS(serviceUrl: string) { } } +export const STAGING_DEFAULT_FEED = (rkey: string) => + `at://did:plc:wqzurwm3kmaig6e6hnc2gqwo/app.bsky.feed.generator/${rkey}` +export const PROD_DEFAULT_FEED = (rkey: string) => + `at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/${rkey}` +export async function DEFAULT_FEEDS( + serviceUrl: string, + resolveHandle: (name: string) => Promise, +) { + if (serviceUrl.includes('localhost')) { + const aliceDid = await resolveHandle('alice.test') + return { + pinned: [`at://${aliceDid}/app.bsky.feed.generator/alice-favs`], + saved: [`at://${aliceDid}/app.bsky.feed.generator/alice-favs`], + } + } else if (serviceUrl.includes('staging')) { + return { + pinned: [ + STAGING_DEFAULT_FEED('skyline'), + STAGING_DEFAULT_FEED('whats-hot'), + ], + saved: [ + STAGING_DEFAULT_FEED('bsky-team'), + STAGING_DEFAULT_FEED('skyline'), + STAGING_DEFAULT_FEED('whats-hot'), + STAGING_DEFAULT_FEED('hot-classic'), + ], + } + } else { + return { + pinned: [ + STAGING_DEFAULT_FEED('skyline'), + STAGING_DEFAULT_FEED('whats-hot'), + ], + saved: [ + STAGING_DEFAULT_FEED('bsky-team'), + STAGING_DEFAULT_FEED('skyline'), + STAGING_DEFAULT_FEED('whats-hot'), + STAGING_DEFAULT_FEED('hot-classic'), + ], + } + } +} + export const POST_IMG_MAX = { width: 2000, height: 2000, -- cgit 1.4.1 From 37acc9e9304b594ff21443e1be896e1e576bb488 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 18 May 2023 18:22:46 -0500 Subject: A few more UX tweaks --- src/lib/constants.ts | 14 ++++-------- src/view/com/feeds/SavedFeeds.tsx | 39 ++++++++++++++++++++++++-------- src/view/com/pager/FeedsTabBar.web.tsx | 2 +- src/view/com/pager/FeedsTabBarMobile.tsx | 2 +- 4 files changed, 36 insertions(+), 21 deletions(-) (limited to 'src/lib/constants.ts') diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 88e429d83..f4c6f5021 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -110,26 +110,20 @@ export async function DEFAULT_FEEDS( } } else if (serviceUrl.includes('staging')) { return { - pinned: [ - STAGING_DEFAULT_FEED('skyline'), - STAGING_DEFAULT_FEED('whats-hot'), - ], + pinned: [STAGING_DEFAULT_FEED('whats-hot')], saved: [ STAGING_DEFAULT_FEED('bsky-team'), - STAGING_DEFAULT_FEED('skyline'), + STAGING_DEFAULT_FEED('with-friends'), STAGING_DEFAULT_FEED('whats-hot'), STAGING_DEFAULT_FEED('hot-classic'), ], } } else { return { - pinned: [ - STAGING_DEFAULT_FEED('skyline'), - STAGING_DEFAULT_FEED('whats-hot'), - ], + pinned: [STAGING_DEFAULT_FEED('whats-hot')], saved: [ STAGING_DEFAULT_FEED('bsky-team'), - STAGING_DEFAULT_FEED('skyline'), + STAGING_DEFAULT_FEED('with-friends'), STAGING_DEFAULT_FEED('whats-hot'), STAGING_DEFAULT_FEED('hot-classic'), ], diff --git a/src/view/com/feeds/SavedFeeds.tsx b/src/view/com/feeds/SavedFeeds.tsx index 110a6e894..e92e741da 100644 --- a/src/view/com/feeds/SavedFeeds.tsx +++ b/src/view/com/feeds/SavedFeeds.tsx @@ -8,7 +8,7 @@ import {FlatList} from 'view/com/util/Views' import {Text} from 'view/com/util/text/Text' import {isDesktopWeb} from 'platform/detection' import {s} from 'lib/styles' -import {Link} from 'view/com/util/Link' +import {Link, TextLink} from 'view/com/util/Link' import {CustomFeed} from './CustomFeed' export const SavedFeeds = observer( @@ -52,14 +52,35 @@ export const SavedFeeds = observer( const renderListFooterComponent = useCallback(() => { return ( - - - - Settings - - + <> + + + + Change Order + + + + + Feeds are custom algorithms that users build with a little coding + expertise.{' '} + {' '} + for more information. + + + ) }, [pal]) diff --git a/src/view/com/pager/FeedsTabBar.web.tsx b/src/view/com/pager/FeedsTabBar.web.tsx index 78937611b..fc04c3b2c 100644 --- a/src/view/com/pager/FeedsTabBar.web.tsx +++ b/src/view/com/pager/FeedsTabBar.web.tsx @@ -28,7 +28,7 @@ const FeedsTabBarDesktop = observer( ) => { const store = useStores() const items = useMemo( - () => ['Following', ...store.me.savedFeeds.pinnedFeedNames, 'My feeds'], + () => ['Following', ...store.me.savedFeeds.pinnedFeedNames, 'My Feeds'], [store.me.savedFeeds.pinnedFeedNames], ) const pal = usePalette('default') diff --git a/src/view/com/pager/FeedsTabBarMobile.tsx b/src/view/com/pager/FeedsTabBarMobile.tsx index a41f0ef32..5954e7f2e 100644 --- a/src/view/com/pager/FeedsTabBarMobile.tsx +++ b/src/view/com/pager/FeedsTabBarMobile.tsx @@ -33,7 +33,7 @@ export const FeedsTabBar = observer( }, [store]) const items = useMemo( - () => ['Following', ...store.me.savedFeeds.pinnedFeedNames, 'My feeds'], + () => ['Following', ...store.me.savedFeeds.pinnedFeedNames, 'My Feeds'], [store.me.savedFeeds.pinnedFeedNames], ) -- cgit 1.4.1 From 762bd15ed625c9a7d50b0ee832a1422bac3321eb Mon Sep 17 00:00:00 2001 From: Ansh Nanda Date: Mon, 22 May 2023 16:12:05 -0700 Subject: fix prod default feeds not working --- src/lib/constants.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/lib/constants.ts') diff --git a/src/lib/constants.ts b/src/lib/constants.ts index f4c6f5021..e492dd61a 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -102,13 +102,13 @@ export async function DEFAULT_FEEDS( serviceUrl: string, resolveHandle: (name: string) => Promise, ) { - if (serviceUrl.includes('localhost')) { + if (serviceUrl.includes('localhost')) { // local dev const aliceDid = await resolveHandle('alice.test') return { pinned: [`at://${aliceDid}/app.bsky.feed.generator/alice-favs`], saved: [`at://${aliceDid}/app.bsky.feed.generator/alice-favs`], } - } else if (serviceUrl.includes('staging')) { + } else if (serviceUrl.includes('staging')) { // staging return { pinned: [STAGING_DEFAULT_FEED('whats-hot')], saved: [ @@ -118,14 +118,14 @@ export async function DEFAULT_FEEDS( STAGING_DEFAULT_FEED('hot-classic'), ], } - } else { + } else { // production return { - pinned: [STAGING_DEFAULT_FEED('whats-hot')], + pinned: [PROD_DEFAULT_FEED('whats-hot')], saved: [ - STAGING_DEFAULT_FEED('bsky-team'), - STAGING_DEFAULT_FEED('with-friends'), - STAGING_DEFAULT_FEED('whats-hot'), - STAGING_DEFAULT_FEED('hot-classic'), + PROD_DEFAULT_FEED('bsky-team'), + PROD_DEFAULT_FEED('with-friends'), + PROD_DEFAULT_FEED('whats-hot'), + PROD_DEFAULT_FEED('hot-classic'), ], } } -- cgit 1.4.1 From 7e555ecc1b04fed96192d3c68b87cf679993abfa Mon Sep 17 00:00:00 2001 From: Ansh Nanda Date: Wed, 24 May 2023 15:00:36 -0700 Subject: fix lint errors --- src/lib/constants.ts | 9 ++++++--- src/view/screens/Notifications.tsx | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src/lib/constants.ts') diff --git a/src/lib/constants.ts b/src/lib/constants.ts index e492dd61a..c42e6f3a9 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -102,13 +102,15 @@ export async function DEFAULT_FEEDS( serviceUrl: string, resolveHandle: (name: string) => Promise, ) { - if (serviceUrl.includes('localhost')) { // local dev + if (serviceUrl.includes('localhost')) { + // local dev const aliceDid = await resolveHandle('alice.test') return { pinned: [`at://${aliceDid}/app.bsky.feed.generator/alice-favs`], saved: [`at://${aliceDid}/app.bsky.feed.generator/alice-favs`], } - } else if (serviceUrl.includes('staging')) { // staging + } else if (serviceUrl.includes('staging')) { + // staging return { pinned: [STAGING_DEFAULT_FEED('whats-hot')], saved: [ @@ -118,7 +120,8 @@ export async function DEFAULT_FEEDS( STAGING_DEFAULT_FEED('hot-classic'), ], } - } else { // production + } else { + // production return { pinned: [PROD_DEFAULT_FEED('whats-hot')], saved: [ diff --git a/src/view/screens/Notifications.tsx b/src/view/screens/Notifications.tsx index df84b541b..67507d009 100644 --- a/src/view/screens/Notifications.tsx +++ b/src/view/screens/Notifications.tsx @@ -98,7 +98,10 @@ export const NotificationsScreen = withAuthRequired( /> {store.me.notifications.hasNewLatest && !store.me.notifications.isRefreshing && ( - + )} ) -- cgit 1.4.1 From 7916c2e02ec66e32de258d2e5a605c1ee1faeac9 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 25 May 2023 17:10:00 -0500 Subject: Add 'popular with friends' to default feeds --- src/lib/constants.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/lib/constants.ts') diff --git a/src/lib/constants.ts b/src/lib/constants.ts index c42e6f3a9..41aab1431 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -123,7 +123,10 @@ export async function DEFAULT_FEEDS( } else { // production return { - pinned: [PROD_DEFAULT_FEED('whats-hot')], + pinned: [ + PROD_DEFAULT_FEED('whats-hot'), + PROD_DEFAULT_FEED('with-friends'), + ], saved: [ PROD_DEFAULT_FEED('bsky-team'), PROD_DEFAULT_FEED('with-friends'), -- cgit 1.4.1 From 7458b6f600a3d25812a64d93096b2a94676a7bb6 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 30 May 2023 20:41:56 -0400 Subject: Move MAX_GRAPHEME_LENGTH to constants.ts (#735) --- src/lib/constants.ts | 2 ++ src/view/com/composer/Composer.tsx | 5 ++--- src/view/com/composer/char-progress/CharProgress.tsx | 15 ++++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src/lib/constants.ts') diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 41aab1431..ada7b2059 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -4,6 +4,8 @@ export const FEEDBACK_FORM_URL = export const MAX_DISPLAY_NAME = 64 export const MAX_DESCRIPTION = 256 +export const MAX_GRAPHEME_LENGTH = 300 + // Recommended is 100 per: https://www.w3.org/WAI/GL/WCAG20/tests/test3.html // but increasing limit per user feedback export const MAX_ALT_TEXT = 1000 diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 3891fa268..d7a4a42d5 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -37,8 +37,7 @@ import {useExternalLinkFetch} from './useExternalLinkFetch' import {isDesktopWeb, isAndroid} from 'platform/detection' import {GalleryModel} from 'state/models/media/gallery' import {Gallery} from './photos/Gallery' - -const MAX_GRAPHEME_LENGTH = 300 +import {MAX_GRAPHEME_LENGTH} from 'lib/constants' type Props = ComposerOpts & { onClose: () => void @@ -310,7 +309,7 @@ export const ComposePost = observer(function ComposePost({ onError={setError} accessible={true} accessibilityLabel="Write post" - accessibilityHint="Compose posts up to 300 characters in length" + accessibilityHint={`Compose posts up to ${MAX_GRAPHEME_LENGTH} characters in length`} /> diff --git a/src/view/com/composer/char-progress/CharProgress.tsx b/src/view/com/composer/char-progress/CharProgress.tsx index eaaaea5e5..6b3b98e47 100644 --- a/src/view/com/composer/char-progress/CharProgress.tsx +++ b/src/view/com/composer/char-progress/CharProgress.tsx @@ -7,9 +7,9 @@ import ProgressCircle from 'react-native-progress/Circle' import ProgressPie from 'react-native-progress/Pie' import {s} from 'lib/styles' import {usePalette} from 'lib/hooks/usePalette' +import {MAX_GRAPHEME_LENGTH} from 'lib/constants' -const MAX_LENGTH = 300 -const DANGER_LENGTH = MAX_LENGTH +const DANGER_LENGTH = MAX_GRAPHEME_LENGTH export function CharProgress({count}: {count: number}) { const pal = usePalette('default') @@ -17,7 +17,9 @@ export function CharProgress({count}: {count: number}) { const circleColor = count > DANGER_LENGTH ? '#e60000' : pal.colors.link return ( <> - {MAX_LENGTH - count} + + {MAX_GRAPHEME_LENGTH - count} + {count > DANGER_LENGTH ? ( ) : ( )} -- cgit 1.4.1 From c0ca27b7ce6518758323e2922e66a3e3a008dbce Mon Sep 17 00:00:00 2001 From: Ollie H Date: Tue, 30 May 2023 18:08:49 -0700 Subject: Use proxy for fetching link meta (#716) * Use proxy for fetching link meta * Remove link meta test due to hitting proxy * setup different staging and prod proxy URLs --------- Co-authored-by: Ansh Nanda Co-authored-by: Paul Frazee --- __tests__/lib/link-meta.test.ts | 104 +--------------------------------------- package.json | 1 - src/lib/constants.ts | 15 ++++++ src/lib/link-meta/link-meta.ts | 38 ++++++++------- 4 files changed, 36 insertions(+), 122 deletions(-) (limited to 'src/lib/constants.ts') diff --git a/__tests__/lib/link-meta.test.ts b/__tests__/lib/link-meta.test.ts index f0ca7a9d4..504b11c22 100644 --- a/__tests__/lib/link-meta.test.ts +++ b/__tests__/lib/link-meta.test.ts @@ -1,106 +1,4 @@ -import { - LikelyType, - getLinkMeta, - getLikelyType, -} from '../../src/lib/link-meta/link-meta' -import {exampleComHtml} from './__mocks__/exampleComHtml' -import {BskyAgent} from '@atproto/api' -import {DEFAULT_SERVICE, RootStoreModel} from '../../src/state' - -describe('getLinkMeta', () => { - let rootStore: RootStoreModel - - beforeEach(() => { - rootStore = new RootStoreModel(new BskyAgent({service: DEFAULT_SERVICE})) - }) - - const inputs = [ - '', - 'httpbadurl', - 'https://example.com', - 'https://example.com/index.html', - 'https://example.com/image.png', - 'https://example.com/video.avi', - 'https://example.com/audio.ogg', - 'https://example.com/text.txt', - 'https://example.com/javascript.js', - 'https://bsky.app/', - 'https://bsky.app/index.html', - ] - const outputs = [ - { - error: 'Invalid URL', - likelyType: LikelyType.Other, - url: '', - }, - { - error: 'Invalid URL', - likelyType: LikelyType.Other, - url: 'httpbadurl', - }, - { - likelyType: LikelyType.HTML, - url: 'https://example.com', - title: 'Example Domain', - description: 'An example website', - }, - { - likelyType: LikelyType.HTML, - url: 'https://example.com/index.html', - title: 'Example Domain', - description: 'An example website', - }, - { - likelyType: LikelyType.Image, - url: 'https://example.com/image.png', - }, - { - likelyType: LikelyType.Video, - url: 'https://example.com/video.avi', - }, - { - likelyType: LikelyType.Audio, - url: 'https://example.com/audio.ogg', - }, - { - likelyType: LikelyType.Text, - url: 'https://example.com/text.txt', - }, - { - likelyType: LikelyType.Other, - url: 'https://example.com/javascript.js', - }, - { - likelyType: LikelyType.AtpData, - url: '/', - }, - { - likelyType: LikelyType.AtpData, - url: '/index.html', - }, - { - likelyType: LikelyType.Other, - url: '', - title: '', - }, - ] - it('correctly handles a set of text inputs', async () => { - for (let i = 0; i < inputs.length; i++) { - global.fetch = jest.fn().mockImplementationOnce(() => { - return new Promise((resolve, _reject) => { - resolve({ - ok: true, - status: 200, - text: () => exampleComHtml, - }) - }) - }) - const input = inputs[i] - const output = await getLinkMeta(rootStore, input) - expect(output).toEqual(outputs[i]) - } - }) -}) +import {LikelyType, getLikelyType} from '../../src/lib/link-meta/link-meta' describe('getLikelyType', () => { it('correctly handles non-parsed url', async () => { diff --git a/package.json b/package.json index e8e7a9e59..576360cd9 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,6 @@ "expo-updates": "~0.16.4", "fast-text-encoding": "^1.0.6", "graphemer": "^1.4.0", - "he": "^1.2.0", "history": "^5.3.0", "js-sha256": "^0.9.0", "lande": "^1.0.10", diff --git a/src/lib/constants.ts b/src/lib/constants.ts index ada7b2059..170fe640f 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -144,3 +144,18 @@ export const POST_IMG_MAX = { height: 2000, size: 1000000, } + +export const STAGING_LINK_META_PROXY = + 'https://cardyb.staging.bsky.dev/v1/extract?url=' + +export const PROD_LINK_META_PROXY = 'https://cardyb.bsky.app/v1/extract?url=' + +export function LINK_META_PROXY(serviceUrl: string) { + if (serviceUrl.includes('localhost')) { + return STAGING_LINK_META_PROXY + } else if (serviceUrl.includes('staging')) { + return STAGING_LINK_META_PROXY + } else { + return PROD_LINK_META_PROXY + } +} diff --git a/src/lib/link-meta/link-meta.ts b/src/lib/link-meta/link-meta.ts index 6c4ad5384..6863798b4 100644 --- a/src/lib/link-meta/link-meta.ts +++ b/src/lib/link-meta/link-meta.ts @@ -1,8 +1,7 @@ -import he from 'he' import {isBskyAppUrl} from '../strings/url-helpers' import {RootStoreModel} from 'state/index' import {extractBskyMeta} from './bsky' -import {extractHtmlMeta} from './html' +import {LINK_META_PROXY} from 'lib/constants' export enum LikelyType { HTML, @@ -54,26 +53,29 @@ export async function getLinkMeta( try { const controller = new AbortController() const to = setTimeout(() => controller.abort(), timeout || 5e3) - const httpRes = await fetch(url, { - headers: {accept: 'text/html'}, - signal: controller.signal, - }) - const httpResBody = await httpRes.text() + + const response = await fetch( + `${LINK_META_PROXY( + store.session.currentSession?.service || '', + )}${encodeURIComponent(url)}`, + ) + + const body = await response.json() clearTimeout(to) - const httpResMeta = extractHtmlMeta({ - html: httpResBody, - hostname: urlp?.hostname, - pathname: urlp?.pathname, - }) - meta.title = httpResMeta.title ? he.decode(httpResMeta.title) : undefined - meta.description = httpResMeta.description - ? he.decode(httpResMeta.description) - : undefined - meta.image = httpResMeta.image + + const {description, error, image, title} = body + + if (error !== '') { + throw new Error(error) + } + + meta.description = description + meta.image = image + meta.title = title } catch (e) { // failed console.error(e) - meta.error = 'Failed to fetch link' + meta.error = e instanceof Error ? e.toString() : 'Failed to fetch link' } return meta -- cgit 1.4.1