Reduce grace period, add setting for telegram notifications
This commit is contained in:
1 parent
d4257e7dab
commit
f6c68aa7d5
5 files changed
+63
-15
No files matched your search
@@ -2,13 +2,13 @@ import React, { useCallback, useEffect, useState } from 'react'
|
||||
import { api } from '../api.js'
|
||||
|
||||
// Meetings are split into three buckets relative to the current time:
|
||||
// * current - occurred within the past day, or happens within the next week
|
||||
// (the default, always visible view). Including the last day
|
||||
// keeps meetings that just happened visible for a while.
|
||||
// * past - occurred more than a day ago
|
||||
// * current - occurred within the past 30 minutes, or happens within the next
|
||||
// week (the default, always visible view). The short grace period
|
||||
// keeps a meeting that just started visible for a while.
|
||||
// * past - occurred more than 30 minutes ago
|
||||
// * future - happens more than a week from now
|
||||
const WEEK_MS = 7 * 24 * 60 * 60 * 1000
|
||||
const DAY_MS = 24 * 60 * 60 * 1000
|
||||
const CURRENT_GRACE_MS = 30 * 60 * 1000
|
||||
|
||||
function categorize(meetings) {
|
||||
const now = Date.now()
|
||||
@@ -17,7 +17,7 @@ function categorize(meetings) {
|
||||
const future = []
|
||||
for (const meeting of meetings) {
|
||||
const at = new Date(meeting.scheduledAt).getTime()
|
||||
if (at < now - DAY_MS) {
|
||||
if (at < now - CURRENT_GRACE_MS) {
|
||||
past.push(meeting)
|
||||
} else if (at <= now + WEEK_MS) {
|
||||
current.push(meeting)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, { useState } from 'react'
|
||||
import { api } from '../api.js'
|
||||
import { notifyTelegramEnabled } from '../settings.js'
|
||||
|
||||
// Formats a Date as the value a `datetime-local` input expects, in local time
|
||||
// (YYYY-MM-DDTHH:mm).
|
||||
@@ -20,9 +21,9 @@ export default function PlanMeetingPage({ onCreated, onCancel }) {
|
||||
// When checked the author is recorded as joining straight away. Checked by
|
||||
// default, since planning a meeting usually means you intend to attend.
|
||||
const [autoJoin, setAutoJoin] = useState(true)
|
||||
// When checked the Telegram bot announces the meeting. Checked by default;
|
||||
// users uncheck it to create a meeting silently.
|
||||
const [hasNotification, setHasNotification] = useState(true)
|
||||
// When checked the Telegram bot announces the meeting. Off by default; the
|
||||
// profile's device-local preference decides whether it starts checked.
|
||||
const [hasNotification, setHasNotification] = useState(notifyTelegramEnabled)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { api } from '../api.js'
|
||||
import { skipGuardEnabled, setSkipGuard } from '../settings.js'
|
||||
import {
|
||||
notifyTelegramEnabled,
|
||||
setNotifyTelegram,
|
||||
setSkipGuard,
|
||||
skipGuardEnabled,
|
||||
} from '../settings.js'
|
||||
|
||||
// Fallback used until GET /api/config answers. Kept in sync with the backend
|
||||
// defaults (user.MaxImageSize and the accepted image formats).
|
||||
@@ -64,6 +69,7 @@ export default function ProfilePage({ user, onUserChange }) {
|
||||
|
||||
// Device/browser-only preferences (stored in localStorage, not on the account).
|
||||
const [skipGuard, setSkipGuardState] = useState(skipGuardEnabled)
|
||||
const [notifyTelegram, setNotifyTelegramState] = useState(notifyTelegramEnabled)
|
||||
|
||||
// Query the backend for the avatar limits instead of hardcoding them, so the
|
||||
// file picker, the size hint and the client-side check always match what the
|
||||
@@ -279,6 +285,21 @@ export default function ProfilePage({ user, onUserChange }) {
|
||||
When enabled, opening a room link joins it directly instead of asking
|
||||
whether to rejoin your most recent room.
|
||||
</p>
|
||||
<label className="checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={notifyTelegram}
|
||||
onChange={(e) => {
|
||||
setNotifyTelegramState(e.target.checked)
|
||||
setNotifyTelegram(e.target.checked)
|
||||
}}
|
||||
/>
|
||||
Announce new meetings on Telegram by default
|
||||
</label>
|
||||
<p className="hint">
|
||||
When enabled, the "Send a Telegram notification" checkbox on the
|
||||
plan-meeting page starts checked. Off by default.
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -2,9 +2,10 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { api } from '../api.js'
|
||||
import { skipGuardEnabled, setSkipGuard } from '../settings.js'
|
||||
|
||||
// Meetings on the rooms page stay visible for a day after they started, so a
|
||||
// meeting the user just missed (or is still running) can still be rejoined.
|
||||
const DAY_MS = 24 * 60 * 60 * 1000
|
||||
// Meetings on the rooms page stay visible for 30 minutes after they started, so
|
||||
// a meeting that just started (or is about to) can still be joined, while
|
||||
// anything older is dropped from the list.
|
||||
const CURRENT_GRACE_MS = 30 * 60 * 1000
|
||||
|
||||
// Room names are case-sensitive on the Jitsi side, so we only trim, collapse
|
||||
// disallowed characters into a dash, and strip leading/trailing dashes. Case is
|
||||
@@ -192,8 +193,8 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
|
||||
}
|
||||
|
||||
// Meetings the user committed to attend that are upcoming or started within
|
||||
// the last day (long-past meetings drop off).
|
||||
const cutoff = Date.now() - DAY_MS
|
||||
// the last 30 minutes (older meetings drop off).
|
||||
const cutoff = Date.now() - CURRENT_GRACE_MS
|
||||
const joiningMeetings = meetings.filter(
|
||||
(meeting) =>
|
||||
meeting.myVote === 'join' &&
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// never sent to the backend; they live in localStorage for this browser only.
|
||||
|
||||
const SKIP_GUARD_KEY = 'gochat.skipGuard'
|
||||
const NOTIFY_TELEGRAM_KEY = 'gochat.notifyTelegram'
|
||||
|
||||
// When enabled, opening a room URL joins it directly instead of running the
|
||||
// recent-room guard.
|
||||
@@ -25,3 +26,27 @@ export function setSkipGuard(enabled) {
|
||||
// Ignore: the preference simply will not persist.
|
||||
}
|
||||
}
|
||||
|
||||
// When enabled, the "Send a Telegram notification" checkbox on the plan-meeting
|
||||
// page starts checked. Off by default so creating a meeting does not announce it
|
||||
// in the Telegram group unless the user opts in.
|
||||
export function notifyTelegramEnabled() {
|
||||
try {
|
||||
return window.localStorage.getItem(NOTIFY_TELEGRAM_KEY) === '1'
|
||||
} catch {
|
||||
// Storage can be unavailable (private mode, disabled cookies).
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function setNotifyTelegram(enabled) {
|
||||
try {
|
||||
if (enabled) {
|
||||
window.localStorage.setItem(NOTIFY_TELEGRAM_KEY, '1')
|
||||
} else {
|
||||
window.localStorage.removeItem(NOTIFY_TELEGRAM_KEY)
|
||||
}
|
||||
} catch {
|
||||
// Ignore: the preference simply will not persist.
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user