Joindable chat, detailed realms, discovery mixed into explore

🐛 bunch of bugs fixes
This commit is contained in:
LittleSheep 2025-06-28 00:24:43 +08:00
parent 536375729f
commit b8dec9f798
18 changed files with 393 additions and 147 deletions

View File

@ -556,5 +556,12 @@
"tags": "Tags", "tags": "Tags",
"tagsHint": "Enter tags, separated by commas", "tagsHint": "Enter tags, separated by commas",
"categories": "Categories", "categories": "Categories",
"categoriesHint": "Enter categories, separated by commas" "categoriesHint": "Enter categories, separated by commas",
"chatNotJoined": "You have not joined this chat yet.",
"chatUnableJoin": "You can't join this chat due to it's access control settings.",
"chatJoin": "Join the Chat",
"realmJoin": "Join the Realm",
"realmJoinSuccess": "Successfully joined the realm.",
"discoverRealms": "Discover Realms",
"discoverPublishers": "Discover Publishers"
} }

View File

@ -3,7 +3,7 @@
archiveVersion = 1; archiveVersion = 1;
classes = { classes = {
}; };
objectVersion = 54; objectVersion = 77;
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
@ -525,10 +525,14 @@
inputFileListPaths = ( inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
); );
inputPaths = (
);
name = "[CP] Copy Pods Resources"; name = "[CP] Copy Pods Resources";
outputFileListPaths = ( outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
); );
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
@ -586,10 +590,14 @@
inputFileListPaths = ( inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
); );
inputPaths = (
);
name = "[CP] Embed Pods Frameworks"; name = "[CP] Embed Pods Frameworks";
outputFileListPaths = ( outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
); );
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
@ -857,7 +865,7 @@
INFOPLIST_FILE = SolianShareExtension/Info.plist; INFOPLIST_FILE = SolianShareExtension/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = SolianShareExtension; INFOPLIST_KEY_CFBundleDisplayName = SolianShareExtension;
INFOPLIST_KEY_NSHumanReadableCopyright = ""; INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 18.5; IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -900,7 +908,7 @@
INFOPLIST_FILE = SolianShareExtension/Info.plist; INFOPLIST_FILE = SolianShareExtension/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = SolianShareExtension; INFOPLIST_KEY_CFBundleDisplayName = SolianShareExtension;
INFOPLIST_KEY_NSHumanReadableCopyright = ""; INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 18.5; IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -940,7 +948,7 @@
INFOPLIST_FILE = SolianShareExtension/Info.plist; INFOPLIST_FILE = SolianShareExtension/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = SolianShareExtension; INFOPLIST_KEY_CFBundleDisplayName = SolianShareExtension;
INFOPLIST_KEY_NSHumanReadableCopyright = ""; INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 18.5; IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -979,7 +987,7 @@
INFOPLIST_FILE = SolianNotificationService/Info.plist; INFOPLIST_FILE = SolianNotificationService/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = SolianNotificationService; INFOPLIST_KEY_CFBundleDisplayName = SolianNotificationService;
INFOPLIST_KEY_NSHumanReadableCopyright = ""; INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 18.5; IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -1021,7 +1029,7 @@
INFOPLIST_FILE = SolianNotificationService/Info.plist; INFOPLIST_FILE = SolianNotificationService/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = SolianNotificationService; INFOPLIST_KEY_CFBundleDisplayName = SolianNotificationService;
INFOPLIST_KEY_NSHumanReadableCopyright = ""; INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 18.5; IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
@ -1060,7 +1068,7 @@
INFOPLIST_FILE = SolianNotificationService/Info.plist; INFOPLIST_FILE = SolianNotificationService/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = SolianNotificationService; INFOPLIST_KEY_CFBundleDisplayName = SolianNotificationService;
INFOPLIST_KEY_NSHumanReadableCopyright = ""; INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 18.5; IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",

View File

@ -71,25 +71,32 @@ class MessageRepository {
bool synced = false, bool synced = false,
}) async { }) async {
try { try {
// For initial load, fetch latest messages in the background to sync.
if (offset == 0 && !synced) {
// Not awaiting this is intentional, for a quicker UI response.
// The UI should rely on a stream from the database to get updates.
_fetchAndCacheMessages(room.id, offset: 0, take: take).catchError((_) {
// Best effort, errors will be handled by later fetches.
return <LocalChatMessage>[];
});
}
final localMessages = await _getCachedMessages( final localMessages = await _getCachedMessages(
room.id, room.id,
offset: offset, offset: offset,
take: take, take: take,
); );
// If it already synced with the remote, skip this // If local cache has messages, return them. This is the common case for scrolling up.
if (offset == 0 && !synced) { if (localMessages.isNotEmpty) {
// Fetch latest messages return localMessages;
_fetchAndCacheMessages(room.id, offset: offset, take: take);
if (localMessages.isNotEmpty) {
return localMessages;
}
} }
// If local cache is empty, we've probably reached the end of cached history.
// Fetch from remote. This will also be hit on first load if cache is empty.
return await _fetchAndCacheMessages(room.id, offset: offset, take: take); return await _fetchAndCacheMessages(room.id, offset: offset, take: take);
} catch (e) { } catch (e) {
// If API fails but we have local messages, return them // Final fallback to cache in case of network errors during fetch.
final localMessages = await _getCachedMessages( final localMessages = await _getCachedMessages(
room.id, room.id,
offset: offset, offset: offset,
@ -117,24 +124,26 @@ class MessageRepository {
final dbLocalMessages = final dbLocalMessages =
dbMessages.map(_database.companionToMessage).toList(); dbMessages.map(_database.companionToMessage).toList();
// Combine with pending messages // Combine with pending messages for the first page
final pendingForRoom = if (offset == 0) {
pendingMessages.values.where((msg) => msg.roomId == roomId).toList(); final pendingForRoom =
pendingMessages.values.where((msg) => msg.roomId == roomId).toList();
// Sort by timestamp descending (newest first) final allMessages = [...pendingForRoom, ...dbLocalMessages];
final allMessages = [...pendingForRoom, ...dbLocalMessages]; allMessages.sort((a, b) => b.createdAt.compareTo(a.createdAt));
allMessages.sort((a, b) => b.createdAt.compareTo(a.createdAt));
// Apply pagination // Remove duplicates by ID, preserving the order
if (offset >= allMessages.length) { final uniqueMessages = <LocalChatMessage>[];
return []; final seenIds = <String>{};
for (final message in allMessages) {
if (seenIds.add(message.id)) {
uniqueMessages.add(message);
}
}
return uniqueMessages;
} }
final end = return dbLocalMessages;
(offset + take) > allMessages.length
? allMessages.length
: (offset + take);
return allMessages.sublist(offset, end);
} }
Future<List<LocalChatMessage>> _fetchAndCacheMessages( Future<List<LocalChatMessage>> _fetchAndCacheMessages(

View File

@ -13,8 +13,8 @@ sealed class SnChatRoom with _$SnChatRoom {
required String? name, required String? name,
required String? description, required String? description,
required int type, required int type,
required bool isPublic, @Default(false) bool isPublic,
required bool isCommunity, @Default(false) bool isCommunity,
required SnCloudFile? picture, required SnCloudFile? picture,
required SnCloudFile? background, required SnCloudFile? background,
required String? realmId, required String? realmId,

View File

@ -129,15 +129,15 @@ $SnRealmCopyWith<$Res>? get realm {
@JsonSerializable() @JsonSerializable()
class _SnChatRoom implements SnChatRoom { class _SnChatRoom implements SnChatRoom {
const _SnChatRoom({required this.id, required this.name, required this.description, required this.type, required this.isPublic, required this.isCommunity, required this.picture, required this.background, required this.realmId, required this.realm, required this.createdAt, required this.updatedAt, required this.deletedAt, required final List<SnChatMember>? members}): _members = members; const _SnChatRoom({required this.id, required this.name, required this.description, required this.type, this.isPublic = false, this.isCommunity = false, required this.picture, required this.background, required this.realmId, required this.realm, required this.createdAt, required this.updatedAt, required this.deletedAt, required final List<SnChatMember>? members}): _members = members;
factory _SnChatRoom.fromJson(Map<String, dynamic> json) => _$SnChatRoomFromJson(json); factory _SnChatRoom.fromJson(Map<String, dynamic> json) => _$SnChatRoomFromJson(json);
@override final String id; @override final String id;
@override final String? name; @override final String? name;
@override final String? description; @override final String? description;
@override final int type; @override final int type;
@override final bool isPublic; @override@JsonKey() final bool isPublic;
@override final bool isCommunity; @override@JsonKey() final bool isCommunity;
@override final SnCloudFile? picture; @override final SnCloudFile? picture;
@override final SnCloudFile? background; @override final SnCloudFile? background;
@override final String? realmId; @override final String? realmId;

View File

@ -11,8 +11,8 @@ _SnChatRoom _$SnChatRoomFromJson(Map<String, dynamic> json) => _SnChatRoom(
name: json['name'] as String?, name: json['name'] as String?,
description: json['description'] as String?, description: json['description'] as String?,
type: (json['type'] as num).toInt(), type: (json['type'] as num).toInt(),
isPublic: json['is_public'] as bool, isPublic: json['is_public'] as bool? ?? false,
isCommunity: json['is_community'] as bool, isCommunity: json['is_community'] as bool? ?? false,
picture: picture:
json['picture'] == null json['picture'] == null
? null ? null

View File

@ -10,7 +10,7 @@ sealed class SnRealm with _$SnRealm {
const factory SnRealm({ const factory SnRealm({
required String id, required String id,
required String slug, required String slug,
required String name, @Default('') String name,
@Default('') String description, @Default('') String description,
required String? verifiedAs, required String? verifiedAs,
required DateTime? verifiedAt, required DateTime? verifiedAt,

View File

@ -117,12 +117,12 @@ $SnCloudFileCopyWith<$Res>? get background {
@JsonSerializable() @JsonSerializable()
class _SnRealm implements SnRealm { class _SnRealm implements SnRealm {
const _SnRealm({required this.id, required this.slug, required this.name, this.description = '', required this.verifiedAs, required this.verifiedAt, required this.isCommunity, required this.isPublic, required this.picture, required this.background, required this.accountId, required this.createdAt, required this.updatedAt, required this.deletedAt}); const _SnRealm({required this.id, required this.slug, this.name = '', this.description = '', required this.verifiedAs, required this.verifiedAt, required this.isCommunity, required this.isPublic, required this.picture, required this.background, required this.accountId, required this.createdAt, required this.updatedAt, required this.deletedAt});
factory _SnRealm.fromJson(Map<String, dynamic> json) => _$SnRealmFromJson(json); factory _SnRealm.fromJson(Map<String, dynamic> json) => _$SnRealmFromJson(json);
@override final String id; @override final String id;
@override final String slug; @override final String slug;
@override final String name; @override@JsonKey() final String name;
@override@JsonKey() final String description; @override@JsonKey() final String description;
@override final String? verifiedAs; @override final String? verifiedAs;
@override final DateTime? verifiedAt; @override final DateTime? verifiedAt;

View File

@ -9,7 +9,7 @@ part of 'realm.dart';
_SnRealm _$SnRealmFromJson(Map<String, dynamic> json) => _SnRealm( _SnRealm _$SnRealmFromJson(Map<String, dynamic> json) => _SnRealm(
id: json['id'] as String, id: json['id'] as String,
slug: json['slug'] as String, slug: json['slug'] as String,
name: json['name'] as String, name: json['name'] as String? ?? '',
description: json['description'] as String? ?? '', description: json['description'] as String? ?? '',
verifiedAs: json['verified_as'] as String?, verifiedAs: json['verified_as'] as String?,
verifiedAt: verifiedAt:

View File

@ -434,17 +434,31 @@ class ChatListScreen extends HookConsumerWidget {
@riverpod @riverpod
Future<SnChatRoom?> chatroom(Ref ref, String? identifier) async { Future<SnChatRoom?> chatroom(Ref ref, String? identifier) async {
if (identifier == null) return null; if (identifier == null) return null;
final client = ref.watch(apiClientProvider); try {
final resp = await client.get('/chat/$identifier'); final client = ref.watch(apiClientProvider);
return SnChatRoom.fromJson(resp.data); final resp = await client.get('/chat/$identifier');
return SnChatRoom.fromJson(resp.data);
} catch (err) {
if (err is DioException && err.response?.statusCode == 404) {
return null; // Chat room not found
}
rethrow; // Rethrow other errors
}
} }
@riverpod @riverpod
Future<SnChatMember?> chatroomIdentity(Ref ref, String? identifier) async { Future<SnChatMember?> chatroomIdentity(Ref ref, String? identifier) async {
if (identifier == null) return null; if (identifier == null) return null;
final client = ref.watch(apiClientProvider); try {
final resp = await client.get('/chat/$identifier/members/me'); final client = ref.watch(apiClientProvider);
return SnChatMember.fromJson(resp.data); final resp = await client.get('/chat/$identifier/members/me');
return SnChatMember.fromJson(resp.data);
} catch (err) {
if (err is DioException && err.response?.statusCode == 404) {
return null; // Chat member not found
}
rethrow; // Rethrow other errors
}
} }
class NewChatScreen extends StatelessWidget { class NewChatScreen extends StatelessWidget {

View File

@ -25,7 +25,7 @@ final chatroomsJoinedProvider =
@Deprecated('Will be removed in 3.0. Use Ref instead') @Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element // ignore: unused_element
typedef ChatroomsJoinedRef = AutoDisposeFutureProviderRef<List<SnChatRoom>>; typedef ChatroomsJoinedRef = AutoDisposeFutureProviderRef<List<SnChatRoom>>;
String _$chatroomHash() => r'dce3c0fc407f178bb7c306a08b9fa545795a9205'; String _$chatroomHash() => r'8dac7aaac50932e6dd213039102d43c1cf5f1d4e';
/// Copied from Dart SDK /// Copied from Dart SDK
class _SystemHash { class _SystemHash {
@ -164,7 +164,7 @@ class _ChatroomProviderElement
String? get identifier => (origin as ChatroomProvider).identifier; String? get identifier => (origin as ChatroomProvider).identifier;
} }
String _$chatroomIdentityHash() => r'4c349ea4265df7b0498cf26c82dbaabe3d868727'; String _$chatroomIdentityHash() => r'ad6ad09b6fc4cf7c4abe146ea97f8e364a3d4fd0';
/// See also [chatroomIdentity]. /// See also [chatroomIdentity].
@ProviderFor(chatroomIdentity) @ProviderFor(chatroomIdentity)

View File

@ -305,7 +305,55 @@ class ChatRoomScreen extends HookConsumerWidget {
// Identity was not found, user was not joined // Identity was not found, user was not joined
return AppScaffold( return AppScaffold(
appBar: AppBar(leading: const PageBackButton()), appBar: AppBar(leading: const PageBackButton()),
body: Center(child: Text('You are not a member of this chat room')), body: Center(
child:
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 280),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
chatRoom.value?.isCommunity == true
? Symbols.person_add
: Symbols.person_remove,
size: 36,
fill: 1,
).padding(bottom: 4),
Text('chatNotJoined').tr(),
if (chatRoom.value?.isCommunity != true)
Text(
'chatUnableJoin',
textAlign: TextAlign.center,
).tr().bold()
else
FilledButton.tonalIcon(
onPressed: () async {
try {
showLoadingModal(context);
final apiClient = ref.read(apiClientProvider);
if (chatRoom.value == null) {
hideLoadingModal(context);
return;
}
await apiClient.post(
'/chat/${chatRoom.value!.id}/members/me',
);
ref.invalidate(chatroomIdentityProvider(id));
} catch (err) {
showErrorAlert(err);
} finally {
if (context.mounted) hideLoadingModal(context);
}
},
label: Text('chatJoin').tr(),
icon: const Icon(Icons.add),
).padding(top: 8),
],
),
).center(),
),
); );
} }
@ -443,6 +491,28 @@ class ChatRoomScreen extends HookConsumerWidget {
return () => subscription.cancel(); return () => subscription.cancel();
}, [ws, chatRoom]); }, [ws, chatRoom]);
useEffect(() {
final wsState = ref.read(websocketStateProvider.notifier);
wsState.sendMessage(
jsonEncode(
WebSocketPacket(
type: 'messages.subscribe',
data: {'chat_room_id': id},
),
),
);
return () {
wsState.sendMessage(
jsonEncode(
WebSocketPacket(
type: 'messages.unsubscribe',
data: {'chat_room_id': id},
),
),
);
};
}, [id]);
Future<void> pickPhotoMedia() async { Future<void> pickPhotoMedia() async {
final result = await ref final result = await ref
.watch(imagePickerProvider) .watch(imagePickerProvider)
@ -617,7 +687,7 @@ class ChatRoomScreen extends HookConsumerWidget {
IconButton( IconButton(
icon: const Icon(Icons.more_vert), icon: const Icon(Icons.more_vert),
onPressed: () { onPressed: () {
context.push('/chat/id/detail'); context.push('/chat/$id/detail');
}, },
), ),
const Gap(8), const Gap(8),

View File

@ -1,4 +1,5 @@
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
@ -12,13 +13,13 @@ import 'package:island/widgets/app_scaffold.dart';
import 'package:island/models/post.dart'; import 'package:island/models/post.dart';
import 'package:island/widgets/check_in.dart'; import 'package:island/widgets/check_in.dart';
import 'package:island/widgets/post/post_item.dart'; import 'package:island/widgets/post/post_item.dart';
import 'package:island/widgets/tour/tour.dart';
import 'package:island/screens/tabs.dart'; import 'package:island/screens/tabs.dart';
import 'package:material_symbols_icons/symbols.dart'; import 'package:material_symbols_icons/symbols.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:riverpod_paging_utils/riverpod_paging_utils.dart'; import 'package:riverpod_paging_utils/riverpod_paging_utils.dart';
import 'package:island/pods/network.dart'; import 'package:island/pods/network.dart';
import 'package:island/widgets/realm/realm_card.dart'; import 'package:island/widgets/realm/realm_card.dart';
import 'package:island/widgets/publisher/publisher_card.dart';
import 'package:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';
part 'explore.g.dart'; part 'explore.g.dart';
@ -85,65 +86,64 @@ class ExploreScreen extends HookConsumerWidget {
activityListNotifierProvider(currentFilter.value).notifier, activityListNotifierProvider(currentFilter.value).notifier,
); );
return TourTriggerWidget( return AppScaffold(
child: AppScaffold( extendBody: false, // Prevent conflicts with tabs navigation
extendBody: false, // Prevent conflicts with tabs navigation appBar: AppBar(
appBar: AppBar( toolbarHeight: 0,
toolbarHeight: 0, bottom: TabBar(
bottom: TabBar(
controller: tabController,
tabs: [
Tab(
child: Text(
'explore'.tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).appBarTheme.foregroundColor!,
),
),
),
Tab(
child: Text(
'exploreFilterSubscriptions'.tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).appBarTheme.foregroundColor!,
),
),
),
Tab(
child: Text(
'exploreFilterFriends'.tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).appBarTheme.foregroundColor!,
),
),
),
],
),
),
floatingActionButton: FloatingActionButton(
heroTag: Key("explore-page-fab"),
onPressed: () {
context.push('/posts/compose').then((value) {
if (value != null) {
activitiesNotifier.forceRefresh();
}
});
},
child: const Icon(Symbols.edit),
),
floatingActionButtonLocation: TabbedFabLocation(context),
body: TabBarView(
controller: tabController, controller: tabController,
children: [ tabs: [
_buildActivityList(ref, null), Tab(
_buildActivityList(ref, 'subscriptions'), child: Text(
_buildActivityList(ref, 'friends'), 'explore'.tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).appBarTheme.foregroundColor!,
),
),
),
Tab(
child: Text(
'exploreFilterSubscriptions'.tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).appBarTheme.foregroundColor!,
),
),
),
Tab(
child: Text(
'exploreFilterFriends'.tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).appBarTheme.foregroundColor!,
),
),
),
], ],
), ),
), ),
floatingActionButton: FloatingActionButton(
heroTag: Key("explore-page-fab"),
onPressed: () {
context.push('/posts/compose').then((value) {
if (value != null) {
activitiesNotifier.forceRefresh();
}
});
},
child: const Icon(Symbols.edit),
),
floatingActionButtonLocation: TabbedFabLocation(context),
body: TabBarView(
controller: tabController,
physics: const NeverScrollableScrollPhysics(),
children: [
_buildActivityList(ref, null),
_buildActivityList(ref, 'subscriptions'),
_buildActivityList(ref, 'friends'),
],
),
); );
} }
@ -180,10 +180,8 @@ class _DiscoveryActivityItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final items = final items = data['items'] as List;
(data['items'] as List) final type = items.firstOrNull?['type'] ?? 'unknown';
.map((e) => SnRealm.fromJson(e['data'] as Map<String, dynamic>))
.toList();
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -194,7 +192,11 @@ class _DiscoveryActivityItem extends StatelessWidget {
const Icon(Symbols.explore, size: 19), const Icon(Symbols.explore, size: 19),
const Gap(8), const Gap(8),
Text( Text(
'discoverCommunities'.tr(), (switch (type) {
'realm' => 'discoverRealms',
'publisher' => 'discoverPublishers',
_ => 'unknown',
}).tr(),
style: Theme.of(context).textTheme.titleMedium, style: Theme.of(context).textTheme.titleMedium,
).padding(top: 1), ).padding(top: 1),
], ],
@ -204,13 +206,26 @@ class _DiscoveryActivityItem extends StatelessWidget {
child: ListView.builder( child: ListView.builder(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
itemCount: items.length, itemCount: items.length,
padding: const EdgeInsets.only(right: 8), padding: const EdgeInsets.symmetric(horizontal: 8),
itemBuilder: (context, index) { itemBuilder: (context, index) {
final realm = items[index]; final item = items[index];
return RealmCard(realm: realm); switch (type) {
case 'realm':
return RealmCard(
realm: SnRealm.fromJson(item['data']),
maxWidth: 280,
);
case 'publisher':
return PublisherCard(
publisher: SnPublisher.fromJson(item['data']),
maxWidth: 280,
);
default:
return Placeholder();
}
}, },
), ),
), ).padding(bottom: 4),
], ],
); );
} }
@ -326,6 +341,7 @@ class ActivityListNotifier extends _$ActivityListNotifier
if (cursor != null) 'cursor': cursor, if (cursor != null) 'cursor': cursor,
'take': take, 'take': take,
if (filter != null) 'filter': filter, if (filter != null) 'filter': filter,
if (kDebugMode) 'debugInclude': 'realms,publishers',
}; };
final response = await client.get( final response = await client.get(

View File

@ -7,7 +7,7 @@ part of 'explore.dart';
// ************************************************************************** // **************************************************************************
String _$activityListNotifierHash() => String _$activityListNotifierHash() =>
r'14ec2f211c86e1e64a9a34b142d0e8f78ff6361a'; r'57e9dcec944a9f88f8508b69fc91342592f5b349';
/// Copied from Dart SDK /// Copied from Dart SDK
class _SystemHash { class _SystemHash {

View File

@ -155,7 +155,7 @@ class RealmDetailScreen extends HookConsumerWidget {
), ),
], ],
), ),
if (identity == null && realm.isPublic) if (identity == null && realm.isCommunity)
FilledButton.tonalIcon( FilledButton.tonalIcon(
onPressed: () async { onPressed: () async {
try { try {
@ -169,14 +169,14 @@ class RealmDetailScreen extends HookConsumerWidget {
realmIdentityProvider(slug), realmIdentityProvider(slug),
); );
ref.invalidate(realmsJoinedProvider); ref.invalidate(realmsJoinedProvider);
showSnackBar('joinRealmSuccess'.tr()); showSnackBar('realmJoinSuccess'.tr());
} catch (err) { } catch (err) {
showErrorAlert(err); showErrorAlert(err);
} }
}, },
icon: const Icon(Symbols.add), icon: const Icon(Symbols.add),
label: const Text('joinRealm').tr(), label: const Text('realmJoin').tr(),
).padding(horizontal: 16, vertical: 8) ).padding(horizontal: 16, vertical: 16)
else else
const SizedBox.shrink(), const SizedBox.shrink(),
], ],

View File

@ -4,6 +4,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/services/notify.dart'; import 'package:island/services/notify.dart';
import 'package:island/services/sharing_intent.dart'; import 'package:island/services/sharing_intent.dart';
import 'package:island/widgets/tour/tour.dart';
class AppWrapper extends HookConsumerWidget { class AppWrapper extends HookConsumerWidget {
final Widget child; final Widget child;
@ -24,6 +25,6 @@ class AppWrapper extends HookConsumerWidget {
}; };
}, const []); }, const []);
return child; return TourTriggerWidget(child: child);
} }
} }

View File

@ -0,0 +1,100 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/models/post.dart';
import 'package:island/widgets/content/cloud_files.dart';
class PublisherCard extends ConsumerWidget {
final SnPublisher publisher;
final double? maxWidth;
const PublisherCard({super.key, required this.publisher, this.maxWidth});
@override
Widget build(BuildContext context, WidgetRef ref) {
Widget imageWidget;
if (publisher.picture != null) {
imageWidget = CloudImageWidget(
file: publisher.background,
fit: BoxFit.cover,
);
} else {
imageWidget = ColoredBox(
color: Theme.of(context).colorScheme.secondaryContainer,
);
}
Widget card = Card(
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () {
context.push('/publishers/${publisher.id}');
},
child: AspectRatio(
aspectRatio: 16 / 7,
child: Stack(
fit: StackFit.expand,
children: [
imageWidget,
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [
Colors.black.withOpacity(0.7),
Colors.transparent,
],
),
),
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: ProfilePictureWidget(
file: publisher.picture,
radius: 12,
),
),
const Gap(2),
Text(
publisher.nick,
style: Theme.of(context).textTheme.titleSmall?.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
],
),
),
),
);
return ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxWidth ?? double.infinity),
child: card,
);
}
}

View File

@ -1,41 +1,33 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/models/realm.dart'; import 'package:island/models/realm.dart';
import 'package:island/pods/network.dart'; import 'package:island/widgets/content/cloud_files.dart';
import 'package:material_symbols_icons/symbols.dart'; import 'package:material_symbols_icons/symbols.dart';
class RealmCard extends ConsumerWidget { class RealmCard extends ConsumerWidget {
final SnRealm realm; final SnRealm realm;
final double? maxWidth;
const RealmCard({super.key, required this.realm}); const RealmCard({super.key, required this.realm, this.maxWidth});
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final client = ref.watch(apiClientProvider);
Widget imageWidget; Widget imageWidget;
if (realm.picture != null) { if (realm.picture != null) {
final imageUrl = '${client.options.baseUrl}/files/${realm.picture!.id}'; imageWidget =
imageWidget = Image.network( imageWidget = CloudImageWidget(
imageUrl, file: realm.background,
fit: BoxFit.cover, fit: BoxFit.cover,
width: double.infinity, );
height: double.infinity,
);
} else { } else {
imageWidget = Container( imageWidget = ColoredBox(
color: Theme.of(context).colorScheme.secondaryContainer, color: Theme.of(context).colorScheme.secondaryContainer,
child: Center(
child: Icon(
Symbols.photo_camera,
color: Theme.of(context).colorScheme.onSecondaryContainer,
),
),
); );
} }
return Card( Widget card = Card(
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
@ -44,6 +36,7 @@ class RealmCard extends ConsumerWidget {
child: AspectRatio( child: AspectRatio(
aspectRatio: 16 / 7, aspectRatio: 16 / 7,
child: Stack( child: Stack(
fit: StackFit.expand,
children: [ children: [
imageWidget, imageWidget,
Positioned( Positioned(
@ -62,14 +55,37 @@ class RealmCard extends ConsumerWidget {
), ),
), ),
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(8),
child: Text( child: Column(
realm.name, crossAxisAlignment: CrossAxisAlignment.start,
style: Theme.of(context).textTheme.titleSmall?.copyWith( children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: ProfilePictureWidget(
file: realm.picture,
fallbackIcon: Symbols.group,
radius: 12,
),
),
const Gap(2),
Text(
realm.name,
style: Theme.of(context).textTheme.titleSmall?.copyWith(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
),
],
), ),
), ),
), ),
@ -78,5 +94,10 @@ class RealmCard extends ConsumerWidget {
), ),
), ),
); );
return ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxWidth ?? double.infinity),
child: card,
);
} }
} }