cheogram-www
created pr with
cheogram-www/new-chat2.1
commented
lgtm
cmds
checkout latest patchset:
ssh pr.pico.sh pull cheogram-www:new-chat2 | git am -3checkout specific patchset revision:
ssh pr.pico.sh pull cheogram-www:new-chat2 [rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh cheogram-www:new-chat2add comment to patch request:
ssh pr.pico.sh comment cheogram-www:new-chat2 "lgtm!"
Patchset
cheogram-www/new-chat2.1
Merge private channel creation into new chat dialog
Stephen Paul Weber
2026-11-17T03:22:52ZDiff stat
5 files changed, 221 insertions(+), 224 deletions(-)
Semantic diff summary
0 added,
1 modified,
0 signature changed,
0 removed
across 5 analyzed files
+0
-24
src/components/Chats.tsx
#
| ... | ... | @@ -64,7 +63,6 @@ import { useHotkeys } from "react-hotkeys-hook"; | |
| 64 | 63 | import { AvatarWithPlaceholder } from "./AvatarWithPlaceholder"; | |
| 65 | 64 | import { AwaitOnce } from "./AwaitOnce"; | |
| 66 | 65 | import { confirmDialog } from "./ConfirmDialog"; | |
| 67 | - | import { CreateChannelDialog } from "./CreateChannelDialog"; | |
| 68 | 66 | import { NewChatDialog } from "./NewChatDialog"; | |
| 69 | 67 | import { Profile } from "./Profile"; | |
| 70 | 68 | import { SettingsContext } from "./Settings"; |
| ... | ... | @@ -199,7 +197,6 @@ export const Chats = () => { | |
| 199 | 197 | const [banMember, setBanMember] = useState<borogove.Member | null>(null); | |
| 200 | 198 | ||
| 201 | 199 | const [popupMember, setPopupMember] = useState<borogove.Member | undefined>(); | |
| 202 | - | const [createChannelOpen, setCreateChannelOpen] = useState(false); | |
| 203 | 200 | const [newChatOpen, setNewChatOpen] = useState(false); | |
| 204 | 201 | const [scanQRCode, setScanQRCode] = useState(false); | |
| 205 | 202 | const [qrStatus, setQRStatus] = useState("Loading camera..."); |
| ... | ... | @@ -611,17 +608,6 @@ export const Chats = () => { | |
| 611 | 608 | </ListItemIcon> | |
| 612 | 609 | Scan QR Code | |
| 613 | 610 | </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> | |
| 625 | 611 | </Menu> | |
| 626 | 612 | </ConversationHeader.Actions> | |
| 627 | 613 | </ConversationHeader> |
| ... | ... | @@ -1244,16 +1230,6 @@ export const Chats = () => { | |
| 1244 | 1230 | </Dialog> | |
| 1245 | 1231 | )} | |
| 1246 | 1232 | ||
| 1247 | - | <CreateChannelDialog | |
| 1248 | - | open={createChannelOpen} | |
| 1249 | - | client={client} | |
| 1250 | - | onClose={() => setCreateChannelOpen(false)} | |
| 1251 | - | onCreated={(channel) => { | |
| 1252 | - | setCreateChannelOpen(false); | |
| 1253 | - | navigateToChat(channel); | |
| 1254 | - | }} | |
| 1255 | - | /> | |
| 1256 | - | ||
| 1257 | 1233 | <NewChatDialog | |
| 1258 | 1234 | open={newChatOpen} | |
| 1259 | 1235 | 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[] = []) => { | |
| 51 | 51 | const startMultiChat = vi | |
| 52 | 52 | .fn<borogove.Client["startMultiChat"]>() | |
| 53 | 53 | .mockReturnValue(multiChat); | |
| 54 | + | const channel = mock<borogove.Channel>(); | |
| 55 | + | const createChannelInstant = vi | |
| 56 | + | .fn<borogove.Client["createChannelInstant"]>() | |
| 57 | + | .mockResolvedValue(channel); | |
| 54 | 58 | const client = mock<borogove.Client>({ | |
| 55 | 59 | accountId: () => "me@example.com", | |
| 56 | 60 | availableChatSources, | |
| 57 | 61 | findAvailableChats, | |
| 58 | 62 | startChat, | |
| 59 | 63 | startMultiChat, | |
| 64 | + | createChannelInstant, | |
| 60 | 65 | }); | |
| 61 | 66 | const onClose = vi.fn(); | |
| 62 | 67 | const onStarted = vi.fn(); |
| ... | ... | @@ -123,37 +130,36 @@ describe("NewChatDialog", () => { | |
| 123 | 130 | expect(startMultiChat).toHaveBeenCalledWith([alice, bob]); | |
| 124 | 131 | }); | |
| 125 | 132 | ||
| 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 () => { | |
| 127 | 134 | const alice = availableChat("alice@example.com", "Alice"); | |
| 128 | 135 | const bob = availableChat("bob@example.com", "Bob"); | |
| 129 | - | const { startChat, startMultiChat, onStarted, chat } = setup([alice, bob]); | |
| 136 | + | setup([alice, bob]); | |
| 130 | 137 | ||
| 131 | 138 | fireEvent.click(await search("example.com", "Alice")); | |
| 139 | + | fireEvent.click(screen.getByText("Bob")); | |
| 132 | 140 | ||
| 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"); | |
| 141 | 147 | }); | |
| 142 | 148 | ||
| 143 | 149 | it("goes back to searching after a non-combinable selection", async () => { | |
| 144 | 150 | 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]); | |
| 147 | 153 | ||
| 148 | - | fireEvent.click(await search("example.com", "Alice")); | |
| 154 | + | fireEvent.click(await search("example.com", "Room")); | |
| 149 | 155 | fireEvent.click(screen.getByRole("button", { name: "Back to Search" })); | |
| 150 | 156 | ||
| 151 | 157 | expect(screen.getByRole("textbox")).toBeTruthy(); | |
| 152 | - | fireEvent.click(screen.getByText("Bob")); | |
| 158 | + | fireEvent.click(screen.getByText("Alice")); | |
| 153 | 159 | fireEvent.click(screen.getByRole("button", { name: "Start Chat" })); | |
| 154 | 160 | ||
| 155 | 161 | await waitFor(() => expect(onStarted).toHaveBeenCalledWith(chat)); | |
| 156 | - | expect(startChat).toHaveBeenCalledWith(bob); | |
| 162 | + | expect(startChat).toHaveBeenCalledWith(alice); | |
| 157 | 163 | }); | |
| 158 | 164 | ||
| 159 | 165 | it("does not offer the current account as a counterpart", async () => { |
| ... | ... | @@ -188,7 +194,6 @@ describe("NewChatDialog", () => { | |
| 188 | 194 | }); | |
| 189 | 195 | ||
| 190 | 196 | it("filters results to chats compatible with a non-Cheogram selection", async () => { | |
| 191 | - | localStorage.setItem("EXPERIMENTAL", "1"); | |
| 192 | 197 | const sms = availableChat("15551234567@cheogram.com", "SMS"); | |
| 193 | 198 | const alice = availableChat("alice@example.com", "Alice"); | |
| 194 | 199 | setup([sms, alice]); |
| ... | ... | @@ -255,6 +260,97 @@ describe("NewChatDialog", () => { | |
| 255 | 260 | ); | |
| 256 | 261 | }); | |
| 257 | 262 | ||
| 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 | + | ||
| 258 | 354 | it("stops searching after selecting a channel", async () => { | |
| 259 | 355 | const alice = availableChat("alice@example.com", "Alice"); | |
| 260 | 356 | const channel = availableChat("room@example.com", "Room", true); |
| ... | ... | @@ -264,6 +360,9 @@ describe("NewChatDialog", () => { | |
| 264 | 360 | ||
| 265 | 361 | expect(screen.queryByRole("textbox")).toBeNull(); | |
| 266 | 362 | expect(screen.queryByText("Alice")).toBeNull(); | |
| 363 | + | expect( | |
| 364 | + | screen.queryByRole("button", { name: "Create Private Channel" }), | |
| 365 | + | ).toBeNull(); | |
| 267 | 366 | ||
| 268 | 367 | fireEvent.click(screen.getByRole("button", { name: "Start Chat" })); | |
| 269 | 368 |
+106
-25
src/components/NewChatDialog.tsx
#
| ... | ... | @@ -27,8 +27,7 @@ const isCheogramChat = (availableChat: borogove.AvailableChat) => | |
| 27 | 27 | ||
| 28 | 28 | const canCombine = (a: borogove.AvailableChat, b: borogove.AvailableChat) => { | |
| 29 | 29 | 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); | |
| 32 | 31 | }; | |
| 33 | 32 | ||
| 34 | 33 | export const NewChatDialog = ({ |
| ... | ... | @@ -50,7 +49,9 @@ export const NewChatDialog = ({ | |
| 50 | 49 | }); | |
| 51 | 50 | const [completedQuery, setCompletedQuery] = useState<string | null>(null); | |
| 52 | 51 | 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); | |
| 54 | 55 | const [error, setError] = useState<string | null>(null); | |
| 55 | 56 | const [sources, setSources] = useState<string[]>([]); | |
| 56 | 57 |
| ... | ... | @@ -102,7 +103,9 @@ export const NewChatDialog = ({ | |
| 102 | 103 | setResults({ q: "", chats: [] }); | |
| 103 | 104 | setCompletedQuery(null); | |
| 104 | 105 | setSelected([]); | |
| 105 | - | setStarting(false); | |
| 106 | + | setChannelName(""); | |
| 107 | + | setCreatingChannel(false); | |
| 108 | + | setStarting(null); | |
| 106 | 109 | setError(null); | |
| 107 | 110 | }; | |
| 108 | 111 |
| ... | ... | @@ -137,7 +140,10 @@ export const NewChatDialog = ({ | |
| 137 | 140 | const canKeepSearching = | |
| 138 | 141 | selected.length === 0 || canJoinSelection(selected[0]); | |
| 139 | 142 | ||
| 143 | + | const multiDMEnabled = localStorage.getItem("EXPERIMENTAL") !== null; | |
| 140 | 144 | const allCheogram = selected.length > 1 && selected.every(isCheogramChat); | |
| 145 | + | const showStartChat = | |
| 146 | + | !allCheogram && (selected.length <= 1 || multiDMEnabled); | |
| 141 | 147 | const groupTextTarget = allCheogram | |
| 142 | 148 | ? [ | |
| 143 | 149 | ...new Set( |
| ... | ... | @@ -156,8 +162,9 @@ export const NewChatDialog = ({ | |
| 156 | 162 | const startChat = (event: React.FormEvent<HTMLFormElement>) => { | |
| 157 | 163 | event.preventDefault(); | |
| 158 | 164 | if (starting || selected.length === 0) return; | |
| 165 | + | if (selected.length > 1 && !allCheogram && !multiDMEnabled) return; | |
| 159 | 166 | ||
| 160 | - | setStarting(true); | |
| 167 | + | setStarting("chat"); | |
| 161 | 168 | setError(null); | |
| 162 | 169 | ||
| 163 | 170 | try { |
| ... | ... | @@ -172,7 +179,28 @@ export const NewChatDialog = ({ | |
| 172 | 179 | } catch (e) { | |
| 173 | 180 | setError(e instanceof Error ? e.message : String(e)); | |
| 174 | 181 | } | |
| 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); | |
| 176 | 204 | }; | |
| 177 | 205 | ||
| 178 | 206 | const currentQuery = query.trim(); |
| ... | ... | @@ -184,10 +212,29 @@ export const NewChatDialog = ({ | |
| 184 | 212 | ||
| 185 | 213 | return ( | |
| 186 | 214 | <Dialog open={open} onClose={close} fullWidth maxWidth="sm"> | |
| 187 | - | <DialogTitle>New Chat</DialogTitle> | |
| 215 | + | <DialogTitle> | |
| 216 | + | {creatingChannel ? "New Private Channel" : "New Chat"} | |
| 217 | + | </DialogTitle> | |
| 188 | 218 | <form onSubmit={startChat}> | |
| 189 | 219 | <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 ? ( | |
| 191 | 238 | <> | |
| 192 | 239 | <DialogContentText sx={{ mt: 1 }}> | |
| 193 | 240 | Starting a chat with: |
| ... | ... | @@ -208,7 +255,10 @@ export const NewChatDialog = ({ | |
| 208 | 255 | </ListItemButton> | |
| 209 | 256 | ))} | |
| 210 | 257 | </List> | |
| 211 | - | <Button onClick={() => setSelected([])} disabled={starting}> | |
| 258 | + | <Button | |
| 259 | + | onClick={() => setSelected([])} | |
| 260 | + | disabled={starting !== null} | |
| 261 | + | > | |
| 212 | 262 | Back to Search | |
| 213 | 263 | </Button> | |
| 214 | 264 | </> |
| ... | ... | @@ -251,7 +301,7 @@ export const NewChatDialog = ({ | |
| 251 | 301 | key={availableChat.chatId} | |
| 252 | 302 | label={availableChat.displayName || availableChat.chatId} | |
| 253 | 303 | onDelete={() => toggleSelected(availableChat)} | |
| 254 | - | disabled={starting} | |
| 304 | + | disabled={starting !== null} | |
| 255 | 305 | /> | |
| 256 | 306 | ))} | |
| 257 | 307 | </Stack> |
| ... | ... | @@ -292,20 +342,51 @@ export const NewChatDialog = ({ | |
| 292 | 342 | )} | |
| 293 | 343 | </DialogContent> | |
| 294 | 344 | <DialogActions> | |
| 295 | - | <Button onClick={close} disabled={starting}> | |
| 345 | + | <Button onClick={close} disabled={starting !== null}> | |
| 296 | 346 | Cancel | |
| 297 | 347 | </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 | + | )} | |
| 309 | 390 | </DialogActions> | |
| 310 | 391 | </form> | |
| 311 | 392 | </Dialog> |