Notify link=: review fixes
- ntfy uses the link only beside a web run view; otherwise it keeps the run click and the receipt says why (app click stays the link). - The outbox retry of a hook's failed publication re-resolves the stage's link=, so the ntfy and app tap targets keep it. - A valid link file is never the attached artifact. - Notification artifacts are read through os.OpenRoot with O_NOFOLLOW. - The link note is recorded once, on the first receipt, and never becomes the run-level failure reason. - Android: a recents relaunch does not reopen the link, and a run thread of several entries opens the run rather than the latest external page. - Docs and the protocol comment say "first non-empty line".
This commit is contained in:
@@ -51,10 +51,12 @@ class MainActivity : FlutterActivity() {
|
||||
/**
|
||||
* A notification whose click is an http(s) page (a stage's `link=`, such
|
||||
* as a published doc) opens it in the browser rather than as an app route.
|
||||
* A relaunch from recents replays the original intent; it opens nothing.
|
||||
*/
|
||||
private fun openExternalLink(intent: Intent?) {
|
||||
val link = intent?.getStringExtra(NotificationPresenter.EXTRA_EXTERNAL_LINK) ?: return
|
||||
intent.removeExtra(NotificationPresenter.EXTRA_EXTERNAL_LINK)
|
||||
if ((intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) return
|
||||
try {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)).addCategory(Intent.CATEGORY_BROWSABLE))
|
||||
} catch (_: ActivityNotFoundException) {
|
||||
|
||||
+22
-5
@@ -156,7 +156,7 @@ class NotificationPresenter(private val context: Context) {
|
||||
.setAutoCancel(true)
|
||||
.setWhen(latest.whenMillis)
|
||||
.setShowWhen(true)
|
||||
.setContentIntent(openIntent(ids, latest.click, id))
|
||||
.setContentIntent(openIntent(ids, threadClick(entries), id))
|
||||
.apply { addRunAction(latest, id) }
|
||||
.setDeleteIntent(dismissIntent(ids, id))
|
||||
builder.setStyle(NotificationCompat.BigTextStyle().bigText(threadPreview(latest)))
|
||||
@@ -285,17 +285,34 @@ class NotificationPresenter(private val context: Context) {
|
||||
/** Builds the deep-link portion of a tray tap without requiring Android Context. */
|
||||
fun notificationIntent(ids: List<String>, click: String): NotificationIntentSpec {
|
||||
val link = notificationLink(click)
|
||||
val scheme = link.substringBefore(":", "")
|
||||
val appLink = scheme == "pipelines"
|
||||
val external = scheme.lowercase() in setOf("http", "https") && link.startsWith("$scheme://")
|
||||
val appLink = link.substringBefore(":", "") == "pipelines"
|
||||
return NotificationIntentSpec(
|
||||
ids = ids.joinToString("\n"),
|
||||
action = if (appLink) Intent.ACTION_VIEW else null,
|
||||
data = if (appLink) link else null,
|
||||
externalLink = if (external) link else null,
|
||||
externalLink = if (isExternalLink(link)) link else null,
|
||||
)
|
||||
}
|
||||
|
||||
/** An http(s) page (a stage's `link=`), opened in the browser. */
|
||||
fun isExternalLink(click: String): Boolean {
|
||||
val scheme = click.substringBefore(":", "")
|
||||
return scheme.lowercase() in setOf("http", "https") && click.startsWith("$scheme://")
|
||||
}
|
||||
|
||||
/**
|
||||
* A thread's tap target: its latest click, except that a thread of
|
||||
* several entries opens the run rather than one entry's external page.
|
||||
*/
|
||||
fun threadClick(entries: List<ThreadEntry>): String {
|
||||
val latest = entries.last()
|
||||
return if (entries.size > 1 && isExternalLink(latest.click) && latest.runClick.isNotEmpty()) {
|
||||
latest.runClick
|
||||
} else {
|
||||
latest.click
|
||||
}
|
||||
}
|
||||
|
||||
fun runActionLabel(runClick: String): String? =
|
||||
if (runClick.isEmpty()) null else "Open run"
|
||||
|
||||
|
||||
+18
@@ -61,6 +61,24 @@ class NotificationProtocolTest {
|
||||
assertNull(NotificationPresenter.notificationIntent(listOf("n-1"), "https:claude.ai").externalLink)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun threadOfSeveralEntriesOpensTheRunInsteadOfAnExternalPage() {
|
||||
val doc = ThreadEntry(
|
||||
id = "n-2",
|
||||
kind = "stage_succeeded",
|
||||
priority = 3,
|
||||
sender = "Run 7",
|
||||
text = "Standup ready",
|
||||
click = "https://claude.ai/public/artifacts/0f3c-standup",
|
||||
whenMillis = 2L,
|
||||
runClick = "pipelines://run/7",
|
||||
)
|
||||
val earlier = doc.copy(id = "n-1", click = "pipelines://run/7", runClick = "", whenMillis = 1L)
|
||||
assertEquals(doc.click, NotificationPresenter.threadClick(listOf(doc)))
|
||||
assertEquals("pipelines://run/7", NotificationPresenter.threadClick(listOf(earlier, doc)))
|
||||
assertEquals("pipelines://run/7", NotificationPresenter.threadClick(listOf(doc, earlier)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun groupedNotificationUsesLatestArtifactPreviewAsExpandedText() {
|
||||
val entry = ThreadEntry(
|
||||
|
||||
Reference in New Issue
Block a user