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 i18n/en.msg
Original file line number Diff line number Diff line change
Expand Up @@ -4474,6 +4474,7 @@ mobile.pill.waiting = Waiting
mobile.snooze.wakes = Wakes in {time}
mobile.bench.all = All projects
mobile.snooze.for = Snooze for
mobile.conn.reconnecting = Reconnecting…
# ---- end ----
# the sidebar's sections (docs/ALWAYS-ON.md section 8): the hub's words, and the window's
sidebar.sections.needs = Needs you
Expand Down
1 change: 1 addition & 0 deletions i18n/es.msg
Original file line number Diff line number Diff line change
Expand Up @@ -4476,6 +4476,7 @@ mobile.pill.waiting = En espera
mobile.snooze.wakes = Vuelve en {time}
mobile.bench.all = Todos los proyectos
mobile.snooze.for = Posponer
mobile.conn.reconnecting = Reconectando…
# ---- end ----
# the sidebar's sections (docs/ALWAYS-ON.md section 8): the hub's words, and the window's
sidebar.sections.needs = Te necesita
Expand Down
1 change: 1 addition & 0 deletions i18n/ja.msg
Original file line number Diff line number Diff line change
Expand Up @@ -4497,6 +4497,7 @@ mobile.pill.waiting = 待機中
mobile.snooze.wakes = {time}後に再開
mobile.bench.all = すべてのプロジェクト
mobile.snooze.for = スヌーズする期間
mobile.conn.reconnecting = 再接続中…
# ---- end ----
# the sidebar's sections (docs/ALWAYS-ON.md section 8): the hub's words, and the window's
sidebar.sections.needs = 対応が必要
Expand Down
66 changes: 55 additions & 11 deletions mobile/android/app/src/main/java/dev/backplane/mobile/DataClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,16 @@ object DataClient {
legacyCacheFile().delete()
setHome(""); leaveHome(); keepOutbox(Outbox()); links = emptyList(); adding = false; prefs().edit().remove("link").remove("links").apply(); reset(clearDisk = true); close(); conn = Conn.OFFLINE; needsRepair = false; pairingError = ""; askLink = null; pairEpoch++
}
private var sectionsJson: JSONArray? = null
private var groupsToJson: JSONArray? = null

private fun reset(clearDisk: Boolean = false) {
saveJob?.cancel()
shellHashes.clear(); threadHashes.clear(); threadIds.clear(); subEntriesById.clear(); subEntryIds = emptyList()
Swarms.reset(); restarting = null; hubBack = null; notice = HubNotice(); star = null; telemetryNotice = null; noProvider = null; migrating = null; migrateOpen = false; projects = emptyList(); threads = emptyList(); entries = emptyMap(); older = emptyMap(); listsLoaded = false; open = null
Swarms.reset(); restarting = null; hubBack = null; notice = HubNotice(); star = null; telemetryNotice = null; noProvider = null; migrating = null; migrateOpen = false
projects = emptyList(); threads = emptyList(); entries = emptyMap(); older = emptyMap(); listsLoaded = false; open = null
sections = emptyList(); groupsTo = emptyList(); sectionsJson = null; groupsToJson = null; features = emptySet(); bots = emptyList(); rooms = emptyList()
home = null
Swarms.reset(); notice = HubNotice(); star = null; telemetryNotice = null; noProvider = null; migrating = null; migrateOpen = false; projects = emptyList(); threads = emptyList(); entries = emptyMap(); older = emptyMap(); listsLoaded = false; open = null
if (clearDisk) link?.let { Pairing.key(it) }?.let { cacheFile(it).delete() }
}

Expand Down Expand Up @@ -395,8 +399,14 @@ object DataClient {
private suspend fun synchronise(g: Int) {
try {
if (has("shell") && machine.isEmpty()) {
val have = JSONObject().also { h -> shellHashes.forEach { (k, v) -> h.put(k, v) } }
val r = call("shell.sync", JSONObject().put("have", have).put("settled", 25))
if (sectionsOpen.isEmpty()) sectionsOpen = prefs().getStringSet("sections.open", emptySet())?.toSet() ?: emptySet()
val have = JSONObject().also { h ->
shellHashes.forEach { (k, v) ->
if ((k == "@sections" && sections.isEmpty()) || (k.startsWith("p:") && projects.isEmpty())) return@forEach
h.put(k, v)
}
}
val r = call("shell.sync", JSONObject().put("have", have).put("settled", 25).put("open", openArr()))
if (g != gen) return
listSub = r.optInt("sub")
val removed = r.optJSONArray("removed")?.let { a -> (0 until a.length()).map { a.optString(it) }.toSet() } ?: emptySet()
Expand All @@ -415,20 +425,25 @@ object DataClient {
}
}
r.optJSONObject("sections")?.let { s ->
sections = DSection.list(s.optJSONArray("sections"))
groupsTo = DSection.groups(s.optJSONArray("groupsTo"))
} ?: r.optJSONArray("sections")?.let { a -> sections = DSection.list(a) }
sectionsJson = s.optJSONArray("sections")
groupsToJson = s.optJSONArray("groupsTo")
sections = DSection.list(sectionsJson)
groupsTo = DSection.groups(groupsToJson)
} ?: r.optJSONArray("sections")?.let { a ->
sectionsJson = a
sections = DSection.list(a)
}
r.optJSONObject("h")?.let { h ->
val next = HashMap<String, String>()
h.keys().forEach { k -> next[k] = h.optString(k) }
shellHashes = next
}
listsLoaded = true; save()
coroutineScope { launch { runCatching { loadLocks() } }; launch { runCatching { loadStar() } }; launch { runCatching { loadTelemetryNotice() } }; launch { loadHistory() }; launch { Swarms.load() } }
coroutineScope { launch { runCatching { if (has("bots")) loadBots() } }; launch { runCatching { loadLocks() } }; launch { runCatching { loadStar() } }; launch { runCatching { loadTelemetryNotice() } }; launch { loadHistory() }; launch { Swarms.load() } }
} else {
listSub = call("subscribe", JSONObject().put("topic", "lists")).optInt("sub")
if (g != gen) return
coroutineScope { launch { loadProjects(g) }; launch { loadThreads(g) }; launch { runCatching { loadLocks() } }; launch { runCatching { loadStar() } }; launch { runCatching { loadTelemetryNotice() } }; launch { loadHistory() }; launch { Swarms.load() }; launch { loadSections() } }
coroutineScope { launch { loadProjects(g) }; launch { loadThreads(g) }; launch { runCatching { if (has("bots")) loadBots() } }; launch { runCatching { loadLocks() } }; launch { runCatching { loadStar() } }; launch { runCatching { loadTelemetryNotice() } }; launch { loadHistory() }; launch { Swarms.load() }; launch { loadSections() } }
}
syncPush()
open?.let { if (has("open")) openThreadBundled(it, g) else { subscribeThread(it, g); refreshThread(it) } }
Expand All @@ -446,7 +461,9 @@ object DataClient {
if (!has("sections")) return
if (sectionsOpen.isEmpty()) sectionsOpen = prefs().getStringSet("sections.open", emptySet())?.toSet() ?: emptySet()
val r = runCatching { call("sidebar.sections", JSONObject().put("open", openArr())) }.getOrNull() ?: return
sections = DSection.list(r.optJSONArray("sections")); groupsTo = DSection.groups(r.optJSONArray("groupsTo"))
sectionsJson = r.optJSONArray("sections"); groupsToJson = r.optJSONArray("groupsTo")
sections = DSection.list(sectionsJson); groupsTo = DSection.groups(groupsToJson)
save()
}
fun toggleSection(t: String) { sectionsOpen = if (t in sectionsOpen) sectionsOpen - t else sectionsOpen + t; prefs().edit().putStringSet("sections.open", sectionsOpen).apply(); scope.launch { loadSections() } }
fun sidebarAct(action: String, value: String) { scope.launch { runCatching { call("sidebar.act", JSONObject().put("action", action).put("value", value)) }; loadSections() } }
Expand Down Expand Up @@ -1117,6 +1134,7 @@ object DataClient {
}
rooms = r.optJSONArray("rooms")?.let { a -> (0 until a.length()).mapNotNull { a.optJSONObject(it) }.map { Room(it.optString("id"), it.optString("name"), it.optJSONObject("mark")?.optString("short") ?: "", it.optBoolean("delete")) } } ?: emptyList()
if (uberAfterPair) bots.firstOrNull { it.uber && it.thread.isNotEmpty() }?.let { uberAfterPair = false; linkTarget = LinkTarget(LinkTarget.Kind.THREAD, it.thread) }
save()
}
data class Post(val from: String, val text: String, val at: Long, val copy: List<CopyPiece>? = null)
suspend fun roomPosts(room: String): List<Post> = call("room.posts", JSONObject().put("room", room).put("limit", 60)).optJSONArray("posts")?.let { a -> (0 until a.length()).mapNotNull { a.optJSONObject(it) }.map { Post(it.optString("from"), it.optString("text"), it.optLong("at"), parseCopy(it.optJSONArray("copy"))) } } ?: emptyList()
Expand Down Expand Up @@ -1374,7 +1392,24 @@ object DataClient {
val c = JSONObject(f.readText()); if (c.optString("hub") != hub) return
projects = parseProjects(c.optJSONArray("projects")); threads = parseThreads(c.optJSONArray("threads"))
val e = c.optJSONObject("entries"); entries = e?.keys()?.asSequence()?.associateWith { parseEntries(e.optJSONArray(it)) } ?: emptyMap()
listsLoaded = threads.isNotEmpty() || projects.isNotEmpty()
c.optJSONArray("features")?.let { a -> features = (0 until a.length()).mapNotNull { a.optString(it).takeIf(String::isNotEmpty) }.toSet() }
c.optJSONArray("sections")?.let { a -> sectionsJson = a; sections = DSection.list(a) }
c.optJSONArray("groupsTo")?.let { a -> groupsToJson = a; groupsTo = DSection.groups(a) }
c.optJSONArray("bots")?.let { a ->
bots = (0 until a.length()).mapNotNull { a.optJSONObject(it) }.map {
Bot(it.optString("id"), it.optString("name"), it.optString("thread"), it.optBoolean("uber"), it.optString("markShort"), it.optString("note"), it.optBoolean("delete"), it.optInt("look"), it.optString("color"),
it.optJSONObject("ask")?.let { ak -> Ask(ak.optString("title"), ak.optString("body"), ak.optString("yes")) } ?: Ask())
}
}
c.optJSONArray("rooms")?.let { a ->
rooms = (0 until a.length()).mapNotNull { a.optJSONObject(it) }.map { Room(it.optString("id"), it.optString("name"), it.optString("markShort"), it.optBoolean("delete")) }
}
c.optJSONObject("shellHashes")?.let { h ->
val next = HashMap<String, String>()
h.keys().forEach { k -> next[k] = h.optString(k) }
shellHashes = next
}
listsLoaded = threads.isNotEmpty() || projects.isNotEmpty() || sections.isNotEmpty()
}
}
private fun save() {
Expand All @@ -1383,13 +1418,22 @@ object DataClient {
delay(1000)
val hub = link?.let { Pairing.key(it) } ?: return@launch
val ps = projects; val ts = threads
val fs = features.sorted()
val sec = sectionsJson; val gto = groupsToJson
val bs = bots; val rs = rooms
val sh = HashMap(shellHashes)
val recent = ts.take(20).map { it.id }.toSet()
val es = entries.filterKeys { it in recent }.mapValues { (_, v) -> v.filter { !it.sending && !it.failed }.takeLast(40) }
withContext(Dispatchers.IO) {
val j = JSONObject().put("hub", hub)
.put("projects", JSONArray(ps.map { JSONObject().put("id", it.id).put("title", it.title).put("root", it.root).put("threadCount", it.threadCount).apply { it.settledCount?.let { n -> put("settledCount", n) } }.put("updatedAt", it.updatedAt).put("waiting", it.waiting).put("also", it.also).put("mark", markJson(it.mark)) }))
.put("threads", JSONArray(ts.map { JSONObject().put("id", it.id).put("project", it.project).put("title", it.title).put("state", it.state).put("updatedAt", it.updatedAt).put("pinned", it.pinned).put("pinOrder", it.pinOrder).put("settled", it.settled).put("settledAt", it.settledAt).put("archived", it.archived).put("provider", it.provider).put("model", it.model).put("effort", it.effort).put("runtime", it.runtime).put("chip", it.chip).put("preview", it.preview).put("waiting", it.waiting).put("mark", markJson(it.mark)).put("swarm", it.swarm).apply { it.planMode?.let { pm -> put("planMode", planModeJson(pm)) } } }))
.put("entries", JSONObject().also { o -> es.forEach { (k, v) -> o.put(k, JSONArray(v.map(::J))) } })
.put("features", JSONArray(fs))
.apply { if (sec != null) put("sections", sec); if (gto != null) put("groupsTo", gto) }
.put("bots", JSONArray(bs.map { JSONObject().put("id", it.id).put("name", it.name).put("thread", it.thread).put("uber", it.uber).put("markShort", it.mark).put("note", it.note).put("delete", it.delete).put("look", it.look).put("color", it.color).put("ask", JSONObject().put("title", it.ask.title).put("body", it.ask.body).put("yes", it.ask.yes)) }))
.put("rooms", JSONArray(rs.map { JSONObject().put("id", it.id).put("name", it.name).put("markShort", it.mark).put("delete", it.delete) }))
.put("shellHashes", JSONObject().also { o -> sh.forEach { (k, v) -> o.put(k, v) } })
runCatching { cacheFile(hub).writeText(j.toString()) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ private fun ConnBanner(hub: () -> Unit, settings: () -> Unit) {
// the hub's restart (RestartStrip.kt) says itself here in place of the usual look: while it is away, and its crash note as we join
val online = DataClient.conn == DataClient.Conn.ONLINE
val restart = DataClient.restartText
val hasCached = DataClient.listsLoaded || DataClient.sections.isNotEmpty() || DataClient.projects.isNotEmpty()
if (online && restart == null) return
if (!online && restart == null && DataClient.conn == DataClient.Conn.CONNECTING && hasCached) return
Row(Modifier.fillMaxWidth().background(dcs.surfaceContainerHigh).padding(horizontal = 12.dp, vertical = 6.dp).testTag("conn.strip"), verticalAlignment = Alignment.CenterVertically) {
DDot(if (online) dcs.primary else if (restart != null || DataClient.conn == DataClient.Conn.CONNECTING) dwarn else dcs.error, 8); Spacer(Modifier.width(8.dp))
DMono(restart?.let { Tr.t(it) } ?: if (DataClient.conn == DataClient.Conn.CONNECTING) Msg.android_conn_connecting(DataClient.hubName) else Msg.android_conn_offline, dcs.onSurface, 12, Modifier.weight(1f))
Expand Down Expand Up @@ -344,7 +346,6 @@ private fun HomeScreen(open: (String) -> Unit, settings: () -> Unit, hub: () ->
var shut by remember { mutableStateOf(prefs.getStringSet("projects.shut", emptySet())!!.toSet()) }
var treeOpen by remember { mutableStateOf(prefs.getStringSet("tree.open", emptySet())!!.toSet()) } // parents whose subthreads show
val termsOpen = LocalTermsOpen.current
LaunchedEffect(DataClient.conn) { DataClient.refresh(); if (DataClient.conn == DataClient.Conn.ONLINE && DataClient.has("bots")) runCatching { DataClient.loadBots() } }
val listState = androidx.compose.foundation.lazy.rememberLazyListState()
var flash by remember { mutableStateOf("") }
val rowOf = remember { mutableMapOf<String, Int>() } // a project's header row in the list
Expand Down Expand Up @@ -557,6 +558,21 @@ private fun HomeScreen(open: (String) -> Unit, settings: () -> Unit, hub: () ->
}
}
}
if (DataClient.conn == DataClient.Conn.CONNECTING && DataClient.restartText == null && (DataClient.listsLoaded || DataClient.sections.isNotEmpty() || DataClient.projects.isNotEmpty())) {
Row(
Modifier
.align(Alignment.BottomCenter)
.padding(bottom = 10.dp)
.background(dcs.surfaceContainerHigh, RectangleShape)
.border(BorderStroke(1.dp, dcs.outlineVariant), RectangleShape)
.padding(horizontal = 10.dp, vertical = 5.dp)
.testTag("conn.reconnecting"),
verticalAlignment = Alignment.CenterVertically,
) {
DDot(dwarn, 6); Spacer(Modifier.width(6.dp))
DMono(Msg.mobile_conn_reconnecting, dcs.onSurfaceVariant, 11)
}
}
}
}
DLine()
Expand Down
Loading
Loading