mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-22 07:00:58 -05:00
Fix mark read logic, should fix #307.
Add bot delete confirmation, closes #302.
This commit is contained in:
parent
26277dc0ce
commit
89c0026fa2
4 changed files with 35 additions and 18 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -469,15 +469,20 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
<div className={styles.buttonRow}>
|
||||
{editMode && (
|
||||
<>
|
||||
<Button accent onClick={save}>
|
||||
<Button onClick={save}>
|
||||
<Text id="app.special.modals.actions.save" />
|
||||
</Button>
|
||||
<Button
|
||||
error
|
||||
accent
|
||||
onClick={async () => {
|
||||
setSaving(true);
|
||||
await client.bots.delete(bot._id);
|
||||
onDelete();
|
||||
openScreen({
|
||||
id: "special_prompt",
|
||||
type: "delete_bot",
|
||||
target: bot._id,
|
||||
name: user.username,
|
||||
cb: onDelete,
|
||||
});
|
||||
}}>
|
||||
<Text id="app.special.modals.actions.delete" />
|
||||
</Button>
|
||||
|
|
Loading…
Reference in a new issue