merge main
This commit is contained in:
+38
-38
@@ -14,40 +14,40 @@ import * as SplashScreen from 'expo-splash-screen'
|
||||
import {msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
|
||||
import {QueryProvider} from '#/lib/react-query'
|
||||
import {
|
||||
initialize,
|
||||
Provider as StatsigProvider,
|
||||
tryFetchGates,
|
||||
} from '#/lib/statsig/statsig'
|
||||
import {s} from '#/lib/styles'
|
||||
import {ThemeProvider} from '#/lib/ThemeContext'
|
||||
import {logger} from '#/logger'
|
||||
import {Provider as MutedThreadsProvider} from '#/state/cache/thread-mutes'
|
||||
import {Provider as DialogStateProvider} from '#/state/dialogs'
|
||||
import {Provider as InvitesStateProvider} from '#/state/invites'
|
||||
import {Provider as LightboxStateProvider} from '#/state/lightbox'
|
||||
import {MessagesProvider} from '#/state/messages'
|
||||
import {Provider as ModalStateProvider} from '#/state/modals'
|
||||
import {init as initPersistedState} from '#/state/persisted'
|
||||
import {Provider as PrefsStateProvider} from '#/state/preferences'
|
||||
import {Provider as LabelDefsProvider} from '#/state/preferences/label-defs'
|
||||
import {Provider as ModerationOptsProvider} from '#/state/preferences/moderation-opts'
|
||||
import {readLastActiveAccount} from '#/state/session/util'
|
||||
import {useIntentHandler} from 'lib/hooks/useIntentHandler'
|
||||
import {QueryProvider} from 'lib/react-query'
|
||||
import {s} from 'lib/styles'
|
||||
import {ThemeProvider} from 'lib/ThemeContext'
|
||||
import {Provider as DialogStateProvider} from 'state/dialogs'
|
||||
import {Provider as InvitesStateProvider} from 'state/invites'
|
||||
import {Provider as LightboxStateProvider} from 'state/lightbox'
|
||||
import {Provider as ModalStateProvider} from 'state/modals'
|
||||
import {Provider as MutedThreadsProvider} from 'state/muted-threads'
|
||||
import {Provider as PrefsStateProvider} from 'state/preferences'
|
||||
import {Provider as UnreadNotifsProvider} from 'state/queries/notifications/unread'
|
||||
import {Provider as UnreadNotifsProvider} from '#/state/queries/notifications/unread'
|
||||
import {
|
||||
Provider as SessionProvider,
|
||||
SessionAccount,
|
||||
useSession,
|
||||
useSessionApi,
|
||||
} from 'state/session'
|
||||
import {Provider as ShellStateProvider} from 'state/shell'
|
||||
import {Provider as LoggedOutViewProvider} from 'state/shell/logged-out'
|
||||
import {Provider as SelectedFeedProvider} from 'state/shell/selected-feed'
|
||||
import {TestCtrls} from 'view/com/testing/TestCtrls'
|
||||
import * as Toast from 'view/com/util/Toast'
|
||||
import {Shell} from 'view/shell'
|
||||
} from '#/state/session'
|
||||
import {readLastActiveAccount} from '#/state/session/util'
|
||||
import {Provider as ShellStateProvider} from '#/state/shell'
|
||||
import {Provider as LoggedOutViewProvider} from '#/state/shell/logged-out'
|
||||
import {Provider as SelectedFeedProvider} from '#/state/shell/selected-feed'
|
||||
import {TestCtrls} from '#/view/com/testing/TestCtrls'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {Shell} from '#/view/shell'
|
||||
import {ThemeProvider as Alf} from '#/alf'
|
||||
import {useColorModeTheme} from '#/alf/util/useColorModeTheme'
|
||||
import {useStarterPackEntry} from '#/components/hooks/useStarterPackEntry'
|
||||
@@ -114,10 +114,12 @@ function InnerApp() {
|
||||
<SelectedFeedProvider>
|
||||
<UnreadNotifsProvider>
|
||||
<BackgroundNotificationPreferencesProvider>
|
||||
<GestureHandlerRootView style={s.h100pct}>
|
||||
<TestCtrls />
|
||||
<Shell />
|
||||
</GestureHandlerRootView>
|
||||
<MutedThreadsProvider>
|
||||
<GestureHandlerRootView style={s.h100pct}>
|
||||
<TestCtrls />
|
||||
<Shell />
|
||||
</GestureHandlerRootView>
|
||||
</MutedThreadsProvider>
|
||||
</BackgroundNotificationPreferencesProvider>
|
||||
</UnreadNotifsProvider>
|
||||
</SelectedFeedProvider>
|
||||
@@ -156,21 +158,19 @@ function App() {
|
||||
<SessionProvider>
|
||||
<ShellStateProvider>
|
||||
<PrefsStateProvider>
|
||||
<MutedThreadsProvider>
|
||||
<InvitesStateProvider>
|
||||
<ModalStateProvider>
|
||||
<DialogStateProvider>
|
||||
<LightboxStateProvider>
|
||||
<I18nProvider>
|
||||
<PortalProvider>
|
||||
<InnerApp />
|
||||
</PortalProvider>
|
||||
</I18nProvider>
|
||||
</LightboxStateProvider>
|
||||
</DialogStateProvider>
|
||||
</ModalStateProvider>
|
||||
</InvitesStateProvider>
|
||||
</MutedThreadsProvider>
|
||||
<InvitesStateProvider>
|
||||
<ModalStateProvider>
|
||||
<DialogStateProvider>
|
||||
<LightboxStateProvider>
|
||||
<I18nProvider>
|
||||
<PortalProvider>
|
||||
<InnerApp />
|
||||
</PortalProvider>
|
||||
</I18nProvider>
|
||||
</LightboxStateProvider>
|
||||
</DialogStateProvider>
|
||||
</ModalStateProvider>
|
||||
</InvitesStateProvider>
|
||||
</PrefsStateProvider>
|
||||
</ShellStateProvider>
|
||||
</SessionProvider>
|
||||
|
||||
+36
-36
@@ -8,35 +8,35 @@ import {SafeAreaProvider} from 'react-native-safe-area-context'
|
||||
import {msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
|
||||
import {QueryProvider} from '#/lib/react-query'
|
||||
import {Provider as StatsigProvider} from '#/lib/statsig/statsig'
|
||||
import {ThemeProvider} from '#/lib/ThemeContext'
|
||||
import {logger} from '#/logger'
|
||||
import {Provider as MutedThreadsProvider} from '#/state/cache/thread-mutes'
|
||||
import {Provider as DialogStateProvider} from '#/state/dialogs'
|
||||
import {Provider as InvitesStateProvider} from '#/state/invites'
|
||||
import {Provider as LightboxStateProvider} from '#/state/lightbox'
|
||||
import {MessagesProvider} from '#/state/messages'
|
||||
import {Provider as ModalStateProvider} from '#/state/modals'
|
||||
import {init as initPersistedState} from '#/state/persisted'
|
||||
import {Provider as PrefsStateProvider} from '#/state/preferences'
|
||||
import {Provider as LabelDefsProvider} from '#/state/preferences/label-defs'
|
||||
import {Provider as ModerationOptsProvider} from '#/state/preferences/moderation-opts'
|
||||
import {readLastActiveAccount} from '#/state/session/util'
|
||||
import {useIntentHandler} from 'lib/hooks/useIntentHandler'
|
||||
import {QueryProvider} from 'lib/react-query'
|
||||
import {ThemeProvider} from 'lib/ThemeContext'
|
||||
import {Provider as DialogStateProvider} from 'state/dialogs'
|
||||
import {Provider as InvitesStateProvider} from 'state/invites'
|
||||
import {Provider as LightboxStateProvider} from 'state/lightbox'
|
||||
import {Provider as ModalStateProvider} from 'state/modals'
|
||||
import {Provider as MutedThreadsProvider} from 'state/muted-threads'
|
||||
import {Provider as PrefsStateProvider} from 'state/preferences'
|
||||
import {Provider as UnreadNotifsProvider} from 'state/queries/notifications/unread'
|
||||
import {Provider as UnreadNotifsProvider} from '#/state/queries/notifications/unread'
|
||||
import {
|
||||
Provider as SessionProvider,
|
||||
SessionAccount,
|
||||
useSession,
|
||||
useSessionApi,
|
||||
} from 'state/session'
|
||||
import {Provider as ShellStateProvider} from 'state/shell'
|
||||
import {Provider as LoggedOutViewProvider} from 'state/shell/logged-out'
|
||||
import {Provider as SelectedFeedProvider} from 'state/shell/selected-feed'
|
||||
import * as Toast from 'view/com/util/Toast'
|
||||
import {ToastContainer} from 'view/com/util/Toast.web'
|
||||
import {Shell} from 'view/shell/index'
|
||||
} from '#/state/session'
|
||||
import {readLastActiveAccount} from '#/state/session/util'
|
||||
import {Provider as ShellStateProvider} from '#/state/shell'
|
||||
import {Provider as LoggedOutViewProvider} from '#/state/shell/logged-out'
|
||||
import {Provider as SelectedFeedProvider} from '#/state/shell/selected-feed'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {ToastContainer} from '#/view/com/util/Toast.web'
|
||||
import {Shell} from '#/view/shell/index'
|
||||
import {ThemeProvider as Alf} from '#/alf'
|
||||
import {useColorModeTheme} from '#/alf/util/useColorModeTheme'
|
||||
import {useStarterPackEntry} from '#/components/hooks/useStarterPackEntry'
|
||||
@@ -98,9 +98,11 @@ function InnerApp() {
|
||||
<SelectedFeedProvider>
|
||||
<UnreadNotifsProvider>
|
||||
<BackgroundNotificationPreferencesProvider>
|
||||
<SafeAreaProvider>
|
||||
<Shell />
|
||||
</SafeAreaProvider>
|
||||
<MutedThreadsProvider>
|
||||
<SafeAreaProvider>
|
||||
<Shell />
|
||||
</SafeAreaProvider>
|
||||
</MutedThreadsProvider>
|
||||
</BackgroundNotificationPreferencesProvider>
|
||||
</UnreadNotifsProvider>
|
||||
</SelectedFeedProvider>
|
||||
@@ -138,21 +140,19 @@ function App() {
|
||||
<SessionProvider>
|
||||
<ShellStateProvider>
|
||||
<PrefsStateProvider>
|
||||
<MutedThreadsProvider>
|
||||
<InvitesStateProvider>
|
||||
<ModalStateProvider>
|
||||
<DialogStateProvider>
|
||||
<LightboxStateProvider>
|
||||
<I18nProvider>
|
||||
<PortalProvider>
|
||||
<InnerApp />
|
||||
</PortalProvider>
|
||||
</I18nProvider>
|
||||
</LightboxStateProvider>
|
||||
</DialogStateProvider>
|
||||
</ModalStateProvider>
|
||||
</InvitesStateProvider>
|
||||
</MutedThreadsProvider>
|
||||
<InvitesStateProvider>
|
||||
<ModalStateProvider>
|
||||
<DialogStateProvider>
|
||||
<LightboxStateProvider>
|
||||
<I18nProvider>
|
||||
<PortalProvider>
|
||||
<InnerApp />
|
||||
</PortalProvider>
|
||||
</I18nProvider>
|
||||
</LightboxStateProvider>
|
||||
</DialogStateProvider>
|
||||
</ModalStateProvider>
|
||||
</InvitesStateProvider>
|
||||
</PrefsStateProvider>
|
||||
</ShellStateProvider>
|
||||
</SessionProvider>
|
||||
|
||||
@@ -18,8 +18,10 @@ import {Text} from '#/components/Typography'
|
||||
|
||||
export function NewskieDialog({
|
||||
profile,
|
||||
disabled,
|
||||
}: {
|
||||
profile: AppBskyActorDefs.ProfileViewDetailed
|
||||
disabled?: boolean
|
||||
}) {
|
||||
const {_} = useLingui()
|
||||
const moderationOpts = useModerationOpts()
|
||||
@@ -30,18 +32,20 @@ export function NewskieDialog({
|
||||
const moderation = moderateProfile(profile, moderationOpts)
|
||||
return sanitizeDisplayName(name, moderation.ui('displayName'))
|
||||
}, [moderationOpts, profile])
|
||||
const [now] = React.useState(() => Date.now())
|
||||
const timeAgo = useGetTimeAgo()
|
||||
const createdAt = profile.createdAt as string | undefined
|
||||
const daysOld = React.useMemo(() => {
|
||||
if (!createdAt) return Infinity
|
||||
return differenceInSeconds(new Date(), new Date(createdAt)) / 86400
|
||||
}, [createdAt])
|
||||
return differenceInSeconds(now, new Date(createdAt)) / 86400
|
||||
}, [createdAt, now])
|
||||
|
||||
if (!createdAt || daysOld > 7) return null
|
||||
|
||||
return (
|
||||
<View style={[a.pr_2xs]}>
|
||||
<Button
|
||||
disabled={disabled}
|
||||
label={_(
|
||||
msg`This user is new here. Press for more info about when they joined.`,
|
||||
)}
|
||||
@@ -70,7 +74,7 @@ export function NewskieDialog({
|
||||
<Text style={[a.text_md]}>
|
||||
<Trans>
|
||||
{profileName} joined Bluesky{' '}
|
||||
{timeAgo(createdAt, {format: 'long'})} ago
|
||||
{timeAgo(createdAt, now, {format: 'long'})} ago
|
||||
</Trans>
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
@@ -469,7 +469,7 @@ function Inner({
|
||||
)}
|
||||
</Text>
|
||||
|
||||
<ProfileHeaderHandle profile={profileShadow} />
|
||||
<ProfileHeaderHandle profile={profileShadow} disableTaps />
|
||||
</View>
|
||||
</Link>
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ export type TrackPropertiesMap = {
|
||||
'Post:ThreadMute': {} // CAN BE SERVER
|
||||
'Post:ThreadUnmute': {} // CAN BE SERVER
|
||||
'Post:Reply': {} // CAN BE SERVER
|
||||
'Post:EditThreadgateOpened': {}
|
||||
'Post:ThreadgateEdited': {}
|
||||
// PROFILE events
|
||||
'Profile:Follow': {
|
||||
username: string
|
||||
|
||||
+12
-5
@@ -270,7 +270,7 @@ export async function post(agent: BskyAgent, opts: PostOpts) {
|
||||
return res
|
||||
}
|
||||
|
||||
async function createThreadgate(
|
||||
export async function createThreadgate(
|
||||
agent: BskyAgent,
|
||||
postUri: string,
|
||||
threadgate: ThreadgateSetting[],
|
||||
@@ -296,10 +296,17 @@ async function createThreadgate(
|
||||
}
|
||||
|
||||
const postUrip = new AtUri(postUri)
|
||||
await agent.api.app.bsky.feed.threadgate.create(
|
||||
{repo: agent.session!.did, rkey: postUrip.rkey},
|
||||
{post: postUri, createdAt: new Date().toISOString(), allow},
|
||||
)
|
||||
await agent.api.com.atproto.repo.putRecord({
|
||||
repo: agent.session!.did,
|
||||
collection: 'app.bsky.feed.threadgate',
|
||||
rkey: postUrip.rkey,
|
||||
record: {
|
||||
$type: 'app.bsky.feed.threadgate',
|
||||
post: postUri,
|
||||
allow,
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {useCallback, useMemo} from 'react'
|
||||
import {useCallback} from 'react'
|
||||
import {msg, plural} from '@lingui/macro'
|
||||
import {I18nContext, useLingui} from '@lingui/react'
|
||||
import {differenceInSeconds} from 'date-fns'
|
||||
@@ -12,25 +12,16 @@ export function useGetTimeAgo() {
|
||||
const {_} = useLingui()
|
||||
return useCallback(
|
||||
(
|
||||
date: number | string | Date,
|
||||
earlier: number | string | Date,
|
||||
later: number | string | Date,
|
||||
options?: Omit<TimeAgoOptions, 'lingui'>,
|
||||
) => {
|
||||
return dateDiff(date, Date.now(), {lingui: _, format: options?.format})
|
||||
return dateDiff(earlier, later, {lingui: _, format: options?.format})
|
||||
},
|
||||
[_],
|
||||
)
|
||||
}
|
||||
|
||||
export function useTimeAgo(
|
||||
date: number | string | Date,
|
||||
options?: Omit<TimeAgoOptions, 'lingui'>,
|
||||
): string {
|
||||
const timeAgo = useGetTimeAgo()
|
||||
return useMemo(() => {
|
||||
return timeAgo(date, {...options})
|
||||
}, [date, options, timeAgo])
|
||||
}
|
||||
|
||||
const NOW = 5
|
||||
const MINUTE = 60
|
||||
const HOUR = MINUTE * 60
|
||||
|
||||
@@ -112,6 +112,8 @@ export type LogEvents = {
|
||||
'post:unrepost': {
|
||||
logContext: 'FeedItem' | 'PostThreadItem' | 'Post'
|
||||
}
|
||||
'post:mute': {}
|
||||
'post:unmute': {}
|
||||
'profile:follow': {
|
||||
didBecomeMutual: boolean | undefined
|
||||
followeeClout: number | undefined
|
||||
|
||||
@@ -12,8 +12,10 @@ import {Text} from '#/components/Typography'
|
||||
|
||||
export function ProfileHeaderHandle({
|
||||
profile,
|
||||
disableTaps,
|
||||
}: {
|
||||
profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>
|
||||
disableTaps?: boolean
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const invalidHandle = isInvalidHandle(profile.handle)
|
||||
@@ -21,8 +23,8 @@ export function ProfileHeaderHandle({
|
||||
return (
|
||||
<View
|
||||
style={[a.flex_row, a.gap_xs, a.align_center]}
|
||||
pointerEvents={isAndroid ? 'box-only' : 'auto'}>
|
||||
<NewskieDialog profile={profile} />
|
||||
pointerEvents={disableTaps ? 'none' : isAndroid ? 'box-only' : 'auto'}>
|
||||
<NewskieDialog profile={profile} disabled={disableTaps} />
|
||||
{profile.viewer?.followedBy && !blockHide ? (
|
||||
<View style={[t.atoms.bg_contrast_25, a.rounded_xs, a.px_sm, a.py_xs]}>
|
||||
<Text style={[t.atoms.text, a.text_sm]}>
|
||||
|
||||
Vendored
+44
@@ -0,0 +1,44 @@
|
||||
import React from 'react'
|
||||
|
||||
type StateContext = Map<string, boolean>
|
||||
type SetStateContext = (uri: string, value: boolean) => void
|
||||
|
||||
const stateContext = React.createContext<StateContext>(new Map())
|
||||
const setStateContext = React.createContext<SetStateContext>(
|
||||
(_: string) => false,
|
||||
)
|
||||
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const [state, setState] = React.useState<StateContext>(() => new Map())
|
||||
|
||||
const setThreadMute = React.useCallback(
|
||||
(uri: string, value: boolean) => {
|
||||
setState(prev => {
|
||||
const next = new Map(prev)
|
||||
next.set(uri, value)
|
||||
return next
|
||||
})
|
||||
},
|
||||
[setState],
|
||||
)
|
||||
return (
|
||||
<stateContext.Provider value={state}>
|
||||
<setStateContext.Provider value={setThreadMute}>
|
||||
{children}
|
||||
</setStateContext.Provider>
|
||||
</stateContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useMutedThreads() {
|
||||
return React.useContext(stateContext)
|
||||
}
|
||||
|
||||
export function useIsThreadMuted(uri: string, defaultValue = false) {
|
||||
const state = React.useContext(stateContext)
|
||||
return state.get(uri) ?? defaultValue
|
||||
}
|
||||
|
||||
export function useSetThreadMute() {
|
||||
return React.useContext(setStateContext)
|
||||
}
|
||||
@@ -70,7 +70,8 @@ export interface SelfLabelModal {
|
||||
export interface ThreadgateModal {
|
||||
name: 'threadgate'
|
||||
settings: ThreadgateSetting[]
|
||||
onChange: (settings: ThreadgateSetting[]) => void
|
||||
onChange?: (settings: ThreadgateSetting[]) => void
|
||||
onConfirm?: (settings: ThreadgateSetting[]) => void
|
||||
}
|
||||
|
||||
export interface ChangeHandleModal {
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import React from 'react'
|
||||
import * as persisted from '#/state/persisted'
|
||||
import {track} from '#/lib/analytics/analytics'
|
||||
|
||||
type StateContext = persisted.Schema['mutedThreads']
|
||||
type ToggleContext = (uri: string) => boolean
|
||||
|
||||
const stateContext = React.createContext<StateContext>(
|
||||
persisted.defaults.mutedThreads,
|
||||
)
|
||||
const toggleContext = React.createContext<ToggleContext>((_: string) => false)
|
||||
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const [state, setState] = React.useState(persisted.get('mutedThreads'))
|
||||
|
||||
const toggleThreadMute = React.useCallback(
|
||||
(uri: string) => {
|
||||
let muted = false
|
||||
setState((arr: string[]) => {
|
||||
if (arr.includes(uri)) {
|
||||
arr = arr.filter(v => v !== uri)
|
||||
muted = false
|
||||
track('Post:ThreadUnmute')
|
||||
} else {
|
||||
arr = arr.concat([uri])
|
||||
muted = true
|
||||
track('Post:ThreadMute')
|
||||
}
|
||||
persisted.write('mutedThreads', arr)
|
||||
return arr
|
||||
})
|
||||
return muted
|
||||
},
|
||||
[setState],
|
||||
)
|
||||
|
||||
React.useEffect(() => {
|
||||
return persisted.onUpdate(() => {
|
||||
setState(persisted.get('mutedThreads'))
|
||||
})
|
||||
}, [setState])
|
||||
|
||||
return (
|
||||
<stateContext.Provider value={state}>
|
||||
<toggleContext.Provider value={toggleThreadMute}>
|
||||
{children}
|
||||
</toggleContext.Provider>
|
||||
</stateContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useMutedThreads() {
|
||||
return React.useContext(stateContext)
|
||||
}
|
||||
|
||||
export function useToggleThreadMute() {
|
||||
return React.useContext(toggleContext)
|
||||
}
|
||||
|
||||
export function isThreadMuted(uri: string) {
|
||||
return persisted.get('mutedThreads').includes(uri)
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {useMutedThreads} from '#/state/muted-threads'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useModerationOpts} from '../../preferences/moderation-opts'
|
||||
import {STALE} from '..'
|
||||
@@ -54,7 +53,6 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const threadMutes = useMutedThreads()
|
||||
const unreads = useUnreadNotificationsApi()
|
||||
const enabled = opts?.enabled !== false
|
||||
const lastPageCountRef = useRef(0)
|
||||
@@ -82,7 +80,6 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||
cursor: pageParam,
|
||||
queryClient,
|
||||
moderationOpts,
|
||||
threadMutes,
|
||||
fetchAdditionalData: true,
|
||||
})
|
||||
).page
|
||||
|
||||
@@ -9,7 +9,6 @@ import EventEmitter from 'eventemitter3'
|
||||
|
||||
import BroadcastChannel from '#/lib/broadcast'
|
||||
import {logger} from '#/logger'
|
||||
import {useMutedThreads} from '#/state/muted-threads'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {resetBadgeCount} from 'lib/notifications/notifications'
|
||||
import {useModerationOpts} from '../../preferences/moderation-opts'
|
||||
@@ -48,7 +47,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const threadMutes = useMutedThreads()
|
||||
|
||||
const [numUnread, setNumUnread] = React.useState('')
|
||||
|
||||
@@ -147,7 +145,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
limit: 40,
|
||||
queryClient,
|
||||
moderationOpts,
|
||||
threadMutes,
|
||||
|
||||
// only fetch subjects when the page is going to be used
|
||||
// in the notifications query, otherwise skip it
|
||||
@@ -192,7 +189,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
}
|
||||
},
|
||||
}
|
||||
}, [setNumUnread, queryClient, moderationOpts, threadMutes, agent])
|
||||
}, [setNumUnread, queryClient, moderationOpts, agent])
|
||||
checkUnreadRef.current = api.checkUnread
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
AppBskyEmbedRecord,
|
||||
AppBskyFeedDefs,
|
||||
AppBskyFeedLike,
|
||||
AppBskyFeedPost,
|
||||
@@ -28,7 +27,6 @@ export async function fetchPage({
|
||||
limit,
|
||||
queryClient,
|
||||
moderationOpts,
|
||||
threadMutes,
|
||||
fetchAdditionalData,
|
||||
}: {
|
||||
agent: BskyAgent
|
||||
@@ -36,7 +34,6 @@ export async function fetchPage({
|
||||
limit: number
|
||||
queryClient: QueryClient
|
||||
moderationOpts: ModerationOpts | undefined
|
||||
threadMutes: string[]
|
||||
fetchAdditionalData: boolean
|
||||
}): Promise<{page: FeedPage; indexedAt: string | undefined}> {
|
||||
const res = await agent.listNotifications({
|
||||
@@ -67,11 +64,6 @@ export async function fetchPage({
|
||||
}
|
||||
}
|
||||
|
||||
// apply thread muting
|
||||
notifsGrouped = notifsGrouped.filter(
|
||||
notif => !isThreadMuted(notif, threadMutes),
|
||||
)
|
||||
|
||||
let seenAt = res.data.seenAt ? new Date(res.data.seenAt) : new Date()
|
||||
if (Number.isNaN(seenAt.getTime())) {
|
||||
seenAt = new Date()
|
||||
@@ -207,45 +199,3 @@ function getSubjectUri(
|
||||
return notif.reasonSubject
|
||||
}
|
||||
}
|
||||
|
||||
export function isThreadMuted(notif: FeedNotification, threadMutes: string[]) {
|
||||
// If there's a subject we want to use that. This will always work on the notifications tab
|
||||
if (notif.subject) {
|
||||
const record = notif.subject.record as AppBskyFeedPost.Record
|
||||
// Check for a quote record
|
||||
if (
|
||||
(record.reply && threadMutes.includes(record.reply.root.uri)) ||
|
||||
(notif.subject.uri && threadMutes.includes(notif.subject.uri))
|
||||
) {
|
||||
return true
|
||||
} else if (
|
||||
AppBskyEmbedRecord.isMain(record.embed) &&
|
||||
threadMutes.includes(record.embed.record.uri)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
// Otherwise we just do the best that we can
|
||||
const record = notif.notification.record
|
||||
if (AppBskyFeedPost.isRecord(record)) {
|
||||
if (record.reply && threadMutes.includes(record.reply.root.uri)) {
|
||||
// We can always filter replies
|
||||
return true
|
||||
} else if (
|
||||
AppBskyEmbedRecord.isMain(record.embed) &&
|
||||
threadMutes.includes(record.embed.record.uri)
|
||||
) {
|
||||
// We can also filter quotes if the quoted post is the root
|
||||
return true
|
||||
}
|
||||
} else if (
|
||||
AppBskyFeedRepost.isRecord(record) &&
|
||||
threadMutes.includes(record.subject.uri)
|
||||
) {
|
||||
// Finally we can filter reposts, again if the post is the root
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@ import {
|
||||
getEmbeddedPost,
|
||||
} from './util'
|
||||
|
||||
const RQKEY_ROOT = 'post-thread'
|
||||
const REPLY_TREE_DEPTH = 10
|
||||
export const RQKEY_ROOT = 'post-thread'
|
||||
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
|
||||
type ThreadViewNode = AppBskyFeedGetPostThread.OutputSchema['thread']
|
||||
|
||||
@@ -90,7 +91,10 @@ export function usePostThreadQuery(uri: string | undefined) {
|
||||
gcTime: 0,
|
||||
queryKey: RQKEY(uri || ''),
|
||||
async queryFn() {
|
||||
const res = await agent.getPostThread({uri: uri!, depth: 10})
|
||||
const res = await agent.getPostThread({
|
||||
uri: uri!,
|
||||
depth: REPLY_TREE_DEPTH,
|
||||
})
|
||||
if (res.success) {
|
||||
const thread = responseToThreadNodes(res.data.thread)
|
||||
annotateSelfThread(thread)
|
||||
@@ -287,7 +291,12 @@ function annotateSelfThread(thread: ThreadNode) {
|
||||
selfThreadNode.ctx.isSelfThread = true
|
||||
}
|
||||
const last = selfThreadNodes[selfThreadNodes.length - 1]
|
||||
if (last && last.post.replyCount && !last.replies?.length) {
|
||||
if (
|
||||
last &&
|
||||
last.ctx.depth === REPLY_TREE_DEPTH && // at the edge of the tree depth
|
||||
last.post.replyCount && // has replies
|
||||
!last.replies?.length // replies were not hydrated
|
||||
) {
|
||||
last.ctx.hasMoreSelfThread = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {logEvent, LogEvents, toClout} from '#/lib/statsig/statsig'
|
||||
import {updatePostShadow} from '#/state/cache/post-shadow'
|
||||
import {Shadow} from '#/state/cache/types'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useIsThreadMuted, useSetThreadMute} from '../cache/thread-mutes'
|
||||
import {findProfileQueryData} from './profile'
|
||||
|
||||
const RQKEY_ROOT = 'post'
|
||||
@@ -291,3 +292,72 @@ export function usePostDeleteMutation() {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useThreadMuteMutationQueue(
|
||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||
rootUri: string,
|
||||
) {
|
||||
const threadMuteMutation = useThreadMuteMutation()
|
||||
const threadUnmuteMutation = useThreadUnmuteMutation()
|
||||
const isThreadMuted = useIsThreadMuted(rootUri, post.viewer?.threadMuted)
|
||||
const setThreadMute = useSetThreadMute()
|
||||
|
||||
const queueToggle = useToggleMutationQueue<boolean>({
|
||||
initialState: isThreadMuted,
|
||||
runMutation: async (_prev, shouldLike) => {
|
||||
if (shouldLike) {
|
||||
await threadMuteMutation.mutateAsync({
|
||||
uri: rootUri,
|
||||
})
|
||||
return true
|
||||
} else {
|
||||
await threadUnmuteMutation.mutateAsync({
|
||||
uri: rootUri,
|
||||
})
|
||||
return false
|
||||
}
|
||||
},
|
||||
onSuccess(finalIsMuted) {
|
||||
// finalize
|
||||
setThreadMute(rootUri, finalIsMuted)
|
||||
},
|
||||
})
|
||||
|
||||
const queueMuteThread = useCallback(() => {
|
||||
// optimistically update
|
||||
setThreadMute(rootUri, true)
|
||||
return queueToggle(true)
|
||||
}, [setThreadMute, rootUri, queueToggle])
|
||||
|
||||
const queueUnmuteThread = useCallback(() => {
|
||||
// optimistically update
|
||||
setThreadMute(rootUri, false)
|
||||
return queueToggle(false)
|
||||
}, [rootUri, setThreadMute, queueToggle])
|
||||
|
||||
return [isThreadMuted, queueMuteThread, queueUnmuteThread] as const
|
||||
}
|
||||
|
||||
function useThreadMuteMutation() {
|
||||
const agent = useAgent()
|
||||
return useMutation<
|
||||
{},
|
||||
Error,
|
||||
{uri: string} // the root post's uri
|
||||
>({
|
||||
mutationFn: ({uri}) => {
|
||||
logEvent('post:mute', {})
|
||||
return agent.api.app.bsky.graph.muteThread({root: uri})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function useThreadUnmuteMutation() {
|
||||
const agent = useAgent()
|
||||
return useMutation<{}, Error, {uri: string}>({
|
||||
mutationFn: ({uri}) => {
|
||||
logEvent('post:unmute', {})
|
||||
return agent.api.app.bsky.graph.unmuteThread({root: uri})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,38 @@
|
||||
import {AppBskyFeedDefs, AppBskyFeedThreadgate} from '@atproto/api'
|
||||
|
||||
export type ThreadgateSetting =
|
||||
| {type: 'nobody'}
|
||||
| {type: 'mention'}
|
||||
| {type: 'following'}
|
||||
| {type: 'list'; list: string}
|
||||
|
||||
export function threadgateViewToSettings(
|
||||
threadgate: AppBskyFeedDefs.ThreadgateView | undefined,
|
||||
): ThreadgateSetting[] {
|
||||
const record =
|
||||
threadgate &&
|
||||
AppBskyFeedThreadgate.isRecord(threadgate.record) &&
|
||||
AppBskyFeedThreadgate.validateRecord(threadgate.record).success
|
||||
? threadgate.record
|
||||
: null
|
||||
if (!record) {
|
||||
return []
|
||||
}
|
||||
if (!record.allow?.length) {
|
||||
return [{type: 'nobody'}]
|
||||
}
|
||||
return record.allow
|
||||
.map(allow => {
|
||||
if (allow.$type === 'app.bsky.feed.threadgate#mentionRule') {
|
||||
return {type: 'mention'}
|
||||
}
|
||||
if (allow.$type === 'app.bsky.feed.threadgate#followingRule') {
|
||||
return {type: 'following'}
|
||||
}
|
||||
if (allow.$type === 'app.bsky.feed.threadgate#listRule') {
|
||||
return {type: 'list', list: allow.list}
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
.filter(Boolean) as ThreadgateSetting[]
|
||||
}
|
||||
|
||||
@@ -26,9 +26,11 @@ export const snapPoints = ['60%']
|
||||
export function Component({
|
||||
settings,
|
||||
onChange,
|
||||
onConfirm,
|
||||
}: {
|
||||
settings: ThreadgateSetting[]
|
||||
onChange: (settings: ThreadgateSetting[]) => void
|
||||
onChange?: (settings: ThreadgateSetting[]) => void
|
||||
onConfirm?: (settings: ThreadgateSetting[]) => void
|
||||
}) {
|
||||
const pal = usePalette('default')
|
||||
const {closeModal} = useModalControls()
|
||||
@@ -38,12 +40,12 @@ export function Component({
|
||||
|
||||
const onPressEverybody = () => {
|
||||
setSelected([])
|
||||
onChange([])
|
||||
onChange?.([])
|
||||
}
|
||||
|
||||
const onPressNobody = () => {
|
||||
setSelected([{type: 'nobody'}])
|
||||
onChange([{type: 'nobody'}])
|
||||
onChange?.([{type: 'nobody'}])
|
||||
}
|
||||
|
||||
const onPressAudience = (setting: ThreadgateSetting) => {
|
||||
@@ -57,7 +59,7 @@ export function Component({
|
||||
newSelected.splice(i, 1)
|
||||
}
|
||||
setSelected(newSelected)
|
||||
onChange(newSelected)
|
||||
onChange?.(newSelected)
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -124,6 +126,7 @@ export function Component({
|
||||
testID="confirmBtn"
|
||||
onPress={() => {
|
||||
closeModal()
|
||||
onConfirm?.(selected)
|
||||
}}
|
||||
style={styles.btn}
|
||||
accessibilityRole="button"
|
||||
|
||||
@@ -25,7 +25,7 @@ import {sanitizeHandle} from 'lib/strings/handles'
|
||||
import {countLines} from 'lib/strings/helpers'
|
||||
import {niceDate} from 'lib/strings/time'
|
||||
import {s} from 'lib/styles'
|
||||
import {isWeb} from 'platform/detection'
|
||||
import {isNative, isWeb} from 'platform/detection'
|
||||
import {useSession} from 'state/session'
|
||||
import {PostThreadFollowBtn} from 'view/com/post-thread/PostThreadFollowBtn'
|
||||
import {atoms as a} from '#/alf'
|
||||
@@ -189,6 +189,7 @@ let PostThreadItemLoaded = ({
|
||||
const itemTitle = _(msg`Post by ${post.author.handle}`)
|
||||
const authorHref = makeProfileLink(post.author)
|
||||
const authorTitle = post.author.handle
|
||||
const isThreadAuthor = getThreadAuthor(post, record) === currentAccount?.did
|
||||
const likesHref = React.useMemo(() => {
|
||||
const urip = new AtUri(post.uri)
|
||||
return makeProfileLink(post.author, 'post', urip.rkey, 'liked-by')
|
||||
@@ -395,7 +396,11 @@ let PostThreadItemLoaded = ({
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
<WhoCanReply post={post} />
|
||||
<WhoCanReply
|
||||
post={post}
|
||||
isThreadAuthor={isThreadAuthor}
|
||||
style={{borderBottomWidth: isNative ? 1 : 0}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
} else {
|
||||
@@ -578,7 +583,9 @@ let PostThreadItemLoaded = ({
|
||||
post={post}
|
||||
style={{
|
||||
marginTop: 4,
|
||||
borderBottomWidth: 1,
|
||||
}}
|
||||
isThreadAuthor={isThreadAuthor}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
@@ -681,6 +688,20 @@ function ExpandedPostDetails({
|
||||
)
|
||||
}
|
||||
|
||||
function getThreadAuthor(
|
||||
post: AppBskyFeedDefs.PostView,
|
||||
record: AppBskyFeedPost.Record,
|
||||
): string {
|
||||
if (!record.reply) {
|
||||
return post.author.did
|
||||
}
|
||||
try {
|
||||
return new AtUri(record.reply.root.uri).host
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
outer: {
|
||||
borderTopWidth: hairlineWidth,
|
||||
|
||||
@@ -1,128 +1,172 @@
|
||||
import React from 'react'
|
||||
import {StyleProp, View, ViewStyle} from 'react-native'
|
||||
import {
|
||||
AppBskyFeedDefs,
|
||||
AppBskyFeedThreadgate,
|
||||
AppBskyGraphDefs,
|
||||
AtUri,
|
||||
} from '@atproto/api'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {Trans} from '@lingui/macro'
|
||||
import {Keyboard, StyleProp, View, ViewStyle} from 'react-native'
|
||||
import {AppBskyFeedDefs, AppBskyGraphDefs, AtUri} from '@atproto/api'
|
||||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {useAnalytics} from '#/lib/analytics/analytics'
|
||||
import {createThreadgate} from '#/lib/api'
|
||||
import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle'
|
||||
import {usePalette} from '#/lib/hooks/usePalette'
|
||||
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||
import {makeListLink, makeProfileLink} from '#/lib/routes/links'
|
||||
import {colors} from '#/lib/styles'
|
||||
import {logger} from '#/logger'
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {RQKEY_ROOT as POST_THREAD_RQKEY_ROOT} from '#/state/queries/post-thread'
|
||||
import {
|
||||
ThreadgateSetting,
|
||||
threadgateViewToSettings,
|
||||
} from '#/state/queries/threadgate'
|
||||
import {useAgent} from '#/state/session'
|
||||
import * as Toast from 'view/com/util/Toast'
|
||||
import {Button} from '#/components/Button'
|
||||
import {TextLink} from '../util/Link'
|
||||
import {Text} from '../util/text/Text'
|
||||
|
||||
export function WhoCanReply({
|
||||
post,
|
||||
isThreadAuthor,
|
||||
style,
|
||||
}: {
|
||||
post: AppBskyFeedDefs.PostView
|
||||
isThreadAuthor: boolean
|
||||
style?: StyleProp<ViewStyle>
|
||||
}) {
|
||||
const {track} = useAnalytics()
|
||||
const {_} = useLingui()
|
||||
const pal = usePalette('default')
|
||||
const {isMobile} = useWebMediaQueries()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
const {openModal} = useModalControls()
|
||||
const containerStyles = useColorSchemeStyle(
|
||||
{
|
||||
borderColor: pal.colors.unreadNotifBorder,
|
||||
backgroundColor: pal.colors.unreadNotifBg,
|
||||
},
|
||||
{
|
||||
borderColor: pal.colors.unreadNotifBorder,
|
||||
backgroundColor: pal.colors.unreadNotifBg,
|
||||
},
|
||||
)
|
||||
const iconStyles = useColorSchemeStyle(
|
||||
{
|
||||
backgroundColor: colors.blue3,
|
||||
},
|
||||
{
|
||||
backgroundColor: colors.blue3,
|
||||
},
|
||||
)
|
||||
const textStyles = useColorSchemeStyle(
|
||||
{color: colors.gray7},
|
||||
{color: colors.blue5},
|
||||
{color: colors.blue1},
|
||||
)
|
||||
const record = React.useMemo(
|
||||
() =>
|
||||
post.threadgate &&
|
||||
AppBskyFeedThreadgate.isRecord(post.threadgate.record) &&
|
||||
AppBskyFeedThreadgate.validateRecord(post.threadgate.record).success
|
||||
? post.threadgate.record
|
||||
: null,
|
||||
const hoverStyles = useColorSchemeStyle(
|
||||
{
|
||||
backgroundColor: colors.white,
|
||||
},
|
||||
{
|
||||
backgroundColor: pal.colors.background,
|
||||
},
|
||||
)
|
||||
const settings = React.useMemo(
|
||||
() => threadgateViewToSettings(post.threadgate),
|
||||
[post],
|
||||
)
|
||||
if (record) {
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
{
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
gap: isMobile ? 8 : 10,
|
||||
paddingHorizontal: isMobile ? 16 : 18,
|
||||
paddingVertical: 12,
|
||||
borderWidth: 1,
|
||||
borderLeftWidth: isMobile ? 0 : 1,
|
||||
borderRightWidth: isMobile ? 0 : 1,
|
||||
},
|
||||
containerStyles,
|
||||
style,
|
||||
]}>
|
||||
<View
|
||||
style={[
|
||||
{
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
width: 32,
|
||||
height: 32,
|
||||
borderRadius: 19,
|
||||
},
|
||||
iconStyles,
|
||||
]}>
|
||||
<FontAwesomeIcon
|
||||
icon={['far', 'comments']}
|
||||
size={16}
|
||||
color={'#fff'}
|
||||
/>
|
||||
</View>
|
||||
<View style={{flex: 1}}>
|
||||
<Text type="sm" style={[{flexWrap: 'wrap'}, textStyles]}>
|
||||
{!record.allow?.length ? (
|
||||
<Trans>Replies to this thread are disabled</Trans>
|
||||
) : (
|
||||
<Trans>
|
||||
Only{' '}
|
||||
{record.allow.map((rule, i) => (
|
||||
<>
|
||||
<Rule
|
||||
key={`rule-${i}`}
|
||||
rule={rule}
|
||||
post={post}
|
||||
lists={post.threadgate!.lists}
|
||||
/>
|
||||
<Separator
|
||||
key={`sep-${i}`}
|
||||
i={i}
|
||||
length={record.allow!.length}
|
||||
/>
|
||||
</>
|
||||
))}{' '}
|
||||
can reply.
|
||||
</Trans>
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
const isRootPost = !('reply' in post.record)
|
||||
|
||||
const onPressEdit = () => {
|
||||
track('Post:EditThreadgateOpened')
|
||||
if (isNative && Keyboard.isVisible()) {
|
||||
Keyboard.dismiss()
|
||||
}
|
||||
openModal({
|
||||
name: 'threadgate',
|
||||
settings,
|
||||
async onConfirm(newSettings: ThreadgateSetting[]) {
|
||||
try {
|
||||
if (newSettings.length) {
|
||||
await createThreadgate(agent, post.uri, newSettings)
|
||||
} else {
|
||||
await agent.api.com.atproto.repo.deleteRecord({
|
||||
repo: agent.session!.did,
|
||||
collection: 'app.bsky.feed.threadgate',
|
||||
rkey: new AtUri(post.uri).rkey,
|
||||
})
|
||||
}
|
||||
Toast.show('Thread settings updated')
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [POST_THREAD_RQKEY_ROOT],
|
||||
})
|
||||
track('Post:ThreadgateEdited')
|
||||
} catch (err) {
|
||||
Toast.show(
|
||||
'There was an issue. Please check your internet connection and try again.',
|
||||
)
|
||||
logger.error('Failed to edit threadgate', {message: err})
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
return null
|
||||
|
||||
if (!isRootPost) {
|
||||
return null
|
||||
}
|
||||
if (!settings.length && !isThreadAuthor) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
{
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
gap: 10,
|
||||
paddingLeft: 18,
|
||||
paddingRight: 14,
|
||||
paddingVertical: 10,
|
||||
borderTopWidth: 1,
|
||||
},
|
||||
pal.border,
|
||||
containerStyles,
|
||||
style,
|
||||
]}>
|
||||
<View style={{flex: 1, paddingVertical: 6}}>
|
||||
<Text type="sm" style={[{flexWrap: 'wrap'}, textStyles]}>
|
||||
{!settings.length ? (
|
||||
<Trans>Everybody can reply.</Trans>
|
||||
) : settings[0].type === 'nobody' ? (
|
||||
<Trans>Replies to this thread are disabled.</Trans>
|
||||
) : (
|
||||
<Trans>
|
||||
Only{' '}
|
||||
{settings.map((rule, i) => (
|
||||
<>
|
||||
<Rule
|
||||
key={`rule-${i}`}
|
||||
rule={rule}
|
||||
post={post}
|
||||
lists={post.threadgate!.lists}
|
||||
/>
|
||||
<Separator key={`sep-${i}`} i={i} length={settings.length} />
|
||||
</>
|
||||
))}{' '}
|
||||
can reply.
|
||||
</Trans>
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
{isThreadAuthor && (
|
||||
<View>
|
||||
<Button label={_(msg`Edit`)} onPress={onPressEdit}>
|
||||
{({hovered}) => (
|
||||
<View
|
||||
style={[
|
||||
hovered && hoverStyles,
|
||||
{paddingVertical: 6, paddingHorizontal: 8, borderRadius: 8},
|
||||
]}>
|
||||
<Text type="sm" style={pal.link}>
|
||||
<Trans>Edit</Trans>
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
function Rule({
|
||||
@@ -130,15 +174,15 @@ function Rule({
|
||||
post,
|
||||
lists,
|
||||
}: {
|
||||
rule: any
|
||||
rule: ThreadgateSetting
|
||||
post: AppBskyFeedDefs.PostView
|
||||
lists: AppBskyGraphDefs.ListViewBasic[] | undefined
|
||||
}) {
|
||||
const pal = usePalette('default')
|
||||
if (AppBskyFeedThreadgate.isMentionRule(rule)) {
|
||||
if (rule.type === 'mention') {
|
||||
return <Trans>mentioned users</Trans>
|
||||
}
|
||||
if (AppBskyFeedThreadgate.isFollowingRule(rule)) {
|
||||
if (rule.type === 'following') {
|
||||
return (
|
||||
<Trans>
|
||||
users followed by{' '}
|
||||
@@ -151,7 +195,7 @@ function Rule({
|
||||
</Trans>
|
||||
)
|
||||
}
|
||||
if (AppBskyFeedThreadgate.isListRule(rule)) {
|
||||
if (rule.type === 'list') {
|
||||
const list = lists?.find(l => l.uri === rule.list)
|
||||
if (list) {
|
||||
const listUrip = new AtUri(list.uri)
|
||||
|
||||
@@ -15,12 +15,14 @@ export function TimeElapsed({
|
||||
const ago = useGetTimeAgo()
|
||||
const format = timeToString ?? ago
|
||||
const tick = useTickEveryMinute()
|
||||
const [timeElapsed, setTimeAgo] = React.useState(() => format(timestamp))
|
||||
const [timeElapsed, setTimeAgo] = React.useState(() =>
|
||||
format(timestamp, tick),
|
||||
)
|
||||
|
||||
const [prevTick, setPrevTick] = React.useState(tick)
|
||||
if (prevTick !== tick) {
|
||||
setPrevTick(tick)
|
||||
setTimeAgo(format(timestamp))
|
||||
setTimeAgo(format(timestamp, tick))
|
||||
}
|
||||
|
||||
return children({timeElapsed})
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from 'react-native'
|
||||
import * as Clipboard from 'expo-clipboard'
|
||||
import {
|
||||
AppBskyActorDefs,
|
||||
AppBskyFeedDefs,
|
||||
AppBskyFeedPost,
|
||||
AtUri,
|
||||
RichText as RichTextAPI,
|
||||
@@ -22,12 +22,15 @@ import {richTextToString} from '#/lib/strings/rich-text-helpers'
|
||||
import {getTranslatorLink} from '#/locale/helpers'
|
||||
import {logger} from '#/logger'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {Shadow} from '#/state/cache/post-shadow'
|
||||
import {useFeedFeedbackContext} from '#/state/feed-feedback'
|
||||
import {useMutedThreads, useToggleThreadMute} from '#/state/muted-threads'
|
||||
import {useLanguagePrefs} from '#/state/preferences'
|
||||
import {useHiddenPosts, useHiddenPostsApi} from '#/state/preferences'
|
||||
import {useOpenLink} from '#/state/preferences/in-app-browser'
|
||||
import {usePostDeleteMutation} from '#/state/queries/post'
|
||||
import {
|
||||
usePostDeleteMutation,
|
||||
useThreadMuteMutationQueue,
|
||||
} from '#/state/queries/post'
|
||||
import {useSession} from '#/state/session'
|
||||
import {getCurrentRoute} from 'lib/routes/helpers'
|
||||
import {shareUrl} from 'lib/sharing'
|
||||
@@ -62,9 +65,7 @@ import * as Toast from '../Toast'
|
||||
|
||||
let PostDropdownBtn = ({
|
||||
testID,
|
||||
postAuthor,
|
||||
postCid,
|
||||
postUri,
|
||||
post,
|
||||
postFeedContext,
|
||||
record,
|
||||
richText,
|
||||
@@ -74,9 +75,7 @@ let PostDropdownBtn = ({
|
||||
timestamp,
|
||||
}: {
|
||||
testID: string
|
||||
postAuthor: AppBskyActorDefs.ProfileViewBasic
|
||||
postCid: string
|
||||
postUri: string
|
||||
post: Shadow<AppBskyFeedDefs.PostView>
|
||||
postFeedContext: string | undefined
|
||||
record: AppBskyFeedPost.Record
|
||||
richText: RichTextAPI
|
||||
@@ -92,8 +91,6 @@ let PostDropdownBtn = ({
|
||||
const {_} = useLingui()
|
||||
const defaultCtrlColor = theme.palette.default.postCtrl
|
||||
const langPrefs = useLanguagePrefs()
|
||||
const mutedThreads = useMutedThreads()
|
||||
const toggleThreadMute = useToggleThreadMute()
|
||||
const postDeleteMutation = usePostDeleteMutation()
|
||||
const hiddenPosts = useHiddenPosts()
|
||||
const {hidePost} = useHiddenPostsApi()
|
||||
@@ -107,9 +104,15 @@ let PostDropdownBtn = ({
|
||||
const loggedOutWarningPromptControl = useDialogControl()
|
||||
const embedPostControl = useDialogControl()
|
||||
const sendViaChatControl = useDialogControl()
|
||||
const postUri = post.uri
|
||||
const postCid = post.cid
|
||||
const postAuthor = post.author
|
||||
|
||||
const rootUri = record.reply?.root?.uri || postUri
|
||||
const isThreadMuted = mutedThreads.includes(rootUri)
|
||||
const [isThreadMuted, muteThread, unmuteThread] = useThreadMuteMutationQueue(
|
||||
post,
|
||||
rootUri,
|
||||
)
|
||||
const isPostHidden = hiddenPosts && hiddenPosts.includes(postUri)
|
||||
const isAuthor = postAuthor.did === currentAccount?.did
|
||||
|
||||
@@ -162,18 +165,22 @@ let PostDropdownBtn = ({
|
||||
|
||||
const onToggleThreadMute = React.useCallback(() => {
|
||||
try {
|
||||
const muted = toggleThreadMute(rootUri)
|
||||
if (muted) {
|
||||
if (isThreadMuted) {
|
||||
unmuteThread()
|
||||
Toast.show(_(msg`You will now receive notifications for this thread`))
|
||||
} else {
|
||||
muteThread()
|
||||
Toast.show(
|
||||
_(msg`You will no longer receive notifications for this thread`),
|
||||
)
|
||||
} else {
|
||||
Toast.show(_(msg`You will now receive notifications for this thread`))
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('Failed to toggle thread mute', {message: e})
|
||||
} catch (e: any) {
|
||||
if (e?.name !== 'AbortError') {
|
||||
logger.error('Failed to toggle thread mute', {message: e})
|
||||
Toast.show(_(msg`Failed to toggle thread mute, please try again`))
|
||||
}
|
||||
}
|
||||
}, [rootUri, toggleThreadMute, _])
|
||||
}, [isThreadMuted, unmuteThread, _, muteThread])
|
||||
|
||||
const onCopyPostText = React.useCallback(() => {
|
||||
const str = richTextToString(richText, true)
|
||||
|
||||
@@ -319,9 +319,7 @@ let PostCtrls = ({
|
||||
<View style={big ? a.align_center : [a.flex_1, a.align_start]}>
|
||||
<PostDropdownBtn
|
||||
testID="postDropdownBtn"
|
||||
postAuthor={post.author}
|
||||
postCid={post.cid}
|
||||
postUri={post.uri}
|
||||
post={post}
|
||||
postFeedContext={feedContext}
|
||||
record={record}
|
||||
richText={richText}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {useFocusEffect} from '@react-navigation/native'
|
||||
|
||||
import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo'
|
||||
import {getEntries} from '#/logger/logDump'
|
||||
import {useTickEveryMinute} from '#/state/shell'
|
||||
import {useSetMinimalShellMode} from '#/state/shell'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {CommonNavigatorParams, NativeStackScreenProps} from 'lib/routes/types'
|
||||
@@ -24,6 +25,7 @@ export function LogScreen({}: NativeStackScreenProps<
|
||||
const setMinimalShellMode = useSetMinimalShellMode()
|
||||
const [expanded, setExpanded] = React.useState<string[]>([])
|
||||
const timeAgo = useGetTimeAgo()
|
||||
const tick = useTickEveryMinute()
|
||||
|
||||
useFocusEffect(
|
||||
React.useCallback(() => {
|
||||
@@ -72,7 +74,7 @@ export function LogScreen({}: NativeStackScreenProps<
|
||||
/>
|
||||
) : undefined}
|
||||
<Text type="sm" style={[styles.ts, pal.textLight]}>
|
||||
{timeAgo(entry.timestamp)}
|
||||
{timeAgo(entry.timestamp, tick)}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
{expanded.includes(entry.id) ? (
|
||||
|
||||
Reference in New Issue
Block a user