feat: Implement permanent deletion and restoration of notes with updated UI
This commit is contained in:
@@ -69,6 +69,13 @@ String _readStringValue(dynamic value) {
|
||||
return jsonEncode(value);
|
||||
}
|
||||
|
||||
String _readOptionalStringValue(dynamic value) {
|
||||
if (value == null) {
|
||||
return '';
|
||||
}
|
||||
return _readStringValue(value);
|
||||
}
|
||||
|
||||
int _readIntValue(dynamic value) {
|
||||
if (value is int) {
|
||||
return value;
|
||||
@@ -127,6 +134,7 @@ class SyncNotePayload {
|
||||
required this.serverVersion,
|
||||
this.position = 0,
|
||||
this.isDeleted = false,
|
||||
this.isPermanentlyDeleted = false,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
@@ -137,12 +145,14 @@ class SyncNotePayload {
|
||||
final int serverVersion;
|
||||
final int position;
|
||||
final bool isDeleted;
|
||||
final bool isPermanentlyDeleted;
|
||||
final DateTime updatedAt;
|
||||
|
||||
factory SyncNotePayload.fromNote(
|
||||
Note note, {
|
||||
required String encryptedTitle,
|
||||
required String encryptedBody,
|
||||
bool isPermanentlyDeleted = false,
|
||||
}) {
|
||||
return SyncNotePayload(
|
||||
id: note.uuid,
|
||||
@@ -152,6 +162,7 @@ class SyncNotePayload {
|
||||
serverVersion: note.serverVersion,
|
||||
position: note.index,
|
||||
isDeleted: note.isDeleted,
|
||||
isPermanentlyDeleted: isPermanentlyDeleted,
|
||||
updatedAt: note.updatedAt,
|
||||
);
|
||||
}
|
||||
@@ -165,6 +176,7 @@ class SyncNotePayload {
|
||||
'serverVersion': serverVersion,
|
||||
if (position != 0) 'position': position,
|
||||
if (isDeleted) 'isDeleted': isDeleted,
|
||||
if (isPermanentlyDeleted) 'isPermanentlyDeleted': isPermanentlyDeleted,
|
||||
'updatedAt': updatedAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
@@ -237,6 +249,7 @@ class SyncNoteResponse {
|
||||
required this.serverVersion,
|
||||
this.position = 0,
|
||||
this.isDeleted = false,
|
||||
this.isPermanentlyDeleted = false,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
@@ -247,6 +260,7 @@ class SyncNoteResponse {
|
||||
final int serverVersion;
|
||||
final int position;
|
||||
final bool isDeleted;
|
||||
final bool isPermanentlyDeleted;
|
||||
final DateTime updatedAt;
|
||||
|
||||
factory SyncNoteResponse.fromJson(Map<String, dynamic> json) {
|
||||
@@ -255,11 +269,12 @@ class SyncNoteResponse {
|
||||
categoryId: json['categoryId'] == null
|
||||
? null
|
||||
: _readStringValue(json['categoryId']),
|
||||
encryptedTitle: _readStringValue(json['encrypted_title']),
|
||||
encryptedBody: _readStringValue(json['encrypted_body']),
|
||||
encryptedTitle: _readOptionalStringValue(json['encrypted_title']),
|
||||
encryptedBody: _readOptionalStringValue(json['encrypted_body']),
|
||||
serverVersion: _readIntValue(json['serverVersion']),
|
||||
position: json['position'] as int? ?? 0,
|
||||
isDeleted: json['isDeleted'] as bool? ?? false,
|
||||
isPermanentlyDeleted: json['isPermanentlyDeleted'] as bool? ?? false,
|
||||
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
||||
);
|
||||
}
|
||||
@@ -267,8 +282,8 @@ class SyncNoteResponse {
|
||||
Note toNote() {
|
||||
return Note(
|
||||
uuid: id,
|
||||
title: 'Encrypted', // placeholder, será descifrado por la app
|
||||
body: 'Encrypted', // placeholder, será descifrado por la app
|
||||
title: isPermanentlyDeleted ? '' : 'Encrypted',
|
||||
body: isPermanentlyDeleted ? '' : 'Encrypted',
|
||||
createdAt: updatedAt,
|
||||
updatedAt: updatedAt,
|
||||
index: position,
|
||||
|
||||
Reference in New Issue
Block a user