mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-22 15:10:57 -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) {
|
export function useUnreads({ channel, unreads }: UnreadProps) {
|
||||||
const firstLoad = useRef(true);
|
// const firstLoad = useRef(true);
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
function checkUnread(target: Channel) {
|
function checkUnread(target: Channel) {
|
||||||
if (!target) return;
|
if (!target) return;
|
||||||
|
@ -24,20 +24,18 @@ export function useUnreads({ channel, unreads }: UnreadProps) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const unread = unreads[channel._id]?.last_id;
|
const unread = unreads[channel._id]?.last_id;
|
||||||
if (target.last_message) {
|
if (target.last_message_id) {
|
||||||
const message =
|
if (
|
||||||
typeof target.last_message === "string"
|
!unread ||
|
||||||
? target.last_message
|
(unread && target.last_message_id.localeCompare(unread) > 0)
|
||||||
: target.last_message._id;
|
) {
|
||||||
if (!unread || (unread && message.localeCompare(unread) > 0)) {
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "UNREADS_MARK_READ",
|
type: "UNREADS_MARK_READ",
|
||||||
channel: channel._id,
|
channel: channel._id,
|
||||||
message,
|
message: target.last_message_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
channel.ack(message, firstLoad.current);
|
channel.ack(target.last_message_id);
|
||||||
firstLoad.current = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ export type Screen =
|
||||||
| { type: "leave_server"; target: Server }
|
| { type: "leave_server"; target: Server }
|
||||||
| { type: "delete_server"; target: Server }
|
| { type: "delete_server"; target: Server }
|
||||||
| { type: "delete_channel"; target: Channel }
|
| { type: "delete_channel"; target: Channel }
|
||||||
|
| { type: "delete_bot"; target: string; name: string; cb: () => void }
|
||||||
| { type: "delete_message"; target: Message }
|
| { type: "delete_message"; target: Message }
|
||||||
| {
|
| {
|
||||||
type: "create_invite";
|
type: "create_invite";
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import { Category } from "revolt-api/types/Servers";
|
|
||||||
import { Channel } from "revolt.js/dist/maps/Channels";
|
import { Channel } from "revolt.js/dist/maps/Channels";
|
||||||
import { Message as MessageI } from "revolt.js/dist/maps/Messages";
|
import { Message as MessageI } from "revolt.js/dist/maps/Messages";
|
||||||
import { Server } from "revolt.js/dist/maps/Servers";
|
import { Server } from "revolt.js/dist/maps/Servers";
|
||||||
|
@ -61,6 +60,7 @@ type SpecialProps = { onClose: () => void } & (
|
||||||
| { type: "leave_server"; target: Server }
|
| { type: "leave_server"; target: Server }
|
||||||
| { type: "delete_server"; target: Server }
|
| { type: "delete_server"; target: Server }
|
||||||
| { type: "delete_channel"; target: Channel }
|
| { type: "delete_channel"; target: Channel }
|
||||||
|
| { type: "delete_bot"; target: string; name: string; cb: () => void }
|
||||||
| { type: "delete_message"; target: MessageI }
|
| { type: "delete_message"; target: MessageI }
|
||||||
| {
|
| {
|
||||||
type: "create_invite";
|
type: "create_invite";
|
||||||
|
@ -86,12 +86,14 @@ export const SpecialPromptModal = observer((props: SpecialProps) => {
|
||||||
case "leave_server":
|
case "leave_server":
|
||||||
case "delete_server":
|
case "delete_server":
|
||||||
case "delete_channel":
|
case "delete_channel":
|
||||||
|
case "delete_bot":
|
||||||
case "unfriend_user":
|
case "unfriend_user":
|
||||||
case "block_user": {
|
case "block_user": {
|
||||||
const EVENTS = {
|
const EVENTS = {
|
||||||
close_dm: ["confirm_close_dm", "close"],
|
close_dm: ["confirm_close_dm", "close"],
|
||||||
delete_server: ["confirm_delete", "delete"],
|
delete_server: ["confirm_delete", "delete"],
|
||||||
delete_channel: ["confirm_delete", "delete"],
|
delete_channel: ["confirm_delete", "delete"],
|
||||||
|
delete_bot: ["confirm_delete", "delete"],
|
||||||
leave_group: ["confirm_leave", "leave"],
|
leave_group: ["confirm_leave", "leave"],
|
||||||
leave_server: ["confirm_leave", "leave"],
|
leave_server: ["confirm_leave", "leave"],
|
||||||
unfriend_user: ["unfriend_user", "remove"],
|
unfriend_user: ["unfriend_user", "remove"],
|
||||||
|
@ -108,6 +110,9 @@ export const SpecialPromptModal = observer((props: SpecialProps) => {
|
||||||
case "close_dm":
|
case "close_dm":
|
||||||
name = props.target.recipient?.username;
|
name = props.target.recipient?.username;
|
||||||
break;
|
break;
|
||||||
|
case "delete_bot":
|
||||||
|
name = props.name;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
name = props.target.name;
|
name = props.target.name;
|
||||||
}
|
}
|
||||||
|
@ -151,6 +156,10 @@ export const SpecialPromptModal = observer((props: SpecialProps) => {
|
||||||
case "delete_server":
|
case "delete_server":
|
||||||
props.target.delete();
|
props.target.delete();
|
||||||
break;
|
break;
|
||||||
|
case "delete_bot":
|
||||||
|
client.bots.delete(props.target);
|
||||||
|
props.cb();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
|
@ -481,9 +490,13 @@ export const SpecialPromptModal = observer((props: SpecialProps) => {
|
||||||
try {
|
try {
|
||||||
props.target.edit({
|
props.target.edit({
|
||||||
categories: [
|
categories: [
|
||||||
...props.target.categories ?? [],
|
...(props.target.categories ?? []),
|
||||||
{ id: ulid(), title: name, channels: [] }
|
{
|
||||||
]
|
id: ulid(),
|
||||||
|
title: name,
|
||||||
|
channels: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
onClose();
|
onClose();
|
||||||
setProcessing(false);
|
setProcessing(false);
|
||||||
|
|
|
@ -469,15 +469,20 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||||
<div className={styles.buttonRow}>
|
<div className={styles.buttonRow}>
|
||||||
{editMode && (
|
{editMode && (
|
||||||
<>
|
<>
|
||||||
<Button accent onClick={save}>
|
<Button onClick={save}>
|
||||||
<Text id="app.special.modals.actions.save" />
|
<Text id="app.special.modals.actions.save" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
error
|
accent
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
await client.bots.delete(bot._id);
|
openScreen({
|
||||||
onDelete();
|
id: "special_prompt",
|
||||||
|
type: "delete_bot",
|
||||||
|
target: bot._id,
|
||||||
|
name: user.username,
|
||||||
|
cb: onDelete,
|
||||||
|
});
|
||||||
}}>
|
}}>
|
||||||
<Text id="app.special.modals.actions.delete" />
|
<Text id="app.special.modals.actions.delete" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
Loading…
Reference in a new issue