feat: admin and channel owner can delete msg
This commit is contained in:
@@ -10,19 +10,17 @@ import { useAppSelector } from "../../../app/store";
|
|||||||
|
|
||||||
interface Params {
|
interface Params {
|
||||||
mid: number;
|
mid: number;
|
||||||
context: string;
|
context: "user" | "channel";
|
||||||
contextId: number;
|
contextId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function useMessageOperation({ mid, context, contextId }: Params) {
|
export default function useMessageOperation({ mid, context, contextId }: Params) {
|
||||||
const { copy } = useCopy();
|
const { copy } = useCopy();
|
||||||
const { content_type, properties, currUid, from_uid, content } = useAppSelector((store) => {
|
const { loginUser, message, channel } = useAppSelector((store) => {
|
||||||
return {
|
return {
|
||||||
content: store.message[mid]?.content,
|
channel: context == "channel" ? store.channels.byId[contextId] : undefined,
|
||||||
from_uid: store.message[mid]?.from_uid,
|
message: store.message[mid],
|
||||||
content_type: store.message[mid]?.content_type,
|
loginUser: store.authData.user
|
||||||
properties: store.message[mid]?.properties,
|
|
||||||
currUid: store.authData.user?.uid
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const { canPin, pins, unpinMessage, isUnpinSuccess } = usePinMessage(
|
const { canPin, pins, unpinMessage, isUnpinSuccess } = usePinMessage(
|
||||||
@@ -32,7 +30,7 @@ export default function useMessageOperation({ mid, context, contextId }: Params)
|
|||||||
const [pinModalVisible, setPinModalVisible] = useState(false);
|
const [pinModalVisible, setPinModalVisible] = useState(false);
|
||||||
const [deleteModalVisible, setDeleteModalVisible] = useState(false);
|
const [deleteModalVisible, setDeleteModalVisible] = useState(false);
|
||||||
const [forwardModalVisible, setForwardModalVisible] = useState(false);
|
const [forwardModalVisible, setForwardModalVisible] = useState(false);
|
||||||
|
const { content_type, properties, from_uid, content } = message ?? {};
|
||||||
const toggleForwardModal = () => {
|
const toggleForwardModal = () => {
|
||||||
// hideAll();
|
// hideAll();
|
||||||
setForwardModalVisible((prev) => !prev);
|
setForwardModalVisible((prev) => !prev);
|
||||||
@@ -74,8 +72,8 @@ export default function useMessageOperation({ mid, context, contextId }: Params)
|
|||||||
!!properties?.content_type &&
|
!!properties?.content_type &&
|
||||||
properties?.content_type.startsWith("image");
|
properties?.content_type.startsWith("image");
|
||||||
const enableEdit =
|
const enableEdit =
|
||||||
currUid == from_uid && [ContentTypes.text, ContentTypes.markdown].includes(content_type);
|
loginUser?.uid == from_uid && [ContentTypes.text, ContentTypes.markdown].includes(content_type);
|
||||||
const canDelete = currUid == from_uid;
|
const canDelete = loginUser?.uid == from_uid || loginUser?.is_admin || (channel && channel.owner == loginUser?.uid);
|
||||||
const canCopy = [ContentTypes.text, ContentTypes.markdown].includes(content_type) || isImage;
|
const canCopy = [ContentTypes.text, ContentTypes.markdown].includes(content_type) || isImage;
|
||||||
return {
|
return {
|
||||||
copyContent: isImage ? copyContent.bind(null, true) : copyContent.bind(null, false),
|
copyContent: isImage ? copyContent.bind(null, true) : copyContent.bind(null, false),
|
||||||
|
|||||||
Reference in New Issue
Block a user