Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
54869a7
feat(core): join by the own slot walk and cut the replaced writer
rodrigopavezi Nov 17, 2026
04db5ee
feat(web-member): join and count writers by the own slot walk
rodrigopavezi Nov 17, 2026
e5352b0
feat(core): hold every writer the slot walk counts per diary
rodrigopavezi Nov 17, 2026
d7573bd
feat(core): stop counting envelopes of a cut writer for the rekey
rodrigopavezi Nov 17, 2026
5dab902
test(web-member): cover root adoption through the slot walk with cuts
rodrigopavezi Nov 17, 2026
980c234
feat(app): say a device slot comes back by disconnecting a device
rodrigopavezi Nov 17, 2026
e214601
docs: describe writer slots on the clients
rodrigopavezi Nov 17, 2026
6046211
Merge remote-tracking branch 'origin/main' into feat/writer-slot-clients
rodrigopavezi Nov 17, 2026
1122d00
feat(app): point the slot copy to Ajustes, Aparelhos conectados
rodrigopavezi Nov 17, 2026
5a8dcac
feat: cut the retired community writer before a community rejoin
rodrigopavezi Nov 17, 2026
d475bd9
fix(web-member): trim a community demotion's cuts like the core node
rodrigopavezi Nov 17, 2026
fbef33b
feat(web-member): read the diaries' cuts in the catalogue fold
rodrigopavezi Nov 17, 2026
64c83c1
docs: describe the community rejoin cut and the fold reading cuts
rodrigopavezi Nov 17, 2026
34c7f07
feat(core): read the diaries' cuts in the catalogue fold
rodrigopavezi Nov 17, 2026
16f01e0
fix(core): name frozen writers in group moderation cuts like the browser
rodrigopavezi Nov 17, 2026
fc584cf
test(core): sort the catalogue fold's groups before comparing
rodrigopavezi Nov 17, 2026
0d3ebc2
fix: repeat the cut on a retired writer the walk still has live
rodrigopavezi Nov 17, 2026
223909e
fix(app): reword the device slot refusal and the no-reserve warning
rodrigopavezi Nov 17, 2026
274567f
docs: describe the slot cap on community.join and the hint slots
rodrigopavezi Nov 17, 2026
662d5d5
Merge remote-tracking branch 'origin/main' into feat/writer-slot-clients
rodrigopavezi Nov 17, 2026
8db7d90
docs: note the boxless writer replacement still skips a repeated cut
rodrigopavezi Nov 17, 2026
0c9be34
test(core): expect the replacement cut before a later creator leave
rodrigopavezi Nov 17, 2026
f5e9b97
Merge remote-tracking branch 'origin/main' into feat/writer-slot-clients
rodrigopavezi Nov 17, 2026
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
87 changes: 84 additions & 3 deletions apps/app/src/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,18 @@ export function needsDeviceJoin (info) {
return MEMBER_ROLES.includes(info.role) && info.writerHere === false
}

// The seeder never frees a device slot (8 per root); the app stops entering by
// itself at 6 and leaves the last two to the person.
// Each account has 8 live device slots per root (writersBound). A slot comes
// back only when a device is disconnected, and only while the root's frozen
// reserve lasts (#350); an older node never gives one back. The app stops
// entering by itself at 6 and leaves the last two to the person.
export function reserveReachedAny (counts) {
if (!Array.isArray(counts)) return false
return counts.some((n) => Number.isSafeInteger(n) && n >= 6)
}

// At the reserve the first tap only shows the warning; the person confirms
// with a second tap, because the slot is never given back.
// with a second tap, because the slot comes back at best by disconnecting a
// device.
export function needsReserveConfirm (counts, confirmed) {
return confirmed !== true && reserveReachedAny(counts)
}
Expand All @@ -230,6 +233,84 @@ export function communityReserveReached (info) {
return reserveReachedAny([info.writersBound, info.generalWritersBound])
}

const ACCOUNT_SLOTS = 8

// The roots a join spends a slot in, as { bound, room } (writersBound and
// frozenRoom): group.join in the group, community.join in the community and
// in Geral.
export function groupSlots (info) {
if (!info || typeof info !== 'object') return []
return [{ bound: info.writersBound, room: info.frozenRoom }]
}

export function communitySlots (info) {
if (!info || typeof info !== 'object') return []
return [{ bound: info.writersBound, room: info.frozenRoom }, { bound: info.generalWritersBound, room: info.generalFrozenRoom }]
}

// What disconnecting a device does in those roots, decided by the field the
// node reports, never by the platform: 'returns' while every root has frozen
// reserve left, 'final' once one has none, 'legacy' when the node omits
// frozenRoom (an older node, where a slot never comes back).
export function slotReturn (slots) {
const rooms = (Array.isArray(slots) ? slots : []).map((s) => s && s.room).filter((n) => Number.isSafeInteger(n) && n >= 0)
if (rooms.length === 0) return 'legacy'
return rooms.some((n) => n === 0) ? 'final' : 'returns'
}

// The way to the screen, as Ajustes lists it (DEVICES_TITLE in devices.js;
// the test holds the two together).
const DEVICES_PATH = 'Ajustes, Aparelhos conectados'
const SLOT_RETURNS_TEXT = 'Desconectar um aparelho antigo em ' + DEVICES_PATH + ', devolve a vaga.'
// With no frozen reserve a disconnect's mark of 1 or more frees no slot; a
// mark at 0 still releases one while the diary has releases left.
const SLOT_FINAL_TEXT = 'desconectar um aparelho pode não devolver a vaga.'

function slotPlace (where) {
return where === 'comunidade' ? 'nesta comunidade' : 'neste grupo'
}

// The warning at the reserve. `where` is 'grupo' or 'comunidade'.
export function reserveText (slots, where = 'grupo') {
const r = slotReturn(slots)
if (r === 'legacy') return DEVICE_RESERVE_TEXT
return 'Cada aparelho usa uma das 8 vagas da conta ' + slotPlace(where) + '. ' + (r === 'final' ? 'Aqui, ' + SLOT_FINAL_TEXT : SLOT_RETURNS_TEXT)
}

// The community info note for a device not in the community yet, at the
// reserve.
export function reserveJoinText (slots) {
if (slotReturn(slots) === 'legacy') return DEVICE_RESERVE_JOIN_TEXT
return 'Este aparelho ainda não participa desta comunidade. Para participar por ele, toque em Participar neste aparelho na lista de grupos. ' + reserveText(slots, 'comunidade')
}

// The node refuses a full group and an account at its 8 live devices there
// with the same words: the counts tell them apart. -> the text for the
// person, or null to keep the node's message (a full group, an older node).
export function slotFullText (slots, where = 'grupo') {
const full = (Array.isArray(slots) ? slots : []).filter((s) => s && Number.isSafeInteger(s.bound) && s.bound >= ACCOUNT_SLOTS)
const r = slotReturn(full)
if (full.length === 0 || r === 'legacy') return null
const head = 'Sua conta já usa as 8 vagas de aparelho ' + slotPlace(where)
return r === 'final' ? head + ', e aqui ' + SLOT_FINAL_TEXT : head + '. Para liberar a vaga, desconecte um aparelho antigo em ' + DEVICES_PATH + '.'
}

const FULL_REFUSALS = Object.freeze(['limite do grupo atingido', 'limite da comunidade atingido'])

// After a full-root refusal the counts are read again (`read`, which may
// throw): the rendered ones may predate a device that just enrolled.
// `slotsOf` is groupSlots or communitySlots. -> the error to show: a new one
// with the slot text, else `err` itself (an uncertain answer always is).
export async function slotRefusal (err, read, slotsOf, where = 'grupo') {
if (!err || err.uncertain === true || !FULL_REFUSALS.includes(err.message)) return err
let info = null
try {
info = await read()
} catch {}
const text = slotFullText(slotsOf(info), where)
return text === null ? err : new Error(text)
}

export function writerOnDevice (info) {
if (!info || typeof info !== 'object') return true
return info.writerHere !== false
Expand Down
27 changes: 20 additions & 7 deletions apps/app/src/screens/Comunidade.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { fetchCommunity } from '../indexClient'
import { relativeTime } from '../format'
import { readsAs } from '../who'
import {
AS_PAGE_LABEL, COMMUNITY_JOIN_LABELS, DEVICE_JOIN_LABEL, DEVICE_JOIN_TEXT, DEVICE_RESERVE_TEXT, DEVICE_WAIT_TEXT, GENERAL_LABEL, OWN_LABEL, PAGE_JOIN_LABEL, PAGE_LEAVE_LABEL, PRIVATE_LABEL,
can, communityReserveReached, lastIsOwn, needsReserveConfirm, lastLine, membersLabel, needsDeviceJoin, pageCommunities, pageErrorText, pageMode, pageRoleLabel, pageRoleOf, reconcile, roleLabel, showNewGroup, unreadLabel, visibilityLabel
AS_PAGE_LABEL, COMMUNITY_JOIN_LABELS, DEVICE_JOIN_LABEL, DEVICE_JOIN_TEXT, DEVICE_WAIT_TEXT, GENERAL_LABEL, OWN_LABEL, PAGE_JOIN_LABEL, PAGE_LEAVE_LABEL, PRIVATE_LABEL,
can, communityReserveReached, communitySlots, lastIsOwn, needsReserveConfirm, reserveText, slotRefusal, lastLine, membersLabel, needsDeviceJoin, pageCommunities, pageErrorText, pageMode, pageRoleLabel, pageRoleOf, reconcile, roleLabel, showNewGroup, unreadLabel, visibilityLabel
} from '../groups'
import { pagesOn } from '../pageGate'
import { actAs, pagesGroup } from '../pages'
Expand Down Expand Up @@ -378,7 +378,13 @@ export function Comunidade ({ community, afterGroup, isTop, seenTick, onBack, on
const doJoin = async () => {
setJoinNote('')
setCheck(null)
const res = await join.run(() => requestRef.current('community.join', { community }))
const res = await join.run(async () => {
try {
return await requestRef.current('community.join', { community })
} catch (err) {
throw await slotRefusal(err, () => requestRef.current('community.info', { community }), communitySlots, 'comunidade')
}
})
if (res.ok) {
const v = res.value || {}
if (v.group) setJoinNote('Você entrou no Geral.')
Expand All @@ -405,8 +411,9 @@ export function Comunidade ({ community, afterGroup, isTop, seenTick, onBack, on
setJoinNote('')
setCheck(null)
// At the reserve the first tap only shows the warning: the slot it would
// spend (community or Geral) never comes back. The counts are read fresh:
// the rendered ones may predate a writer that just landed.
// spend (community or Geral) comes back at best by disconnecting a device.
// The counts are read fresh: the rendered ones may predate a writer that
// just landed.
let fresh = info
if (!reserveConfirm) {
try {
Expand All @@ -417,7 +424,13 @@ export function Comunidade ({ community, afterGroup, isTop, seenTick, onBack, on
setReserveConfirm(true)
return
}
const res = await join.run(() => requestRef.current('community.join', { community }))
const res = await join.run(async () => {
try {
return await requestRef.current('community.join', { community })
} catch (err) {
throw await slotRefusal(err, () => requestRef.current('community.info', { community }), communitySlots, 'comunidade')
}
})
if (res.ok) {
setDeviceJoinSent(true)
load()
Expand Down Expand Up @@ -554,7 +567,7 @@ export function Comunidade ({ community, afterGroup, isTop, seenTick, onBack, on
? (
<View style={styles.block}>
<Soft>{DEVICE_JOIN_TEXT}</Soft>
{reserveConfirm || communityReserveReached(info) ? <Soft>{DEVICE_RESERVE_TEXT}</Soft> : null}
{reserveConfirm || communityReserveReached(info) ? <Soft>{reserveText(communitySlots(info), 'comunidade')}</Soft> : null}
<Btn label={DEVICE_JOIN_LABEL} onPress={doDeviceJoin} pending={join.pending} disabled={offline} />
<ErrorText>{join.error}</ErrorText>
</View>
Expand Down
6 changes: 3 additions & 3 deletions apps/app/src/screens/ComunidadeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { useMemberSearch } from '../useMemberSearch'
import { whoOf } from '../who'
import { shortKey } from '../format'
import {
COMMUNITY_JOIN_LABELS, DEVICE_PENDING_JOIN_TEXT, DEVICE_RESERVE_JOIN_TEXT, DEVICE_ROOT_TEXT, DEVICE_STAFF_TEXT,
authorityHere, can, communityReserveReached, deviceStaffNote, membersLabel, rootAdminHere, roleLabel, writerOnDevice
COMMUNITY_JOIN_LABELS, DEVICE_PENDING_JOIN_TEXT, DEVICE_ROOT_TEXT, DEVICE_STAFF_TEXT,
authorityHere, can, communityReserveReached, communitySlots, deviceStaffNote, membersLabel, reserveJoinText, rootAdminHere, roleLabel, writerOnDevice
} from '../groups'
import { Btn, ConfirmStack, ErrorText, Field, SectionHeader, Soft, UNCERTAIN, errorText, useAction, useBottomPad } from '../ui'
import { refusalOf } from '../wordCheck'
Expand Down Expand Up @@ -493,7 +493,7 @@ export function ComunidadeInfo ({ community, onBack, onOpenMember, onMessage })
</View>
)
: null}
{staffNote ? <View style={styles.block}><Soft>{staffNote === 'join' ? (communityReserveReached(info) ? DEVICE_RESERVE_JOIN_TEXT : DEVICE_PENDING_JOIN_TEXT) : staffNote === 'root' ? DEVICE_ROOT_TEXT : DEVICE_STAFF_TEXT}</Soft></View> : null}
{staffNote ? <View style={styles.block}><Soft>{staffNote === 'join' ? (communityReserveReached(info) ? reserveJoinText(communitySlots(info)) : DEVICE_PENDING_JOIN_TEXT) : staffNote === 'root' ? DEVICE_ROOT_TEXT : DEVICE_STAFF_TEXT}</Soft></View> : null}
{staff && authOk
? (
<View>
Expand Down
24 changes: 17 additions & 7 deletions apps/app/src/screens/Grupo.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ import { UNNAMED, readsAs, whoOf } from '../who'
import { copyText } from '../share'
import { shareNav } from '../shareNav'
import {
AS_PAGE_LABEL, DEVICE_APPROVAL_TEXT, DEVICE_JOIN_LABEL, DEVICE_JOIN_TEXT, DEVICE_RESERVE_TEXT, DEVICE_WAIT_TEXT,
AS_PAGE_LABEL, DEVICE_APPROVAL_TEXT, DEVICE_JOIN_LABEL, DEVICE_JOIN_TEXT, DEVICE_WAIT_TEXT,
EMPTY_PAGES, OWN_LABEL, PAGE_GROUP_LOADING_TEXT, PAGE_NO_KEY_TEXT, PAGE_JOIN_LABEL, PAGE_LEAVE_LABEL, PAGE_REKEYING_TEXT, PAGE_SEAL_AGAIN_LABEL, PRIVATE_LABEL, REKEY_PENDING_LABEL,
applyPage, mergeNewest, reloadDone, reloadWalks, can, canWriteHere, reserveReachedAny, needsReserveConfirm, itemsOf, knownVisibility, membersLabel, needsDeviceJoin, pageCan, pagePostVisibility, postAsPage, readAsPage, pageGroupErrorText, pageMode, pageRoleLabel, pageRoleOf, reconcile, roleLabel, roleOf, sealRaced, sealedLabel, visibilityLabel
applyPage, mergeNewest, reloadDone, reloadWalks, can, canWriteHere, communitySlots, groupSlots, reserveReachedAny, reserveText, slotRefusal, needsReserveConfirm, itemsOf, knownVisibility, membersLabel, needsDeviceJoin, pageCan, pagePostVisibility, postAsPage, readAsPage, pageGroupErrorText, pageMode, pageRoleLabel, pageRoleOf, reconcile, roleLabel, roleOf, sealRaced, sealedLabel, visibilityLabel
} from '../groups'
import { Btn, ConfirmStack, ErrorText, Notice, Soft, errorText, useAction, useNow } from '../ui'
import { useStyles, useTheme } from '../ui/ThemeProvider'
Expand Down Expand Up @@ -204,7 +204,7 @@ function GrupoScreen ({ group, onBack, onOpenCommunity, onOpenMember, onMessage,
const [communityJoin, setCommunityJoin] = useState(null)
const [communityWriterHere, setCommunityWriterHere] = useState(null)
// The community's and Geral's bound writers: the tap spends slots there too when it calls community.join.
const [communityBound, setCommunityBound] = useState([])
const [communitySlotsKnown, setCommunitySlotsKnown] = useState([])
const [needCommunity, setNeedCommunity] = useState(false)
// Set once a device join was sent (answered or not): a second tap could bind another writer.
const [deviceJoinSent, setDeviceJoinSent] = useState(false)
Expand Down Expand Up @@ -1280,7 +1280,7 @@ function GrupoScreen ({ group, onBack, onOpenCommunity, onOpenMember, onMessage,
if (typeof c.name === 'string') setCommunityName(c.name)
setCommunityJoin(typeof c.join === 'string' ? c.join : null)
setCommunityWriterHere(typeof c.writerHere === 'boolean' ? c.writerHere : null)
setCommunityBound([c.writersBound, c.generalWritersBound])
setCommunitySlotsKnown(communitySlots(c))
}, () => {})
return () => { live = false }
}, [hosted, heldCommunity, request, version])
Expand Down Expand Up @@ -1341,7 +1341,12 @@ function GrupoScreen ({ group, onBack, onOpenCommunity, onOpenMember, onMessage,
held = true
return null
}
const joined = await request('community.join', { community: communityKey })
let joined
try {
joined = await request('community.join', { community: communityKey })
} catch (err) {
throw await slotRefusal(err, () => request('community.info', { community: communityKey }), communitySlots, 'comunidade')
}
// Landed: a later tap must not send community.join again.
setCommunityWriterHere(true)
if (joined && joined.group === group) return joined
Expand All @@ -1351,7 +1356,11 @@ function GrupoScreen ({ group, onBack, onOpenCommunity, onOpenMember, onMessage,
held = true
return null
}
return await request('group.join', { group })
try {
return await request('group.join', { group })
} catch (err) {
throw await slotRefusal(err, () => request('group.info', { group }), groupSlots)
}
})
if (held) {
setReserveConfirm(true)
Expand Down Expand Up @@ -1693,10 +1702,11 @@ function GrupoScreen ({ group, onBack, onOpenCommunity, onOpenMember, onMessage,
const replyBar = replyKey !== null && !asPage.page ? (quoteOf(replyKey) || replyQuote) : null
let composer = null
if (reader && showJoinCard && !orphan) {
const reserveSlots = [...groupSlots(info), ...(communityWriterHere === false ? communitySlotsKnown : [])]
composer = (
<View style={styles.composer}>
<Soft>{DEVICE_JOIN_TEXT}</Soft>
{reserveConfirm || reserveReachedAny([info && info.writersBound, ...(communityWriterHere === false ? communityBound : [])]) ? <Soft>{DEVICE_RESERVE_TEXT}</Soft> : null}
{reserveConfirm || reserveReachedAny(reserveSlots.map((s) => s.bound)) ? <Soft>{reserveText(reserveSlots)}</Soft> : null}
<Btn label={DEVICE_JOIN_LABEL} onPress={enterHere} pending={join.pending} disabled={!node.online} />
<ErrorText>{join.error}</ErrorText>
</View>
Expand Down
8 changes: 6 additions & 2 deletions apps/app/src/vitrine/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ export function createVitrineRequest (fixtures, options) {
},
'group.info': ({ group }) => {
const g = groupOf(group)
return { ...groupRow(g), creator: g.creator, state: active(g) ? 'member' : g.role, orphan: communityOf(g.community).dropped.includes(g.group), visibility: g.visibility, memberInvite: g.memberInvite, writerHere: true, canWrite: active(g) && active(communityOf(g.community)) && !communityOf(g.community).dropped.includes(g.group), writersBound: 1 }
return { ...groupRow(g), creator: g.creator, state: active(g) ? 'member' : g.role, orphan: communityOf(g.community).dropped.includes(g.group), visibility: g.visibility, memberInvite: g.memberInvite, writerHere: true, canWrite: active(g) && active(communityOf(g.community)) && !communityOf(g.community).dropped.includes(g.group), writersBound: 1, writersFrozen: 0, frozenRoom: 8 }
},
'group.seen': ({ group, upTo }) => {
const g = groupOf(group)
Expand Down Expand Up @@ -1229,7 +1229,11 @@ export function createVitrineRequest (fixtures, options) {
rootHere: c.creator === data.own,
authorityHere: active(c) && (c.role === 'admin' || c.role === 'creator'),
writersBound: 1,
generalWritersBound: 1
writersFrozen: 0,
frozenRoom: 8,
generalWritersBound: 1,
generalWritersFrozen: 0,
generalFrozenRoom: 8
}
},
'feed.read': ({ limit, before }) => ({
Expand Down
Loading
Loading