Skip to content

Commit

Permalink
TW-1360: Add Slidable Chat List Item - Read/Unread
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE committed Feb 1, 2024
1 parent 37fb89e commit 06e9266
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 179 deletions.
2 changes: 1 addition & 1 deletion assets/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,7 @@
"@errorPreviewingFile": {},
"youAreUploadingPhotosDoYouWantToCancelOrContinue": "Erreur de téléchargement d'image ! Voulez-vous toujours continuer à créer une discussion ?",
"@youAreUploadingPhotosDoYouWantToCancelOrContinue": {},
"unread": "Non lu",
"unread": "Ne pas lire",
"@unread": {},
"company": "Entreprise",
"@company": {},
Expand Down
26 changes: 19 additions & 7 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class ChatListController extends State<ChatList>
});
}

Future<void> toggleUnread() async {
Future<void> toggleUnreadSelections() async {
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
final markUnread = anySelectedRoomNotMarkedUnread;
Expand Down Expand Up @@ -505,7 +505,7 @@ class ChatListController extends State<ChatList>
) async {
switch (chatListBottomNavigatorBar) {
case ChatListSelectionActions.read:
await actionWithToggleSelectMode(toggleUnread);
await actionWithToggleSelectMode(toggleUnreadSelections);
return;
case ChatListSelectionActions.mute:
await actionWithToggleSelectMode(toggleMuted);
Expand Down Expand Up @@ -567,11 +567,7 @@ class ChatListController extends State<ChatList>
) async {
switch (action) {
case ChatListSelectionActions.read:
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
await client.getRoomById(room.id)!.markUnread(!room.markedUnread);
},
);
await toggleRead(room);
return;
case ChatListSelectionActions.pin:
await togglePin(room);
Expand All @@ -592,6 +588,22 @@ class ChatListController extends State<ChatList>
}
}

Future<void> toggleRead(Room room) async {
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
if (room.isUnread) {
await room.markUnread(false);
await room.setReadMarker(
room.lastEvent!.eventId,
mRead: room.lastEvent!.eventId,
);
} else {
await room.markUnread(true);
}
},
);
}

Future<void> togglePin(Room room) async {
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
Expand Down
282 changes: 143 additions & 139 deletions lib/pages/chat_list/chat_list_body_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:fluffychat/utils/stream_extension.dart';
import 'package:fluffychat/widgets/connection_status_header.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:linagora_design_flutter/linagora_design_flutter.dart';
import 'package:matrix/matrix.dart';
Expand Down Expand Up @@ -40,163 +41,166 @@ class ChatListBodyView extends StatelessWidget {
child: child,
);
},
child: StreamBuilder(
key: ValueKey(
controller.client.userID.toString() +
controller.activeFilter.toString() +
controller.activeSpaceId.toString(),
),
stream: controller.client.onSync.stream
.where((s) => s.hasRoomUpdate)
.rateLimit(const Duration(seconds: 1)),
builder: (context, _) {
if (controller.activeFilter == ActiveFilter.spaces) {
return SpaceView(
controller,
scrollController: controller.scrollController,
key: Key(controller.activeSpaceId ?? 'Spaces'),
);
}
if (controller.waitForFirstSync &&
controller.client.prevBatch != null) {
if (controller.chatListBodyIsEmpty) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: ChatListBodyViewStyle.paddingIconSkeletons,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
ImagePaths.icSkeletons,
),
],
),
),
Padding(
padding: ChatListBodyViewStyle.paddingOwnProfile,
child: FutureBuilder<Profile?>(
future: controller.client
.fetchOwnProfile(getFromRooms: false),
builder: (context, snapshotProfile) {
if (snapshotProfile.connectionState !=
ConnectionState.done) {
return const SizedBox();
}
final name =
snapshotProfile.data?.displayName ?? '👋';
return Column(
children: [
Text(
L10n.of(context)!.welcomeToTwake(name),
style: Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
Padding(
padding: ChatListBodyViewStyle
.paddingTextStartNewChatMessage,
child: Text(
L10n.of(context)!.startNewChatMessage,
style: Theme.of(context).textTheme.bodyMedium,
textAlign: TextAlign.center,
),
),
],
);
},
),
),
],
child: SlidableAutoCloseBehavior(
child: StreamBuilder(
key: ValueKey(
controller.client.userID.toString() +
controller.activeFilter.toString() +
controller.activeSpaceId.toString(),
),
stream: controller.client.onSync.stream
.where((s) => s.hasRoomUpdate)
.rateLimit(const Duration(seconds: 1)),
builder: (context, _) {
if (controller.activeFilter == ActiveFilter.spaces) {
return SpaceView(
controller,
scrollController: controller.scrollController,
key: Key(controller.activeSpaceId ?? 'Spaces'),
);
}
return SingleChildScrollView(
controller: controller.scrollController,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const ConnectionStatusHeader(),
AnimatedContainer(
height: ChatListBodyViewStyle.heightIsTorBrowser(
controller.isTorBrowser,
),
duration: TwakeThemes.animationDuration,
curve: TwakeThemes.animationCurve,
clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(),
child: Material(
color: Theme.of(context).colorScheme.surface,
child: ListTile(
leading: const Icon(Icons.vpn_key),
title: Text(L10n.of(context)!.dehydrateTor),
subtitle: Text(L10n.of(context)!.dehydrateTorLong),
trailing: const Icon(Icons.chevron_right_outlined),
onTap: controller.dehydrate,
if (controller.waitForFirstSync &&
controller.client.prevBatch != null) {
if (controller.chatListBodyIsEmpty) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: ChatListBodyViewStyle.paddingIconSkeletons,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
ImagePaths.icSkeletons,
),
],
),
),
),
if (!controller.filteredRoomsForPinIsEmpty)
ValueListenableBuilder(
valueListenable: controller.expandRoomsForPinNotifier,
builder: (context, isExpanded, child) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ExpandableTitleBuilder(
title: L10n.of(context)!.countPinChat(
controller.filteredRoomsForPin.length,
Padding(
padding: ChatListBodyViewStyle.paddingOwnProfile,
child: FutureBuilder<Profile?>(
future: controller.client
.fetchOwnProfile(getFromRooms: false),
builder: (context, snapshotProfile) {
if (snapshotProfile.connectionState !=
ConnectionState.done) {
return const SizedBox();
}
final name =
snapshotProfile.data?.displayName ?? '👋';
return Column(
children: [
Text(
L10n.of(context)!.welcomeToTwake(name),
style: Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
isExpanded: isExpanded,
onTap:
controller.expandRoomsForPinNotifier.toggle,
),
if (isExpanded) child!,
],
);
},
child: ChatListViewBuilder(
controller: controller,
rooms: controller.filteredRoomsForPin,
Padding(
padding: ChatListBodyViewStyle
.paddingTextStartNewChatMessage,
child: Text(
L10n.of(context)!.startNewChatMessage,
style:
Theme.of(context).textTheme.bodyMedium,
textAlign: TextAlign.center,
),
),
],
);
},
),
),
],
);
}
return SingleChildScrollView(
controller: controller.scrollController,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const ConnectionStatusHeader(),
AnimatedContainer(
height: ChatListBodyViewStyle.heightIsTorBrowser(
controller.isTorBrowser,
),
duration: TwakeThemes.animationDuration,
curve: TwakeThemes.animationCurve,
clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(),
child: Material(
color: Theme.of(context).colorScheme.surface,
child: ListTile(
leading: const Icon(Icons.vpn_key),
title: Text(L10n.of(context)!.dehydrateTor),
subtitle: Text(L10n.of(context)!.dehydrateTorLong),
trailing: const Icon(Icons.chevron_right_outlined),
onTap: controller.dehydrate,
),
),
),
if (!controller.filteredRoomsForAllIsEmpty)
ValueListenableBuilder(
valueListenable: controller.expandRoomsForAllNotifier,
builder: (context, isExpanded, child) {
return Padding(
padding: ChatListBodyViewStyle
.paddingTopExpandableTitleBuilder,
child: Column(
if (!controller.filteredRoomsForPinIsEmpty)
ValueListenableBuilder(
valueListenable: controller.expandRoomsForPinNotifier,
builder: (context, isExpanded, child) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ExpandableTitleBuilder(
title: L10n.of(context)!.countAllChat(
controller.filteredRoomsForAll.length,
title: L10n.of(context)!.countPinChat(
controller.filteredRoomsForPin.length,
),
isExpanded: isExpanded,
onTap: controller
.expandRoomsForAllNotifier.toggle,
.expandRoomsForPinNotifier.toggle,
),
if (isExpanded) child!,
],
),
);
},
child: ChatListViewBuilder(
controller: controller,
rooms: controller.filteredRoomsForAll,
);
},
child: ChatListViewBuilder(
controller: controller,
rooms: controller.filteredRoomsForPin,
),
),
),
],
),
);
}
return const SizedBox.shrink();
},
if (!controller.filteredRoomsForAllIsEmpty)
ValueListenableBuilder(
valueListenable: controller.expandRoomsForAllNotifier,
builder: (context, isExpanded, child) {
return Padding(
padding: ChatListBodyViewStyle
.paddingTopExpandableTitleBuilder,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ExpandableTitleBuilder(
title: L10n.of(context)!.countAllChat(
controller.filteredRoomsForAll.length,
),
isExpanded: isExpanded,
onTap: controller
.expandRoomsForAllNotifier.toggle,
),
if (isExpanded) child!,
],
),
);
},
child: ChatListViewBuilder(
controller: controller,
rooms: controller.filteredRoomsForAll,
),
),
],
),
);
}
return const SizedBox.shrink();
},
),
),
),
);
Expand Down
Loading

0 comments on commit 06e9266

Please sign in to comment.