Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ _Avoid_: export, backup, archive export
Creating one new, disconnected Bluesky local account from a prepared Cyd Bluesky archive for an identity this installation does not already hold. It is the commit half of a Bluesky archive import for a new Bluesky identity; an identity Cyd already has a Bluesky local account for is merged instead.
_Avoid_: restore, import, replace

**Bluesky archive merge**:
The commit half of a Bluesky archive import for an identity this installation already holds: a union of the Cyd Bluesky archive into that Bluesky local account's Bluesky saved data, previewed before it is written. It adds and enriches Bluesky saved records and never touches the account's identifier, Bluesky account settings, schedules or Bluesky connection.
_Avoid_: merge, sync, overwrite, import

**Bluesky account settings**:
Local preferences governing how Cyd saves and manages a Bluesky identity. A Cyd Bluesky archive can supply defaults for a new Bluesky local account, but does not silently override an existing Bluesky local account's preferences or schedules.
_Avoid_: account settings, account data, archive state
Expand Down
80 changes: 17 additions & 63 deletions app/account/[accountId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ import iconHome from "@/assets/images/icon-home.png";
import iconSave from "@/assets/images/icon-save.png";
import iconSchedule from "@/assets/images/icon-schedule.png";

import {
AccountAvatar,
accountDisplayName,
accountUsername,
} from "@/components/account/identity";
import { getThemePalette } from "@/constants/theme";
import {
ACCOUNT_AUTH_STATUS,
Expand All @@ -51,7 +56,7 @@ import { useColorScheme } from "@/hooks/use-color-scheme";
import { onAuthStatusChange } from "@/services/auth-events";
import { verifyBlueskyAccountAuthStatus } from "@/services/bluesky-account-auth-status";
import { disconnectBlueskyAccount } from "@/services/bluesky-disconnect";
import { authenticateBlueskyAccount } from "@/services/bluesky-oauth";
import { connectBlueskyAccount } from "@/services/bluesky-sign-in";
import type { AccountTabKey, AccountTabProps } from "@/types/account-tabs";
import { BrowseTab } from "./tabs/browse-tab";
import { DashboardTab } from "./tabs/dashboard-tab";
Expand Down Expand Up @@ -147,13 +152,10 @@ export default function AccountScreen() {

try {
console.log("[AccountScreen] handleReauthenticate -> start", account.id);
await authenticateBlueskyAccount(account.handle);
console.log(
"[AccountScreen] authenticateBlueskyAccount -> success",
account.id,
);
const nextStatus = await runWithAccountController(account, (controller) =>
verifyBlueskyAccountAuthStatus(controller, account, { force: true }),
// Signing in is more than authorizing: it also refreshes what this
// account knows about itself, which is why it is not done by hand here.
const { status: nextStatus } = await connectBlueskyAccount(
account.handle,
);
console.log(
"[AccountScreen] handleReauthenticate -> verified",
Expand Down Expand Up @@ -311,14 +313,8 @@ export default function AccountScreen() {
}, [account]),
);

const avatarUri = account?.avatarUrl ?? null;
const username = account?.handle
? account.handle.startsWith("@")
? account.handle
: `@${account.handle}`
: null;
const displayName = account?.displayName ?? username ?? "Unknown";
const initial = displayName.replace(/^@/, "").charAt(0).toUpperCase() || "?";
const username = account?.handle ? accountUsername(account.handle) : null;
const displayName = account ? accountDisplayName(account) : "Unknown";
const accountStatus = error
? "Unable to load account"
: loading
Expand Down Expand Up @@ -374,35 +370,11 @@ export default function AccountScreen() {
headerBackTitle: "Back",
headerTitle: () => (
<View style={styles.headerTitle}>
{avatarUri ? (
<Image
source={{ uri: avatarUri }}
style={[
styles.avatar,
{
borderColor: palette.icon + "33",
backgroundColor: palette.icon + "20",
},
]}
accessibilityIgnoresInvertColors
/>
) : (
<View
style={[
styles.avatarFallback,
{
borderColor: palette.icon + "33",
backgroundColor: palette.icon + "20",
},
]}
>
<Text
style={[styles.avatarInitial, { color: palette.text }]}
>
{initial}
</Text>
</View>
)}
<AccountAvatar
uri={account?.avatarUrl ?? null}
size={40}
palette={palette}
/>
<View style={styles.headerTextStack}>
<View style={styles.accountNameRow}>
<Text
Expand Down Expand Up @@ -619,24 +591,6 @@ const styles = StyleSheet.create({
headerTextStack: {
flex: 1,
},
avatar: {
width: 40,
height: 40,
borderRadius: 20,
borderWidth: StyleSheet.hairlineWidth,
},
avatarFallback: {
width: 40,
height: 40,
borderRadius: 20,
borderWidth: StyleSheet.hairlineWidth,
alignItems: "center",
justifyContent: "center",
},
avatarInitial: {
fontSize: 16,
fontWeight: "700",
},
accountName: {
fontSize: 16,
fontWeight: "700",
Expand Down
30 changes: 3 additions & 27 deletions app/add-account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ import {
import { SafeAreaView } from "react-native-safe-area-context";

import { getThemePalette } from "@/constants/theme";
import { withBlueskyController } from "@/controllers";
import { useAccounts } from "@/hooks/use-accounts";
import { useColorScheme } from "@/hooks/use-color-scheme";
import { trackEvent } from "@/services/analytics";
import { verifyBlueskyAccountAuthStatus } from "@/services/bluesky-account-auth-status";
import {
authenticateBlueskyAccount,
normalizeHandle,
} from "@/services/bluesky-oauth";
import { PlausibleEvents } from "@/types/analytics";
import { normalizeHandle } from "@/services/bluesky-oauth";
import { connectBlueskyAccount } from "@/services/bluesky-sign-in";

export default function AddAccountScreen() {
const router = useRouter();
Expand Down Expand Up @@ -56,25 +50,7 @@ export default function AddAccountScreen() {
setSubmitting(true);
setError(null);
try {
const savedAccount = await authenticateBlueskyAccount(handle);
// Track successful sign-in
trackEvent(PlausibleEvents.BLUESKY_USER_SIGNED_IN);
try {
await withBlueskyController(
savedAccount.id,
savedAccount.uuid,
async (controller) => {
await verifyBlueskyAccountAuthStatus(controller, savedAccount, {
force: true,
});
},
);
} catch (verifyError) {
console.warn(
"[AddAccount] Failed to persist auth status after OAuth",
verifyError,
);
}
const { account: savedAccount } = await connectBlueskyAccount(handle);
router.replace({
pathname: "/account/[accountId]",
params: { accountId: savedAccount.uuid },
Expand Down
64 changes: 12 additions & 52 deletions app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useCallback, useMemo, useState } from "react";
import {
ActivityIndicator,
FlatList,
Image,
Linking,
Pressable,
RefreshControl,
Expand All @@ -16,6 +15,11 @@ import { SafeAreaView } from "react-native-safe-area-context";

import WordmarkDark from "@/assets/images/cyd-wordmark-dark.svg";
import WordmarkLight from "@/assets/images/cyd-wordmark.svg";
import {
AccountAvatar,
accountDisplayName,
accountUsername,
} from "@/components/account/identity";
import { Colors, getThemePalette } from "@/constants/theme";
import type { AccountListItem } from "@/database/accounts";
import { useAccounts } from "@/hooks/use-accounts";
Expand Down Expand Up @@ -235,12 +239,8 @@ function AccountCard({
disabled,
busy,
}: AccountCardProps) {
const avatarUri = account.avatarUrl || null;
const username = account.handle.startsWith("@")
? account.handle
: `@${account.handle}`;
const displayName = account.displayName ?? username;
const initial = displayName.replace(/^@/, "").charAt(0).toUpperCase() || "?";
const username = accountUsername(account.handle);
const displayName = accountDisplayName(account);

return (
<Pressable
Expand All @@ -256,33 +256,11 @@ function AccountCard({
]}
android_ripple={{ color: palette.icon + "33" }}
>
{avatarUri ? (
<Image
source={{ uri: avatarUri }}
style={[
styles.avatar,
{
borderColor: palette.icon + "33",
backgroundColor: palette.icon + "20",
},
]}
accessibilityIgnoresInvertColors
/>
) : (
<View
style={[
styles.avatarFallback,
{
borderColor: palette.icon + "33",
backgroundColor: palette.icon + "20",
},
]}
>
<Text style={[styles.avatarInitial, { color: palette.text }]}>
{initial}
</Text>
</View>
)}
<AccountAvatar
uri={account.avatarUrl || null}
size={48}
palette={palette}
/>
<View style={styles.accountTextStack}>
<Text
style={[styles.accountName, { color: palette.text }]}
Expand Down Expand Up @@ -375,24 +353,6 @@ const styles = StyleSheet.create({
fontSize: 14,
opacity: 0.9,
},
avatar: {
width: 48,
height: 48,
borderRadius: 24,
borderWidth: StyleSheet.hairlineWidth,
},
avatarFallback: {
width: 48,
height: 48,
borderRadius: 24,
borderWidth: StyleSheet.hairlineWidth,
alignItems: "center",
justifyContent: "center",
},
avatarInitial: {
fontSize: 16,
fontWeight: "700",
},
addAccountButton: {
borderRadius: 16,
paddingVertical: 16,
Expand Down
Loading