diff --git a/src/components/common/messaging/MessageBox.tsx b/src/components/common/messaging/MessageBox.tsx index d97be03a..cdae5341 100644 --- a/src/components/common/messaging/MessageBox.tsx +++ b/src/components/common/messaging/MessageBox.tsx @@ -31,15 +31,14 @@ import { import { useApplicationState } from "../../../mobx/State"; import { Reply } from "../../../mobx/stores/MessageQueue"; +import { emojiDictionary } from "../../../assets/emojis"; +import { useClient } from "../../../controllers/client/ClientController"; +import { takeError } from "../../../controllers/client/jsx/error"; import { FileUploader, grabFiles, uploadFile, -} from "../../../context/revoltjs/FileUploads"; -import { takeError } from "../../../context/revoltjs/util"; - -import { emojiDictionary } from "../../../assets/emojis"; -import { useClient } from "../../../controllers/client/ClientController"; +} from "../../../controllers/client/jsx/legacy/FileUploads"; import { modalController } from "../../../controllers/modals/ModalController"; import AutoComplete, { useAutoComplete } from "../AutoComplete"; import Emoji from "../Emoji"; diff --git a/src/components/common/messaging/embed/EmbedInvite.tsx b/src/components/common/messaging/embed/EmbedInvite.tsx index 63700c8c..0cc1aa46 100644 --- a/src/components/common/messaging/embed/EmbedInvite.tsx +++ b/src/components/common/messaging/embed/EmbedInvite.tsx @@ -11,13 +11,13 @@ import { Button, Category, Preloader } from "@revoltchat/ui"; import { isTouchscreenDevice } from "../../../../lib/isTouchscreenDevice"; import { I18nError } from "../../../../context/Locale"; -import { takeError } from "../../../../context/revoltjs/util"; import ServerIcon from "../../../../components/common/ServerIcon"; import { useClient, useSession, } from "../../../../controllers/client/ClientController"; +import { takeError } from "../../../../controllers/client/jsx/error"; const EmbedInviteBase = styled.div` width: 400px; diff --git a/src/components/settings/account/MultiFactorAuthentication.tsx b/src/components/settings/account/MultiFactorAuthentication.tsx index 5d794bf8..a65ef824 100644 --- a/src/components/settings/account/MultiFactorAuthentication.tsx +++ b/src/components/settings/account/MultiFactorAuthentication.tsx @@ -7,9 +7,8 @@ import { useCallback, useEffect, useState } from "preact/hooks"; import { Category, CategoryButton, Error, Tip } from "@revoltchat/ui"; -import { takeError } from "../../../context/revoltjs/util"; - import { useSession } from "../../../controllers/client/ClientController"; +import { takeError } from "../../../controllers/client/jsx/error"; import { modalController } from "../../../controllers/modals/ModalController"; /** diff --git a/src/context/DO_NOT_TOUCH.md b/src/context/DO_NOT_TOUCH.md deleted file mode 100644 index db75657b..00000000 --- a/src/context/DO_NOT_TOUCH.md +++ /dev/null @@ -1,2 +0,0 @@ -hello do not touch `intermediate` or `revoltjs` folders -they are being rewritten diff --git a/src/context/revoltjs/events.ts b/src/context/revoltjs/events.ts deleted file mode 100644 index 8232036f..00000000 --- a/src/context/revoltjs/events.ts +++ /dev/null @@ -1,80 +0,0 @@ -export const _ = ""; - -/*export function registerEvents( - state: State, - setStatus: StateUpdater, - client: Client, -) { - if (!client) return; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - let listeners: Record void> = { - connecting: () => setStatus(ClientStatus.CONNECTING), - dropped: () => setStatus(ClientStatus.DISCONNECTED), - - ready: () => { - resetMemberSidebarFetched(); - setStatus(ClientStatus.ONLINE); - }, - - logout: () => { - state.auth.logout(); - state.reset(); - setStatus(ClientStatus.READY); - }, - - "channel/delete": (channel_id: string) => { - deleteRenderer(channel_id); - }, - - "server/delete": (_, server: Server) => { - if (server) { - for (const channel_id of server.channel_ids) { - deleteRenderer(channel_id); - } - } - }, - }; - - if (import.meta.env.DEV) { - listeners = new Proxy(listeners, { - get: - (target, listener) => - (...args: unknown[]) => { - console.debug(`Calling ${listener.toString()} with`, args); - Reflect.get(target, listener)(...args); - }, - }); - } - - // TODO: clean this a bit and properly handle types - for (const listener in listeners) { - client.addListener(listener, listeners[listener]); - } - - const online = () => { - setStatus(ClientStatus.RECONNECTING); - client.options.autoReconnect = false; - client.websocket.connect(); - }; - - const offline = () => { - client.options.autoReconnect = false; - client.websocket.disconnect(); - }; - - window.addEventListener("online", online); - window.addEventListener("offline", offline); - - return () => { - for (const listener in listeners) { - client.removeListener( - listener, - listeners[listener as keyof typeof listeners], - ); - } - - window.removeEventListener("online", online); - window.removeEventListener("offline", offline); - }; -}*/ diff --git a/src/controllers/client/jsx/ChannelName.tsx b/src/controllers/client/jsx/ChannelName.tsx new file mode 100644 index 00000000..d695eeac --- /dev/null +++ b/src/controllers/client/jsx/ChannelName.tsx @@ -0,0 +1,34 @@ +// ! This should be moved into @revoltchat/ui +import { Channel } from "revolt.js"; + +import { Text } from "preact-i18n"; + +interface Props { + channel?: Channel; + prefix?: boolean; +} + +/** + * Channel display name + */ +export function ChannelName({ channel, prefix }: Props) { + if (!channel) return <>; + + if (channel.channel_type === "SavedMessages") + return ; + + if (channel.channel_type === "DirectMessage") { + return ( + <> + {prefix && "@"} + {channel.recipient!.username} + + ); + } + + if (channel.channel_type === "TextChannel" && prefix) { + return <>{`#${channel.name}`}; + } + + return <>{channel.name}; +} diff --git a/src/context/revoltjs/CheckAuth.tsx b/src/controllers/client/jsx/CheckAuth.tsx similarity index 93% rename from src/context/revoltjs/CheckAuth.tsx rename to src/controllers/client/jsx/CheckAuth.tsx index eec8e8e5..546801a3 100644 --- a/src/context/revoltjs/CheckAuth.tsx +++ b/src/controllers/client/jsx/CheckAuth.tsx @@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom"; import { Preloader } from "@revoltchat/ui"; -import { clientController } from "../../controllers/client/ClientController"; +import { clientController } from "../ClientController"; interface Props { auth?: boolean; diff --git a/src/context/revoltjs/util.tsx b/src/controllers/client/jsx/error.tsx similarity index 55% rename from src/context/revoltjs/util.tsx rename to src/controllers/client/jsx/error.tsx index 2523ba0c..c171c55a 100644 --- a/src/context/revoltjs/util.tsx +++ b/src/controllers/client/jsx/error.tsx @@ -1,7 +1,3 @@ -import { Channel } from "revolt.js"; - -import { Text } from "preact-i18n"; - // eslint-disable-next-line @typescript-eslint/no-explicit-any export function takeError(error: any): string { if (error.response) { @@ -31,26 +27,3 @@ export function takeError(error: any): string { export function mapError(error: any): never { throw takeError(error); } - -export function getChannelName( - channel: Channel, - prefixType?: boolean, -): Children { - if (channel.channel_type === "SavedMessages") - return ; - - if (channel.channel_type === "DirectMessage") { - return ( - <> - {prefixType && "@"} - {channel.recipient!.username} - - ); - } - - if (channel.channel_type === "TextChannel" && prefixType) { - return <>#{channel.name}; - } - - return <>{channel.name}; -} diff --git a/src/context/revoltjs/FileUploads.module.scss b/src/controllers/client/jsx/legacy/FileUploads.module.scss similarity index 100% rename from src/context/revoltjs/FileUploads.module.scss rename to src/controllers/client/jsx/legacy/FileUploads.module.scss diff --git a/src/context/revoltjs/FileUploads.tsx b/src/controllers/client/jsx/legacy/FileUploads.tsx similarity index 97% rename from src/context/revoltjs/FileUploads.tsx rename to src/controllers/client/jsx/legacy/FileUploads.tsx index f0887c90..f6597af0 100644 --- a/src/context/revoltjs/FileUploads.tsx +++ b/src/controllers/client/jsx/legacy/FileUploads.tsx @@ -9,11 +9,11 @@ import { useEffect, useState } from "preact/hooks"; import { IconButton, Preloader } from "@revoltchat/ui"; -import { determineFileSize } from "../../lib/fileSize"; +import { determineFileSize } from "../../../../lib/fileSize"; -import { useClient } from "../../controllers/client/ClientController"; -import { modalController } from "../../controllers/modals/ModalController"; -import { takeError } from "./util"; +import { modalController } from "../../../modals/ModalController"; +import { useClient } from "../../ClientController"; +import { takeError } from "../error"; type BehaviourType = | { behaviour: "ask"; onChange: (file: File) => void } diff --git a/src/controllers/modals/components/CreateGroup.tsx b/src/controllers/modals/components/CreateGroup.tsx index af3b96c7..d98f3afc 100644 --- a/src/controllers/modals/components/CreateGroup.tsx +++ b/src/controllers/modals/components/CreateGroup.tsx @@ -4,9 +4,8 @@ import { Text } from "preact-i18n"; import { ModalForm } from "@revoltchat/ui"; -import { mapError } from "../../../context/revoltjs/util"; - import { useClient } from "../../client/ClientController"; +import { mapError } from "../../client/jsx/error"; import { ModalProps } from "../types"; /** diff --git a/src/controllers/modals/components/CreateInvite.tsx b/src/controllers/modals/components/CreateInvite.tsx index d070c08f..45295545 100644 --- a/src/controllers/modals/components/CreateInvite.tsx +++ b/src/controllers/modals/components/CreateInvite.tsx @@ -7,8 +7,7 @@ import { ModalForm } from "@revoltchat/ui"; import { noopAsync } from "../../../lib/js"; -import { takeError } from "../../../context/revoltjs/util"; - +import { takeError } from "../../client/jsx/error"; import { modalController } from "../ModalController"; import { ModalProps } from "../types"; diff --git a/src/controllers/modals/components/CreateServer.tsx b/src/controllers/modals/components/CreateServer.tsx index 08da9c91..9e9bbff8 100644 --- a/src/controllers/modals/components/CreateServer.tsx +++ b/src/controllers/modals/components/CreateServer.tsx @@ -4,9 +4,8 @@ import { Text } from "preact-i18n"; import { ModalForm } from "@revoltchat/ui"; -import { mapError } from "../../../context/revoltjs/util"; - import { useClient } from "../../client/ClientController"; +import { mapError } from "../../client/jsx/error"; import { ModalProps } from "../types"; /** diff --git a/src/controllers/modals/components/ModifyAccount.tsx b/src/controllers/modals/components/ModifyAccount.tsx index 70dd3d11..8103647d 100644 --- a/src/controllers/modals/components/ModifyAccount.tsx +++ b/src/controllers/modals/components/ModifyAccount.tsx @@ -7,10 +7,9 @@ import { Category, Error, Modal } from "@revoltchat/ui"; import { noopTrue } from "../../../lib/js"; -import { takeError } from "../../../context/revoltjs/util"; - import FormField from "../../../pages/login/FormField"; import { useClient } from "../../client/ClientController"; +import { takeError } from "../../client/jsx/error"; import { ModalProps } from "../types"; interface FormInputs { diff --git a/src/controllers/modals/components/ServerIdentity.tsx b/src/controllers/modals/components/ServerIdentity.tsx index 5a8dfc9a..508aadae 100644 --- a/src/controllers/modals/components/ServerIdentity.tsx +++ b/src/controllers/modals/components/ServerIdentity.tsx @@ -19,8 +19,7 @@ import { import { noop } from "../../../lib/js"; -import { FileUploader } from "../../../context/revoltjs/FileUploads"; - +import { FileUploader } from "../../client/jsx/legacy/FileUploads"; import { ModalProps } from "../types"; const Preview = styled(Centred)` diff --git a/src/controllers/modals/components/legacy/CreateBot.tsx b/src/controllers/modals/components/legacy/CreateBot.tsx index b880ef5a..7c977cb2 100644 --- a/src/controllers/modals/components/legacy/CreateBot.tsx +++ b/src/controllers/modals/components/legacy/CreateBot.tsx @@ -9,10 +9,10 @@ import { Category, Modal } from "@revoltchat/ui"; import { noopTrue } from "../../../../lib/js"; import { I18nError } from "../../../../context/Locale"; -import { takeError } from "../../../../context/revoltjs/util"; import FormField from "../../../../pages/login/FormField"; import { useClient } from "../../../client/ClientController"; +import { takeError } from "../../../client/jsx/error"; import { modalController } from "../../ModalController"; import { ModalProps } from "../../types"; diff --git a/src/controllers/modals/components/legacy/Onboarding.tsx b/src/controllers/modals/components/legacy/Onboarding.tsx index 53cc681f..bc3f22c3 100644 --- a/src/controllers/modals/components/legacy/Onboarding.tsx +++ b/src/controllers/modals/components/legacy/Onboarding.tsx @@ -6,11 +6,10 @@ import { useState } from "preact/hooks"; import { Button, Preloader } from "@revoltchat/ui"; -import { takeError } from "../../../../context/revoltjs/util"; - import wideSVG from "/assets/wide.svg"; import FormField from "../../../../pages/login/FormField"; +import { takeError } from "../../../client/jsx/error"; import { ModalProps } from "../../types"; interface FormInputs { diff --git a/src/lib/ContextMenus.tsx b/src/lib/ContextMenus.tsx index b75eed1a..90e3869c 100644 --- a/src/lib/ContextMenus.tsx +++ b/src/lib/ContextMenus.tsx @@ -26,12 +26,12 @@ import { useApplicationState } from "../mobx/State"; import { QueuedMessage } from "../mobx/stores/MessageQueue"; import { NotificationState } from "../mobx/stores/NotificationOptions"; -import { takeError } from "../context/revoltjs/util"; import CMNotifications from "./contextmenu/CMNotifications"; import Tooltip from "../components/common/Tooltip"; import UserStatus from "../components/common/user/UserStatus"; import { useSession } from "../controllers/client/ClientController"; +import { takeError } from "../controllers/client/jsx/error"; import { modalController } from "../controllers/modals/ModalController"; import { internalEmit } from "./eventEmitter"; import { getRenderer } from "./renderer/Singleton"; diff --git a/src/pages/app.tsx b/src/pages/app.tsx index 2251e942..f84078df 100644 --- a/src/pages/app.tsx +++ b/src/pages/app.tsx @@ -7,8 +7,8 @@ import { Masks, Preloader } from "@revoltchat/ui"; import ErrorBoundary from "../lib/ErrorBoundary"; import Context from "../context"; -import { CheckAuth } from "../context/revoltjs/CheckAuth"; +import { CheckAuth } from "../controllers/client/jsx/CheckAuth"; import Invite from "./invite/Invite"; const Login = lazy(() => import("./login/Login")); diff --git a/src/pages/channels/ChannelHeader.tsx b/src/pages/channels/ChannelHeader.tsx index e2def382..e4c20c80 100644 --- a/src/pages/channels/ChannelHeader.tsx +++ b/src/pages/channels/ChannelHeader.tsx @@ -6,12 +6,11 @@ import styled from "styled-components/macro"; import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice"; -import { getChannelName } from "../../context/revoltjs/util"; - import { useStatusColour } from "../../components/common/user/UserIcon"; import UserStatus from "../../components/common/user/UserStatus"; import Markdown from "../../components/markdown/Markdown"; import { PageHeader } from "../../components/ui/Header"; +import { ChannelName } from "../../controllers/client/jsx/ChannelName"; import { modalController } from "../../controllers/modals/ModalController"; import HeaderActions from "./actions/HeaderActions"; @@ -64,7 +63,6 @@ const Info = styled.div` `; export default observer(({ channel }: ChannelHeaderProps) => { - const name = getChannelName(channel); let icon, recipient: User | undefined; switch (channel.channel_type) { case "SavedMessages": @@ -85,7 +83,9 @@ export default observer(({ channel }: ChannelHeaderProps) => { return ( - {name} + + + {isTouchscreenDevice && channel.channel_type === "DirectMessage" && ( <> diff --git a/src/pages/channels/messaging/ConversationStart.tsx b/src/pages/channels/messaging/ConversationStart.tsx index 09ebf235..ced692c4 100644 --- a/src/pages/channels/messaging/ConversationStart.tsx +++ b/src/pages/channels/messaging/ConversationStart.tsx @@ -4,7 +4,7 @@ import styled from "styled-components/macro"; import { Text } from "preact-i18n"; -import { getChannelName } from "../../../context/revoltjs/util"; +import { ChannelName } from "../../../controllers/client/jsx/ChannelName"; const StartBase = styled.div` margin: 18px 16px 10px 16px; @@ -28,7 +28,9 @@ interface Props { export default observer(({ channel }: Props) => { return ( -

{getChannelName(channel, true)}

+

+ +

diff --git a/src/pages/invite/Invite.tsx b/src/pages/invite/Invite.tsx index d7307efb..b7e3e16e 100644 --- a/src/pages/invite/Invite.tsx +++ b/src/pages/invite/Invite.tsx @@ -12,8 +12,6 @@ import { TextReact } from "../../lib/i18n"; import { useApplicationState } from "../../mobx/State"; -import { takeError } from "../../context/revoltjs/util"; - import ServerIcon from "../../components/common/ServerIcon"; import UserIcon from "../../components/common/user/UserIcon"; import { @@ -21,6 +19,7 @@ import { useSession, } from "../../controllers/client/ClientController"; import RequiresOnline from "../../controllers/client/jsx/RequiresOnline"; +import { takeError } from "../../controllers/client/jsx/error"; export default function Invite() { const history = useHistory(); diff --git a/src/pages/login/forms/Form.tsx b/src/pages/login/forms/Form.tsx index 2a1b7d6b..630a1155 100644 --- a/src/pages/login/forms/Form.tsx +++ b/src/pages/login/forms/Form.tsx @@ -9,11 +9,11 @@ import { useState } from "preact/hooks"; import { Button, Category, Preloader, Tip } from "@revoltchat/ui"; import { I18nError } from "../../../context/Locale"; -import { takeError } from "../../../context/revoltjs/util"; import WaveSVG from "../../settings/assets/wave.svg"; import { clientController } from "../../../controllers/client/ClientController"; +import { takeError } from "../../../controllers/client/jsx/error"; import FormField from "../FormField"; import { CaptchaBlock, CaptchaProps } from "./CaptchaBlock"; import { MailProvider } from "./MailProvider"; diff --git a/src/pages/login/forms/FormVerify.tsx b/src/pages/login/forms/FormVerify.tsx index 362e835a..32d0e4b4 100644 --- a/src/pages/login/forms/FormVerify.tsx +++ b/src/pages/login/forms/FormVerify.tsx @@ -5,9 +5,9 @@ import { useEffect, useState } from "preact/hooks"; import { Category, Preloader } from "@revoltchat/ui"; import { I18nError } from "../../../context/Locale"; -import { takeError } from "../../../context/revoltjs/util"; import { useApi } from "../../../controllers/client/ClientController"; +import { takeError } from "../../../controllers/client/jsx/error"; import { Form } from "./Form"; export function FormResend() { diff --git a/src/pages/settings/ChannelSettings.tsx b/src/pages/settings/ChannelSettings.tsx index dc67aaa1..3910af62 100644 --- a/src/pages/settings/ChannelSettings.tsx +++ b/src/pages/settings/ChannelSettings.tsx @@ -4,9 +4,8 @@ import { Route, Switch, useHistory, useParams } from "react-router-dom"; import { Text } from "preact-i18n"; -import { getChannelName } from "../../context/revoltjs/util"; - import { useClient } from "../../controllers/client/ClientController"; +import { ChannelName } from "../../controllers/client/jsx/ChannelName"; import { GenericSettings } from "./GenericSettings"; import Overview from "./channel/Overview"; import Permissions from "./channel/Permissions"; @@ -47,7 +46,7 @@ export default function ChannelSettings() { {getChannelName(channel, true)}, + category: , id: "overview", icon: , title: ( diff --git a/src/pages/settings/channel/Overview.tsx b/src/pages/settings/channel/Overview.tsx index 8b2dae96..392fb216 100644 --- a/src/pages/settings/channel/Overview.tsx +++ b/src/pages/settings/channel/Overview.tsx @@ -9,7 +9,7 @@ import { Button, Checkbox, InputBox } from "@revoltchat/ui"; import TextAreaAutoSize from "../../../lib/TextAreaAutoSize"; -import { FileUploader } from "../../../context/revoltjs/FileUploads"; +import { FileUploader } from "../../../controllers/client/jsx/legacy/FileUploads"; interface Props { channel: Channel; diff --git a/src/pages/settings/panes/MyBots.tsx b/src/pages/settings/panes/MyBots.tsx index 122ae7ff..03af49c0 100644 --- a/src/pages/settings/panes/MyBots.tsx +++ b/src/pages/settings/panes/MyBots.tsx @@ -23,8 +23,6 @@ import { internalEmit } from "../../../lib/eventEmitter"; import { useTranslation } from "../../../lib/i18n"; import { stopPropagation } from "../../../lib/stopPropagation"; -import { FileUploader } from "../../../context/revoltjs/FileUploads"; - import AutoComplete, { useAutoComplete, } from "../../../components/common/AutoComplete"; @@ -32,6 +30,7 @@ import CollapsibleSection from "../../../components/common/CollapsibleSection"; import Tooltip from "../../../components/common/Tooltip"; import UserIcon from "../../../components/common/user/UserIcon"; import { useClient } from "../../../controllers/client/ClientController"; +import { FileUploader } from "../../../controllers/client/jsx/legacy/FileUploads"; import { modalController } from "../../../controllers/modals/ModalController"; interface Data { diff --git a/src/pages/settings/panes/Profile.tsx b/src/pages/settings/panes/Profile.tsx index c0c9e0c3..76f68e37 100644 --- a/src/pages/settings/panes/Profile.tsx +++ b/src/pages/settings/panes/Profile.tsx @@ -12,12 +12,11 @@ import { Button, LineDivider, Tip } from "@revoltchat/ui"; import TextAreaAutoSize from "../../../lib/TextAreaAutoSize"; import { useTranslation } from "../../../lib/i18n"; -import { FileUploader } from "../../../context/revoltjs/FileUploads"; - import AutoComplete, { useAutoComplete, } from "../../../components/common/AutoComplete"; import { useSession } from "../../../controllers/client/ClientController"; +import { FileUploader } from "../../../controllers/client/jsx/legacy/FileUploads"; import { UserProfile } from "../../../controllers/modals/components/legacy/UserProfile"; export const Profile = observer(() => { diff --git a/src/pages/settings/server/Invites.tsx b/src/pages/settings/server/Invites.tsx index f20f8e53..d4256427 100644 --- a/src/pages/settings/server/Invites.tsx +++ b/src/pages/settings/server/Invites.tsx @@ -9,10 +9,9 @@ import { useEffect, useState } from "preact/hooks"; import { IconButton, Preloader } from "@revoltchat/ui"; -import { getChannelName } from "../../../context/revoltjs/util"; - import UserIcon from "../../../components/common/user/UserIcon"; import { Username } from "../../../components/common/user/UserShort"; +import { ChannelName } from "../../../controllers/client/jsx/ChannelName"; interface InnerProps { invite: API.Invite; @@ -33,7 +32,9 @@ const Inner = observer(({ invite, server, removeSelf }: InnerProps) => { {" "} - {channel ? getChannelName(channel, true) : "#??"} + + + { setDelete(true); diff --git a/src/pages/settings/server/Overview.tsx b/src/pages/settings/server/Overview.tsx index c04f1c06..7dc56c39 100644 --- a/src/pages/settings/server/Overview.tsx +++ b/src/pages/settings/server/Overview.tsx @@ -12,8 +12,8 @@ import { Button, ComboBox, InputBox } from "@revoltchat/ui"; import TextAreaAutoSize from "../../../lib/TextAreaAutoSize"; import { noop } from "../../../lib/js"; -import { FileUploader } from "../../../context/revoltjs/FileUploads"; -import { getChannelName } from "../../../context/revoltjs/util"; +import { ChannelName } from "../../../controllers/client/jsx/ChannelName"; +import { FileUploader } from "../../../controllers/client/jsx/legacy/FileUploads"; interface Props { server: Server; @@ -172,7 +172,7 @@ export const Overview = observer(({ server }: Props) => { ) .map((channel) => ( ))}