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
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8467,6 +8467,7 @@
"mobile.select.hint": "Touch and hold to select, then drag the handles",
"mobile.select.copyAll": "Copy all",
"mobile.message.share": "Share",
"mobile.shortcut.handoffFailed": "Couldn't carry that action to the other place. Open the place first, then try again.",
"mobile.link.open": "Open link",
"mobile.link.copy": "Copy link",
"mobile.link.share": "Share link",
Expand Down
42 changes: 41 additions & 1 deletion src/mobile/shortcuts.dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { initialState, type AppState, type Bot } from "@/state/store";
import type { MobileConnectionRecord } from "../../shared/mobile-link";
import type { MobilePlatform } from "./platform";
import { getDraft } from "@/lib/drafts";
import { installSystemDialogs } from "@/lib/system-dialog";
import { useOfferedComposerFiles } from "@/lib/composer-offers";
import { shareBot, shortcutAction, useShortcuts, type ShortcutAction, type ShortcutsBridge } from "./shortcuts";

Expand All @@ -23,7 +24,7 @@ beforeEach(() => {
setBots = vi.fn<ShortcutsBridge["setBots"]>(); forget = vi.fn<ShortcutsBridge["forget"]>();
bridge = { setBots, forget, onAction: (listener) => { fire = listener; return () => {}; } };
});
afterEach(() => { act(() => root.unmount()); });
afterEach(() => { act(() => root.unmount()); installSystemDialogs(null); });

function mount(state: Partial<AppState>, connections = linked) {
const dispatch = vi.fn(), switchTo = vi.fn(async () => {}), openChat = vi.fn();
Expand Down Expand Up @@ -117,6 +118,45 @@ describe("a share from another app", () => {
expect(app.switchTo).toHaveBeenCalledWith("cloud");
expect(app.openChat).not.toHaveBeenCalled();
});

it("keeps this place open and explains when an image-only share cannot be retained", () => {
const alert = vi.fn(async () => "confirm" as const);
installSystemDialogs({ alert, form: vi.fn() });
const app = mount({});
vi.stubGlobal("sessionStorage", {
getItem: () => null,
setItem: () => { throw new DOMException("Quota exceeded", "QuotaExceededError"); },
removeItem: () => {},
});
try {
act(() => fire({ kind: "share", place: "env-cloud", botId: "nova", text: "", images: [PIXEL] }));
expect(app.switchTo).not.toHaveBeenCalled();
expect(app.dispatch).toHaveBeenCalledWith({ type: "error", message: "Couldn't carry that action to the other place. Open the place first, then try again." });
expect(alert).toHaveBeenCalledWith({ title: "Couldn't carry that action to the other place. Open the place first, then try again.", confirmLabel: "OK", singleAction: true, tone: "neutral" });
} finally {
vi.unstubAllGlobals();
}
});

it("does not carry only the text when a shared image exceeds storage", () => {
const app = mount({});
const saved: string[] = [];
vi.stubGlobal("sessionStorage", {
getItem: () => null,
setItem: (_key: string, value: string) => {
if (JSON.parse(value).images.length) throw new DOMException("Quota exceeded", "QuotaExceededError");
saved.push(value);
},
removeItem: () => {},
});
try {
act(() => fire({ kind: "share", place: "env-cloud", botId: "nova", text: "See this", images: [PIXEL] }));
expect(app.switchTo).not.toHaveBeenCalled();
expect(saved).toEqual([]);
} finally {
vi.unstubAllGlobals();
}
});
});

describe("an asked call", () => {
Expand Down
21 changes: 16 additions & 5 deletions src/mobile/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { askForCall } from "@/lib/call";
import { offerComposerFiles } from "@/lib/composer-offers";
import { appendComposerDraft } from "@/lib/drafts";
import { t } from "@/lib/i18n";
import { systemDialogs } from "@/lib/system-dialog";
import type { Action, AppState } from "@/state/store";
import type { MobileConnectionRecord } from "../../shared/mobile-link";
import type { MobilePlatform } from "./platform";
Expand Down Expand Up @@ -126,7 +128,14 @@ export function useShortcuts({ platform, state, dispatch, place, connections, lo
}
if (action.place !== here) {
const elsewhere = action === held ? undefined : linked.find((one) => one.environmentId === action.place);
if (elsewhere) { hold(action); void switchTo(elsewhere.id); }
if (elsewhere) {
if (hold(action)) void switchTo(elsewhere.id);
else {
const message = t("mobile.shortcut.handoffFailed");
dispatch({ type: "error", message });
void systemDialogs()?.alert({ title: message, confirmLabel: t("common.ok"), singleAction: true, tone: "neutral" });
}
}
return;
}
const bot = now.bots.find((one) => one.id === action.botId) ?? (action.kind === "share" ? shareBot(now.bots) : undefined);
Expand All @@ -149,10 +158,12 @@ export function useShortcuts({ platform, state, dispatch, place, connections, lo
}

/** a run kept across the reload that switches places; one that still finds no place after it is dropped */
function hold(action: ShortcutAction) {
try { sessionStorage.setItem(HELD_KEY, JSON.stringify(action)); } catch {
// pictures past the storage quota: the words still go
if (action.kind === "share" && action.text) try { sessionStorage.setItem(HELD_KEY, JSON.stringify({ ...action, images: [] })); } catch { /* storage unavailable */ }
function hold(action: ShortcutAction): boolean {
try {
sessionStorage.setItem(HELD_KEY, JSON.stringify(action));
return true;
} catch {
return false;
}
}

Expand Down
Loading