~ knotless Search/
↑↓ move↵ open⇧↵ all results

grain.social/grain

photography-focused photo sharing platform

grain.social
1 collaborator
0
2

next: Delete account in Settings, asking no new scope; Identity & data and Instagram import gone

Merged chadtmiller.com asked to merge into feature/hud from grain.social/grain:next/delete-data

Only what this pull adds. It is built on The next grain.social and grain-ios, drawn by HUD.

next/views/grain-settings.json+39−57
@@ -3,7 +3,7 @@
"method": "social.grain.actor.getPreferences",
"app": "Grain",
"service": "did:web:grain.social#grain_appview",
"description": "Your Grain settings: account, theme, notifications, muted and blocked accounts, upload defaults, import and policies; at feeds, your pinned feeds to reorder and unpin (no params; signed in)",
"description": "Your Grain settings: account (and deleting it), theme, notifications, muted and blocked accounts, upload defaults and policies; at feeds, your pinned feeds to reorder and unpin (no params; signed in)",
"origins": [
"https://cdn.grain.social"
],
@@ -608,18 +608,49 @@
}
]
},
{
"component": "Action",
"props": {
"label": "Delete account",
"tone": "danger",
"confirm": "Delete your Grain account?\n\nThis removes all your Grain galleries, stories, photos, favorites, comments, follows, blocks, and profile. Your atproto identity is separate and is not affected. This cannot be undone.",
"handle": {
"$": "me.handle"
},
"deletes": {
"method": "social.grain.server.getAccountDeletionPlan",
"service": "did:web:grain.social#grain_appview",
"repeat": true,
"collections": [
"social.grain.actor.profile",
"social.grain.comment",
"social.grain.favorite",
"social.grain.gallery",
"social.grain.gallery.item",
"social.grain.graph.block",
"social.grain.graph.follow",
"social.grain.photo",
"social.grain.photo.exif",
"social.grain.story"
],
"then": {
"method": "social.grain.server.deleteAccount",
"service": "did:web:grain.social#grain_appview",
"input": {
"did": {
"$did": true
}
}
}
},
"signOut": true
}
},
{
"component": "List",
"props": {
"style": "rows",
"items": [
{
"label": "Identity & data",
"about": "Your DID, and deleting your Grain data, on grain.social",
"open": {
"url": "https://grain.social/settings/account"
}
},
{
"label": "Sign out",
"open": {
@@ -2423,55 +2454,6 @@
}
}
},
{
"component": "Text",
"props": {
"value": "Tools",
"style": "heading"
}
},
{
"component": "List",
"props": {
"style": "rows",
"items": [
{
"label": "Import from Instagram",
"about": "From your Instagram export, on grain.social",
"open": {
"url": "https://grain.social/settings/import"
}
}
]
},
"children": [
{
"component": "Stack",
"props": {
"gap": "xs"
},
"children": [
{
"component": "Text",
"props": {
"value": {
"$": "label"
}
}
},
{
"component": "Text",
"props": {
"value": {
"$": "about"
},
"style": "muted"
}
}
]
}
]
},
{
"component": "Text",
"props": {
vendor/hud/ios/HUDKit/Sources/HUDKit/Data/JSON.swift+20−0
@@ -70,6 +70,26 @@ public enum JSON: Sendable, Hashable {
return at
}
/// The value at a dotted path of an app file's (a scheme's `at`, a
/// tab's `first`), as the web shell's `at` reads one (app.ts): each key
/// an object's, and a key `@name` the element of an array whose `$type`
/// is `name` or ends `#name`; nil where it leads nowhere.
public func at(_ path: String) -> JSON? {
var found: JSON? = self
for key in path.split(separator: ".").map(String.init) {
if key.hasPrefix("@"), let items = found?.array {
let name = key.dropFirst()
found = items.first { item in
guard let type = item.str("$type") else { return false }
return type == name || type.hasSuffix("#\(name)")
}
} else {
found = found?[key]
}
}
return found
}
/// A string or a number as text, as JavaScript's `String()` writes them.
public var text: String? {
switch self {
vendor/hud/ios/HUDKit/Sources/HUDKit/Data/SchemeChoice.swift+3−16
@@ -4,23 +4,10 @@ import SwiftUI
/// light or dark forced, anything else (system, none) the device's. The
/// iOS counterpart of the web shell's `schemeIn` (app/src/theme.ts).
public enum SchemeChoice {
/// What `answer` holds at `path` (dotted; a key `@name` the element of an
/// array whose `$type` is `name` or ends `#name`), as a scheme: light or
/// dark; else nil, the device's.
/// What `answer` holds at `path` (as `JSON.at` reads one), as a scheme:
/// light or dark; else nil, the device's.
public static func scheme(in answer: JSON?, at path: String) -> ColorScheme? {
var found = answer
for key in path.split(separator: ".").map(String.init) {
if key.hasPrefix("@"), let items = found?.array {
let name = key.dropFirst()
found = items.first { item in
guard let type = item.str("$type") else { return false }
return type == name || type.hasSuffix("#\(name)")
}
} else {
found = found?[key]
}
}
switch found?.string {
switch answer?.at(path)?.string {
case "light": return .light
case "dark": return .dark
default: return nil
vendor/hud/ios/HUDKit/Sources/HUDKit/Data/TabFirst.swiftnew+45−0
@@ -0,0 +1,45 @@
import Foundation
/// Where an app file's tab finds its root in the account's data, signed in
/// (its `first`, HUD's docs/views.md, "A tab's root from the account's
/// data"): a query (`call`), the list in its answer (`at`), where in each
/// item a path of the app's own site is (`path`), and the procedure after
/// which it is chosen again (`after`). Grain's Home opens the first feed
/// the person pinned so. The iOS counterpart of the web shell's
/// `chosenRoot` (web/shell/src/app.ts).
public struct TabFirst: Sendable, Equatable {
public let call: Call
public let at: String
public let path: String
public let after: String?
public init(call: Call, at: String, path: String, after: String? = nil) {
self.call = call
self.at = at
self.path = path
self.after = after
}
/// A tab's `first` as its app file has it; nil where it has none, or
/// one without a call, a list's path or an item's.
public init?(_ json: JSON?) {
guard let json, let name = json["call"]?.str("name"), let at = json.str("at"), let path = json.str("path") else { return nil }
self.init(call: Call(name, json["call"]?["args"]?.object ?? [:]), at: at, path: path, after: json.str("after"))
}
/// The root its query's answer (in a query's `response`, else itself)
/// chooses: the screen of the first item whose path has one, the tab's
/// own call (`own`) at its own path (`ownPath`: Grain's Recent, pinned
/// as `/` by its older apps), any other by `routes`; nil where none has
/// (nothing listed, or nothing the app draws, as Grain's Groups is not).
public func root(in answer: JSON?, own: Call, ownPath: String?, routes: [Route]) -> Call? {
let data = answer?["response"] ?? answer
for item in data?.at(at)?.array ?? [] {
// A path of the app's own: never another site's (`//host`, `/\host`).
guard let path = item.at(self.path)?.string, path.hasPrefix("/"), !path.hasPrefix("//"), !path.hasPrefix("/\\") else { continue }
if let ownPath, path == ownPath || (!ownPath.contains("?") && Pattern.split(path).0 == ownPath) { return own }
if let screen = Route.screen(path, in: routes) { return screen.call }
}
return nil
}
}
vendor/hud/ios/HUDKit/Tests/HUDKitTests/TabFirstTests.swiftnew+79−0
@@ -0,0 +1,79 @@
import Testing
@testable import HUDKit
// A tab's root chosen from the account's data (its `first`), as Grain's
// Home opens the first feed pinned: the first listed path with a screen.
@Suite struct TabRootChoosing {
private static func feed(_ id: String, _ more: [String: JSON] = [:]) -> Call {
var params: [String: JSON] = ["feed": .string("at://did:web:grain.social/social.grain.feed.generator/\(id)")]
params.merge(more) { _, new in new }
return Call("query", ["method": "social.grain.feed.getFeed", "params": .object(params)])
}
private static let recent = feed("recent")
private static let routes: [Route] = [
Route(path: "/feeds/recent", call: recent),
Route(path: "/feeds/following", call: feed("following")),
Route(path: "/feeds/for-you", call: feed("foryou")),
Route(path: "/camera/{name}", call: feed("camera", ["camera": "{name}"]), tab: "Explore"),
Route(path: "/location/{h3}?name={name}", call: feed("location", ["location": "{h3}", "name": "{name}"]), tab: "Explore"),
]
private static let first = TabFirst([
"call": ["name": "query", "args": ["method": "social.grain.actor.getPreferences", "params": [:]]],
"at": "preferences.@pinnedFeedsPref.items",
"path": "path",
"after": "social.grain.actor.setPreference",
])!
private static func pinned(_ paths: [JSON], wrapped: Bool = true) -> JSON {
let items: [JSON] = paths.map { ["id": "x", "label": "x", "type": "feed", "path": $0] }
let prefs: JSON = ["preferences": [["$type": "social.grain.actor.defs#themePref", "theme": "dark"], ["$type": "social.grain.actor.defs#pinnedFeedsPref", "items": .array(items)]]]
return wrapped ? ["response": prefs] : prefs
}
private static func root(_ paths: [JSON], wrapped: Bool = true) -> Call? {
first.root(in: pinned(paths, wrapped: wrapped), own: recent, ownPath: "/", routes: routes)
}
@Test func readsTheAppFilesFirst() {
#expect(Self.first.call == Call("query", ["method": "social.grain.actor.getPreferences", "params": [:]]))
#expect(Self.first.at == "preferences.@pinnedFeedsPref.items")
#expect(Self.first.path == "path")
#expect(Self.first.after == "social.grain.actor.setPreference")
#expect(TabFirst(["call": ["name": "query"], "at": "a", "path": "p"])?.after == nil)
#expect(TabFirst(nil) == nil)
#expect(TabFirst(["at": "a", "path": "p"]) == nil)
#expect(TabFirst(["call": ["name": "query"], "path": "p"]) == nil)
#expect(TabFirst(["call": ["name": "query"], "at": "a"]) == nil)
}
@Test func theFirstListedPathWithAScreenIsTheRoot() {
#expect(Self.root(["/feeds/for-you", "/feeds/recent"]) == Self.feed("foryou"))
#expect(Self.root(["/feeds/following"], wrapped: false) == Self.feed("following"))
#expect(Self.root(["/feeds/groups", 5, "/feeds/following"]) == Self.feed("following"))
#expect(Self.root(["/camera/Fuji X100V"]) == Self.feed("camera", ["camera": "Fuji X100V"]))
#expect(Self.root(["/location/8a2a1072b59ffff?name=Brooklyn%2C+NY"]) == Self.feed("location", ["location": "8a2a1072b59ffff", "name": "Brooklyn, NY"]))
// The tab's own path is its own call: Recent, as grain-ios pinned it.
#expect(Self.root(["/", "/feeds/for-you"]) == Self.recent)
#expect(Self.root(["/?utm_source=x"]) == Self.recent)
}
@Test func nothingWithAScreenChoosesNothing() {
#expect(Self.root([]) == nil)
#expect(Self.root(["//evil.test/feeds/recent", "/\\evil.test/feeds/recent", "https://evil.test/feeds/recent", "feeds/recent"]) == nil)
#expect(Self.first.root(in: nil, own: Self.recent, ownPath: "/", routes: Self.routes) == nil)
#expect(Self.first.root(in: ["preferences": []], own: Self.recent, ownPath: "/", routes: Self.routes) == nil)
#expect(Self.first.root(in: Self.pinned(["/"]), own: Self.recent, ownPath: nil, routes: Self.routes) == nil)
}
@Test func aPathReadsListsByTheirTypes() {
let answer: JSON = ["prefs": [["$type": "themePref", "theme": "light"], ["$type": "a.b#pinnedFeedsPref", "items": []]]]
#expect(answer.at("prefs.@themePref.theme") == "light")
#expect(answer.at("prefs.@pinnedFeedsPref.items") == [])
#expect(answer.at("prefs.@nothing") == nil)
#expect(answer.at("prefs.theme") == nil)
#expect(answer.at("nothing.@themePref") == nil)
}
}
vendor/hud/web/renderer/src/tree/Action.svelte+8−0
@@ -300,6 +300,14 @@
white-space: pre-wrap;
}
/* In a stack its parts are lines of the stack, in order: what went wrong
right under the button. Put after the row's items there, it would go
after everything the stack holds, out of sight below a long screen
(Settings' Delete account refused said nothing). */
:global(.stack) > .action > .error {
order: 0;
}
/* An alert in the middle of the screen, what is behind it dimmed: the
question, then Cancel and the action side by side, as a phone asks. */
.confirm {
vendor/hud/web/renderer/src/tree/Compose.svelte+6−0
@@ -292,6 +292,12 @@
overflow-wrap: anywhere;
}
/* In a stack, as an Action's: right under what it is of, not after
everything the stack holds. */
:global(.stack) > .compose > .error {
order: 0;
}
/* A field to write in, as a photo app's Add a comment… under a post's
comments: the whole width, a pill holding its words in the muted
colour, as an empty text field's placeholder. */
vendor/hud/web/shell/src/app.ts+76−15
@@ -10,7 +10,10 @@
// `path` its URL at its root, where that is not its call's route (Grain's
// home, `/`); its `badge`, signed in, a count on its icon: a call (`call`)
// and where in its answer the count is (`count`, a dotted path, in a
// query's `response`). Its `scheme`, signed in, where the account chose
// query's `response`); its `first`, signed in, where its root is chosen
// from the account's data: the first of a list's items that names a
// screen of the app's (Grain's Home, the first of the feeds the person
// pinned). Its `scheme`, signed in, where the account chose
// light or dark (theme.ts). Its `search`, the search the frame's
// navigation opens: a people typeahead (`typeahead`, a call its `params`
// are given `q` in), and the URLs, by its routes, of the results for a
@@ -25,7 +28,7 @@ import type { Call } from '../../shared/result';
import type { IconName, UiNode, UiTabsProps, UiTree } from '@hud/renderer';
import type { Frame } from './frame';
import type { AppHead } from './head';
import { pathOf, same, type Names, type Route } from './routes';
import { callOf, Names, pathOf, same, type Route } from './routes';
import type { Look, Scheme } from './theme';
export type Badge = { call: Call; count: string };
@@ -34,7 +37,14 @@ export type Search = { typeahead: Call; results: string; person: string };
export type Typeahead = { url: string; method: string; param: string; params?: Record<string, string | number | boolean>; items: string; did: string; handle: string; name?: string; avatar?: string; avatarFallback?: string };
/** The app's own sign-in screen: its heading, a line under it and one under the form (their links Markdown's `[label](href)`), the field's placeholder, making an account, and the typeahead. */
export type SignInPlan = { title: string; text?: string; placeholder?: string; legal?: string; create?: { text?: string; label: string }; typeahead?: Typeahead };
export type Tab = { label: string; icon: IconName; call: Call; guest?: Call | 'call'; wordmark?: string; path?: string; badge?: Badge };
/**
* Where a tab's root is chosen from the account's data, signed in: a query
* (`call`), the list in its answer (`at`, a path as `at` reads one), where
* in each of its items a path of the app's is (`path`, dotted), and the
* procedure after which it is read again (`after`).
*/
export type First = { call: Call; at: string; path: string; after?: string };
export type Tab = { label: string; icon: IconName; call: Call; guest?: Call | 'call'; wordmark?: string; path?: string; badge?: Badge; first?: First };
export type Page = { path: string; title: string; description?: string; markdown: string };
export type App = { domain: string; name: string; look?: Look; head: AppHead; scheme?: Scheme; search?: Search; signIn?: SignInPlan; tabs: Tab[]; routes: Route[]; pages?: Page[]; frame?: Frame };
@@ -65,6 +75,52 @@ export function tabCall(tab: Tab, signedIn: boolean): Call | null {
/** A tab's URL at its root. */
export const tabPath = (app: App, tab: Tab, names: Names) => tab.path ?? pathOf(tab.call, routesOf(app), names) ?? '/';
/** Whether a path (with its query string) is a tab's own URL, `own`: the same, or with a query a link added (`?utm_source=`) where the tab's has none. */
export const isTabPath = (own: string, pathname: string, search: string) => own === pathname + search || (!own.includes('?') && own === pathname);
/** The origin a listed path is read against: a path of the app's own, never another site's (`//host`, `/\host`). */
const OWN = 'https://app.invalid';
/**
* The root a tab's `first` chooses from what its query answered: the
* screen of the first item whose path has one, the tab's own URL its
* `call` (Grain's Recent, pinned as `/` by older apps), any other by the
* app's routes; null where none has (nothing listed, or nothing the app
* draws, as Grain's Groups is not).
*/
export async function chosenRoot(app: App, tab: Tab, answer: unknown, resolve: (actor: string) => Promise<string>): Promise<Call | null> {
const first = tab.first;
const items = first ? at(answer, first.at) : null;
if (!first || !Array.isArray(items)) return null;
const own = tabPath(app, tab, new Names());
for (const item of items) {
const path = at(item, first.path);
const url = typeof path === 'string' && path.startsWith('/') ? new URL(path, OWN) : null;
if (url?.origin !== OWN) continue;
if (isTabPath(own, url.pathname, url.search)) return tab.call;
const found = await callOf(url.pathname, url.search, routesOf(app), resolve);
if (found) return found.call;
}
return null;
}
/**
* Each tab's root: its call, signed in or not (`tabCall`); signed in, a
* tab with `first` the screen its query's answer chooses (`chosenRoot`),
* its call where the query fails (`ask` answers its data, or null) or
* chooses none. Made for each page, so a list the person reordered is
* what the next page's tab opens.
*/
export async function rootsOf(app: App, signedIn: boolean, ask: (call: Call) => Promise<unknown>, resolve: (actor: string) => Promise<string>): Promise<(Call | null)[]> {
return Promise.all(
app.tabs.map(async (tab) => {
const own = tabCall(tab, signedIn);
if (!signedIn || !tab.first) return own;
return (await chosenRoot(app, tab, await ask(tab.first.call), resolve)) ?? own;
})
);
}
/** A tree's first `Tabs` strip, depth first through its children; null where it has none. */
function stripOf(node: UiNode): UiTabsProps | null {
if (node.c === 'Tabs') return node.p as UiTabsProps;
@@ -78,26 +134,31 @@ function stripOf(node: UiNode): UiTabsProps | null {
/**
* The tab a screen is the root of, in its root's place: where the screen's
* tree has a `Tabs` strip that offers the screen itself (its item
* `selected`) and a tab's root call beside it, that tab (Grain's Following,
* or a pinned feed, a choice of Home's strip); else -1. Choosing a strip's
* tab draws its call in the root's place (Stack's `swap`), so a URL of one
* is drawn so too, by the server as by the browser: the tab's root level,
* its strip shown and no back.
* `selected`) and a tab's root call (`roots`, `rootsOf`'s) beside it, that
* tab (Grain's Following, or a pinned feed, a choice of Home's strip);
* else -1. Choosing a strip's tab draws its call in the root's place
* (Stack's `swap`), so a URL of one is drawn so too, by the server as by
* the browser: the tab's root level, its strip shown and no back.
*/
export function swappedTab(app: App, ui: UiTree, signedIn: boolean): number {
export function swappedTab(roots: (Call | null)[], ui: UiTree): number {
const items = stripOf(ui.root)?.items ?? [];
if (!items.some((item) => item.selected)) return -1;
const offered = items.flatMap((item) => (item.open && 'call' in item.open ? [item.open.call] : []));
return app.tabs.findIndex((t) => {
const own = tabCall(t, signedIn);
return own !== null && offered.some((call) => same(call, own));
});
return roots.findIndex((own) => own !== null && offered.some((call) => same(call, own)));
}
/** What is at a dotted path in an answer: in a query's `response`, else in the answer itself. */
/** What is at a dotted path in an answer: in a query's `response`, else in the answer itself; a key `@name` is the element of an array whose `$type` is `name` or ends `#name`. */
export function at(answer: unknown, path: string): unknown {
const data = answer as Record<string, unknown> | null;
let found: unknown = data && typeof data === 'object' && 'response' in data ? data.response : data;
for (const key of path.split('.')) found = typeof found === 'object' && found !== null ? (found as Record<string, unknown>)[key] : undefined;
for (const key of path.split('.')) {
if (key.startsWith('@') && Array.isArray(found)) {
const name = key.slice(1);
found = found.find((item) => {
const type = (item as { $type?: unknown } | null)?.$type;
return typeof type === 'string' && (type === name || type.endsWith(`#${name}`));
});
} else found = typeof found === 'object' && found !== null ? (found as Record<string, unknown>)[key] : undefined;
}
return found;
}
vendor/hud/web/shell/src/index.ts+1−1
@@ -10,7 +10,7 @@
export { default as Shell, type Here, type Host, type Navigation } from './Shell.svelte';
export { default as Head } from './Head.svelte';
export { at, measureOf, pageCall, routesOf, tabCall, tabPath, type App, type Badge, type Measure, type Page, type Search, type SignInPlan, type Tab, type Typeahead } from './app';
export { at, measureOf, pageCall, rootsOf, routesOf, tabCall, tabPath, type App, type Badge, type First, type Measure, type Page, type Search, type SignInPlan, type Tab, type Typeahead } from './app';
export { Client, SignInNeeded, toolRequest, toolResult, type Endpoints } from './client';
export { areasOf, frameCss, layoutOf, type AccountItem, type Frame, type Layout } from './frame';
export { headOf, headOfAnswer, headOfView, type AppHead, type Head as PageHead, type ScreenHead } from './head';
vendor/hud/web/shell/src/screen.ts+2−0
@@ -23,6 +23,8 @@ export type Screen = {
names: [string, string][];
/** No route has the URL's path: the page says so, over no tab. */
missing: boolean;
/** Each tab's root as the server chose it for the page (app.ts's `rootsOf`), so the browser's tabs open the same; none where the page draws no tab (not found, signing in). */
roots?: (Call | null)[];
/** How wide its root level is drawn where the screen is in a tab's root's place by that root's strip (`swappedTab`): the root's own measure, not the screen's. */
measure?: Measure;
/** The app's own sign-in screen, over no tab: where signing in comes back to (`back`), the handle typed, and why the last try did not sign in, if it did not. */
vendor/hud/web/shell/src/server.ts+27−30
vendor/hud/web/shell/src/session.ts+1−4
vendor/hud/web/shell/src/Shell.svelte+72−16
vendor/hud/web/shell/src/theme.ts+6−15
vendor/hud/COMMIT+1−1