feat: NIP-51
This commit is contained in:
56
src/Hooks/useModeration.tsx
Normal file
56
src/Hooks/useModeration.tsx
Normal file
@ -0,0 +1,56 @@
|
||||
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";
|
||||
|
||||
|
||||
export default function useModeration() {
|
||||
const dispatch = useDispatch()
|
||||
const { 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")
|
||||
}
|
||||
}
|
||||
|
||||
function isMuted(id: HexKey) {
|
||||
return muted.includes(id)
|
||||
}
|
||||
|
||||
function unmute(id: HexKey) {
|
||||
const newMuted = muted.filter(p => p !== id)
|
||||
dispatch(setMuted({
|
||||
at: new Date().getTime(),
|
||||
keys: newMuted
|
||||
}))
|
||||
setMutedList(newMuted)
|
||||
}
|
||||
|
||||
function mute(id: HexKey) {
|
||||
const newMuted = muted.concat([id])
|
||||
setMutedList(newMuted)
|
||||
dispatch(setMuted({
|
||||
at: new Date().getTime(),
|
||||
keys: newMuted
|
||||
}))
|
||||
}
|
||||
|
||||
function muteAll(ids: HexKey[]) {
|
||||
const newMuted = Array.from(new Set(muted.concat(ids)))
|
||||
setMutedList(newMuted)
|
||||
dispatch(setMuted({
|
||||
at: new Date().getTime(),
|
||||
keys: newMuted
|
||||
}))
|
||||
}
|
||||
|
||||
return { muted, mute, muteAll, unmute, isMuted }
|
||||
}
|
Reference in New Issue
Block a user