feat: wire discuss button in briefing RSS cards, cap cards at 3
Adds discussArticle() to BriefingApi and wires it through to the RSS news cards in BriefingScreen so tapping Discuss opens a chat conversation seeded with the article. Also caps RSS cards per message at 3 to avoid overly long briefing threads. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,22 @@ class BriefingApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// POST /api/briefing/articles/{itemId}/discuss body: {"conv_id": convId}
|
||||||
|
/// Injects the article as context and triggers LLM generation.
|
||||||
|
/// Returns the assistant_message_id of the generating placeholder.
|
||||||
|
Future<int> discussArticle(int convId, int itemId) async {
|
||||||
|
try {
|
||||||
|
final response = await _dio.post(
|
||||||
|
'/api/briefing/articles/$itemId/discuss',
|
||||||
|
data: {'conv_id': convId},
|
||||||
|
);
|
||||||
|
final data = response.data as Map<String, dynamic>;
|
||||||
|
return data['assistant_message_id'] as int;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
throw dioToApp(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// DELETE /api/briefing/rss-reactions/{rssItemId}
|
/// DELETE /api/briefing/rss-reactions/{rssItemId}
|
||||||
Future<void> deleteRssReaction(int rssItemId) async {
|
Future<void> deleteRssReaction(int rssItemId) async {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -93,6 +93,23 @@ class _BriefingScreenState extends ConsumerState<BriefingScreen>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _handleDiscuss(int convId, int itemId) async {
|
||||||
|
try {
|
||||||
|
await ref.read(briefingProvider.notifier).discussArticle(convId, itemId);
|
||||||
|
} on AppException catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context)
|
||||||
|
.showSnackBar(SnackBar(content: Text(e.message)));
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Failed to start discussion.')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _handleReaction(int itemId, String reaction) async {
|
Future<void> _handleReaction(int itemId, String reaction) async {
|
||||||
final current = _reactions[itemId];
|
final current = _reactions[itemId];
|
||||||
final next = current == reaction ? null : reaction;
|
final next = current == reaction ? null : reaction;
|
||||||
@@ -268,8 +285,10 @@ class _BriefingScreenState extends ConsumerState<BriefingScreen>
|
|||||||
final msg = conv.messages[i];
|
final msg = conv.messages[i];
|
||||||
return _BriefingMessageItem(
|
return _BriefingMessageItem(
|
||||||
message: msg,
|
message: msg,
|
||||||
|
convId: conv.id,
|
||||||
reactions: _reactions,
|
reactions: _reactions,
|
||||||
onReaction: _handleReaction,
|
onReaction: _handleReaction,
|
||||||
|
onDiscuss: _handleDiscuss,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -370,13 +389,17 @@ class _BriefingScreenState extends ConsumerState<BriefingScreen>
|
|||||||
/// and RSS reaction buttons below it (for assistant messages with metadata).
|
/// and RSS reaction buttons below it (for assistant messages with metadata).
|
||||||
class _BriefingMessageItem extends StatelessWidget {
|
class _BriefingMessageItem extends StatelessWidget {
|
||||||
final Message message;
|
final Message message;
|
||||||
|
final int convId;
|
||||||
final Map<int, String?> reactions;
|
final Map<int, String?> reactions;
|
||||||
final void Function(int itemId, String reaction) onReaction;
|
final void Function(int itemId, String reaction) onReaction;
|
||||||
|
final void Function(int convId, int itemId) onDiscuss;
|
||||||
|
|
||||||
const _BriefingMessageItem({
|
const _BriefingMessageItem({
|
||||||
required this.message,
|
required this.message,
|
||||||
|
required this.convId,
|
||||||
required this.reactions,
|
required this.reactions,
|
||||||
required this.onReaction,
|
required this.onReaction,
|
||||||
|
required this.onDiscuss,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -388,11 +411,11 @@ class _BriefingMessageItem extends StatelessWidget {
|
|||||||
final bool hasWeatherKey = isAssistant && meta != null && meta.containsKey('weather');
|
final bool hasWeatherKey = isAssistant && meta != null && meta.containsKey('weather');
|
||||||
final weatherData = hasWeatherKey ? meta['weather'] as Map<String, dynamic>? : null;
|
final weatherData = hasWeatherKey ? meta['weather'] as Map<String, dynamic>? : null;
|
||||||
|
|
||||||
// RSS news cards
|
// RSS news cards — cap at 3
|
||||||
final rssItemsRaw = isAssistant && meta != null
|
final rssItemsRaw = isAssistant && meta != null
|
||||||
? (meta['rss_items'] as List<dynamic>?)?.cast<Map<String, dynamic>>() ?? []
|
? (meta['rss_items'] as List<dynamic>?)?.cast<Map<String, dynamic>>() ?? []
|
||||||
: <Map<String, dynamic>>[];
|
: <Map<String, dynamic>>[];
|
||||||
final rssItems = rssItemsRaw.map(RssItemMeta.fromJson).toList();
|
final rssItems = rssItemsRaw.map(RssItemMeta.fromJson).take(3).toList();
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
@@ -408,6 +431,7 @@ class _BriefingMessageItem extends StatelessWidget {
|
|||||||
item: item,
|
item: item,
|
||||||
reaction: reactions[item.id],
|
reaction: reactions[item.id],
|
||||||
onReaction: onReaction,
|
onReaction: onReaction,
|
||||||
|
onDiscuss: () => onDiscuss(convId, item.id),
|
||||||
)).toList(),
|
)).toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <flutter_timezone/flutter_timezone_plugin.h>
|
#include <flutter_timezone/flutter_timezone_plugin.h>
|
||||||
#include <open_file_linux/open_file_linux_plugin.h>
|
#include <open_file_linux/open_file_linux_plugin.h>
|
||||||
|
#include <record_linux/record_linux_plugin.h>
|
||||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||||
|
|
||||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||||
@@ -17,6 +18,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
|
|||||||
g_autoptr(FlPluginRegistrar) open_file_linux_registrar =
|
g_autoptr(FlPluginRegistrar) open_file_linux_registrar =
|
||||||
fl_plugin_registry_get_registrar_for_plugin(registry, "OpenFileLinuxPlugin");
|
fl_plugin_registry_get_registrar_for_plugin(registry, "OpenFileLinuxPlugin");
|
||||||
open_file_linux_plugin_register_with_registrar(open_file_linux_registrar);
|
open_file_linux_plugin_register_with_registrar(open_file_linux_registrar);
|
||||||
|
g_autoptr(FlPluginRegistrar) record_linux_registrar =
|
||||||
|
fl_plugin_registry_get_registrar_for_plugin(registry, "RecordLinuxPlugin");
|
||||||
|
record_linux_plugin_register_with_registrar(record_linux_registrar);
|
||||||
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
||||||
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
||||||
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
flutter_timezone
|
flutter_timezone
|
||||||
open_file_linux
|
open_file_linux
|
||||||
|
record_linux
|
||||||
url_launcher_linux
|
url_launcher_linux
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,18 +5,24 @@
|
|||||||
import FlutterMacOS
|
import FlutterMacOS
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
import audio_session
|
||||||
import flutter_inappwebview_macos
|
import flutter_inappwebview_macos
|
||||||
import flutter_timezone
|
import flutter_timezone
|
||||||
|
import just_audio
|
||||||
import open_file_mac
|
import open_file_mac
|
||||||
import package_info_plus
|
import package_info_plus
|
||||||
|
import record_darwin
|
||||||
import shared_preferences_foundation
|
import shared_preferences_foundation
|
||||||
import url_launcher_macos
|
import url_launcher_macos
|
||||||
|
|
||||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||||
|
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin"))
|
||||||
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
|
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
|
||||||
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))
|
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))
|
||||||
|
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))
|
||||||
OpenFilePlugin.register(with: registry.registrar(forPlugin: "OpenFilePlugin"))
|
OpenFilePlugin.register(with: registry.registrar(forPlugin: "OpenFilePlugin"))
|
||||||
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
|
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
|
||||||
|
RecordPlugin.register(with: registry.registrar(forPlugin: "RecordPlugin"))
|
||||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
|
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
|
||||||
#include <flutter_timezone/flutter_timezone_plugin_c_api.h>
|
#include <flutter_timezone/flutter_timezone_plugin_c_api.h>
|
||||||
#include <permission_handler_windows/permission_handler_windows_plugin.h>
|
#include <permission_handler_windows/permission_handler_windows_plugin.h>
|
||||||
|
#include <record_windows/record_windows_plugin_c_api.h>
|
||||||
#include <url_launcher_windows/url_launcher_windows.h>
|
#include <url_launcher_windows/url_launcher_windows.h>
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
@@ -18,6 +19,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
|
|||||||
registry->GetRegistrarForPlugin("FlutterTimezonePluginCApi"));
|
registry->GetRegistrarForPlugin("FlutterTimezonePluginCApi"));
|
||||||
PermissionHandlerWindowsPluginRegisterWithRegistrar(
|
PermissionHandlerWindowsPluginRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
|
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
|
||||||
|
RecordWindowsPluginCApiRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("RecordWindowsPluginCApi"));
|
||||||
UrlLauncherWindowsRegisterWithRegistrar(
|
UrlLauncherWindowsRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
|
|||||||
flutter_inappwebview_windows
|
flutter_inappwebview_windows
|
||||||
flutter_timezone
|
flutter_timezone
|
||||||
permission_handler_windows
|
permission_handler_windows
|
||||||
|
record_windows
|
||||||
url_launcher_windows
|
url_launcher_windows
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user