-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Processing memory with status, capturing to, get list and more. #930
Changes from 8 commits
d013348
280adb7
e02d7da
15b0580
e6c8d3e
6076bc4
7fcacfd
8f761c8
2b96942
75bd737
d0a8e69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,16 +21,13 @@ Future<UpdateProcessingMemoryResponse?> updateProcessingMemoryServer({ | |
bodyData.addAll({"geolocation": geolocation.toJson()}); | ||
} | ||
|
||
debugPrint(jsonEncode(bodyData)); | ||
|
||
var response = await makeApiCall( | ||
url: '${Env.apiBaseUrl}v1/processing-memories/$id', | ||
headers: {}, | ||
method: 'PATCH', | ||
body: jsonEncode(bodyData), | ||
); | ||
if (response == null) return null; | ||
debugPrint('updateProcessingMemoryServer: ${response.body}'); | ||
if (response.statusCode == 200) { | ||
return UpdateProcessingMemoryResponse.fromJson(jsonDecode(response.body)); | ||
} else { | ||
Comment on lines
24
to
33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - headers: {},
+ headers: {
+ 'Authorization': 'Bearer $token',
+ }, - } else {
+ } else {
+ // Log or report error
+ print('Error updating processing memory: ${response.statusCode}');
+ } |
||
|
@@ -46,3 +43,29 @@ Future<UpdateProcessingMemoryResponse?> updateProcessingMemoryServer({ | |
} | ||
return null; | ||
} | ||
|
||
Future<ProcessingMemoryResponse?> fetchProcessingMemoryServer({ | ||
required String id, | ||
}) async { | ||
var response = await makeApiCall( | ||
url: '${Env.apiBaseUrl}v1/processing-memories/$id', | ||
headers: {}, | ||
method: 'GET', | ||
body: "", | ||
); | ||
if (response == null) return null; | ||
if (response.statusCode == 200) { | ||
return ProcessingMemoryResponse.fromJson(jsonDecode(response.body)); | ||
} else { | ||
// TODO: Server returns 304 doesn't recover | ||
CrashReporting.reportHandledCrash( | ||
Exception('Failed to create memory'), | ||
StackTrace.current, | ||
level: NonFatalExceptionLevel.info, | ||
userAttributes: { | ||
'response': response.body, | ||
}, | ||
); | ||
} | ||
return null; | ||
Comment on lines
+50
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, the - headers: {},
+ headers: {
+ 'Authorization': 'Bearer $token',
+ },
- body: "", - Exception('Failed to create memory'),
+ Exception('Failed to fetch memory'), |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import 'dart:convert'; | ||
import 'dart:math'; | ||
|
||
import 'package:collection/collection.dart'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
import 'package:flutter/material.dart'; | ||
import 'package:friend_private/backend/schema/geolocation.dart'; | ||
import 'package:friend_private/backend/schema/message.dart'; | ||
|
@@ -57,22 +58,52 @@ class MemoryPostProcessing { | |
toJson() => {'status': status.toString().split('.').last, 'model': model.toString().split('.').last}; | ||
} | ||
|
||
enum ServerProcessingMemoryStatus { | ||
capturing('capturing'), | ||
processing('processing'), | ||
done('done'), | ||
unknown('unknown'), | ||
; | ||
|
||
final String value; | ||
const ServerProcessingMemoryStatus(this.value); | ||
|
||
static ServerProcessingMemoryStatus valuesFromString(String value) { | ||
return ServerProcessingMemoryStatus.values.firstWhereOrNull((e) => e.value == value) ?? | ||
ServerProcessingMemoryStatus.unknown; | ||
} | ||
} | ||
Comment on lines
+61
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The static ServerProcessingMemoryStatus valuesFromString(String value) {
return ServerProcessingMemoryStatus.values.firstWhereOrNull((e) => e.value == value) ??
- 73: ServerProcessingMemoryStatus.unknown;
+ 73: (throw ArgumentError('Unknown ServerProcessingMemoryStatus: $value'));
} |
||
|
||
class ServerProcessingMemory { | ||
final String id; | ||
final DateTime createdAt; | ||
final DateTime? startedAt; | ||
final DateTime? capturingTo; | ||
final ServerProcessingMemoryStatus? status; | ||
final List<TranscriptSegment> transcriptSegments; | ||
final String? memoryId; | ||
|
||
ServerProcessingMemory({ | ||
required this.id, | ||
required this.createdAt, | ||
this.startedAt, | ||
this.capturingTo, | ||
this.status, | ||
this.transcriptSegments = const [], | ||
this.memoryId, | ||
}); | ||
|
||
factory ServerProcessingMemory.fromJson(Map<String, dynamic> json) { | ||
return ServerProcessingMemory( | ||
id: json['id'], | ||
createdAt: DateTime.parse(json['created_at']).toLocal(), | ||
startedAt: json['started_at'] != null ? DateTime.parse(json['started_at']).toLocal() : null, | ||
capturingTo: json['capturing_to'] != null ? DateTime.parse(json['capturing_to']).toLocal() : null, | ||
status: json['status'] != null ? ServerProcessingMemoryStatus.valuesFromString(json['status']) : null, | ||
transcriptSegments: ((json['transcript_segments'] ?? []) as List<dynamic>) | ||
.map((segment) => TranscriptSegment.fromJson(segment)) | ||
.toList(), | ||
memoryId: json['memory_id'], | ||
Comment on lines
77
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The factory ServerProcessingMemory.fromJson(Map<String, dynamic> json) {
- 97: return ServerProcessingMemory(
- 98: id: json['id'],
- 99: createdAt: DateTime.parse(json['created_at']).toLocal(),
+ 97: if (json['id'] != null && json['created_at'] != null) {
+ 98: return ServerProcessingMemory(
+ 99: id: json['id'],
+ 100: createdAt: DateTime.parse(json['created_at']).toLocal(),
startedAt: json['started_at'] != null ? DateTime.parse(json['started_at']).toLocal() : null,
capturingTo: json['capturing_to'] != null ? DateTime.parse(json['capturing_to']).toLocal() : null,
status: json['status'] != null ? ServerProcessingMemoryStatus.valuesFromString(json['status']) : null,
transcriptSegments: ((json['transcript_segments'] ?? []) as List<dynamic>)
.map((segment) => TranscriptSegment.fromJson(segment))
.toList(),
memoryId: json['memory_id'],
+ 107: );
+ 108: } else {
+ 109: throw ArgumentError('Missing required fields in JSON');
+ 110: }
111:} |
||
); | ||
} | ||
|
||
|
@@ -81,6 +112,10 @@ class ServerProcessingMemory { | |
'id': id, | ||
'created_at': createdAt.toUtc().toIso8601String(), | ||
'started_at': startedAt?.toUtc().toIso8601String(), | ||
'capturing_to': capturingTo?.toUtc().toIso8601String(), | ||
'status': status.toString(), | ||
Comment on lines
+115
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
'transcript_segments': transcriptSegments.map((segment) => segment.toJson()).toList(), | ||
Comment on lines
+115
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
'memory_id': memoryId, | ||
Comment on lines
+115
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - 'status': status.toString(),
+ 'status': status.toString().split('.').last, |
||
}; | ||
} | ||
|
||
|
@@ -97,6 +132,18 @@ class ServerProcessingMemory { | |
} | ||
} | ||
|
||
class ProcessingMemoryResponse { | ||
final ServerProcessingMemory? result; | ||
|
||
ProcessingMemoryResponse({required this.result}); | ||
|
||
factory ProcessingMemoryResponse.fromJson(Map<String, dynamic> json) { | ||
return ProcessingMemoryResponse( | ||
result: json['result'] != null ? ServerProcessingMemory.fromJson(json['result']) : null, | ||
); | ||
} | ||
} | ||
Comment on lines
+135
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new class factory ProcessingMemoryResponse.fromJson(Map<String, dynamic> json) {
- 141: return ProcessingMemoryResponse(
- 142: result: json['result'] != null ? ServerProcessingMemory.fromJson(json['result']) : null,
+ 141: if (json['result'] != null) {
+ 142: try {
+ 143: return ProcessingMemoryResponse(
+ 144: result: ServerProcessingMemory.fromJson(json['result']),
+ 145: );
+ 146: } catch (e) {
+ 147: throw FormatException('Invalid format for ServerProcessingMemory');
+ 148: }
+ 149: } else {
+ 150: return ProcessingMemoryResponse(result: null);
+ 151: }
} |
||
|
||
class UpdateProcessingMemoryResponse { | ||
final ServerProcessingMemory? result; | ||
|
||
|
@@ -135,6 +182,9 @@ class ServerMemory { | |
final bool failed; | ||
int retries; | ||
|
||
// local label | ||
bool isNew = false; | ||
|
||
Comment on lines
+185
to
+187
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
ServerMemory({ | ||
required this.id, | ||
required this.createdAt, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ class _MemoriesPageState extends State<MemoriesPage> with AutomaticKeepAliveClie | |
const SliverToBoxAdapter(child: SizedBox(height: 32)), | ||
const SliverToBoxAdapter(child: SpeechProfileCardWidget()), | ||
SliverToBoxAdapter(child: getMemoryCaptureWidget()), | ||
getProcessingMemoriesWidget(memoryProvider.processingMemories), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - getProcessingMemoriesWidget(memoryProvider.processingMemories),
+ getProcessingMemoriesWidget(memoryProvider.processingMemories ?? []), This will ensure that an empty list is passed to the function if |
||
if (memoryProvider.groupedMemories.isEmpty && !memoryProvider.isLoadingMemories) | ||
const SliverToBoxAdapter( | ||
child: Center( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,10 +46,18 @@ class _MemoryListItemState extends State<MemoryListItem> { | |
EdgeInsets.only(top: 12, left: widget.isFromOnboarding ? 0 : 16, right: widget.isFromOnboarding ? 0 : 16), | ||
child: Container( | ||
width: double.maxFinite, | ||
decoration: BoxDecoration( | ||
color: Colors.grey.shade900, | ||
borderRadius: BorderRadius.circular(16.0), | ||
), | ||
decoration: widget.memory.isNew | ||
? BoxDecoration( | ||
color: Colors.grey.shade900, | ||
borderRadius: BorderRadius.circular(16.0), | ||
border: Border.all( | ||
color: Colors.lightBlue, | ||
width: 1, | ||
)) | ||
: BoxDecoration( | ||
color: Colors.grey.shade900, | ||
borderRadius: BorderRadius.circular(16.0), | ||
), | ||
Comment on lines
+50
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change introduces a conditional decoration for the widget based on whether the memory is new or not. It seems fine from a logic perspective, but make sure that the UI changes have been thoroughly tested across different screen sizes and resolutions to ensure that they look as expected. |
||
child: ClipRRect( | ||
borderRadius: BorderRadius.circular(16.0), | ||
child: Dismissible( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entelligence.AI
The
getProcessingMemories
function is making an API call but it doesn't handle all possible HTTP status codes. It only checks for a 200 status code, and if the response is not null. However, there could be other status codes returned by the server such as 400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 500 (Internal Server Error), etc. These should be handled appropriately to provide meaningful feedback to the user or for debugging purposes.Also, the headers for the API call are empty. If your API requires any form of authentication, you might need to include appropriate headers.
Lastly, the debug print statements on lines 99 and 102 are not ideal for production code. Consider using a logging library that can be toggled for different environments (development, staging, production).
Here's a suggestion on how to improve this:
Please replace
/* Add necessary headers here */
with the actual headers required for your API call and replacelog
with your preferred logging method.