summaryrefslogtreecommitdiff
path: root/bin/pi-forum
diff options
context:
space:
mode:
Diffstat (limited to 'bin/pi-forum')
-rwxr-xr-xbin/pi-forum17
1 files changed, 13 insertions, 4 deletions
diff --git a/bin/pi-forum b/bin/pi-forum
index 9d87440..37ea051 100755
--- a/bin/pi-forum
+++ b/bin/pi-forum
@@ -80,7 +80,9 @@ function forums() {
.sort((a, b) => a.createdAt - b.createdAt);
}
-// Agents running now, with their registrations.
+// Registered agents, each marked stopped when no pi is running for it: one a
+// signal or crash stopped while it was in a forum, which the next pi to open
+// its session takes back.
function agents() {
let files;
try {
@@ -90,7 +92,12 @@ function agents() {
}
return files
.map((f) => readJson(path.join(AGENTS, f)))
- .filter((a) => a && typeof a.id === "string" && typeof a.pid === "number" && alive(a.pid));
+ .filter((a) => a && typeof a.id === "string" && typeof a.pid === "number")
+ .map((a) => ({
+ ...a,
+ stopped: a.stoppedAt !== undefined || !alive(a.pid) || !fs.existsSync(path.join(AGENTS, `${a.id}.sock`)),
+ }))
+ .filter((a) => !a.stopped || (a.forums || []).length);
}
function find(arg) {
@@ -139,7 +146,8 @@ function format(post, no, forum, opts) {
}
function memberLine(a) {
- return ` ${who(a)}${dim(` ${a.cwd}`)}`;
+ if (!a.stopped) return ` ${who(a)}${dim(` ${a.cwd}`)}`;
+ return dim(` ${who(a)} stopped${a.stoppedAt ? ` since ${when(a.stoppedAt)}` : ""}`);
}
function list() {
@@ -154,7 +162,8 @@ function list() {
const members = live.filter((a) => (a.forums || []).includes(f.id));
const last = posts.length ? `, last ${when(posts[posts.length - 1].at)}` : "";
console.log(`${bold(f.name)} ${dim(`[${f.id}] ${posts.length} post(s)${last}`)}`);
- console.log(members.length ? members.map(memberLine).join("\n") : dim(" no members running"));
+ members.sort((a, b) => a.stopped - b.stopped);
+ console.log(members.length ? members.map(memberLine).join("\n") : dim(" no members"));
if (f.pin) console.log(` ${yellow("pin")}: ${f.pin.text} ${dim(`(${who(f.pin.by)}, ${when(f.pin.at)})`)}`);
console.log();
}