Tweek join guard
This commit is contained in:
1 parent
e01393c550
commit
13f2ac95b5
1 file changed
+51
-21
@@ -17,20 +17,36 @@ function sanitizeRoomName(value) {
|
||||
.replace(/^-+|-+$/g, '')
|
||||
}
|
||||
|
||||
// Heuristic for a machine-generated room name: four PascalCase words in a row,
|
||||
// each being an uppercase letter followed by one or more lowercase letters
|
||||
// (e.g. "ObstinateEngineerDifferLargely"). Names people type by hand rarely
|
||||
// look like this, and Jitsi bounces users to freshly generated rooms, so this
|
||||
// is the main case worth guarding against.
|
||||
const AUTO_GENERATED_ROOM = /(?:[A-Z][a-z]+){4}/
|
||||
|
||||
function looksAutoGenerated(roomName) {
|
||||
return AUTO_GENERATED_ROOM.test(roomName)
|
||||
}
|
||||
|
||||
// `room` and `noguard` come from the URL (e.g. /rooms/daily-standup?noguard=1);
|
||||
// `onNavigate(room, noguard)` pushes a new route. Selecting a room asks the API
|
||||
// for a JWT and then redirects the browser to the Jitsi server for that room.
|
||||
//
|
||||
// Guard: a room arriving through the URL is joined only when the user has
|
||||
// visited it before. Otherwise we offer to rejoin the most recent room - the
|
||||
// common case when Jitsi bounces the user back to a freshly generated room. A
|
||||
// room flagged with `?noguard=1` is a deliberate join and skips the guard.
|
||||
// Guard: a room arriving through the URL is prompted about only when it looks
|
||||
// machine-generated - four PascalCase words in a row - AND it is not referenced
|
||||
// by any meeting AND the user has not joined it before. Anything else is joined
|
||||
// directly, so normal, hand-typed or known rooms are never interrupted; only
|
||||
// likely Jitsi-generated rooms can be. A room flagged with `?noguard=1` (a
|
||||
// deliberate join) always skips the guard, as does the "always join rooms
|
||||
// without asking" device preference.
|
||||
export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
|
||||
const [room, setRoom] = useState('')
|
||||
const [history, setHistory] = useState([])
|
||||
const [historyLoaded, setHistoryLoaded] = useState(false)
|
||||
// Meetings the current user voted to join, shown below the rooms grid.
|
||||
// All meetings, used both for the "Your meetings" list and for the join guard
|
||||
// (a room referenced by a meeting is a known room).
|
||||
const [meetings, setMeetings] = useState([])
|
||||
const [meetingsLoaded, setMeetingsLoaded] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
const [joining, setJoining] = useState(false)
|
||||
const [copied, setCopied] = useState('')
|
||||
@@ -67,6 +83,8 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
|
||||
setMeetings(data || [])
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
} finally {
|
||||
setMeetingsLoaded(true)
|
||||
}
|
||||
}, [])
|
||||
|
||||
@@ -113,9 +131,11 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
|
||||
enter(target)
|
||||
}
|
||||
|
||||
// Join a room that arrived through the URL. `?noguard=1` joins directly;
|
||||
// otherwise the room is joined when it is in recent rooms, and unknown rooms
|
||||
// are shown in the confirmation notice.
|
||||
// Join a room that arrived through the URL. `?noguard=1` or the "always join"
|
||||
// preference joins directly; a room that is not machine-generated, or that is
|
||||
// referenced by a meeting, or already in the recent rooms list, is joined too.
|
||||
// Only a likely generated room that is otherwise unknown is shown in the
|
||||
// confirmation notice.
|
||||
useEffect(() => {
|
||||
if (!routeRoom) {
|
||||
entered.current = null
|
||||
@@ -125,22 +145,30 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
|
||||
const target = sanitizeRoomName(routeRoom)
|
||||
if (!target || target === entered.current) return
|
||||
// A deliberate join (?noguard=1) or the stored "always join" preference
|
||||
// skips the guard entirely, so the recent rooms list is not needed.
|
||||
// skips the guard entirely, so neither list is needed.
|
||||
const skip = noguard || alwaysJoin
|
||||
if (!skip && !historyLoaded) return
|
||||
// Both lists feed the guard, so wait until they have loaded before deciding.
|
||||
if (!skip && (!historyLoaded || !meetingsLoaded)) return
|
||||
entered.current = target
|
||||
|
||||
if (skip || history.some((item) => item.roomName === target)) {
|
||||
const knownRoom =
|
||||
history.some((item) => item.roomName === target) ||
|
||||
meetings.some((meeting) => meeting.room === target)
|
||||
|
||||
// Prompt only for a machine-generated room that is neither in a meeting nor
|
||||
// in the recent rooms list.
|
||||
if (skip || !looksAutoGenerated(target) || knownRoom) {
|
||||
setPending(null)
|
||||
enter(target)
|
||||
return
|
||||
}
|
||||
|
||||
// Unknown room: suggest the most recent one when there is one. An empty
|
||||
// history means there is nothing to suggest, so lastRoom stays null and the
|
||||
// notice only informs the user about the (possibly generated) room name.
|
||||
// Likely generated, unknown room: suggest the most recent one when there is
|
||||
// one. An empty history means there is nothing to suggest, so lastRoom stays
|
||||
// null and the notice only informs the user about the (possibly generated)
|
||||
// room name.
|
||||
setPending({ room: target, lastRoom: history[0]?.roomName ?? null })
|
||||
}, [routeRoom, noguard, alwaysJoin, enter, history, historyLoaded])
|
||||
}, [routeRoom, noguard, alwaysJoin, enter, history, historyLoaded, meetings, meetingsLoaded])
|
||||
|
||||
const submit = (event) => {
|
||||
event.preventDefault()
|
||||
@@ -207,10 +235,11 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
|
||||
<section className="card notice">
|
||||
{pending.lastRoom ? (
|
||||
<>
|
||||
<h2>Room not in your recent list</h2>
|
||||
<h2>Room looks automatically generated</h2>
|
||||
<p>
|
||||
You are about to join <strong>{pending.room}</strong>, which is
|
||||
not in your recent rooms. Would you like to rejoin your most
|
||||
You are about to join <strong>{pending.room}</strong>, which
|
||||
looks automatically generated and is not linked to any meeting
|
||||
or in your recent rooms. Would you like to rejoin your most
|
||||
recent room instead?
|
||||
</p>
|
||||
<div className="row">
|
||||
@@ -236,9 +265,10 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
|
||||
<>
|
||||
<h2>New room</h2>
|
||||
<p>
|
||||
This is your first join to <strong>{pending.room}</strong>. If you
|
||||
did not type this name yourself it may be a randomly generated
|
||||
room.
|
||||
The name <strong>{pending.room}</strong> looks automatically
|
||||
generated and is not linked to any meeting or in your recent
|
||||
rooms. If you did not type this name yourself it may be a
|
||||
randomly generated room.
|
||||
</p>
|
||||
<div className="row">
|
||||
{/* Same secondary style as the "Join anyway" fallback in the
|
||||
|
||||
Reference in new issue
Block a user