You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-08-07 23:03:36 +02:00
feat: memories in new timeline (#19720)
* feat: memories sliver * memories lane * display and show memory * fix: get correct memories * naming * pr feedback * use equalsValue for visibility --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||
|
||||
enum MemoryTypeEnum {
|
||||
// do not change this order!
|
||||
onThisDay,
|
||||
@ -53,7 +57,7 @@ class MemoryData {
|
||||
}
|
||||
|
||||
// Model for a memory stored in the server
|
||||
class Memory {
|
||||
class DriftMemory {
|
||||
final String id;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
@ -68,8 +72,9 @@ class Memory {
|
||||
final DateTime? seenAt;
|
||||
final DateTime? showAt;
|
||||
final DateTime? hideAt;
|
||||
final List<RemoteAsset> assets;
|
||||
|
||||
const Memory({
|
||||
const DriftMemory({
|
||||
required this.id,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
@ -82,9 +87,10 @@ class Memory {
|
||||
this.seenAt,
|
||||
this.showAt,
|
||||
this.hideAt,
|
||||
required this.assets,
|
||||
});
|
||||
|
||||
Memory copyWith({
|
||||
DriftMemory copyWith({
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
@ -97,8 +103,9 @@ class Memory {
|
||||
DateTime? seenAt,
|
||||
DateTime? showAt,
|
||||
DateTime? hideAt,
|
||||
List<RemoteAsset>? assets,
|
||||
}) {
|
||||
return Memory(
|
||||
return DriftMemory(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
@ -111,64 +118,19 @@ class Memory {
|
||||
seenAt: seenAt ?? this.seenAt,
|
||||
showAt: showAt ?? this.showAt,
|
||||
hideAt: hideAt ?? this.hideAt,
|
||||
assets: assets ?? this.assets,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return <String, dynamic>{
|
||||
'id': id,
|
||||
'createdAt': createdAt.millisecondsSinceEpoch,
|
||||
'updatedAt': updatedAt.millisecondsSinceEpoch,
|
||||
'deletedAt': deletedAt?.millisecondsSinceEpoch,
|
||||
'ownerId': ownerId,
|
||||
'type': type.index,
|
||||
'data': data.toMap(),
|
||||
'isSaved': isSaved,
|
||||
'memoryAt': memoryAt.millisecondsSinceEpoch,
|
||||
'seenAt': seenAt?.millisecondsSinceEpoch,
|
||||
'showAt': showAt?.millisecondsSinceEpoch,
|
||||
'hideAt': hideAt?.millisecondsSinceEpoch,
|
||||
};
|
||||
}
|
||||
|
||||
factory Memory.fromMap(Map<String, dynamic> map) {
|
||||
return Memory(
|
||||
id: map['id'] as String,
|
||||
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt'] as int),
|
||||
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt'] as int),
|
||||
deletedAt: map['deletedAt'] != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(map['deletedAt'] as int)
|
||||
: null,
|
||||
ownerId: map['ownerId'] as String,
|
||||
type: MemoryTypeEnum.values[map['type'] as int],
|
||||
data: MemoryData.fromMap(map['data'] as Map<String, dynamic>),
|
||||
isSaved: map['isSaved'] as bool,
|
||||
memoryAt: DateTime.fromMillisecondsSinceEpoch(map['memoryAt'] as int),
|
||||
seenAt: map['seenAt'] != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(map['seenAt'] as int)
|
||||
: null,
|
||||
showAt: map['showAt'] != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(map['showAt'] as int)
|
||||
: null,
|
||||
hideAt: map['hideAt'] != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(map['hideAt'] as int)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory Memory.fromJson(String source) =>
|
||||
Memory.fromMap(json.decode(source) as Map<String, dynamic>);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Memory(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, ownerId: $ownerId, type: $type, data: $data, isSaved: $isSaved, memoryAt: $memoryAt, seenAt: $seenAt, showAt: $showAt, hideAt: $hideAt)';
|
||||
return 'Memory(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, ownerId: $ownerId, type: $type, data: $data, isSaved: $isSaved, memoryAt: $memoryAt, seenAt: $seenAt, showAt: $showAt, hideAt: $hideAt, assets: $assets)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant Memory other) {
|
||||
bool operator ==(covariant DriftMemory other) {
|
||||
if (identical(this, other)) return true;
|
||||
final listEquals = const DeepCollectionEquality().equals;
|
||||
|
||||
return other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
@ -181,7 +143,8 @@ class Memory {
|
||||
other.memoryAt == memoryAt &&
|
||||
other.seenAt == seenAt &&
|
||||
other.showAt == showAt &&
|
||||
other.hideAt == hideAt;
|
||||
other.hideAt == hideAt &&
|
||||
listEquals(other.assets, assets);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -197,6 +160,7 @@ class Memory {
|
||||
memoryAt.hashCode ^
|
||||
seenAt.hashCode ^
|
||||
showAt.hashCode ^
|
||||
hideAt.hashCode;
|
||||
hideAt.hashCode ^
|
||||
assets.hashCode;
|
||||
}
|
||||
}
|
||||
|
15
mobile/lib/domain/services/memory.service.dart
Normal file
15
mobile/lib/domain/services/memory.service.dart
Normal file
@ -0,0 +1,15 @@
|
||||
import 'package:immich_mobile/domain/models/memory.model.dart';
|
||||
import 'package:immich_mobile/infrastructure/repositories/memory.repository.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class DriftMemoryService {
|
||||
final log = Logger("DriftMemoryService");
|
||||
|
||||
final DriftMemoryRepository _repository;
|
||||
|
||||
DriftMemoryService(this._repository);
|
||||
|
||||
Future<List<DriftMemory>> getMemoryLane(String ownerId) {
|
||||
return _repository.getAll(ownerId);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user