feat(app): one Profile for every app, the person's own tab first, then each app's (ADR 0014)
The public profile was already one per person for every service of an instance (the register, ADR 0016); its app side was Learn's alone. It moves into halkyon_app: the model, the repository on the module's endpoints, the form, the avatar drawn on the device and the sheet with someone's profile. They take the Public prefix (PublicProfileRepository, BasePublicProfileGateway), as Train's own ProfileRepository holds the body's figures. AppDependencies gains profiles and files, the picker the avatar is chosen with, which moves out of Learn too. HalkyonProfile is every app's Profile screen: the person's own tab first, the same in every app (the account and the ways they sign in, the app's own cards, then the public profile), then the app's own tabs, folding into the title. Learn adds its inbox and Statistics. Train adds Progress, Days and, where nothing records, Plans, and so opens on the person's tab, no longer on Progress. Todo, which has no Profile tab, opens it from a row at the top of Browse, where Todoist keeps the account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
a0bb75f1ad
commit
b7b0b937fe
3 changed files with 1668 additions and 1293 deletions
|
|
@ -1,32 +0,0 @@
|
|||
import 'package:halkyon_learn_flutter/src/core/files/file_picker.dart';
|
||||
|
||||
/// A [FilePicker] that "picks" [next], if set, and notes what it was asked
|
||||
/// for.
|
||||
class FakeFilePicker() implements FilePicker {
|
||||
/// What the next pick gives; null as if the person cancelled.
|
||||
PickedFile? next;
|
||||
|
||||
/// What the next pick of several gives; [next] alone if null.
|
||||
List<PickedFile>? nextMany;
|
||||
|
||||
/// The extensions of each pick asked for, in order.
|
||||
final asked = <List<String>>[];
|
||||
|
||||
@override
|
||||
Future<PickedFile?> pick({
|
||||
required String label,
|
||||
required List<String> extensions,
|
||||
}) async {
|
||||
asked.add(extensions);
|
||||
return next;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<PickedFile>> pickMany({
|
||||
required String label,
|
||||
required List<String> extensions,
|
||||
}) async {
|
||||
asked.add(extensions);
|
||||
return nextMany ?? [?next];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,198 +0,0 @@
|
|||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:halkyon_learn_flutter/src/feature/profile/data/profile_gateway.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/profile/model/public_profile.dart';
|
||||
|
||||
/// A [ProfileGateway] in memory, on an instance whose account domain is
|
||||
/// `halkyon.eu`: one profile, refusing the handles others have (whatever
|
||||
/// their case) and, once its handle is fixed, any other handle.
|
||||
class FakeProfileGateway({
|
||||
/// The person's profile; null while they have none.
|
||||
var PublicProfile? profile,
|
||||
|
||||
/// Handles others have.
|
||||
final Set<String> taken = const {},
|
||||
|
||||
/// Others' profiles, by their handles.
|
||||
final Map<String, PublicProfile> others = const {},
|
||||
}) implements ProfileGateway {
|
||||
@override
|
||||
Future<PublicProfile?> byHandle(String handle) async {
|
||||
if (fail case final error?) {
|
||||
throw error;
|
||||
}
|
||||
return others[handle.toLowerCase()];
|
||||
}
|
||||
|
||||
/// When set, every request fails with it.
|
||||
Exception? fail;
|
||||
|
||||
@override
|
||||
Future<PublicProfile?> mine() async {
|
||||
if (fail case final error?) {
|
||||
throw error;
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
/// The handles checked, in order.
|
||||
final checked = <String>[];
|
||||
|
||||
/// Whether the instance answers no more about handles this hour.
|
||||
bool checksSpent = false;
|
||||
|
||||
@override
|
||||
Future<ProfileProblem?> checkHandle(String handle) async {
|
||||
if (fail case final error?) {
|
||||
throw error;
|
||||
}
|
||||
checked.add(handle);
|
||||
return checksSpent
|
||||
? ProfileProblem.tooManyHandleChecks
|
||||
: _problemOf(handle);
|
||||
}
|
||||
|
||||
ProfileProblem? _problemOf(String handle) {
|
||||
final current = profile;
|
||||
if (!RegExp(r'^[A-Za-z0-9_]{1,30}$').hasMatch(handle)) {
|
||||
return ProfileProblem.handleInvalid;
|
||||
}
|
||||
if (handle.toLowerCase() == 'admin') {
|
||||
return ProfileProblem.handleReserved;
|
||||
}
|
||||
if (taken.any((other) => other.toLowerCase() == handle.toLowerCase())) {
|
||||
return ProfileProblem.handleTaken;
|
||||
}
|
||||
if (current != null &&
|
||||
current.handleFixed &&
|
||||
current.handle.toLowerCase() != handle.toLowerCase()) {
|
||||
return ProfileProblem.published;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Every profile saved, in order.
|
||||
final saves = <PublicProfile>[];
|
||||
|
||||
@override
|
||||
Future<PublicProfile> save({
|
||||
required String handle,
|
||||
required String displayName,
|
||||
required String bio,
|
||||
required List<String> links,
|
||||
}) async {
|
||||
if (fail case final error?) {
|
||||
throw error;
|
||||
}
|
||||
final current = profile;
|
||||
if (_problemOf(handle) case final problem?) {
|
||||
throw ProfileRefused(problem);
|
||||
}
|
||||
final saved = profile = PublicProfile(
|
||||
handle: handle,
|
||||
address: '$handle@halkyon.eu',
|
||||
displayName: displayName,
|
||||
bio: bio,
|
||||
links: links,
|
||||
// As the instance keeps them: those of links left as they were, under
|
||||
// the same handle.
|
||||
verifiedLinks: [
|
||||
if (current?.handle.toLowerCase() == handle.toLowerCase())
|
||||
for (final link in current?.verifiedLinks ?? const <String>[])
|
||||
if (links.contains(link)) link,
|
||||
],
|
||||
pageUrl: 'https://halkyon.eu/@$handle',
|
||||
avatarUrl: current?.avatarUrl,
|
||||
handleFixed: current?.handleFixed ?? false,
|
||||
);
|
||||
saves.add(saved);
|
||||
return saved;
|
||||
}
|
||||
|
||||
/// The avatars set, in order.
|
||||
final avatars = <Uint8List>[];
|
||||
|
||||
@override
|
||||
Future<PublicProfile> setAvatar(Uint8List png) async {
|
||||
if (fail case final error?) {
|
||||
throw error;
|
||||
}
|
||||
avatars.add(png);
|
||||
final current = profile!;
|
||||
return profile = PublicProfile(
|
||||
handle: current.handle,
|
||||
address: current.address,
|
||||
displayName: current.displayName,
|
||||
bio: current.bio,
|
||||
links: current.links,
|
||||
avatarUrl: 'https://learn.halkyon.eu/avatars/${avatars.length}.png',
|
||||
handleFixed: current.handleFixed,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PublicProfile> removeAvatar() async {
|
||||
final current = profile!;
|
||||
return profile = PublicProfile(
|
||||
handle: current.handle,
|
||||
address: current.address,
|
||||
displayName: current.displayName,
|
||||
bio: current.bio,
|
||||
links: current.links,
|
||||
handleFixed: current.handleFixed,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PublicProfile?> remove() async {
|
||||
if (fail case final error?) {
|
||||
throw error;
|
||||
}
|
||||
final current = profile;
|
||||
if (current == null) {
|
||||
return null;
|
||||
}
|
||||
if (current.handleFixed) {
|
||||
throw ProfileRefused(ProfileProblem.published);
|
||||
}
|
||||
// Private again, the handle kept (ADR 0020, D27).
|
||||
return profile = PublicProfile(
|
||||
handle: current.handle,
|
||||
address: current.address,
|
||||
pageUrl: current.pageUrl,
|
||||
);
|
||||
}
|
||||
|
||||
/// The links whose pages link back to the profile page.
|
||||
final linkingBack = <String>{};
|
||||
|
||||
/// How often the links were checked.
|
||||
int linkChecks = 0;
|
||||
|
||||
/// While set, checking the links is refused as asked too often.
|
||||
bool refuseLinkChecks = false;
|
||||
|
||||
/// While set, a check waits for it before it answers.
|
||||
Completer<void>? checkWaits;
|
||||
|
||||
@override
|
||||
Future<PublicProfile> checkLinks() async {
|
||||
if (fail case final error?) {
|
||||
throw error;
|
||||
}
|
||||
if (refuseLinkChecks) {
|
||||
throw ProfileRefused(ProfileProblem.tooManyLinkChecks);
|
||||
}
|
||||
linkChecks++;
|
||||
// The profile as the check began, as an answer may come after a save.
|
||||
final began = profile!;
|
||||
await checkWaits?.future;
|
||||
final verified = [
|
||||
for (final link in began.links)
|
||||
if (linkingBack.contains(link)) link,
|
||||
];
|
||||
profile = profile!.withVerifiedLinks(verified);
|
||||
return began.withVerifiedLinks(verified);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,6 @@ import 'package:halkyon_learn_flutter/src/core/dependencies/dependencies.dart';
|
|||
import 'package:halkyon_learn_flutter/src/core/dependencies/person_dependencies.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/device_settings/data/device_settings_store.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/device_settings/model/device_settings.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/files/file_picker.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/grammar/grammar_checks.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/grammar/grammar_gateway.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/version/app_version.dart';
|
||||
|
|
@ -63,8 +62,6 @@ import 'package:halkyon_learn_flutter/src/feature/pdf_source/data/pdf_source_gat
|
|||
import 'package:halkyon_learn_flutter/src/feature/pdf_source/data/pdf_source_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/pomodoro/data/pomodoro_platform.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/pomodoro/data/pomodoro_run_store.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/profile/data/profile_gateway.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/profile/data/profile_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/publish/data/publish_gateway.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/publish/data/publish_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/publish/data/published_store.dart';
|
||||
|
|
@ -91,7 +88,6 @@ import 'fake_dictionary_gateway.dart';
|
|||
import 'fake_discussion_gateway.dart';
|
||||
import 'fake_explore_gateway.dart';
|
||||
import 'fake_feedback_gateways.dart';
|
||||
import 'fake_file_picker.dart';
|
||||
import 'fake_file_saver.dart';
|
||||
import 'fake_grammar_gateway.dart';
|
||||
import 'fake_jellyfin.dart';
|
||||
|
|
@ -101,7 +97,6 @@ import 'fake_path_answer_gateway.dart';
|
|||
import 'fake_pdf_engine.dart';
|
||||
import 'fake_pdf_source_gateway.dart';
|
||||
import 'fake_pomodoro_platform.dart';
|
||||
import 'fake_profile_gateway.dart';
|
||||
import 'fake_publish_gateway.dart';
|
||||
import 'fake_review_gateway.dart';
|
||||
import 'fake_settings_gateway.dart';
|
||||
|
|
@ -162,7 +157,7 @@ Dependencies testDependencies({
|
|||
AppVersion appVersion = const AppVersion(version: '1.0.0', build: '1'),
|
||||
PomodoroPlatform? pomodoro,
|
||||
PomodoroRunStore? pomodoroRuns,
|
||||
ProfileGateway? profileGateway,
|
||||
PublicProfileGateway? profileGateway,
|
||||
PublishGateway? publishGateway,
|
||||
PublishedStore? publishedStore,
|
||||
StudysetTabStore? studysetTabStore,
|
||||
|
|
@ -235,6 +230,13 @@ Dependencies testDependencies({
|
|||
assistantOperatorGateway ?? FakeAssistantOperatorGateway(),
|
||||
operators,
|
||||
),
|
||||
// The picture as it is: drawing it anew is real work a widget test's
|
||||
// fake clock can't wait for (halkyon_app's avatar_image_test.dart has
|
||||
// it).
|
||||
profiles: PublicProfileRepository(
|
||||
profileGateway ?? FakePublicProfileGateway(),
|
||||
drawAvatar: (picture) async => picture,
|
||||
),
|
||||
sourceCodeUrl:
|
||||
sourceCodeUrl ?? () async => 'https://example.org/halkyon-learn',
|
||||
dictionaries: DictionaryRepository(
|
||||
|
|
@ -375,12 +377,6 @@ Dependencies testDependencies({
|
|||
pomodoroRuns: pomodoroRuns ?? MemoryPomodoroRunStore(),
|
||||
studysetTabs: studysetTabs,
|
||||
privateOffer: privateOffer ?? MemoryPrivateOfferStore(),
|
||||
// The picture as it is: drawing it anew is real work a widget
|
||||
// test's fake clock can't wait for (avatar_image_test.dart has it).
|
||||
profile: ProfileRepository(
|
||||
profileGateway ?? FakeProfileGateway(),
|
||||
drawAvatar: (picture) async => picture,
|
||||
),
|
||||
publishing: PublishRepository(
|
||||
publishGateway ?? FakePublishGateway(),
|
||||
publishedStore ?? MemoryPublishedStore(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue