Skip to content

Commit 7227c73

Browse files
fix(mobile): remove inaccurate activity timer and format Kotlin
1 parent 5e23def commit 7227c73

4 files changed

Lines changed: 55 additions & 24 deletions

File tree

‎apps/mobile/modules/t3-agent-notifications/android/src/main/java/expo/modules/t3agentnotifications/AgentActivityPresentation.kt‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ internal class ActivityPresentation(data: Map<String, String>, private val activ
106106
private val attentionCount = data["activity_attention_count"]?.toIntOrNull()?.coerceAtLeast(0)
107107
?: rows.count { ActivityPhase.forStatus(it.status)?.needsUser == true }
108108
private val failedCount = rows.count { it.status == ActivityPhase.FAILED.status }
109-
val threadCount = activeCount + rows.count { ActivityPhase.forStatus(it.status)?.finished == true }
109+
val threadCount =
110+
activeCount + rows.count { ActivityPhase.forStatus(it.status)?.finished == true }
110111
private val singleProject = rows.map { it.project }.distinct().size == 1
111112
private val legacyBody = (0..4).mapNotNull { data["activity_line_$it"]?.take(300) }
112113
.takeIf { it.isNotEmpty() }?.joinToString("\n")
113114
?: data["activity_body"].orEmpty().take(240)
114-
/** Epoch millis the priority thread entered its phase; drives the waiting chronometer. */
115-
val since = data["activity_since"]?.toLongOrNull()?.takeIf { it > 0 }
116115

117116
val summary = when {
118-
hero == null -> data["activity_title"]?.takeIf { it.isNotBlank() }?.take(120) ?: "Agent activity"
117+
hero == null -> data["activity_title"]?.takeIf { it.isNotBlank() }?.take(120)
118+
?: "Agent activity"
119119
rows.size == 1 -> hero.title
120120
attentionCount == 1 -> "1 needs you"
121121
attentionCount > 1 -> "$attentionCount need you"
@@ -128,7 +128,8 @@ internal class ActivityPresentation(data: Map<String, String>, private val activ
128128
val chip = when {
129129
!active -> null
130130
phase == null -> data["activity_chip"]?.takeIf { it.isNotBlank() }?.take(7) ?: "Active"
131-
phase == ActivityPhase.RUNNING && activeCount > 1 -> "${if (activeCount > 9) "9+" else activeCount} live"
131+
phase == ActivityPhase.RUNNING && activeCount > 1 ->
132+
"${if (activeCount > 9) "9+" else activeCount} live"
132133
else -> phase.chip
133134
}
134135

@@ -166,13 +167,9 @@ internal class ActivityPresentation(data: Map<String, String>, private val activ
166167
val lineBreak = body.indexOf('\n')
167168
val firstLine = if (lineBreak >= 0) body.subSequence(0, lineBreak) else body
168169
builder.setContentText(firstLine).setStyle(NotificationCompat.BigTextStyle().bigText(body))
169-
// How long the agent has been blocked on you. System UI owns the ticking, so
170-
// there is nothing to repaint and no push needed to keep it current.
171-
if (active && phase?.needsUser == true && since != null) {
172-
builder.setWhen(since).setShowWhen(true).setUsesChronometer(true)
173-
} else {
174-
builder.setShowWhen(false).setUsesChronometer(false)
175-
}
170+
// Thread update timestamps can change while an approval remains pending.
171+
// Leave the timer hidden until the payload has a stable phase-entry timestamp.
172+
builder.setShowWhen(false).setUsesChronometer(false)
176173
}
177174

178175
private fun statusLine(context: Context, row: ActivityRow, trailing: String): CharSequence =

‎apps/mobile/modules/t3-agent-notifications/android/src/test/java/expo/modules/t3agentnotifications/AgentNotificationsTest.kt‎

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,12 @@ class AgentNotificationsTest {
297297
fun severalThreadsListEveryRowWithItsStatusAndActionsFollowThePriorityThread() {
298298
lifecycle.currentState = Lifecycle.State.RESUMED
299299
val title = "A long thread title that should wrap rather than disappear"
300-
val since = System.currentTimeMillis() - 4 * 60 * 1000L
301300
val data = update("attention", true) + mapOf(
302301
"activity_line_0" to "Approval $title Project",
303302
"activity_line_1" to "Working Another thread Other project",
304303
"activity_phase" to "waiting_for_approval",
305304
"activity_active_count" to "8",
306305
"activity_attention_count" to "1",
307-
"activity_since" to since.toString(),
308306
)
309307
AgentNotifications.receive(context, data)
310308
val card = manager.activeNotifications.single().notification
@@ -314,15 +312,16 @@ class AgentNotificationsTest {
314312
"Approval $title · Project\nWorking Another thread · Other project",
315313
card.extras.getCharSequence(Notification.EXTRA_BIG_TEXT).toString()
316314
)
317-
assertEquals("Approval $title · Project", card.extras.getCharSequence(Notification.EXTRA_TEXT).toString())
315+
assertEquals(
316+
"Approval $title · Project",
317+
card.extras.getCharSequence(Notification.EXTRA_TEXT).toString()
318+
)
318319
assertEquals(listOf("Approve", "Dismiss"), card.actions.map { it.title.toString() })
319320
assertEquals(
320321
"t3code-dev://threads/environment/thread",
321322
shadowOf(card.actions[0].actionIntent).savedIntent.dataString
322323
)
323324
assertEquals("Approve", card.extras.getString(NotificationCompat.EXTRA_SHORT_CRITICAL_TEXT))
324-
assertEquals(since, card.`when`)
325-
assertTrue(card.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER))
326325

327326
AgentNotifications.receive(
328327
context,
@@ -342,6 +341,29 @@ class AgentNotificationsTest {
342341
assertEquals("Answer", next.extras.getString(NotificationCompat.EXTRA_SHORT_CRITICAL_TEXT))
343342
}
344343

344+
@Test
345+
fun waitingCardsIgnoreMutableThreadTimestampsEvenAfterRename() {
346+
lifecycle.currentState = Lifecycle.State.RESUMED
347+
val now = System.currentTimeMillis()
348+
for (phase in listOf("waiting_for_approval", "waiting_for_input")) {
349+
val status = if (phase == "waiting_for_approval") "Approval" else "Input"
350+
for ((title, updatedAt) in listOf("Original" to now - 1200000L, "Renamed" to now)) {
351+
AgentNotifications.receive(
352+
context,
353+
update("waiting", true) + mapOf(
354+
"activity_line_0" to "$status\t$title\tProject",
355+
"activity_phase" to phase,
356+
"activity_since" to updatedAt.toString()
357+
)
358+
)
359+
val card = manager.activeNotifications.single().notification
360+
assertEquals(title, card.extras.getCharSequence(Notification.EXTRA_TITLE).toString())
361+
assertFalse(card.extras.getBoolean(Notification.EXTRA_SHOW_WHEN))
362+
assertFalse(card.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER))
363+
}
364+
}
365+
}
366+
345367
@Test
346368
fun aSingleThreadUsesItsTitleAndNeverShowsAProgressBar() {
347369
lifecycle.currentState = Lifecycle.State.RESUMED
@@ -351,12 +373,24 @@ class AgentNotificationsTest {
351373
)
352374
AgentNotifications.receive(context, data)
353375
val working = manager.activeNotifications.single().notification
354-
assertEquals("Update dashboard", working.extras.getCharSequence(Notification.EXTRA_TITLE).toString())
355-
assertEquals("Working Project", working.extras.getCharSequence(Notification.EXTRA_BIG_TEXT).toString())
376+
assertEquals(
377+
"Update dashboard",
378+
working.extras.getCharSequence(Notification.EXTRA_TITLE).toString()
379+
)
380+
assertEquals(
381+
"Working Project",
382+
working.extras.getCharSequence(Notification.EXTRA_BIG_TEXT).toString()
383+
)
356384
assertEquals(null, working.extras.getString(Notification.EXTRA_SUB_TEXT))
357385
assertEquals("Working", working.extras.getString(NotificationCompat.EXTRA_SHORT_CRITICAL_TEXT))
358386
assertFalse(working.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER))
359-
for (phase in listOf("waiting_for_approval", "waiting_for_input", "stale", "failed", "completed")) {
387+
for (phase in listOf(
388+
"waiting_for_approval",
389+
"waiting_for_input",
390+
"stale",
391+
"failed",
392+
"completed"
393+
)) {
360394
val active = phase != "failed" && phase != "completed"
361395
AgentNotifications.receive(
362396
context,
@@ -430,7 +464,10 @@ class AgentNotificationsTest {
430464
)
431465
)
432466
val finished = manager.activeNotifications.single().notification
433-
assertEquals("Finished, 1 failed", finished.extras.getCharSequence(Notification.EXTRA_TITLE).toString())
467+
assertEquals(
468+
"Finished, 1 failed",
469+
finished.extras.getCharSequence(Notification.EXTRA_TITLE).toString()
470+
)
434471
assertEquals("Project · 2 threads", finished.extras.getString(Notification.EXTRA_SUB_TEXT))
435472
}
436473

‎infra/relay/src/agentActivity/FcmDeliveries.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,6 @@ describe("Android delivery routing", () => {
620620
expect(data.activity_phase).toBe("waiting_for_approval");
621621
expect(data.activity_active_count).toBe("3");
622622
expect(data.activity_attention_count).toBe("2");
623-
expect(data.activity_since).toBe(String(Date.parse(state.updatedAt)));
624623
const input = androidActivityData(aggregateFor([{ ...state, phase: "waiting_for_input" }]));
625624
expect(input.activity_phase).toBe("waiting_for_input");
626625
expect(input.activity_active_count).toBe("1");

‎infra/relay/src/agentActivity/fcmPayloads.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ export function androidActivityData(aggregate: RelayAgentActivityAggregateState
4646
activity_phase: hero?.phase ?? "",
4747
activity_active_count: String(activeCount),
4848
activity_attention_count: String(attentionCount),
49-
// When the priority thread started waiting on the user; the card shows it as a chronometer.
50-
activity_since: hero ? String(Math.max(0, Date.parse(hero.updatedAt) || 0)) : "0",
5149
activity_body: hero
5250
? `${hero.status}: ${clean(hero.threadTitle)} · ${clean(hero.projectTitle)}`
5351
: "",

0 commit comments

Comments
 (0)