Skip to content

Commit beecccd

Browse files
feat: drift
1 parent 4f25512 commit beecccd

22 files changed

+2293
-30
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ mobile/openapi/**/*.dart linguist-generated=true
66
mobile/lib/**/*.g.dart -diff -merge
77
mobile/lib/**/*.g.dart linguist-generated=true
88

9+
mobile/lib/**/*.drift.dart -diff -merge
10+
mobile/lib/**/*.drift.dart linguist-generated=true
11+
912
open-api/typescript-sdk/fetch-client.ts -diff -merge
1013
open-api/typescript-sdk/fetch-client.ts linguist-generated=true
1114

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
],
4040
"explorer.fileNesting.enabled": true,
4141
"explorer.fileNesting.patterns": {
42-
"*.ts": "${capture}.spec.ts,${capture}.mock.ts"
42+
"*.ts": "${capture}.spec.ts,${capture}.mock.ts",
43+
"*.dart": "${capture}.g.dart,${capture}.gr.dart,${capture}.drift.dart"
4344
}
4445
}

mobile/analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ analyzer:
3636
exclude:
3737
- openapi/**
3838
- lib/generated_plugin_registrant.dart
39+
- lib/**/*.g.dart
40+
- lib/**/*.drift.dart
3941

4042
plugins:
4143
- custom_lint

mobile/build.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
targets:
2+
$default:
3+
builders:
4+
#drift @DriftDatabase()
5+
drift_dev:
6+
# Disable default builder to use modular builder instead
7+
enabled: false
8+
drift_dev:analyzer:
9+
enabled: true
10+
options: &drift_options
11+
store_date_time_values_as_text: true
12+
named_parameters: true
13+
write_from_json_string_constructor: false
14+
data_class_to_companions: false
15+
# Required for make-migrations
16+
databases:
17+
main: lib/infrastructure/repositories/db.repository.dart
18+
generate_for: &drift_generate_for
19+
- lib/infrastructure/entities/*.dart
20+
- lib/infrastructure/repositories/db.repository.dart
21+
drift_dev:modular:
22+
enabled: true
23+
options: *drift_options
24+
generate_for: *drift_generate_for
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_meta":{"description":"This file contains a serialized version of schema entities for drift.","version":"1.2.0"},"options":{"store_date_time_values_as_text":true},"entities":[{"id":0,"references":[],"type":"table","data":{"name":"user_entity","was_declared_in_moor":false,"columns":[{"name":"id","getter_name":"id","moor_type":"string","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"name","getter_name":"name","moor_type":"string","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"is_admin","getter_name":"isAdmin","moor_type":"bool","nullable":false,"customConstraints":null,"defaultConstraints":"CHECK (\"is_admin\" IN (0, 1))","dialectAwareDefaultConstraints":{"sqlite":"CHECK (\"is_admin\" IN (0, 1))"},"default_dart":"const CustomExpression('0')","default_client_dart":null,"dsl_features":[]},{"name":"email","getter_name":"email","moor_type":"string","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"profile_image_path","getter_name":"profileImagePath","moor_type":"string","nullable":false,"customConstraints":null,"default_dart":"const CustomExpression('\\'\\'')","default_client_dart":null,"dsl_features":[]},{"name":"updated_at","getter_name":"updatedAt","moor_type":"dateTime","nullable":false,"customConstraints":null,"default_dart":"const CustomExpression('CURRENT_TIMESTAMP')","default_client_dart":null,"dsl_features":[]},{"name":"quota_size_in_bytes","getter_name":"quotaSizeInBytes","moor_type":"int","nullable":true,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"quota_usage_in_bytes","getter_name":"quotaUsageInBytes","moor_type":"int","nullable":false,"customConstraints":null,"default_dart":"const CustomExpression('0')","default_client_dart":null,"dsl_features":[]}],"is_virtual":false,"without_rowid":false,"constraints":[],"explicit_pk":["id"]}},{"id":1,"references":[0],"type":"table","data":{"name":"user_metadata_entity","was_declared_in_moor":false,"columns":[{"name":"user_id","getter_name":"userId","moor_type":"string","nullable":false,"customConstraints":null,"defaultConstraints":"REFERENCES user_entity (id) ON DELETE CASCADE","dialectAwareDefaultConstraints":{"sqlite":"REFERENCES user_entity (id) ON DELETE CASCADE"},"default_dart":null,"default_client_dart":null,"dsl_features":["unknown"]},{"name":"preferences","getter_name":"preferences","moor_type":"string","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[],"type_converter":{"dart_expr":"userPreferenceConverter","dart_type_name":"UserPreferences"}}],"is_virtual":false,"without_rowid":false,"constraints":[],"explicit_pk":["user_id"]}},{"id":2,"references":[0],"type":"table","data":{"name":"partner_entity","was_declared_in_moor":false,"columns":[{"name":"shared_by_id","getter_name":"sharedById","moor_type":"string","nullable":false,"customConstraints":null,"defaultConstraints":"REFERENCES user_entity (id) ON DELETE CASCADE","dialectAwareDefaultConstraints":{"sqlite":"REFERENCES user_entity (id) ON DELETE CASCADE"},"default_dart":null,"default_client_dart":null,"dsl_features":["unknown"]},{"name":"shared_with_id","getter_name":"sharedWithId","moor_type":"string","nullable":false,"customConstraints":null,"defaultConstraints":"REFERENCES user_entity (id) ON DELETE CASCADE","dialectAwareDefaultConstraints":{"sqlite":"REFERENCES user_entity (id) ON DELETE CASCADE"},"default_dart":null,"default_client_dart":null,"dsl_features":["unknown"]},{"name":"in_timeline","getter_name":"inTimeline","moor_type":"bool","nullable":false,"customConstraints":null,"defaultConstraints":"CHECK (\"in_timeline\" IN (0, 1))","dialectAwareDefaultConstraints":{"sqlite":"CHECK (\"in_timeline\" IN (0, 1))"},"default_dart":"const CustomExpression('0')","default_client_dart":null,"dsl_features":[]}],"is_virtual":false,"without_rowid":false,"constraints":[],"explicit_pk":["shared_by_id","shared_with_id"]}}]}

mobile/lib/domain/models/user.model.dart

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,4 @@
1-
import 'dart:ui';
2-
3-
enum AvatarColor {
4-
// do not change this order or reuse indices for other purposes, adding is OK
5-
primary,
6-
pink,
7-
red,
8-
yellow,
9-
blue,
10-
green,
11-
purple,
12-
orange,
13-
gray,
14-
amber;
15-
16-
Color toColor({bool isDarkTheme = false}) => switch (this) {
17-
AvatarColor.primary =>
18-
isDarkTheme ? const Color(0xFFABCBFA) : const Color(0xFF4250AF),
19-
AvatarColor.pink => const Color.fromARGB(255, 244, 114, 182),
20-
AvatarColor.red => const Color.fromARGB(255, 239, 68, 68),
21-
AvatarColor.yellow => const Color.fromARGB(255, 234, 179, 8),
22-
AvatarColor.blue => const Color.fromARGB(255, 59, 130, 246),
23-
AvatarColor.green => const Color.fromARGB(255, 22, 163, 74),
24-
AvatarColor.purple => const Color.fromARGB(255, 147, 51, 234),
25-
AvatarColor.orange => const Color.fromARGB(255, 234, 88, 12),
26-
AvatarColor.gray => const Color.fromARGB(255, 75, 85, 99),
27-
AvatarColor.amber => const Color.fromARGB(255, 217, 119, 6),
28-
};
29-
}
1+
import 'package:immich_mobile/domain/models/user_metadata.model.dart';
302

313
// TODO: Rename to User once Isar is removed
324
class UserDto {
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
import 'dart:ui';
2+
3+
enum UserMetadata {
4+
preferences,
5+
}
6+
7+
class _BaseUserPreference {
8+
final bool enabled;
9+
10+
const _BaseUserPreference({required this.enabled});
11+
12+
@override
13+
bool operator ==(covariant _BaseUserPreference other) {
14+
if (identical(this, other)) return true;
15+
16+
return other.enabled == enabled;
17+
}
18+
19+
@override
20+
int get hashCode => enabled.hashCode;
21+
}
22+
23+
class UserFolderPreference extends _BaseUserPreference {
24+
const UserFolderPreference({super.enabled = false});
25+
26+
Map<String, Object?> toMap() {
27+
return {"folders-Enabled": enabled};
28+
}
29+
30+
factory UserFolderPreference.fromMap(Map<String, Object?> map) {
31+
return UserFolderPreference(
32+
enabled: map["folders-Enabled"] as bool? ?? false,
33+
);
34+
}
35+
}
36+
37+
class UserMemoryPreference extends _BaseUserPreference {
38+
const UserMemoryPreference({super.enabled = true});
39+
40+
Map<String, Object?> toMap() {
41+
return {"memories-Enabled": enabled};
42+
}
43+
44+
factory UserMemoryPreference.fromMap(Map<String, Object?> map) {
45+
return UserMemoryPreference(
46+
enabled: map["memories-Enabled"] as bool? ?? true,
47+
);
48+
}
49+
}
50+
51+
class UserPeoplePreference extends _BaseUserPreference {
52+
const UserPeoplePreference({super.enabled = true});
53+
54+
Map<String, Object?> toMap() {
55+
return {"people-Enabled": enabled};
56+
}
57+
58+
factory UserPeoplePreference.fromMap(Map<String, Object?> map) {
59+
return UserPeoplePreference(
60+
enabled: map["people-Enabled"] as bool? ?? true,
61+
);
62+
}
63+
}
64+
65+
class UserRatingPreference extends _BaseUserPreference {
66+
const UserRatingPreference({super.enabled = false});
67+
68+
Map<String, Object?> toMap() {
69+
return {"ratings-Enabled": enabled};
70+
}
71+
72+
factory UserRatingPreference.fromMap(Map<String, Object?> map) {
73+
return UserRatingPreference(
74+
enabled: map["ratings-Enabled"] as bool? ?? false,
75+
);
76+
}
77+
}
78+
79+
class UserSharedLinksPreference extends _BaseUserPreference {
80+
const UserSharedLinksPreference({super.enabled = true});
81+
82+
Map<String, Object?> toMap() {
83+
return {"sharedLinks-Enabled": enabled};
84+
}
85+
86+
factory UserSharedLinksPreference.fromMap(Map<String, Object?> map) {
87+
return UserSharedLinksPreference(
88+
enabled: map["sharedLinks-Enabled"] as bool? ?? true,
89+
);
90+
}
91+
}
92+
93+
class UserTagPreference extends _BaseUserPreference {
94+
const UserTagPreference({super.enabled = false});
95+
96+
Map<String, Object?> toMap() {
97+
return {"tags-Enabled": enabled};
98+
}
99+
100+
factory UserTagPreference.fromMap(Map<String, Object?> map) {
101+
return UserTagPreference(enabled: map["tags-Enabled"] as bool? ?? false);
102+
}
103+
}
104+
105+
enum AvatarColor {
106+
// do not change this order or reuse indices for other purposes, adding is OK
107+
primary("primary"),
108+
pink("pink"),
109+
red("red"),
110+
yellow("yellow"),
111+
blue("blue"),
112+
green("green"),
113+
purple("purple"),
114+
orange("orange"),
115+
gray("gray"),
116+
amber("amber");
117+
118+
final String value;
119+
const AvatarColor(this.value);
120+
121+
Color toColor({bool isDarkTheme = false}) => switch (this) {
122+
AvatarColor.primary =>
123+
isDarkTheme ? const Color(0xFFABCBFA) : const Color(0xFF4250AF),
124+
AvatarColor.pink => const Color.fromARGB(255, 244, 114, 182),
125+
AvatarColor.red => const Color.fromARGB(255, 239, 68, 68),
126+
AvatarColor.yellow => const Color.fromARGB(255, 234, 179, 8),
127+
AvatarColor.blue => const Color.fromARGB(255, 59, 130, 246),
128+
AvatarColor.green => const Color.fromARGB(255, 22, 163, 74),
129+
AvatarColor.purple => const Color.fromARGB(255, 147, 51, 234),
130+
AvatarColor.orange => const Color.fromARGB(255, 234, 88, 12),
131+
AvatarColor.gray => const Color.fromARGB(255, 75, 85, 99),
132+
AvatarColor.amber => const Color.fromARGB(255, 217, 119, 6),
133+
};
134+
}
135+
136+
class UserAvatarPreference {
137+
final AvatarColor color;
138+
139+
const UserAvatarPreference({this.color = AvatarColor.primary});
140+
141+
@override
142+
bool operator ==(covariant UserAvatarPreference other) {
143+
if (identical(this, other)) return true;
144+
145+
return other.color == color;
146+
}
147+
148+
@override
149+
int get hashCode => color.hashCode;
150+
151+
Map<String, Object?> toMap() {
152+
return {"avatar-Color": color.value};
153+
}
154+
155+
factory UserAvatarPreference.fromMap(Map<String, Object?> map) {
156+
return UserAvatarPreference(
157+
color: AvatarColor.values.firstWhere(
158+
(e) => e.value == map["avatar-Color"] as String?,
159+
orElse: () => AvatarColor.primary,
160+
),
161+
);
162+
}
163+
}
164+
165+
class UserPurchasePreference {
166+
final bool showSupportBadge;
167+
168+
const UserPurchasePreference({this.showSupportBadge = true});
169+
170+
@override
171+
bool operator ==(covariant UserPurchasePreference other) {
172+
if (identical(this, other)) return true;
173+
174+
return other.showSupportBadge == showSupportBadge;
175+
}
176+
177+
@override
178+
int get hashCode => showSupportBadge.hashCode;
179+
180+
Map<String, Object?> toMap() {
181+
return {"purchase-ShowSupportBadge": showSupportBadge};
182+
}
183+
184+
factory UserPurchasePreference.fromMap(Map<String, Object?> map) {
185+
return UserPurchasePreference(
186+
showSupportBadge: map["purchase-ShowSupportBadge"] as bool? ?? true,
187+
);
188+
}
189+
}
190+
191+
class UserPreferences {
192+
final UserFolderPreference folders;
193+
final UserMemoryPreference memories;
194+
final UserPeoplePreference people;
195+
final UserRatingPreference ratings;
196+
final UserSharedLinksPreference sharedLinks;
197+
final UserTagPreference tags;
198+
final UserAvatarPreference avatar;
199+
final UserPurchasePreference purchase;
200+
201+
const UserPreferences({
202+
this.folders = const UserFolderPreference(),
203+
this.memories = const UserMemoryPreference(),
204+
this.people = const UserPeoplePreference(),
205+
this.ratings = const UserRatingPreference(),
206+
this.sharedLinks = const UserSharedLinksPreference(),
207+
this.tags = const UserTagPreference(),
208+
this.avatar = const UserAvatarPreference(),
209+
this.purchase = const UserPurchasePreference(),
210+
});
211+
212+
UserPreferences copyWith({
213+
UserFolderPreference? folders,
214+
UserMemoryPreference? memories,
215+
UserPeoplePreference? people,
216+
UserRatingPreference? ratings,
217+
UserSharedLinksPreference? sharedLinks,
218+
UserTagPreference? tags,
219+
UserAvatarPreference? avatar,
220+
UserPurchasePreference? purchase,
221+
}) =>
222+
UserPreferences(
223+
folders: folders ?? this.folders,
224+
memories: memories ?? this.memories,
225+
people: people ?? this.people,
226+
ratings: ratings ?? this.ratings,
227+
sharedLinks: sharedLinks ?? this.sharedLinks,
228+
tags: tags ?? this.tags,
229+
avatar: avatar ?? this.avatar,
230+
purchase: purchase ?? this.purchase,
231+
);
232+
233+
Map<String, Object?> toMap() {
234+
final preferences = <String, Object?>{};
235+
preferences.addAll(folders.toMap());
236+
preferences.addAll(memories.toMap());
237+
preferences.addAll(people.toMap());
238+
preferences.addAll(ratings.toMap());
239+
preferences.addAll(sharedLinks.toMap());
240+
preferences.addAll(tags.toMap());
241+
preferences.addAll(avatar.toMap());
242+
preferences.addAll(purchase.toMap());
243+
return preferences;
244+
}
245+
246+
factory UserPreferences.fromMap(Map<String, Object?> map) {
247+
return UserPreferences(
248+
folders: UserFolderPreference.fromMap(map),
249+
memories: UserMemoryPreference.fromMap(map),
250+
people: UserPeoplePreference.fromMap(map),
251+
ratings: UserRatingPreference.fromMap(map),
252+
sharedLinks: UserSharedLinksPreference.fromMap(map),
253+
tags: UserTagPreference.fromMap(map),
254+
avatar: UserAvatarPreference.fromMap(map),
255+
purchase: UserPurchasePreference.fromMap(map),
256+
);
257+
}
258+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:drift/drift.dart';
2+
import 'package:immich_mobile/infrastructure/entities/user.entity.dart';
3+
4+
class PartnerEntity extends Table {
5+
const PartnerEntity();
6+
7+
TextColumn get sharedById =>
8+
text().references(UserEntity, #id, onDelete: KeyAction.cascade)();
9+
10+
TextColumn get sharedWithId =>
11+
text().references(UserEntity, #id, onDelete: KeyAction.cascade)();
12+
13+
BoolColumn get inTimeline => boolean().withDefault(const Constant(false))();
14+
15+
@override
16+
Set<Column> get primaryKey => {sharedById, sharedWithId};
17+
}

0 commit comments

Comments
 (0)