thread age limit

This commit is contained in:
smolgrrr 2024-01-31 17:25:46 +11:00
parent 5661d9da0e
commit 89c58d209c
4 changed files with 26 additions and 7 deletions

View File

@ -15,6 +15,7 @@ const DEFAULT_DIFFICULTY = 20;
const Board = () => { const Board = () => {
const { id } = useParams(); const { id } = useParams();
const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY; const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY;
const age = Number(localStorage.getItem("age")) || 24;
const [sortByTime, setSortByTime] = useState<boolean>(localStorage.getItem('sortBy') !== 'false'); const [sortByTime, setSortByTime] = useState<boolean>(localStorage.getItem('sortBy') !== 'false');
const [setAnon, setSetAnon] = useState<boolean>(localStorage.getItem('anonMode') !== 'false'); const [setAnon, setSetAnon] = useState<boolean>(localStorage.getItem('anonMode') !== 'false');
@ -27,7 +28,7 @@ const Board = () => {
useEffect(() => { useEffect(() => {
const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]); const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]);
console.log(events) console.log(events)
const unsubscribe = subBoardFeed(pubkey, onEvent); const unsubscribe = subBoardFeed(pubkey, onEvent, age);
subProfile(pubkey, onEvent) subProfile(pubkey, onEvent)
return unsubscribe; return unsubscribe;

View File

@ -12,10 +12,11 @@ const DEFAULT_DIFFICULTY = 20;
const useUniqEvents = () => { const useUniqEvents = () => {
const [events, setEvents] = useState<Event[]>([]); const [events, setEvents] = useState<Event[]>([]);
const age = Number(localStorage.getItem("age")) || 24;
useEffect(() => { useEffect(() => {
const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]); const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]);
const unsubscribe = subGlobalFeed(onEvent); const unsubscribe = subGlobalFeed(onEvent, age);
return unsubscribe; return unsubscribe;
}, []); }, []);

View File

@ -10,6 +10,7 @@ type TestResponse = {
const Settings = () => { const Settings = () => {
const [filterDifficulty, setFilterDifficulty] = useState(localStorage.getItem('filterDifficulty') || 20); const [filterDifficulty, setFilterDifficulty] = useState(localStorage.getItem('filterDifficulty') || 20);
const [difficulty, setDifficulty] = useState(localStorage.getItem('difficulty') || 21); const [difficulty, setDifficulty] = useState(localStorage.getItem('difficulty') || 21);
const [age, setAge] = useState(localStorage.getItem('age') || 24);
const [showAdvancedSettings, setShowAdvancedSettings] = useState(false); const [showAdvancedSettings, setShowAdvancedSettings] = useState(false);
const [powServer, setPowServer] = useState(localStorage.getItem('powserver') || ''); const [powServer, setPowServer] = useState(localStorage.getItem('powserver') || '');
const [testDiff, setTestDiff] = useState('21') const [testDiff, setTestDiff] = useState('21')
@ -22,11 +23,13 @@ const Settings = () => {
localStorage.setItem('filterDifficulty', String(filterDifficulty)); localStorage.setItem('filterDifficulty', String(filterDifficulty));
localStorage.setItem('difficulty', String(difficulty)); localStorage.setItem('difficulty', String(difficulty));
localStorage.setItem('powserver', String(powServer)); localStorage.setItem('powserver', String(powServer));
localStorage.setItem('age', String(age));
const eventData = { const eventData = {
difficulty: String(difficulty), difficulty: String(difficulty),
filterDifficulty: String(filterDifficulty), filterDifficulty: String(filterDifficulty),
powServer: String(powServer), powServer: String(powServer),
age: String(age),
}; };
const event = new CustomEvent('settingsChanged', { detail: eventData }); const event = new CustomEvent('settingsChanged', { detail: eventData });
window.dispatchEvent(event); window.dispatchEvent(event);
@ -68,7 +71,7 @@ const Settings = () => {
<div className="w-full md:w-1/3 px-2 mb-4 md:mb-0"> <div className="w-full md:w-1/3 px-2 mb-4 md:mb-0">
<label className="block text-xs mb-2" htmlFor="filterDifficulty"> <label className="block text-xs mb-2" htmlFor="filterDifficulty">
<span style={{ display: 'inline-flex', alignItems: 'center' }}> <span style={{ display: 'inline-flex', alignItems: 'center' }}>
Proof-of-Work Difficulty Filter {'('}<CpuChipIcon className="h-4 w-4" />{'>'}X to appear on feed{')'}: Proof-of-Work Filter:
</span> </span>
</label> </label>
<input <input
@ -79,7 +82,6 @@ const Settings = () => {
className="w-full px-3 py-2 border rounded-md bg-black" className="w-full px-3 py-2 border rounded-md bg-black"
/> />
</div> </div>
<div className="w-full md:w-1/3 px-2 mb-4 md:mb-0"> <div className="w-full md:w-1/3 px-2 mb-4 md:mb-0">
<label className="block text-xs mb-2" htmlFor="difficulty"> <label className="block text-xs mb-2" htmlFor="difficulty">
<span style={{ display: 'inline-flex', alignItems: 'center' }}> <span style={{ display: 'inline-flex', alignItems: 'center' }}>
@ -94,6 +96,20 @@ const Settings = () => {
className="w-full px-3 py-2 border rounded-md bg-black" className="w-full px-3 py-2 border rounded-md bg-black"
/> />
</div> </div>
<div className="w-full md:w-1/3 px-2 mb-4 md:mb-0">
<label className="block text-xs mb-2" htmlFor="difficulty">
<span style={{ display: 'inline-flex', alignItems: 'center' }}>
Thread Age Limit (hrs):
</span>
</label>
<input
id="age"
type="number"
value={age}
onChange={e => setAge(e.target.value)}
className="w-full px-3 py-2 border rounded-md bg-black"
/>
</div>
</div> </div>
<div className='pb-4'> <div className='pb-4'>
<span onClick={() => setShowAdvancedSettings(!showAdvancedSettings)} className=""> <span onClick={() => setShowAdvancedSettings(!showAdvancedSettings)} className="">

View File

@ -7,7 +7,7 @@ type SubCallback = (
) => void; ) => void;
/** subscribe to global feed */ /** subscribe to global feed */
export const subGlobalFeed = (onEvent: SubCallback) => { export const subGlobalFeed = (onEvent: SubCallback, age: number) => {
console.info('subscribe to global feed'); console.info('subscribe to global feed');
unsubAll(); unsubAll();
const now = Math.floor(Date.now() * 0.001); const now = Math.floor(Date.now() * 0.001);
@ -23,7 +23,7 @@ export const subGlobalFeed = (onEvent: SubCallback) => {
filter: { filter: {
...(prefix && { ids: ['0'.repeat(prefix)] }), ...(prefix && { ids: ['0'.repeat(prefix)] }),
kinds: [1, 6], kinds: [1, 6],
since: Math.floor((Date.now() * 0.001) - (24 * 60 * 60)), since: Math.floor((Date.now() * 0.001) - (age * 60 * 60)),
limit: 500, limit: 500,
}, },
unsub: true unsub: true
@ -266,6 +266,7 @@ export const subNotifications = (
export const subBoardFeed = ( export const subBoardFeed = (
board: string, board: string,
onEvent: SubCallback, onEvent: SubCallback,
age: number
) => { ) => {
console.info('subscribe to board'); console.info('subscribe to board');
unsubAll(); unsubAll();
@ -283,7 +284,7 @@ export const subBoardFeed = (
...(prefix && { ids: ['0'.repeat(prefix)] }), ...(prefix && { ids: ['0'.repeat(prefix)] }),
"#d": [board], "#d": [board],
kinds: [1, 6], kinds: [1, 6],
since: Math.floor((Date.now() * 0.001) - (24 * 60 * 60)), since: Math.floor((Date.now() * 0.001) - (age * 60 * 60)),
limit: 500, limit: 500,
}, },
unsub: true unsub: true