Files
iiEsaywebUIapp/lib/core/models/conversation.dart
cogwheel0 762155500b feat: Improve offline detection logic
This commit refactors the connectivity service to be more robust and less prone to UI flicker.

Key changes:
- Any successful API response now briefly suppresses the offline warning. This prevents the UI from flashing an offline message between regular connectivity checks.
- The threshold for showing the offline warning is increased from 2 to 3 consecutive failed health checks.
- The timeout for health checks is increased to better handle slow networks.
- The offline warning is now suppressed if there are active data streams to avoid interrupting the user.
- A custom JSON converter is added for conversation metadata to handle potential type mismatches from local storage.
2025-10-16 11:34:28 +05:30

47 lines
1.3 KiB
Dart

import 'package:freezed_annotation/freezed_annotation.dart';
import 'chat_message.dart';
part 'conversation.freezed.dart';
part 'conversation.g.dart';
@freezed
sealed class Conversation with _$Conversation {
const factory Conversation({
required String id,
required String title,
required DateTime createdAt,
required DateTime updatedAt,
String? model,
String? systemPrompt,
@Default([]) List<ChatMessage> messages,
@Default({}) @_MetadataConverter() Map<String, dynamic> metadata,
@Default(false) bool pinned,
@Default(false) bool archived,
String? shareId,
String? folderId,
@Default([]) List<String> tags,
}) = _Conversation;
factory Conversation.fromJson(Map<String, dynamic> json) =>
_$ConversationFromJson(json);
}
/// Custom converter to handle Map<dynamic, dynamic> from storage
class _MetadataConverter
implements JsonConverter<Map<String, dynamic>, Object?> {
const _MetadataConverter();
@override
Map<String, dynamic> fromJson(Object? json) {
if (json == null) return {};
if (json is Map<String, dynamic>) return json;
if (json is Map) {
return json.map((key, value) => MapEntry(key.toString(), value));
}
return {};
}
@override
Object? toJson(Map<String, dynamic> object) => object;
}