cheogram-www

created pr with cheogram-www/new-chat2.1 on 2026-11-17T04:43:56Z · by 9e834e0d
commented on 2026-11-18T17:30:15Z · by 3c31bc8c
lgtm
cmds
checkout latest patchset:
ssh pr.pico.sh pull cheogram-www:new-chat2 | git am -3
checkout specific patchset revision:
ssh pr.pico.sh pull cheogram-www:new-chat2 [rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh cheogram-www:new-chat2
add comment to patch request:
ssh pr.pico.sh comment cheogram-www:new-chat2 "lgtm!"

Patchset cheogram-www/new-chat2.1 on 2026-11-17T04:43:56Z · commit c7eddd5

+0 -24 src/components/Chats.tsx #
......@@ -54,7 +54,6 @@ import {
5454 faPlus,
5555 faXmark,
5656 faComment,
57- faUserGroup,
5857 faMagnifyingGlassArrowRight,
5958 faThumbtack,
6059 } from "@fortawesome/free-solid-svg-icons";
......@@ -64,7 +63,6 @@ import { useHotkeys } from "react-hotkeys-hook";
6463 import { AvatarWithPlaceholder } from "./AvatarWithPlaceholder";
6564 import { AwaitOnce } from "./AwaitOnce";
6665 import { confirmDialog } from "./ConfirmDialog";
67-import { CreateChannelDialog } from "./CreateChannelDialog";
6866 import { NewChatDialog } from "./NewChatDialog";
6967 import { Profile } from "./Profile";
7068 import { SettingsContext } from "./Settings";
......@@ -199,7 +197,6 @@ export const Chats = () => {
199197 const [banMember, setBanMember] = useState<borogove.Member | null>(null);
200198
201199 const [popupMember, setPopupMember] = useState<borogove.Member | undefined>();
202- const [createChannelOpen, setCreateChannelOpen] = useState(false);
203200 const [newChatOpen, setNewChatOpen] = useState(false);
204201 const [scanQRCode, setScanQRCode] = useState(false);
205202 const [qrStatus, setQRStatus] = useState("Loading camera...");
......@@ -611,17 +608,6 @@ export const Chats = () => {
611608 </ListItemIcon>
612609 Scan QR Code
613610 </MenuItem>
614- <MenuItem
615- onClick={() => {
616- setCreateChannelOpen(true);
617- setAddContactAnchorEl(null);
618- }}
619- >
620- <ListItemIcon>
621- <FontAwesomeIcon icon={faUserGroup} />
622- </ListItemIcon>
623- New Private Channel
624- </MenuItem>
625611 </Menu>
626612 </ConversationHeader.Actions>
627613 </ConversationHeader>
......@@ -1244,16 +1230,6 @@ export const Chats = () => {
12441230 </Dialog>
12451231 )}
12461232
1247- <CreateChannelDialog
1248- open={createChannelOpen}
1249- client={client}
1250- onClose={() => setCreateChannelOpen(false)}
1251- onCreated={(channel) => {
1252- setCreateChannelOpen(false);
1253- navigateToChat(channel);
1254- }}
1255- />
1256-
12571233 <NewChatDialog
12581234 open={newChatOpen}
12591235 client={client}
+0 -73 src/components/CreateChannelDialog.test.tsx #
......@@ -1,73 +0,0 @@
1-// @vitest-environment jsdom
2-
3-import * as borogove from "borogove";
4-import {
5- cleanup,
6- fireEvent,
7- render,
8- screen,
9- waitFor,
10-} from "@testing-library/react";
11-import { afterEach, describe, expect, it, vi } from "vitest";
12-import { mock } from "vitest-mock-extended";
13-import { CreateChannelDialog } from "./CreateChannelDialog";
14-
15-afterEach(cleanup);
16-
17-const setup = () => {
18- const channel = mock<borogove.Channel>();
19- const createChannelInstant = vi
20- .fn<borogove.Client["createChannelInstant"]>()
21- .mockResolvedValue(channel);
22- const client = mock<borogove.Client>({ createChannelInstant });
23- const onClose = vi.fn();
24- const onCreated = vi.fn();
25- const view = render(
26- <CreateChannelDialog
27- open
28- client={client}
29- onClose={onClose}
30- onCreated={onCreated}
31- />,
32- );
33-
34- return { ...view, channel, createChannelInstant, onClose, onCreated };
35-};
36-
37-describe("CreateChannelDialog", () => {
38- it("creates a private channel with a trimmed, optional name", async () => {
39- const { createChannelInstant, onCreated, channel } = setup();
40-
41- fireEvent.change(screen.getByLabelText("Channel name"), {
42- target: { value: " Team Chat " },
43- });
44- fireEvent.click(screen.getByRole("button", { name: "Create Channel" }));
45-
46- await waitFor(() => expect(onCreated).toHaveBeenCalledWith(channel));
47- expect(createChannelInstant).toHaveBeenCalledWith("Team Chat");
48- });
49-
50- it("leaves the name unset when the field is blank", async () => {
51- const { createChannelInstant, onCreated, channel } = setup();
52-
53- fireEvent.click(screen.getByRole("button", { name: "Create Channel" }));
54-
55- await waitFor(() => expect(onCreated).toHaveBeenCalledWith(channel));
56- expect(createChannelInstant).toHaveBeenCalledWith(null);
57- });
58-
59- it("shows an error and keeps the dialog open when creation fails", async () => {
60- const { createChannelInstant, onClose, onCreated } = setup();
61- createChannelInstant.mockRejectedValue(
62- new Error("No default service on which to make a channel"),
63- );
64-
65- fireEvent.click(screen.getByRole("button", { name: "Create Channel" }));
66-
67- expect((await screen.findByRole("alert")).textContent).toContain(
68- "No default service on which to make a channel",
69- );
70- expect(onCreated).not.toHaveBeenCalled();
71- expect(onClose).not.toHaveBeenCalled();
72- });
73-});
+0 -86 src/components/CreateChannelDialog.tsx #
......@@ -1,86 +0,0 @@
1-import * as borogove from "borogove";
2-import { useState } from "react";
3-import {
4- Button,
5- Dialog,
6- DialogActions,
7- DialogContent,
8- DialogContentText,
9- DialogTitle,
10- TextField,
11-} from "@mui/material";
12-
13-export const CreateChannelDialog = ({
14- open,
15- client,
16- onClose,
17- onCreated,
18-}: {
19- open: boolean;
20- client: borogove.Client;
21- onClose: () => void;
22- onCreated: (channel: borogove.Channel) => void;
23-}) => {
24- const [name, setName] = useState("");
25- const [creating, setCreating] = useState(false);
26- const [error, setError] = useState<string | null>(null);
27-
28- const close = () => {
29- if (creating) return;
30- setName("");
31- setError(null);
32- onClose();
33- };
34-
35- const createChannel = async (event: React.FormEvent<HTMLFormElement>) => {
36- event.preventDefault();
37- if (creating) return;
38-
39- setCreating(true);
40- setError(null);
41-
42- try {
43- const channel = await client.createChannelInstant(name.trim() || null);
44- setName("");
45- onCreated(channel);
46- } catch (e) {
47- setError(e instanceof Error ? e.message : String(e));
48- }
49- setCreating(false);
50- };
51-
52- return (
53- <Dialog open={open} onClose={close} fullWidth maxWidth="sm">
54- <DialogTitle>New Private Channel</DialogTitle>
55- <form onSubmit={createChannel}>
56- <DialogContent>
57- <DialogContentText>Create an invite-only channel.</DialogContentText>
58- <TextField
59- autoFocus
60- fullWidth
61- margin="dense"
62- label="Channel name"
63- helperText="Optional. Leave blank to generate one automatically."
64- value={name}
65- onChange={(e) => setName(e.target.value)}
66- disabled={creating}
67- error={!!error}
68- />
69- {error && (
70- <DialogContentText role="alert" color="error">
71- {error}
72- </DialogContentText>
73- )}
74- </DialogContent>
75- <DialogActions>
76- <Button onClick={close} disabled={creating}>
77- Cancel
78- </Button>
79- <Button type="submit" variant="contained" disabled={creating}>
80- {creating ? "Creating..." : "Create Channel"}
81- </Button>
82- </DialogActions>
83- </form>
84- </Dialog>
85- );
86-};
+115 -16 src/components/NewChatDialog.test.tsx #
......@@ -51,12 +51,17 @@ const setup = (chats: borogove.AvailableChat[] = []) => {
5151 const startMultiChat = vi
5252 .fn<borogove.Client["startMultiChat"]>()
5353 .mockReturnValue(multiChat);
54+ const channel = mock<borogove.Channel>();
55+ const createChannelInstant = vi
56+ .fn<borogove.Client["createChannelInstant"]>()
57+ .mockResolvedValue(channel);
5458 const client = mock<borogove.Client>({
5559 accountId: () => "me@example.com",
5660 availableChatSources,
5761 findAvailableChats,
5862 startChat,
5963 startMultiChat,
64+ createChannelInstant,
6065 });
6166 const onClose = vi.fn();
6267 const onStarted = vi.fn();
......@@ -76,6 +81,8 @@ const setup = (chats: borogove.AvailableChat[] = []) => {
7681 findAvailableChats,
7782 startChat,
7883 startMultiChat,
84+ channel,
85+ createChannelInstant,
7986 onClose,
8087 onStarted,
8188 };
......@@ -123,37 +130,36 @@ describe("NewChatDialog", () => {
123130 expect(startMultiChat).toHaveBeenCalledWith([alice, bob]);
124131 });
125132
126- it("stops searching after a non-Cheogram selection when EXPERIMENTAL is not set", async () => {
133+ it("keeps searching for multiple non-Cheogram chats without EXPERIMENTAL", async () => {
127134 const alice = availableChat("alice@example.com", "Alice");
128135 const bob = availableChat("bob@example.com", "Bob");
129- const { startChat, startMultiChat, onStarted, chat } = setup([alice, bob]);
136+ setup([alice, bob]);
130137
131138 fireEvent.click(await search("example.com", "Alice"));
139+ fireEvent.click(screen.getByText("Bob"));
132140
133- expect(screen.queryByRole("textbox")).toBeNull();
134- expect(screen.queryByText("Bob")).toBeNull();
135-
136- fireEvent.click(screen.getByRole("button", { name: "Start Chat" }));
137-
138- await waitFor(() => expect(onStarted).toHaveBeenCalledWith(chat));
139- expect(startChat).toHaveBeenCalledWith(alice);
140- expect(startMultiChat).not.toHaveBeenCalled();
141+ expect(screen.getByRole("textbox")).toBeTruthy();
142+ expect(screen.queryByRole("button", { name: "Start Chat" })).toBeNull();
143+ const create = screen.getByRole("button", {
144+ name: "Create Private Channel",
145+ });
146+ expect(create.className).toContain("MuiButton-contained");
141147 });
142148
143149 it("goes back to searching after a non-combinable selection", async () => {
144150 const alice = availableChat("alice@example.com", "Alice");
145- const bob = availableChat("bob@example.com", "Bob");
146- const { startChat, onStarted, chat } = setup([alice, bob]);
151+ const room = availableChat("room@example.com", "Room", true);
152+ const { startChat, onStarted, chat } = setup([alice, room]);
147153
148- fireEvent.click(await search("example.com", "Alice"));
154+ fireEvent.click(await search("example.com", "Room"));
149155 fireEvent.click(screen.getByRole("button", { name: "Back to Search" }));
150156
151157 expect(screen.getByRole("textbox")).toBeTruthy();
152- fireEvent.click(screen.getByText("Bob"));
158+ fireEvent.click(screen.getByText("Alice"));
153159 fireEvent.click(screen.getByRole("button", { name: "Start Chat" }));
154160
155161 await waitFor(() => expect(onStarted).toHaveBeenCalledWith(chat));
156- expect(startChat).toHaveBeenCalledWith(bob);
162+ expect(startChat).toHaveBeenCalledWith(alice);
157163 });
158164
159165 it("does not offer the current account as a counterpart", async () => {
......@@ -188,7 +194,6 @@ describe("NewChatDialog", () => {
188194 });
189195
190196 it("filters results to chats compatible with a non-Cheogram selection", async () => {
191- localStorage.setItem("EXPERIMENTAL", "1");
192197 const sms = availableChat("15551234567@cheogram.com", "SMS");
193198 const alice = availableChat("alice@example.com", "Alice");
194199 setup([sms, alice]);
......@@ -255,6 +260,97 @@ describe("NewChatDialog", () => {
255260 );
256261 });
257262
263+ it("shows Start Chat disabled when nothing is selected", () => {
264+ setup();
265+
266+ const start = screen.getByRole("button", {
267+ name: "Start Chat",
268+ }) as HTMLButtonElement;
269+ expect(start.disabled).toBe(true);
270+ });
271+
272+ it("creates an empty private channel when nothing is selected", async () => {
273+ const { createChannelInstant, onStarted, channel } = setup();
274+
275+ fireEvent.click(
276+ screen.getByRole("button", { name: "Create Private Channel" }),
277+ );
278+ fireEvent.click(screen.getByRole("button", { name: "Create Channel" }));
279+
280+ await waitFor(() => expect(onStarted).toHaveBeenCalledWith(channel));
281+ expect(createChannelInstant).toHaveBeenCalledWith(null);
282+ });
283+
284+ it("creates a private channel with a trimmed, optional name", async () => {
285+ const { createChannelInstant, onStarted, channel } = setup();
286+
287+ fireEvent.click(
288+ screen.getByRole("button", { name: "Create Private Channel" }),
289+ );
290+ fireEvent.change(screen.getByLabelText("Channel name"), {
291+ target: { value: " Team Chat " },
292+ });
293+ fireEvent.click(screen.getByRole("button", { name: "Create Channel" }));
294+
295+ await waitFor(() => expect(onStarted).toHaveBeenCalledWith(channel));
296+ expect(createChannelInstant).toHaveBeenCalledWith("Team Chat");
297+ });
298+
299+ it("creates a private channel and invites the selected chats", async () => {
300+ const alice = availableChat("alice@example.com", "Alice");
301+ const bob = availableChat("bob@example.com", "Bob");
302+ const { createChannelInstant, startChat, channel, onStarted } = setup([
303+ alice,
304+ bob,
305+ ]);
306+
307+ fireEvent.click(await search("example.com", "Alice"));
308+ fireEvent.click(screen.getByText("Bob"));
309+
310+ expect(screen.queryByRole("button", { name: "Start Chat" })).toBeNull();
311+
312+ fireEvent.click(
313+ screen.getByRole("button", { name: "Create Private Channel" }),
314+ );
315+ fireEvent.click(screen.getByRole("button", { name: "Create Channel" }));
316+
317+ await waitFor(() => expect(onStarted).toHaveBeenCalledWith(channel));
318+ expect(createChannelInstant).toHaveBeenCalledWith(null);
319+ expect(startChat).toHaveBeenCalledWith(alice);
320+ expect(startChat).toHaveBeenCalledWith(bob);
321+ expect(channel.invite).toHaveBeenCalledTimes(2);
322+ });
323+
324+ it("does not offer a private channel with a Cheogram selection", async () => {
325+ const sms = availableChat("15551234567@cheogram.com", "SMS");
326+ const other = availableChat("15559876543@cheogram.com", "Phone");
327+ setup([sms, other]);
328+
329+ fireEvent.click(await search("a", "SMS"));
330+
331+ expect(
332+ screen.queryByRole("button", { name: "Create Private Channel" }),
333+ ).toBeNull();
334+ });
335+
336+ it("shows an error and keeps the dialog open when creating a channel fails", async () => {
337+ const { createChannelInstant, onClose, onStarted } = setup();
338+ createChannelInstant.mockRejectedValue(
339+ new Error("No default service on which to make a channel"),
340+ );
341+
342+ fireEvent.click(
343+ screen.getByRole("button", { name: "Create Private Channel" }),
344+ );
345+ fireEvent.click(screen.getByRole("button", { name: "Create Channel" }));
346+
347+ expect((await screen.findByRole("alert")).textContent).toContain(
348+ "No default service on which to make a channel",
349+ );
350+ expect(onStarted).not.toHaveBeenCalled();
351+ expect(onClose).not.toHaveBeenCalled();
352+ });
353+
258354 it("stops searching after selecting a channel", async () => {
259355 const alice = availableChat("alice@example.com", "Alice");
260356 const channel = availableChat("room@example.com", "Room", true);
......@@ -264,6 +360,9 @@ describe("NewChatDialog", () => {
264360
265361 expect(screen.queryByRole("textbox")).toBeNull();
266362 expect(screen.queryByText("Alice")).toBeNull();
363+ expect(
364+ screen.queryByRole("button", { name: "Create Private Channel" }),
365+ ).toBeNull();
267366
268367 fireEvent.click(screen.getByRole("button", { name: "Start Chat" }));
269368
+106 -25 src/components/NewChatDialog.tsx #
......@@ -27,8 +27,7 @@ const isCheogramChat = (availableChat: borogove.AvailableChat) =>
2727
2828 const canCombine = (a: borogove.AvailableChat, b: borogove.AvailableChat) => {
2929 if (a.isChannel() || b.isChannel()) return false;
30- if (isCheogramChat(a) !== isCheogramChat(b)) return false;
31- return isCheogramChat(a) || localStorage.getItem("EXPERIMENTAL") !== null;
30+ return isCheogramChat(a) === isCheogramChat(b);
3231 };
3332
3433 export const NewChatDialog = ({
......@@ -50,7 +49,9 @@ export const NewChatDialog = ({
5049 });
5150 const [completedQuery, setCompletedQuery] = useState<string | null>(null);
5251 const [selected, setSelected] = useState<borogove.AvailableChat[]>([]);
53- const [starting, setStarting] = useState(false);
52+ const [channelName, setChannelName] = useState("");
53+ const [creatingChannel, setCreatingChannel] = useState(false);
54+ const [starting, setStarting] = useState<"chat" | "channel" | null>(null);
5455 const [error, setError] = useState<string | null>(null);
5556 const [sources, setSources] = useState<string[]>([]);
5657
......@@ -102,7 +103,9 @@ export const NewChatDialog = ({
102103 setResults({ q: "", chats: [] });
103104 setCompletedQuery(null);
104105 setSelected([]);
105- setStarting(false);
106+ setChannelName("");
107+ setCreatingChannel(false);
108+ setStarting(null);
106109 setError(null);
107110 };
108111
......@@ -137,7 +140,10 @@ export const NewChatDialog = ({
137140 const canKeepSearching =
138141 selected.length === 0 || canJoinSelection(selected[0]);
139142
143+ const multiDMEnabled = localStorage.getItem("EXPERIMENTAL") !== null;
140144 const allCheogram = selected.length > 1 && selected.every(isCheogramChat);
145+ const showStartChat =
146+ !allCheogram && (selected.length <= 1 || multiDMEnabled);
141147 const groupTextTarget = allCheogram
142148 ? [
143149 ...new Set(
......@@ -156,8 +162,9 @@ export const NewChatDialog = ({
156162 const startChat = (event: React.FormEvent<HTMLFormElement>) => {
157163 event.preventDefault();
158164 if (starting || selected.length === 0) return;
165+ if (selected.length > 1 && !allCheogram && !multiDMEnabled) return;
159166
160- setStarting(true);
167+ setStarting("chat");
161168 setError(null);
162169
163170 try {
......@@ -172,7 +179,28 @@ export const NewChatDialog = ({
172179 } catch (e) {
173180 setError(e instanceof Error ? e.message : String(e));
174181 }
175- setStarting(false);
182+ setStarting(null);
183+ };
184+
185+ const createPrivateChannel = async () => {
186+ if (starting) return;
187+
188+ setStarting("channel");
189+ setError(null);
190+
191+ try {
192+ const channel = await client.createChannelInstant(
193+ channelName.trim() || null,
194+ );
195+ for (const availableChat of selected) {
196+ channel.invite(client.startChat(availableChat));
197+ }
198+ reset();
199+ onStarted(channel);
200+ } catch (e) {
201+ setError(e instanceof Error ? e.message : String(e));
202+ }
203+ setStarting(null);
176204 };
177205
178206 const currentQuery = query.trim();
......@@ -184,10 +212,29 @@ export const NewChatDialog = ({
184212
185213 return (
186214 <Dialog open={open} onClose={close} fullWidth maxWidth="sm">
187- <DialogTitle>New Chat</DialogTitle>
215+ <DialogTitle>
216+ {creatingChannel ? "New Private Channel" : "New Chat"}
217+ </DialogTitle>
188218 <form onSubmit={startChat}>
189219 <DialogContent>
190- {!canKeepSearching ? (
220+ {creatingChannel ? (
221+ <>
222+ <DialogContentText>
223+ Create an invite-only channel.
224+ </DialogContentText>
225+ <TextField
226+ autoFocus
227+ fullWidth
228+ margin="dense"
229+ label="Channel name"
230+ helperText="Optional. Leave blank to generate one automatically."
231+ value={channelName}
232+ onChange={(e) => setChannelName(e.target.value)}
233+ disabled={starting !== null}
234+ error={!!error}
235+ />
236+ </>
237+ ) : !canKeepSearching ? (
191238 <>
192239 <DialogContentText sx={{ mt: 1 }}>
193240 Starting a chat with:
......@@ -197,7 +244,7 @@ export const NewChatDialog = ({
197244 <ListItemButton
198245 key={availableChat.chatId}
199246 selected
200- disabled={starting}
247+ disabled={starting !== null}
201248 >
202249 <ListItemText
203250 primary={
......@@ -208,7 +255,10 @@ export const NewChatDialog = ({
208255 </ListItemButton>
209256 ))}
210257 </List>
211- <Button onClick={() => setSelected([])} disabled={starting}>
258+ <Button
259+ onClick={() => setSelected([])}
260+ disabled={starting !== null}
261+ >
212262 Back to Search
213263 </Button>
214264 </>
......@@ -225,7 +275,7 @@ export const NewChatDialog = ({
225275 setCompletedQuery(null);
226276 setError(null);
227277 }}
228- disabled={starting}
278+ disabled={starting !== null}
229279 error={!!error}
230280 slotProps={{
231281 input: {
......@@ -251,7 +301,7 @@ export const NewChatDialog = ({
251301 key={availableChat.chatId}
252302 label={availableChat.displayName || availableChat.chatId}
253303 onDelete={() => toggleSelected(availableChat)}
254- disabled={starting}
304+ disabled={starting !== null}
255305 />
256306 ))}
257307 </Stack>
......@@ -264,7 +314,7 @@ export const NewChatDialog = ({
264314 key={availableChat.chatId}
265315 selected={isSelected(availableChat)}
266316 onClick={() => toggleSelected(availableChat)}
267- disabled={starting}
317+ disabled={starting !== null}
268318 >
269319 <ListItemText
270320 primary={
......@@ -292,20 +342,51 @@ export const NewChatDialog = ({
292342 )}
293343 </DialogContent>
294344 <DialogActions>
295- <Button onClick={close} disabled={starting}>
345+ <Button onClick={close} disabled={starting !== null}>
296346 Cancel
297347 </Button>
298- <Button
299- type="submit"
300- variant="contained"
301- disabled={starting || selected.length === 0}
302- >
303- {starting
304- ? "Starting..."
305- : allCheogram
306- ? "Start Group Text"
307- : "Start Chat"}
308- </Button>
348+ {creatingChannel ? (
349+ <Button
350+ type="button"
351+ variant="contained"
352+ onClick={createPrivateChannel}
353+ disabled={starting !== null}
354+ >
355+ {starting === "channel" ? "Creating..." : "Create Channel"}
356+ </Button>
357+ ) : (
358+ <>
359+ {!selected.some(
360+ (availableChat) =>
361+ isCheogramChat(availableChat) || availableChat.isChannel(),
362+ ) && (
363+ <Button
364+ type="button"
365+ variant={showStartChat ? "text" : "contained"}
366+ onClick={() => {
367+ setCreatingChannel(true);
368+ setError(null);
369+ }}
370+ disabled={starting !== null}
371+ >
372+ Create Private Channel
373+ </Button>
374+ )}
375+ {(showStartChat || allCheogram) && (
376+ <Button
377+ type="submit"
378+ variant="contained"
379+ disabled={starting !== null || selected.length === 0}
380+ >
381+ {starting === "chat"
382+ ? "Starting..."
383+ : allCheogram
384+ ? "Start Group Text"
385+ : "Start Chat"}
386+ </Button>
387+ )}
388+ </>
389+ )}
309390 </DialogActions>
310391 </form>
311392 </Dialog>
Back to top