diff --git a/src/components/navigation/left/common.ts b/src/components/navigation/left/common.ts index 443f0e1c..774934f4 100644 --- a/src/components/navigation/left/common.ts +++ b/src/components/navigation/left/common.ts @@ -12,7 +12,7 @@ type UnreadProps = { }; export function useUnreads({ channel, unreads }: UnreadProps) { - const firstLoad = useRef(true); + // const firstLoad = useRef(true); useLayoutEffect(() => { function checkUnread(target: Channel) { if (!target) return; @@ -24,20 +24,18 @@ export function useUnreads({ channel, unreads }: UnreadProps) { return; const unread = unreads[channel._id]?.last_id; - if (target.last_message) { - const message = - typeof target.last_message === "string" - ? target.last_message - : target.last_message._id; - if (!unread || (unread && message.localeCompare(unread) > 0)) { + if (target.last_message_id) { + if ( + !unread || + (unread && target.last_message_id.localeCompare(unread) > 0) + ) { dispatch({ type: "UNREADS_MARK_READ", channel: channel._id, - message, + message: target.last_message_id, }); - channel.ack(message, firstLoad.current); - firstLoad.current = false; + channel.ack(target.last_message_id); } } } diff --git a/src/context/intermediate/Intermediate.tsx b/src/context/intermediate/Intermediate.tsx index 5831e287..149e1043 100644 --- a/src/context/intermediate/Intermediate.tsx +++ b/src/context/intermediate/Intermediate.tsx @@ -42,6 +42,7 @@ export type Screen = | { type: "leave_server"; target: Server } | { type: "delete_server"; target: Server } | { type: "delete_channel"; target: Channel } + | { type: "delete_bot"; target: string; name: string; cb: () => void } | { type: "delete_message"; target: Message } | { type: "create_invite"; diff --git a/src/context/intermediate/modals/Prompt.tsx b/src/context/intermediate/modals/Prompt.tsx index f041f010..79258ce5 100644 --- a/src/context/intermediate/modals/Prompt.tsx +++ b/src/context/intermediate/modals/Prompt.tsx @@ -1,6 +1,5 @@ import { observer } from "mobx-react-lite"; import { useHistory } from "react-router-dom"; -import { Category } from "revolt-api/types/Servers"; import { Channel } from "revolt.js/dist/maps/Channels"; import { Message as MessageI } from "revolt.js/dist/maps/Messages"; import { Server } from "revolt.js/dist/maps/Servers"; @@ -61,6 +60,7 @@ type SpecialProps = { onClose: () => void } & ( | { type: "leave_server"; target: Server } | { type: "delete_server"; target: Server } | { type: "delete_channel"; target: Channel } + | { type: "delete_bot"; target: string; name: string; cb: () => void } | { type: "delete_message"; target: MessageI } | { type: "create_invite"; @@ -86,12 +86,14 @@ export const SpecialPromptModal = observer((props: SpecialProps) => { case "leave_server": case "delete_server": case "delete_channel": + case "delete_bot": case "unfriend_user": case "block_user": { const EVENTS = { close_dm: ["confirm_close_dm", "close"], delete_server: ["confirm_delete", "delete"], delete_channel: ["confirm_delete", "delete"], + delete_bot: ["confirm_delete", "delete"], leave_group: ["confirm_leave", "leave"], leave_server: ["confirm_leave", "leave"], unfriend_user: ["unfriend_user", "remove"], @@ -108,6 +110,9 @@ export const SpecialPromptModal = observer((props: SpecialProps) => { case "close_dm": name = props.target.recipient?.username; break; + case "delete_bot": + name = props.name; + break; default: name = props.target.name; } @@ -151,6 +156,10 @@ export const SpecialPromptModal = observer((props: SpecialProps) => { case "delete_server": props.target.delete(); break; + case "delete_bot": + client.bots.delete(props.target); + props.cb(); + break; } onClose(); @@ -481,9 +490,13 @@ export const SpecialPromptModal = observer((props: SpecialProps) => { try { props.target.edit({ categories: [ - ...props.target.categories ?? [], - { id: ulid(), title: name, channels: [] } - ] + ...(props.target.categories ?? []), + { + id: ulid(), + title: name, + channels: [], + }, + ], }); onClose(); setProcessing(false); diff --git a/src/pages/settings/panes/MyBots.tsx b/src/pages/settings/panes/MyBots.tsx index fa26c56c..ca9a4468 100644 --- a/src/pages/settings/panes/MyBots.tsx +++ b/src/pages/settings/panes/MyBots.tsx @@ -469,15 +469,20 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {