✨ Pinned chat room
This commit is contained in:
@@ -20,8 +20,8 @@ import 'package:island/widgets/navigation/fab_menu.dart';
|
||||
import 'package:island/widgets/response.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:super_sliver_list/super_sliver_list.dart';
|
||||
import 'package:island/pods/chat/chat_room.dart';
|
||||
import 'package:super_sliver_list/super_sliver_list.dart';
|
||||
|
||||
class ChatListBodyWidget extends HookConsumerWidget {
|
||||
final bool isFloating;
|
||||
@@ -55,50 +55,95 @@ class ChatListBodyWidget extends HookConsumerWidget {
|
||||
),
|
||||
Expanded(
|
||||
child: chats.when(
|
||||
data: (items) => RefreshIndicator(
|
||||
onRefresh: () => Future.sync(() {
|
||||
ref.invalidate(chatRoomJoinedProvider);
|
||||
}),
|
||||
child: SuperListView.builder(
|
||||
padding: EdgeInsets.only(bottom: 96),
|
||||
itemCount: items
|
||||
.where(
|
||||
(item) =>
|
||||
selectedTab.value == 0 ||
|
||||
(selectedTab.value == 1 && item.type == 1) ||
|
||||
(selectedTab.value == 2 && item.type != 1),
|
||||
)
|
||||
.length,
|
||||
itemBuilder: (context, index) {
|
||||
final filteredItems = items
|
||||
.where(
|
||||
(item) =>
|
||||
selectedTab.value == 0 ||
|
||||
(selectedTab.value == 1 && item.type == 1) ||
|
||||
(selectedTab.value == 2 && item.type != 1),
|
||||
)
|
||||
.toList();
|
||||
final item = filteredItems[index];
|
||||
return ChatRoomListTile(
|
||||
room: item,
|
||||
isDirect: item.type == 1,
|
||||
onTap: () {
|
||||
if (isWideScreen(context)) {
|
||||
context.replaceNamed(
|
||||
'chatRoom',
|
||||
pathParameters: {'id': item.id},
|
||||
);
|
||||
} else {
|
||||
context.pushNamed(
|
||||
'chatRoom',
|
||||
pathParameters: {'id': item.id},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
data: (items) {
|
||||
final filteredItems = items.where(
|
||||
(item) =>
|
||||
selectedTab.value == 0 ||
|
||||
(selectedTab.value == 1 && item.type == 1) ||
|
||||
(selectedTab.value == 2 && item.type != 1),
|
||||
);
|
||||
final pinnedItems = filteredItems
|
||||
.where((item) => item.isPinned)
|
||||
.toList();
|
||||
final unpinnedItems = filteredItems
|
||||
.where((item) => !item.isPinned)
|
||||
.toList();
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () => Future.sync(() {
|
||||
ref.invalidate(chatRoomJoinedProvider);
|
||||
}),
|
||||
child: Column(
|
||||
children: [
|
||||
ExpansionTile(
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainer.withOpacity(0.5),
|
||||
collapsedBackgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainer.withOpacity(0.5),
|
||||
title: Text('pinnedChatRoom'.tr()),
|
||||
leading: const Icon(Symbols.keep, fill: 1),
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
initiallyExpanded: true,
|
||||
children: [
|
||||
for (final item in pinnedItems)
|
||||
ChatRoomListTile(
|
||||
room: item,
|
||||
isDirect: item.type == 1,
|
||||
onTap: () {
|
||||
if (isWideScreen(context)) {
|
||||
context.replaceNamed(
|
||||
'chatRoom',
|
||||
pathParameters: {'id': item.id},
|
||||
);
|
||||
} else {
|
||||
context.pushNamed(
|
||||
'chatRoom',
|
||||
pathParameters: {'id': item.id},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: SuperListView.builder(
|
||||
padding: EdgeInsets.only(bottom: 96),
|
||||
itemCount: unpinnedItems
|
||||
.where(
|
||||
(item) =>
|
||||
selectedTab.value == 0 ||
|
||||
(selectedTab.value == 1 && item.type == 1) ||
|
||||
(selectedTab.value == 2 && item.type != 1),
|
||||
)
|
||||
.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = unpinnedItems[index];
|
||||
return ChatRoomListTile(
|
||||
room: item,
|
||||
isDirect: item.type == 1,
|
||||
onTap: () {
|
||||
if (isWideScreen(context)) {
|
||||
context.replaceNamed(
|
||||
'chatRoom',
|
||||
pathParameters: {'id': item.id},
|
||||
);
|
||||
} else {
|
||||
context.pushNamed(
|
||||
'chatRoom',
|
||||
pathParameters: {'id': item.id},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) => ResponseErrorWidget(
|
||||
error: error,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
@@ -42,6 +43,20 @@ class ChatDetailScreen extends HookConsumerWidget {
|
||||
final roomIdentity = ref.watch(chatRoomIdentityProvider(id));
|
||||
final totalMessages = ref.watch(totalMessagesCountProvider(id));
|
||||
|
||||
// Local state for pinned status to provide immediate UI feedback
|
||||
final isPinned = useState<bool?>(null);
|
||||
|
||||
// Initialize pinned state from database
|
||||
useEffect(() {
|
||||
final db = ref.read(databaseProvider);
|
||||
(db.select(
|
||||
db.chatRooms,
|
||||
)..where((r) => r.id.equals(id))).getSingleOrNull().then((room) {
|
||||
isPinned.value = room?.isPinned ?? false;
|
||||
});
|
||||
return null;
|
||||
}, [id]);
|
||||
|
||||
const kNotifyLevelText = [
|
||||
'chatNotifyLevelAll',
|
||||
'chatNotifyLevelMention',
|
||||
@@ -83,46 +98,45 @@ class ChatDetailScreen extends HookConsumerWidget {
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder:
|
||||
(context) => SheetScaffold(
|
||||
height: 320,
|
||||
titleText: 'chatNotifyLevel'.tr(),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
title: const Text('chatNotifyLevelAll').tr(),
|
||||
subtitle: const Text('chatNotifyLevelDescription').tr(),
|
||||
leading: const Icon(Icons.notifications_active),
|
||||
selected: identity.notify == 0,
|
||||
onTap: () {
|
||||
setNotifyLevel(0);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatNotifyLevelMention').tr(),
|
||||
subtitle: const Text('chatNotifyLevelDescription').tr(),
|
||||
leading: const Icon(Icons.alternate_email),
|
||||
selected: identity.notify == 1,
|
||||
onTap: () {
|
||||
setNotifyLevel(1);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatNotifyLevelNone').tr(),
|
||||
subtitle: const Text('chatNotifyLevelDescription').tr(),
|
||||
leading: const Icon(Icons.notifications_off),
|
||||
selected: identity.notify == 2,
|
||||
onTap: () {
|
||||
setNotifyLevel(2);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
builder: (context) => SheetScaffold(
|
||||
height: 320,
|
||||
titleText: 'chatNotifyLevel'.tr(),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
title: const Text('chatNotifyLevelAll').tr(),
|
||||
subtitle: const Text('chatNotifyLevelDescription').tr(),
|
||||
leading: const Icon(Icons.notifications_active),
|
||||
selected: identity.notify == 0,
|
||||
onTap: () {
|
||||
setNotifyLevel(0);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatNotifyLevelMention').tr(),
|
||||
subtitle: const Text('chatNotifyLevelDescription').tr(),
|
||||
leading: const Icon(Icons.alternate_email),
|
||||
selected: identity.notify == 1,
|
||||
onTap: () {
|
||||
setNotifyLevel(1);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatNotifyLevelNone').tr(),
|
||||
subtitle: const Text('chatNotifyLevelDescription').tr(),
|
||||
leading: const Icon(Icons.notifications_off),
|
||||
selected: identity.notify == 2,
|
||||
onTap: () {
|
||||
setNotifyLevel(2);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -132,118 +146,117 @@ class ChatDetailScreen extends HookConsumerWidget {
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: const Text('chatBreak').tr(),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('chatBreakDescription').tr(),
|
||||
const Gap(16),
|
||||
ListTile(
|
||||
title: const Text('chatBreakClearButton').tr(),
|
||||
subtitle: const Text('chatBreakClear').tr(),
|
||||
leading: const Icon(Icons.notifications_active),
|
||||
onTap: () {
|
||||
setChatBreak(now);
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakCleared'.tr());
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatBreak5m').tr(),
|
||||
subtitle: const Text(
|
||||
'chatBreakHour',
|
||||
).tr(args: ['chatBreak5m'.tr()]),
|
||||
leading: const Icon(Symbols.circle),
|
||||
onTap: () {
|
||||
setChatBreak(now.add(const Duration(minutes: 5)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakSet'.tr(args: ['5m']));
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatBreak10m').tr(),
|
||||
subtitle: const Text(
|
||||
'chatBreakHour',
|
||||
).tr(args: ['chatBreak10m'.tr()]),
|
||||
leading: const Icon(Symbols.circle),
|
||||
onTap: () {
|
||||
setChatBreak(now.add(const Duration(minutes: 10)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakSet'.tr(args: ['10m']));
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatBreak15m').tr(),
|
||||
subtitle: const Text(
|
||||
'chatBreakHour',
|
||||
).tr(args: ['chatBreak15m'.tr()]),
|
||||
leading: const Icon(Symbols.timer_3),
|
||||
onTap: () {
|
||||
setChatBreak(now.add(const Duration(minutes: 15)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakSet'.tr(args: ['15m']));
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatBreak30m').tr(),
|
||||
subtitle: const Text(
|
||||
'chatBreakHour',
|
||||
).tr(args: ['chatBreak30m'.tr()]),
|
||||
leading: const Icon(Symbols.timer),
|
||||
onTap: () {
|
||||
setChatBreak(now.add(const Duration(minutes: 30)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakSet'.tr(args: ['30m']));
|
||||
}
|
||||
},
|
||||
),
|
||||
const Gap(8),
|
||||
TextField(
|
||||
controller: durationController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'chatBreakCustomMinutes'.tr(),
|
||||
hintText: 'chatBreakEnterMinutes'.tr(),
|
||||
border: const OutlineInputBorder(),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.check),
|
||||
onPressed: () {
|
||||
final minutes = int.tryParse(durationController.text);
|
||||
if (minutes != null && minutes > 0) {
|
||||
setChatBreak(now.add(Duration(minutes: minutes)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar(
|
||||
'chatBreakSet'.tr(args: ['${minutes}m']),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
onTapOutside:
|
||||
(_) => FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
],
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('chatBreak').tr(),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('chatBreakDescription').tr(),
|
||||
const Gap(16),
|
||||
ListTile(
|
||||
title: const Text('chatBreakClearButton').tr(),
|
||||
subtitle: const Text('chatBreakClear').tr(),
|
||||
leading: const Icon(Icons.notifications_active),
|
||||
onTap: () {
|
||||
setChatBreak(now);
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakCleared'.tr());
|
||||
}
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('cancel').tr(),
|
||||
ListTile(
|
||||
title: const Text('chatBreak5m').tr(),
|
||||
subtitle: const Text(
|
||||
'chatBreakHour',
|
||||
).tr(args: ['chatBreak5m'.tr()]),
|
||||
leading: const Icon(Symbols.circle),
|
||||
onTap: () {
|
||||
setChatBreak(now.add(const Duration(minutes: 5)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakSet'.tr(args: ['5m']));
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatBreak10m').tr(),
|
||||
subtitle: const Text(
|
||||
'chatBreakHour',
|
||||
).tr(args: ['chatBreak10m'.tr()]),
|
||||
leading: const Icon(Symbols.circle),
|
||||
onTap: () {
|
||||
setChatBreak(now.add(const Duration(minutes: 10)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakSet'.tr(args: ['10m']));
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatBreak15m').tr(),
|
||||
subtitle: const Text(
|
||||
'chatBreakHour',
|
||||
).tr(args: ['chatBreak15m'.tr()]),
|
||||
leading: const Icon(Symbols.timer_3),
|
||||
onTap: () {
|
||||
setChatBreak(now.add(const Duration(minutes: 15)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakSet'.tr(args: ['15m']));
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('chatBreak30m').tr(),
|
||||
subtitle: const Text(
|
||||
'chatBreakHour',
|
||||
).tr(args: ['chatBreak30m'.tr()]),
|
||||
leading: const Icon(Symbols.timer),
|
||||
onTap: () {
|
||||
setChatBreak(now.add(const Duration(minutes: 30)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar('chatBreakSet'.tr(args: ['30m']));
|
||||
}
|
||||
},
|
||||
),
|
||||
const Gap(8),
|
||||
TextField(
|
||||
controller: durationController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'chatBreakCustomMinutes'.tr(),
|
||||
hintText: 'chatBreakEnterMinutes'.tr(),
|
||||
border: const OutlineInputBorder(),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.check),
|
||||
onPressed: () {
|
||||
final minutes = int.tryParse(durationController.text);
|
||||
if (minutes != null && minutes > 0) {
|
||||
setChatBreak(now.add(Duration(minutes: minutes)));
|
||||
Navigator.pop(context);
|
||||
if (context.mounted) {
|
||||
showSnackBar(
|
||||
'chatBreakSet'.tr(args: ['${minutes}m']),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
keyboardType: TextInputType.number,
|
||||
onTapOutside: (_) =>
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('cancel').tr(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -256,175 +269,197 @@ class ChatDetailScreen extends HookConsumerWidget {
|
||||
return AppScaffold(
|
||||
body: roomState.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error:
|
||||
(error, _) => Center(
|
||||
child: Text('errorGeneric'.tr(args: [error.toString()])),
|
||||
),
|
||||
data:
|
||||
(currentRoom) => CustomScrollView(
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
expandedHeight: 180,
|
||||
pinned: true,
|
||||
leading: PageBackButton(shadows: [iconShadow]),
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background:
|
||||
(currentRoom!.type == 1 &&
|
||||
currentRoom.background?.id != null)
|
||||
? CloudImageWidget(
|
||||
fileId: currentRoom.background!.id,
|
||||
)
|
||||
: (currentRoom.type == 1 &&
|
||||
currentRoom.members!.length == 1 &&
|
||||
currentRoom
|
||||
.members!
|
||||
.first
|
||||
.account
|
||||
.profile
|
||||
.background
|
||||
?.id !=
|
||||
null)
|
||||
? CloudImageWidget(
|
||||
fileId:
|
||||
currentRoom
|
||||
.members!
|
||||
.first
|
||||
.account
|
||||
.profile
|
||||
.background!
|
||||
.id,
|
||||
)
|
||||
: currentRoom.background?.id != null
|
||||
? CloudImageWidget(
|
||||
fileId: currentRoom.background!.id,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Container(
|
||||
color:
|
||||
Theme.of(context).appBarTheme.backgroundColor,
|
||||
),
|
||||
title: Text(
|
||||
(currentRoom.type == 1 && currentRoom.name == null)
|
||||
? currentRoom.members!
|
||||
.map((e) => e.account.nick)
|
||||
.join(', ')
|
||||
: currentRoom.name!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).appBarTheme.foregroundColor,
|
||||
shadows: [iconShadow],
|
||||
error: (error, _) =>
|
||||
Center(child: Text('errorGeneric'.tr(args: [error.toString()]))),
|
||||
data: (currentRoom) => CustomScrollView(
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
expandedHeight: 180,
|
||||
pinned: true,
|
||||
leading: PageBackButton(shadows: [iconShadow]),
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background:
|
||||
(currentRoom!.type == 1 &&
|
||||
currentRoom.background?.id != null)
|
||||
? CloudImageWidget(fileId: currentRoom.background!.id)
|
||||
: (currentRoom.type == 1 &&
|
||||
currentRoom.members!.length == 1 &&
|
||||
currentRoom
|
||||
.members!
|
||||
.first
|
||||
.account
|
||||
.profile
|
||||
.background
|
||||
?.id !=
|
||||
null)
|
||||
? CloudImageWidget(
|
||||
fileId: currentRoom
|
||||
.members!
|
||||
.first
|
||||
.account
|
||||
.profile
|
||||
.background!
|
||||
.id,
|
||||
)
|
||||
: currentRoom.background?.id != null
|
||||
? CloudImageWidget(
|
||||
fileId: currentRoom.background!.id,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Container(
|
||||
color: Theme.of(context).appBarTheme.backgroundColor,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
(currentRoom.type == 1 && currentRoom.name == null)
|
||||
? currentRoom.members!
|
||||
.map((e) => e.account.nick)
|
||||
.join(', ')
|
||||
: currentRoom.name!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).appBarTheme.foregroundColor,
|
||||
shadows: [iconShadow],
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.people, shadows: [iconShadow]),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder:
|
||||
(context) => _ChatMemberListSheet(roomId: id),
|
||||
);
|
||||
},
|
||||
),
|
||||
_ChatRoomActionMenu(id: id, iconShadow: iconShadow),
|
||||
const Gap(8),
|
||||
],
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Column(
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.people, shadows: [iconShadow]),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) => _ChatMemberListSheet(roomId: id),
|
||||
);
|
||||
},
|
||||
),
|
||||
_ChatRoomActionMenu(id: id, iconShadow: iconShadow),
|
||||
const Gap(8),
|
||||
],
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
currentRoom.description ?? 'descriptionNone'.tr(),
|
||||
style: const TextStyle(fontSize: 16),
|
||||
).padding(all: 24),
|
||||
const Divider(height: 1),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
currentRoom.description ?? 'descriptionNone'.tr(),
|
||||
style: const TextStyle(fontSize: 16),
|
||||
).padding(all: 24),
|
||||
const Divider(height: 1),
|
||||
// Pin/Unpin Switch
|
||||
if (isPinned.value != null)
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 24),
|
||||
secondary: Icon(
|
||||
Symbols.push_pin,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
title: const Text('pinChatRoom').tr(),
|
||||
subtitle: const Text('pinChatRoomDescription').tr(),
|
||||
value: isPinned.value!,
|
||||
onChanged: (value) async {
|
||||
// Update local state immediately for instant UI feedback
|
||||
isPinned.value = value;
|
||||
final db = ref.read(databaseProvider);
|
||||
await db.toggleChatRoomPinned(id);
|
||||
// Re-verify the state from database in case of error
|
||||
final room = await (db.select(
|
||||
db.chatRooms,
|
||||
)..where((r) => r.id.equals(id))).getSingleOrNull();
|
||||
final actualPinned = room?.isPinned ?? false;
|
||||
if (actualPinned != value) {
|
||||
// Revert if database operation failed
|
||||
isPinned.value = actualPinned;
|
||||
}
|
||||
showSnackBar(
|
||||
value
|
||||
? 'chatRoomPinned'.tr()
|
||||
: 'chatRoomUnpinned'.tr(),
|
||||
);
|
||||
},
|
||||
),
|
||||
roomIdentity.when(
|
||||
data:
|
||||
(identity) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
),
|
||||
leading: const Icon(Symbols.notifications),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
title: const Text('chatNotifyLevel').tr(),
|
||||
subtitle: Text(
|
||||
kNotifyLevelText[identity!.notify].tr(),
|
||||
),
|
||||
onTap:
|
||||
() =>
|
||||
showNotifyLevelBottomSheet(identity),
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
),
|
||||
leading: const Icon(Icons.timer),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
title: const Text('chatBreak').tr(),
|
||||
subtitle:
|
||||
identity.breakUntil != null &&
|
||||
identity.breakUntil!.isAfter(
|
||||
DateTime.now(),
|
||||
)
|
||||
? Text(
|
||||
DateFormat(
|
||||
'yyyy-MM-dd HH:mm',
|
||||
).format(identity.breakUntil!),
|
||||
)
|
||||
: const Text('chatBreakNone').tr(),
|
||||
onTap: () => showChatBreakDialog(),
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
),
|
||||
leading: const Icon(Icons.search),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
title: const Text('searchMessages').tr(),
|
||||
subtitle: totalMessages.when(
|
||||
data:
|
||||
(count) => Text(
|
||||
'messagesCount'.tr(
|
||||
args: [count.toString()],
|
||||
),
|
||||
),
|
||||
loading:
|
||||
() => const CircularProgressIndicator(),
|
||||
error:
|
||||
(err, stack) => Text(
|
||||
'errorGeneric'.tr(
|
||||
args: [err.toString()],
|
||||
),
|
||||
),
|
||||
),
|
||||
onTap: () async {
|
||||
final result = await context.pushNamed(
|
||||
'searchMessages',
|
||||
pathParameters: {'id': id},
|
||||
);
|
||||
if (result is SearchMessagesResult) {
|
||||
// Navigate back to room screen with message to jump to
|
||||
if (context.mounted) {
|
||||
context.pop(result);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
data: (identity) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
),
|
||||
leading: const Icon(Symbols.notifications),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
title: const Text('chatNotifyLevel').tr(),
|
||||
subtitle: Text(
|
||||
kNotifyLevelText[identity!.notify].tr(),
|
||||
),
|
||||
onTap: () => showNotifyLevelBottomSheet(identity),
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
),
|
||||
leading: const Icon(Icons.timer),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
title: const Text('chatBreak').tr(),
|
||||
subtitle:
|
||||
identity.breakUntil != null &&
|
||||
identity.breakUntil!.isAfter(
|
||||
DateTime.now(),
|
||||
)
|
||||
? Text(
|
||||
DateFormat(
|
||||
'yyyy-MM-dd HH:mm',
|
||||
).format(identity.breakUntil!),
|
||||
)
|
||||
: const Text('chatBreakNone').tr(),
|
||||
onTap: () => showChatBreakDialog(),
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
),
|
||||
leading: const Icon(Icons.search),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
title: const Text('searchMessages').tr(),
|
||||
subtitle: totalMessages.when(
|
||||
data: (count) => Text(
|
||||
'messagesCount'.tr(args: [count.toString()]),
|
||||
),
|
||||
loading: () =>
|
||||
const CircularProgressIndicator(),
|
||||
error: (err, stack) => Text(
|
||||
'errorGeneric'.tr(args: [err.toString()]),
|
||||
),
|
||||
),
|
||||
onTap: () async {
|
||||
final result = await context.pushNamed(
|
||||
'searchMessages',
|
||||
pathParameters: {'id': id},
|
||||
);
|
||||
if (result is SearchMessagesResult) {
|
||||
// Navigate back to room screen with message to jump to
|
||||
if (context.mounted) {
|
||||
context.pop(result);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
error: (_, _) => const SizedBox.shrink(),
|
||||
loading: () => const SizedBox.shrink(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -447,97 +482,94 @@ class _ChatRoomActionMenu extends HookConsumerWidget {
|
||||
|
||||
return PopupMenuButton(
|
||||
icon: Icon(Icons.more_vert, shadows: [iconShadow]),
|
||||
itemBuilder:
|
||||
(context) => [
|
||||
if (isManagable)
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => EditChatScreen(id: id),
|
||||
).then((value) {
|
||||
if (value != null) {
|
||||
// Invalidate to refresh room data after edit
|
||||
ref.invalidate(chatMemberListProvider(id));
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.edit,
|
||||
color: Theme.of(context).colorScheme.onSecondaryContainer,
|
||||
),
|
||||
const Gap(12),
|
||||
const Text('editChatRoom').tr(),
|
||||
],
|
||||
itemBuilder: (context) => [
|
||||
if (isManagable)
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => EditChatScreen(id: id),
|
||||
).then((value) {
|
||||
if (value != null) {
|
||||
// Invalidate to refresh room data after edit
|
||||
ref.invalidate(chatMemberListProvider(id));
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.edit,
|
||||
color: Theme.of(context).colorScheme.onSecondaryContainer,
|
||||
),
|
||||
),
|
||||
if (isManagable)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.delete, color: Colors.red),
|
||||
const Gap(12),
|
||||
const Text(
|
||||
'deleteChatRoom',
|
||||
style: TextStyle(color: Colors.red),
|
||||
).tr(),
|
||||
],
|
||||
const Gap(12),
|
||||
const Text('editChatRoom').tr(),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (isManagable)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.delete, color: Colors.red),
|
||||
const Gap(12),
|
||||
const Text(
|
||||
'deleteChatRoom',
|
||||
style: TextStyle(color: Colors.red),
|
||||
).tr(),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
showConfirmAlert(
|
||||
'deleteChatRoomHint'.tr(),
|
||||
'deleteChatRoom'.tr(),
|
||||
isDanger: true,
|
||||
).then((confirm) async {
|
||||
if (confirm) {
|
||||
final client = ref.watch(apiClientProvider);
|
||||
await client.delete('/sphere/chat/$id');
|
||||
ref.invalidate(chatRoomJoinedProvider);
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
)
|
||||
else
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.exit_to_app,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
onTap: () {
|
||||
showConfirmAlert(
|
||||
'deleteChatRoomHint'.tr(),
|
||||
'deleteChatRoom'.tr(),
|
||||
isDanger: true,
|
||||
).then((confirm) async {
|
||||
if (confirm) {
|
||||
final client = ref.watch(apiClientProvider);
|
||||
await client.delete('/sphere/chat/$id');
|
||||
ref.invalidate(chatRoomJoinedProvider);
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
)
|
||||
else
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.exit_to_app,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const Gap(12),
|
||||
Text(
|
||||
'leaveChatRoom',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
).tr(),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
showConfirmAlert(
|
||||
'leaveChatRoomHint'.tr(),
|
||||
'leaveChatRoom'.tr(),
|
||||
).then((confirm) async {
|
||||
if (confirm) {
|
||||
final client = ref.watch(apiClientProvider);
|
||||
await client.delete('/sphere/chat/$id/members/me');
|
||||
ref.invalidate(chatRoomJoinedProvider);
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
const Gap(12),
|
||||
Text(
|
||||
'leaveChatRoom',
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
).tr(),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
showConfirmAlert(
|
||||
'leaveChatRoomHint'.tr(),
|
||||
'leaveChatRoom'.tr(),
|
||||
).then((confirm) async {
|
||||
if (confirm) {
|
||||
final client = ref.watch(apiClientProvider);
|
||||
await client.delete('/sphere/chat/$id/members/me');
|
||||
ref.invalidate(chatRoomJoinedProvider);
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -576,11 +608,10 @@ class ChatMemberListNotifier extends AsyncNotifier<List<SnChatMember>>
|
||||
);
|
||||
|
||||
totalCount = int.parse(response.headers.value('X-Total') ?? '0');
|
||||
final members =
|
||||
response.data
|
||||
.map((e) => SnChatMember.fromJson(e))
|
||||
.cast<SnChatMember>()
|
||||
.toList();
|
||||
final members = response.data
|
||||
.map((e) => SnChatMember.fromJson(e))
|
||||
.cast<SnChatMember>()
|
||||
.toList();
|
||||
|
||||
return members;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user