Merge: clickable links in chat

This commit is contained in:
2026-11-03 16:17:54 +00:00
16 changed files with 1081 additions and 113 deletions
+16 -3
View File
@@ -11,7 +11,9 @@
// `?live=N` 3 s after a chat subscribes, N text deltas stream into a
// new reply, one every 60 ms;
// `?tasks=N` the history ends with N consecutive background-task notices
// in the server's wording (every third one failed).
// in the server's wording (every third one failed);
// `?links=1` answers and operator turns carry a markdown link, an
// autolink, a bare URL and URLs inside code (never linkified).
import 'dart:async';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -21,6 +23,7 @@ Map<String, String> _params = const {};
void configureChatScrollFixture(Map<String, String> params) => _params = params;
bool get _rich => _params['rich'] == '1';
bool get _links => _params['links'] == '1';
bool get _older => _params['older'] == '1';
int get _live => int.tryParse(_params['live'] ?? '') ?? 0;
int get _tasks => int.tryParse(_params['tasks'] ?? '') ?? 0;
@@ -72,9 +75,19 @@ String _answer(int i) {
: '';
return '## Answer $i\n\nSome **bold** text with `code`.\n\n'
'```dart\n${List.generate(8, (l) => 'final v$l = $i * $l;').join('\n')}'
'\n```\n$wide\n- one\n- two\n';
'\n```\n$wide\n- one\n- two\n${_links ? _answerLinks : ''}';
}
const _answerLinks =
'\nRead [the release notes](https://example.com/releases/v2) or '
'<https://example.com/auto>; the bare https://example.com/bare/path. '
'and www.example.org work too. Not `https://example.com/inline`:\n\n'
'```sh\ncurl https://example.com/fenced\n```\n';
const _questionLinks =
' See https://example.com/question?id=1, [md](https://example.com/md) '
'and `https://example.com/code`.';
JsonMap _message(String chat, int i) {
final id = '$chat-m$i';
if (_rich && i % 10 == 5) {
@@ -114,7 +127,7 @@ JsonMap _message(String chat, int i) {
'name': 'shot$i.png',
'uri': _png,
},
{'type': 'text', 'text': 'Question $i'},
{'type': 'text', 'text': 'Question $i${_links ? _questionLinks : ''}'},
],
};
}