Skip to content

Commit 0efcda5

Browse files
authored
Merge pull request #132 from camelus-hq/copilot/show-feed-without-login
Enable feed viewing without login using read-only NDK accounts
2 parents 847b7eb + 1d66433 commit 0efcda5

24 files changed

+459
-96
lines changed

lib/config/camelus_config.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ class CamelusConfig {
1111
static const notificationGUid = "7d199e2a-2278-478f-88c7-af410c4ebbad";
1212

1313
static const firebaseEnabled = true;
14+
15+
/// Default read-only pubkey for anonymous users (before login)
16+
/// This is a well-known public account used to populate the feed for new users
17+
/// Users can follow popular accounts through this read-only view
18+
static const String defaultAnonReadPubkey =
19+
"76c71aae3a491f1d9eec47cba17e229cda4113a0bbb6e6ae1776d7643e29cafa";
1420
}

lib/domain_layer/entities/stored_account.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:ndk/ndk.dart';
22

33
import 'key_pair.dart';
44

5-
enum LoginType { register, privateKey, amber, bunkerConnection }
5+
enum LoginType { register, privateKey, amber, bunkerConnection, readOnly, anon }
66

77
class StartupAccountData {
88
final LoginType loginType;

lib/domain_layer/usecases/app_auth.dart

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import 'dart:async';
22
import 'dart:convert';
3+
import 'dart:ui';
34

45
import 'package:amberflutter/amberflutter.dart';
56
import 'package:flutter/foundation.dart';
7+
import 'package:flutter/material.dart';
68
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
9+
import 'package:go_router/go_router.dart';
710
import 'package:ndk/data_layer/repositories/signers/nip46_event_signer.dart';
811
import 'package:ndk/ndk.dart';
912
import 'package:ndk/shared/nips/nip19/nip19.dart';
1013
import 'package:ndk_amber/ndk_amber.dart';
14+
import 'package:phosphor_flutter/phosphor_flutter.dart';
15+
import '../../l10n/app_localizations.dart';
1116
import '../../presentation_layer/providers/signer_provider.dart';
1217
import '../entities/stored_account.dart';
1318

@@ -127,6 +132,18 @@ class AppAuth {
127132
return null;
128133
}
129134

135+
case LoginType.readOnly:
136+
// For read-only accounts, use NDK's loginReadOnlyPubkey
137+
if (startupAccountData.account?.pubkey != null) {
138+
ndk.accounts.loginPublicKey(
139+
pubkey: startupAccountData.account!.pubkey!,
140+
);
141+
}
142+
return null;
143+
144+
case LoginType.anon:
145+
return null;
146+
130147
case LoginType.register:
131148
return null;
132149
}
@@ -141,7 +158,7 @@ class AppAuth {
141158
);
142159

143160
if (activeAccountPubkey == null || storedAccountsString == null) {
144-
return StartupAccountData(loginType: LoginType.register);
161+
return StartupAccountData(loginType: LoginType.anon);
145162
}
146163

147164
final storedAccounts = jsonDecode(storedAccountsString) as List;
@@ -160,7 +177,7 @@ class AppAuth {
160177
// if no match found, use last account or register if list is empty
161178
matchedAccount = storedAccountsList.isNotEmpty
162179
? storedAccountsList.last
163-
: LocalStorageAccount(loginType: LoginType.register);
180+
: LocalStorageAccount(loginType: LoginType.anon);
164181
}
165182

166183
return StartupAccountData(
@@ -202,4 +219,42 @@ class AppAuth {
202219
await secureStorage.delete(key: AppAuth.activeAccountPubkeyStorageKey);
203220
await secureStorage.delete(key: AppAuth.accountStorageKey);
204221
}
222+
223+
static void showLoginPrompt(BuildContext context) {
224+
showDialog(
225+
context: context,
226+
builder: (context) => BackdropFilter(
227+
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
228+
child: AlertDialog(
229+
icon: Icon(
230+
PhosphorIcons.lockKey(),
231+
size: 48,
232+
color: Theme.of(context).colorScheme.primary,
233+
),
234+
title: Text(
235+
AppLocalizations.of(context)!.loginRegistrationRequired,
236+
textAlign: TextAlign.center,
237+
),
238+
content: Text(
239+
AppLocalizations.of(context)!.pleaseLoginToInteract,
240+
textAlign: TextAlign.center,
241+
),
242+
actionsAlignment: MainAxisAlignment.center,
243+
actions: [
244+
TextButton(
245+
onPressed: () => Navigator.pop(context),
246+
child: Text(AppLocalizations.of(context)!.cancel),
247+
),
248+
FilledButton(
249+
onPressed: () {
250+
Navigator.pop(context);
251+
context.push('/onboarding');
252+
},
253+
child: Text(AppLocalizations.of(context)!.loginRegister),
254+
),
255+
],
256+
),
257+
),
258+
);
259+
}
205260
}

lib/l10n/app_de.arb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@
195195
"removingFromBookmarks": "Wird aus Lesezeichen entfernt...",
196196
"failedToAddBookmark": "Lesezeichen konnte nicht hinzugefügt werden",
197197
"failedToRemoveBookmark": "Lesezeichen konnte nicht entfernt werden",
198+
"pleaseLoginToManageFileServers": "Bitte melden Sie sich an, um Dateiserver zu verwalten",
199+
"browseWithoutLogin": "Ohne Anmeldung durchsuchen",
200+
"loginRegistrationRequired": "Anmeldung/Registrierung erforderlich",
201+
"pleaseLoginToInteract": "Bitte melden Sie sich an/registrieren Sie sich, um mit Beiträgen zu interagieren",
202+
"loginRegister": "Anmelden/Registrieren",
198203
"all": "Alle",
199204
"mentions": "Erwähnungen",
200205
"preview": "Vorschau",

lib/l10n/app_en.arb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,34 @@
815815
"@welcome": {
816816
"description": "Welcome greeting text"
817817
},
818+
"pleaseLoginToManageFileServers": "Please login to manage file servers",
819+
"@pleaseLoginToManageFileServers": {
820+
"description": "Message shown when user is not logged in on file servers page"
821+
},
822+
"welcomeTo": "welcome to",
823+
"@welcomeTo": {
824+
"description": "Welcome greeting prefix on onboarding page"
825+
},
826+
"joinTheConversation": "join the conversation",
827+
"@joinTheConversation": {
828+
"description": "Button text to register/join Camelus"
829+
},
830+
"browseWithoutLogin": "Browse without login",
831+
"@browseWithoutLogin": {
832+
"description": "Button text to browse app without logging in"
833+
},
834+
"loginRegistrationRequired": "Login/Registration Required",
835+
"@loginRegistrationRequired": {
836+
"description": "Dialog title prompting user to login or register"
837+
},
838+
"pleaseLoginToInteract": "Please login/register to interact with posts",
839+
"@pleaseLoginToInteract": {
840+
"description": "Message explaining user needs to login to interact with content"
841+
},
842+
"loginRegister": "Login/Register",
843+
"@loginRegister": {
844+
"description": "Button text for login or register action"
845+
},
818846
"all": "All",
819847
"@all": {
820848
"description": "All tab label for notifications and filters"

lib/l10n/app_es.arb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"following": "Siguiendo",
5353
"followers": "Seguidores",
5454
"profile": "Perfil",
55-
5655
"notImplementedYet": "Aún no implementado",
5756
"payments": "Pagos",
5857
"blocklist": "Lista de Bloqueados",
@@ -195,6 +194,14 @@
195194
"addingToBookmarks": "Agregando a marcadores...",
196195
"removingFromBookmarks": "Eliminando de marcadores...",
197196
"failedToAddBookmark": "No se pudo agregar el marcador",
197+
"welcomeTo": "bienvenido a",
198+
"joinTheConversation": "únete a la conversación",
199+
"browseWithoutLogin": "Navegar sin iniciar sesión",
200+
"loginRegistrationRequired": "Inicio de sesión/Registro requerido",
201+
"pleaseLoginToInteract": "Por favor, inicia sesión/regístrate para interactuar con las publicaciones",
202+
"loginRegister": "Iniciar sesión/Registrarse",
203+
"failedToRemoveBookmark": "No se pudo eliminar el marcador",
204+
"pleaseLoginToManageFileServers": "Por favor, inicia sesión para administrar los servidores de archivos",
198205
"failedToRemoveBookmark": "No se pudo eliminar el marcador",
199206
"all": "Todos",
200207
"mentions": "Menciones",
@@ -362,4 +369,4 @@
362369
}
363370
}
364371
}
365-
}
372+
}

lib/l10n/app_fr.arb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@
195195
"removingFromBookmarks": "Suppression des favoris...",
196196
"failedToAddBookmark": "Échec de l'ajout du favori",
197197
"failedToRemoveBookmark": "Échec de la suppression du favori",
198+
"pleaseLoginToManageFileServers": "Veuillez vous connecter pour gérer les serveurs de fichiers",
199+
"welcomeTo": "bienvenue à",
200+
"joinTheConversation": "rejoindre la conversation",
201+
"browseWithoutLogin": "Parcourir sans se connecter",
202+
"loginRegistrationRequired": "Connexion/Inscription requise",
203+
"pleaseLoginToInteract": "Veuillez vous connecter/vous inscrire pour interagir avec les publications",
204+
"loginRegister": "Se connecter/S'inscrire",
198205
"all": "Tous",
199206
"mentions": "Mentions",
200207
"preview": "Aperçu",

lib/l10n/app_ja.arb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@
195195
"removingFromBookmarks": "ブックマークから削除中...",
196196
"failedToAddBookmark": "ブックマークの追加に失敗しました",
197197
"failedToRemoveBookmark": "ブックマークの削除に失敗しました",
198+
"pleaseLoginToManageFileServers": "ファイルサーバーを管理するにはログインしてください",
199+
"welcomeTo": "ようこそ",
200+
"joinTheConversation": "会話に参加する",
201+
"browseWithoutLogin": "ログインせずに閲覧",
202+
"loginRegistrationRequired": "ログイン/登録が必要です",
203+
"pleaseLoginToInteract": "投稿とやり取りするにはログイン/登録してください",
204+
"loginRegister": "ログイン/登録",
198205
"all": "すべて",
199206
"mentions": "メンション",
200207
"preview": "プレビュー",

lib/l10n/app_pt.arb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@
195195
"removingFromBookmarks": "Removendo dos favoritos...",
196196
"failedToAddBookmark": "Falha ao adicionar favorito",
197197
"failedToRemoveBookmark": "Falha ao remover favorito",
198+
"pleaseLoginToManageFileServers": "Por favor, faça login para gerenciar servidores de arquivos",
199+
"welcomeTo": "bem-vindo ao",
200+
"joinTheConversation": "participe da conversa",
201+
"browseWithoutLogin": "Navegar sem fazer login",
202+
"loginRegistrationRequired": "Login/Registro necessário",
203+
"pleaseLoginToInteract": "Por favor, faça login/registre-se para interagir com publicações",
204+
"loginRegister": "Login/Registro",
198205
"all": "Todos",
199206
"mentions": "Menções",
200207
"preview": "Visualização",

lib/l10n/app_ru.arb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@
195195
"removingFromBookmarks": "Удаление из закладок...",
196196
"failedToAddBookmark": "Не удалось добавить закладку",
197197
"failedToRemoveBookmark": "Не удалось удалить закладку",
198+
"pleaseLoginToManageFileServers": "Пожалуйста, войдите, чтобы управлять файловыми серверами",
199+
"welcomeTo": "добро пожаловать в",
200+
"joinTheConversation": "присоединиться к разговору",
201+
"browseWithoutLogin": "Просмотр без входа",
202+
"loginRegistrationRequired": "Требуется вход/регистрация",
203+
"pleaseLoginToInteract": "Пожалуйста, войдите/зарегистрируйтесь, чтобы взаимодействовать с постами",
204+
"loginRegister": "Войти/Зарегистрироваться",
198205
"all": "Все",
199206
"mentions": "Упоминания",
200207
"preview": "Предпросмотр",

0 commit comments

Comments
 (0)