Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/823-empty-members-count.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An invite card no longer shows an unknown member count as `0 / 8 in the room`: an empty or non-numeric value is treated as missing, while a real `0` still shows as a real count ([#823](https://github.com/ThinkFlowLab/FlyBot/issues/823)).
14 changes: 12 additions & 2 deletions plugins/social/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,14 +893,24 @@ window.__ModuleLoader__.load({
.replace(/\s+/g, ' ')
.trim()
.slice(0, ROOM_NAME_MAX) || fallback
// A count is only what reads as one (#823): `Number('')` is 0, which would draw an unknown room
// as empty, so an empty or non-numeric string is "not sent", like null.
const roomCount = (value) => {
if (typeof value === 'number') return Number.isFinite(value) ? value : NaN
if (typeof value !== 'string') return NaN
const text = value.trim()
if (!text) return NaN
const count = Number(text)
return Number.isFinite(count) ? count : NaN
}
// What the card can honestly say, and nothing else: a room with no field worth showing is no
// card at all, so the join below runs as before.
const faceInvitePreview = (seen) => {
if (!seen || typeof seen !== 'object' || seen.unsupported === true) return null
const name = cleanRoomName(seen.name)
const lead = cleanRoomName(seen.lead)
const members = seen.members === undefined || seen.members === null ? NaN : Number(seen.members)
const maxMembers = seen.maxMembers === undefined || seen.maxMembers === null ? NaN : Number(seen.maxMembers)
const members = roomCount(seen.members)
const maxMembers = roomCount(seen.maxMembers)
const people = Number.isFinite(members) && Number.isFinite(maxMembers)
? `${members} / ${maxMembers} in the room`
: Number.isFinite(members) ? `${members} in the room` : ''
Expand Down
25 changes: 25 additions & 0 deletions plugins/social/test/social.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9122,6 +9122,31 @@ test('#798: a room name with markup renders cleaned, and a count without a maxim
assert.equal(dialog.text(dialog.find('face-link-preview-members')), '2 in the room')
})

test('#823: an empty count is missing, not a zero, and a real zero still shows', async () => {
const card = async (members) => {
const dialog = dialogWithState(async (endpoint) => {
if (endpoint === 'social/face-invite-preview') return { name: 'Kitchen sync', members, maxMembers: 8 }
return {}
})
dialog.find('face-link-join-go').props.onClick()
await dialog.settle()
dialog.render()
return dialog
}
const empty = await card('')
assert.equal(empty.has('face-link-preview-members'), false, "an empty string is a missing count, not '0 / 8'")
const blank = await card(' ')
assert.equal(blank.has('face-link-preview-members'), false, 'whitespace is a missing count, not 0')
const word = await card('eight')
assert.equal(word.has('face-link-preview-members'), false, 'a non-number is a missing count')
const zeroNumber = await card(0)
assert.equal(zeroNumber.text(zeroNumber.find('face-link-preview-members')), '0 / 8 in the room', 'a real numeric zero is a real count')
const zero = await card('0')
assert.equal(zero.text(zero.find('face-link-preview-members')), '0 / 8 in the room', 'a real zero is a real count')
const spaced = await card(' 8 ')
assert.equal(spaced.text(spaced.find('face-link-preview-members')), '8 / 8 in the room', 'whitespace around a number is trimmed')
})

test('#798: an older host says so and does not join; a 404 still joins', async () => {
const older = []
const unsupported = dialogWithState(async (endpoint, payload) => {
Expand Down
Loading