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
50 changes: 42 additions & 8 deletions apps/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ import { refreshMomentSeen } from './src/momentSeenStore'
import SalvosScreen from './src/screens/Salvos'
import EventosScreen from './src/screens/Eventos'
import VisitasScreen from './src/screens/Visitas'
import VarandinhaScreen from './src/screens/Varandinha'
import VarandinhaRuaScreen from './src/screens/VarandinhaRua'
import MomentosScreen from './src/screens/Momentos'
import FeiraScreen from './src/screens/Feira'
import AnuncioScreen from './src/screens/Anuncio'
Expand Down Expand Up @@ -256,6 +258,8 @@ const Assunto = memo(AssuntoScreen)
const Recados = memo(RecadosScreen)
const Eventos = memo(EventosScreen)
const Visitas = memo(VisitasScreen)
const Varandinha = memo(VarandinhaScreen)
const VarandinhaRua = memo(VarandinhaRuaScreen)
const Mensagens = memo(MensagensScreen)
const Mensagem = memo(MensagemScreen)
const Anuncio = memo(AnuncioScreen)
Expand Down Expand Up @@ -2253,6 +2257,11 @@ function Member () {
pushScreen({ screen: 'recados', key: key.toLowerCase(), params: {} })
}, [pushScreen])
const openVisitas = useCallback(() => pushScreen({ screen: 'visitas' }), [pushScreen])
const openVarandinha = useCallback((key) => {
if (typeof key !== 'string') return
pushScreen({ screen: 'varandinha', key: key.toLowerCase(), params: {} })
}, [pushScreen])
const openVarandinhaRua = useCallback(() => pushScreen({ screen: 'varandinha-rua' }), [pushScreen])
const openEventos = useCallback((key) => {
if (typeof key !== 'string') return
pushScreen({ screen: 'eventos', key: key.toLowerCase(), params: {} })
Expand Down Expand Up @@ -2318,11 +2327,13 @@ function Member () {
const helpOpen = useHelpOpen()
const helpOpenRef = useRef(helpOpen)
helpOpenRef.current = helpOpen
const backGuardRef = useRef(null)
// Every registered guard checks at call time that its own screen is on top,
// so at most one of them answers a back press.
const backGuardsRef = useRef(new Set())
const registerBackGuard = useCallback((fn) => {
backGuardRef.current = fn
backGuardsRef.current.add(fn)
return () => {
if (backGuardRef.current === fn) backGuardRef.current = null
backGuardsRef.current.delete(fn)
}
}, [])
// Help opened inside Ajustes or Denunciar keeps sheetOpen true, so it stays.
Expand Down Expand Up @@ -3206,10 +3217,14 @@ function Member () {
})
}, [action, node.online, inviteTick])
useEffect(() => {
const guarded = () => {
for (const fn of backGuardsRef.current) if (fn() === true) return true
return false
}
if (Platform.OS === 'android') {
const sub = BackHandler.addEventListener('hardwareBackPress', () => {
if (helpOpenRef.current || sheetOpenRef.current) return false
if (backGuardRef.current?.() === true) return true
if (guarded()) return true
if (nav.depth(stackRef.current) === 0) {
if (tabRef.current !== 'avisos') return false
closeAvisos()
Expand All @@ -3224,7 +3239,7 @@ function Member () {
if (Platform.OS !== 'web' || typeof globalThis.addEventListener !== 'function') return
const onKey = (event) => {
if (event.key !== 'Escape' || event.defaultPrevented || helpOpenRef.current || sheetOpenRef.current) return
if (backGuardRef.current?.() === true) {
if (guarded()) {
event.preventDefault()
return
}
Expand Down Expand Up @@ -3853,6 +3868,7 @@ function Member () {
handleOpenRecados: node.hosted === true ? openRecados : undefined,
handleOpenEventos: node.hosted === true ? openEventos : undefined,
handleOpenVisitas: node.hosted === true ? openVisitas : undefined,
handleOpenVarandinha: node.hosted === true ? openVarandinha : undefined,
handleOpenAgenda: node.hosted === true ? openAgenda : undefined,
handleOpenTop: node.hosted === true ? openTop : undefined,
handleComposeSeen: () => setComposeSignal(null),
Expand Down Expand Up @@ -3880,6 +3896,7 @@ function Member () {
onOpenPeople: openPeople,
onOpenTestimonials: openTestimonials,
onOpenRecados: h.handleOpenRecados,
onOpenVarandinha: h.handleOpenVarandinha,
onOpenEventos: h.handleOpenEventos,
onOpenListings: h.handleOpenListings
}
Expand Down Expand Up @@ -3935,6 +3952,23 @@ function Member () {
</StackLayer>
)
}
if (entry.screen === 'varandinha') {
// Queued acts make Android Back and Escape ask first, as the top bar
// arrow does; the guard answers only while this entry is on top.
const guardRegistrar = entryHandlers.current.for(i + ':varandinha', { handleRegisterBackGuard: (fn) => registerBackGuard(() => stackRef.current.length - 1 === i && stackRef.current[i].screen === 'varandinha' && fn()) }).handleRegisterBackGuard
return (
<StackLayer key={i + ':varandinha:' + entry.key + ':' + nodeEpoch} motion={stackMotion} index={i} entry={entry} onPop={goBack}>
<Varandinha entry={entry} ownKey={ownKey} onBack={goBack} onOpenStreet={openVarandinhaRua} onToast={h.handleShowToast} registerBackGuard={guardRegistrar} />
</StackLayer>
)
}
if (entry.screen === 'varandinha-rua') {
return (
<StackLayer key={i + ':varandinha-rua:' + nodeEpoch} motion={stackMotion} index={i} entry={entry} onPop={goBack}>
<VarandinhaRua ownKey={ownKey} onBack={goBack} onOpenBalcony={openVarandinha} />
</StackLayer>
)
}
if (entry.screen === 'melhores-amigos') {
return (
<StackLayer key={i + ':melhores-amigos:' + nodeEpoch} motion={stackMotion} index={i} entry={entry} onPop={goBack}>
Expand Down Expand Up @@ -4051,8 +4085,7 @@ function Member () {
}
if (entry.screen === 'anunciar') {
// Anunciar registers once per mount, so the guard checks the stack at
// call time. backGuardRef holds one guard and Anunciar is its only
// registrant: a second one would need Anunciar to register again.
// call time and answers only while this entry is on top.
const guardRegistrar = entryHandlers.current.for(i + ':anunciar', { handleRegisterBackGuard: (fn) => registerBackGuard(() => stackRef.current.length - 1 === i && stackRef.current[i].screen === 'anunciar' && fn()) }).handleRegisterBackGuard
return (
<StackLayer key={i + ':anunciar:' + actingIdentity} motion={stackMotion} index={i} entry={entry} onPop={goBack}>
Expand Down Expand Up @@ -4348,6 +4381,7 @@ function Member () {
onOpenRecados={h.handleOpenRecados}
onOpenEventos={h.handleOpenEventos}
onOpenVisitas={h.handleOpenVisitas}
onOpenVarandinha={h.handleOpenVarandinha}
onOpenTop={h.handleOpenTop}
/>
)}
Expand Down Expand Up @@ -4487,7 +4521,7 @@ function Member () {
showToast(text)
}}
/>
<Ajustes key={locked ? 'locked' : 'open'} screen={ajustes} onNavigate={navigateAjustes} onClose={() => setAjustes(null)} onInfo={ajustesInfo} termsInfo={termsInfo} onTermsReset={dropTermsAndSync} scheduledDeletion={scheduledDeletion} onDeletionChanged={refreshAccount} inviteNudge={inviteNudge} onOpenPaginas={!deleteFromAviso && pagesOn({ hosted: node.hosted, accountOrigin: node.accountOrigin }) ? () => pushScreen({ screen: 'paginas' }) : undefined} node={node} member={member} phoneGate={phone.gate} phoneKey={phone.key} phoneChecking={phone.pending} phoneVerified={phone.state === 'verificado' && !phone.error} markVerified={markPhoneVerified} recheckPhone={recheckPhone} termsBeforeCreate={termsBeforeCreate} />
<Ajustes key={locked ? 'locked' : 'open'} screen={ajustes} onNavigate={navigateAjustes} onClose={() => setAjustes(null)} onInfo={ajustesInfo} termsInfo={termsInfo} onTermsReset={dropTermsAndSync} scheduledDeletion={scheduledDeletion} onDeletionChanged={refreshAccount} inviteNudge={inviteNudge} onOpenVarandinha={!deleteFromAviso && node.hosted === true && ownKey ? () => openVarandinha(ownKey) : undefined} onOpenPaginas={!deleteFromAviso && pagesOn({ hosted: node.hosted, accountOrigin: node.accountOrigin }) ? () => pushScreen({ screen: 'paginas' }) : undefined} node={node} member={member} phoneGate={phone.gate} phoneKey={phone.key} phoneChecking={phone.pending} phoneVerified={phone.state === 'verificado' && !phone.error} markVerified={markPhoneVerified} recheckPhone={recheckPhone} termsBeforeCreate={termsBeforeCreate} />
{/* Mounted after the splash, so it wins: while the boot cover shows it
follows the splash, which stays cream on native (Splash.js). */}
<StatusBar style={coveringBoot ? statusBarStyle(Platform.OS === 'web' || previewOn ? scheme : 'light') : statusBarStyle(scheme, { overBand: light || viewerOnTop })} />
Expand Down
33 changes: 32 additions & 1 deletion apps/app/src/garden.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function emptyBalcony () {
on: false,
pots: new Array(rpc.garden.GARDEN_POTS).fill(null),
helpers: [],
received: new Array(rpc.garden.GARDEN_POTS).fill(0),
isPage: false,
stale: false,
loading: false,
Expand Down Expand Up @@ -168,12 +169,42 @@ export function assembleBalcony (args) {
helps.push({ author: row.author, seq: row.seq, record, follow })
}
const folded = rpc.garden.foldBalcony({ owner, flag, state, helps, given, now })
return { on: folded.on, pots: folded.pots, helpers: folded.helpers, isPage: false, stale: folded.stale, loading, incomplete, indexing: idx.indexing, refetch }
// Helps counted per pot, as the fold counts them: the helper list keeps
// one row per neighbour, but a neighbour's helps of several days each
// count.
const received = folded.on && state !== null
? rpc.garden.foldHelps({ owner, pots: state.pots, helps, now }).perPot
: new Array(rpc.garden.GARDEN_POTS).fill(0)
return { on: folded.on, pots: folded.pots, helpers: folded.helpers, received, isPage: false, stale: folded.stale, loading, incomplete, indexing: idx.indexing, refetch }
} catch {
return emptyBalcony()
}
}

// Whether a balcony read proves its owner is not playing: an off answer
// counts only when both first blocks and every pointer were read, the index
// was complete and nothing was dated ahead of the reader.
export function provenOff (result, forced) {
return isObject(result) && result.isPage !== true && result.on === false && result.indexing !== true &&
result.incomplete !== true && result.stale !== true && forced !== true
}

// Varandas da rua: the seeder's street page is a claim, so only keys the
// viewer's own follow list holds are offered, once each, in the seeder's
// order. Without a follow set nothing is offered.
export function streetKeys (items, follows) {
if (!Array.isArray(items) || !(follows instanceof Set)) return []
const out = []
const seen = new Set()
for (const it of items) {
const key = isObject(it) && typeof it.key === 'string' ? it.key.toLowerCase() : null
if (key === null || !HEX64.test(key) || seen.has(key) || !follows.has(key)) continue
seen.add(key)
out.push(key)
}
return out
}

export function nextLoadStep (args) {
const { attempt, result } = isObject(args) ? args : {}
if (!isObject(result) || result.refetch !== true) return 'done'
Expand Down
21 changes: 21 additions & 0 deletions apps/app/src/gardenClock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* global __DEV__ */

// The reader clock of the Varandinha screens. Growth, the dry check and the
// 72 h help window are judged on the reader's own clock, so this is
// Date.now(). The Vitrine answers on its demo clock instead (fixtures.now,
// plus a second per write), so a Vitrine bundle reads that clock here too:
// on the real clock every demo plant would read ripe, no demo watering would
// fall inside the window, and nothing could be watered.

import { vitrineEnabled } from './vitrine/enabled.js'

const VITRINE = vitrineEnabled({ EXPO_PUBLIC_VARANDA_VITRINE: process.env.EXPO_PUBLIC_VARANDA_VITRINE }, typeof __DEV__ !== 'undefined' && __DEV__)
let offset = 0
if (typeof __DEV__ !== 'undefined' && __DEV__ && process.env.EXPO_PUBLIC_VARANDA_VITRINE === '1' && VITRINE) {
const { fixtures } = require('./vitrine/fixtures')
offset = Date.parse(fixtures.now) - Date.now()
}

export function gardenTime (ms = Date.now()) {
return ms + offset
}
Loading
Loading