address review comments and add private blocking
This commit is contained in:
@ -3,26 +3,30 @@ import { useSelector, useDispatch } from "react-redux";
|
||||
import type { RootState } from "State/Store";
|
||||
import { HexKey } from "Nostr";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import { setMuted } from "State/Login";
|
||||
import { setMuted, setBlocked } from "State/Login";
|
||||
|
||||
|
||||
export default function useModeration() {
|
||||
const dispatch = useDispatch()
|
||||
const { muted } = useSelector((s: RootState) => s.login)
|
||||
const { blocked, muted } = useSelector((s: RootState) => s.login)
|
||||
const publisher = useEventPublisher()
|
||||
|
||||
async function setMutedList(ids: HexKey[]) {
|
||||
try {
|
||||
const ev = await publisher.muted(ids)
|
||||
console.debug(ev);
|
||||
publisher.broadcast(ev)
|
||||
} catch (error) {
|
||||
console.debug("Couldn't change mute list")
|
||||
}
|
||||
async function setMutedList(pub: HexKey[], priv: HexKey[]) {
|
||||
try {
|
||||
const ev = await publisher.muted(pub, priv)
|
||||
console.debug(ev);
|
||||
publisher.broadcast(ev)
|
||||
} catch (error) {
|
||||
console.debug("Couldn't change mute list")
|
||||
}
|
||||
}
|
||||
|
||||
function isMuted(id: HexKey) {
|
||||
return muted.includes(id)
|
||||
return muted.includes(id) || blocked.includes(id)
|
||||
}
|
||||
|
||||
function isBlocked(id: HexKey) {
|
||||
return blocked.includes(id)
|
||||
}
|
||||
|
||||
function unmute(id: HexKey) {
|
||||
@ -31,26 +35,44 @@ export default function useModeration() {
|
||||
createdAt: new Date().getTime(),
|
||||
keys: newMuted
|
||||
}))
|
||||
setMutedList(newMuted)
|
||||
setMutedList(newMuted, blocked)
|
||||
}
|
||||
|
||||
function unblock(id: HexKey) {
|
||||
const newBlocked = blocked.filter(p => p !== id)
|
||||
dispatch(setBlocked({
|
||||
createdAt: new Date().getTime(),
|
||||
keys: newBlocked
|
||||
}))
|
||||
setMutedList(muted, newBlocked)
|
||||
}
|
||||
|
||||
function mute(id: HexKey) {
|
||||
const newMuted = muted.concat([id])
|
||||
setMutedList(newMuted)
|
||||
const newMuted = muted.includes(id) ? muted : muted.concat([id])
|
||||
setMutedList(newMuted, blocked)
|
||||
dispatch(setMuted({
|
||||
createdAt: new Date().getTime(),
|
||||
keys: newMuted
|
||||
}))
|
||||
}
|
||||
|
||||
function block(id: HexKey) {
|
||||
const newBlocked = blocked.includes(id) ? blocked : blocked.concat([id])
|
||||
setMutedList(muted, newBlocked)
|
||||
dispatch(setBlocked({
|
||||
createdAt: new Date().getTime(),
|
||||
keys: newBlocked
|
||||
}))
|
||||
}
|
||||
|
||||
function muteAll(ids: HexKey[]) {
|
||||
const newMuted = Array.from(new Set(muted.concat(ids)))
|
||||
setMutedList(newMuted)
|
||||
setMutedList(newMuted, blocked)
|
||||
dispatch(setMuted({
|
||||
createdAt: new Date().getTime(),
|
||||
keys: newMuted
|
||||
}))
|
||||
}
|
||||
|
||||
return { muted, mute, muteAll, unmute, isMuted }
|
||||
return { muted, mute, muteAll, unmute, isMuted, blocked, block, unblock, isBlocked }
|
||||
}
|
||||
|
Reference in New Issue
Block a user