feat: Swipe to archive rooms

pull/1425/head
Krille 9 months ago
parent fcc43e3328
commit 3f9c7f3e91
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -35,29 +35,31 @@ class ChatListItem extends StatelessWidget {
super.key,
});
Future<void> archiveAction(BuildContext context) async {
Future<bool> archiveAction(BuildContext context, {bool? confirmed}) async {
{
if ([Membership.leave, Membership.ban].contains(room.membership)) {
await showFutureLoadingDialog(
context: context,
future: () => room.forget(),
);
return;
return true;
}
final confirmed = await showOkCancelAlertDialog(
confirmed ??= (await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).areYouSure,
okLabel: L10n.of(context).yes,
cancelLabel: L10n.of(context).no,
okLabel: L10n.of(context).leave,
cancelLabel: L10n.of(context).cancel,
message: L10n.of(context).archiveRoomDescription,
);
if (confirmed == OkCancelResult.cancel) return;
isDestructiveAction: true,
)) ==
OkCancelResult.ok;
if (!confirmed) return false;
await showFutureLoadingDialog(
context: context,
future: () => room.leave(),
);
return;
return true;
}
}
@ -93,7 +95,28 @@ class ChatListItem extends StatelessWidget {
: room.getState(EventTypes.RoomMember, lastEvent.senderId) == null;
final space = this.space;
return Padding(
return Dismissible(
key: ValueKey(room.id),
confirmDismiss: (_) async =>
(await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).areYouSure,
okLabel: L10n.of(context).leave,
cancelLabel: L10n.of(context).cancel,
message: L10n.of(context).archiveRoomDescription,
isDestructiveAction: true,
)) ==
OkCancelResult.ok,
onDismissed: (_) => archiveAction(context, confirmed: true),
background: Material(
color: theme.colorScheme.errorContainer,
child: Icon(
Icons.archive_outlined,
color: theme.colorScheme.onErrorContainer,
),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 1,
@ -210,7 +233,8 @@ class ChatListItem extends StatelessWidget {
size: 16,
),
),
if (room.isFavourite || room.membership == Membership.invite)
if (room.isFavourite ||
room.membership == Membership.invite)
Padding(
padding: EdgeInsets.only(
right: hasNotifications ? 4.0 : 0.0,
@ -252,7 +276,8 @@ class ChatListItem extends StatelessWidget {
const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
child:
CircularProgressIndicator.adaptive(strokeWidth: 2),
),
const SizedBox(width: 4),
],
@ -274,7 +299,8 @@ class ChatListItem extends StatelessWidget {
? Text(
L10n.of(context).countChatsAndCountParticipants(
room.spaceChildren.length.toString(),
(room.summary.mJoinedMemberCount ?? 1).toString(),
(room.summary.mJoinedMemberCount ?? 1)
.toString(),
),
)
: typingText.isNotEmpty
@ -297,7 +323,8 @@ class ChatListItem extends StatelessWidget {
hideEdit: true,
plaintextBody: true,
removeMarkdown: true,
withSenderNamePrefix: (!isDirectChat ||
withSenderNamePrefix:
(!isDirectChat ||
directChatMatrixId !=
room.lastEvent?.senderId),
)
@ -328,7 +355,8 @@ class ChatListItem extends StatelessWidget {
? FontWeight.bold
: null,
color: theme.colorScheme.onSurfaceVariant,
decoration: room.lastEvent?.redacted == true
decoration:
room.lastEvent?.redacted == true
? TextDecoration.lineThrough
: null,
),
@ -341,7 +369,8 @@ class ChatListItem extends StatelessWidget {
curve: FluffyThemes.animationCurve,
padding: const EdgeInsets.symmetric(horizontal: 7),
height: unreadBubbleSize,
width: !hasNotifications && !unread && !room.hasNewMessages
width:
!hasNotifications && !unread && !room.hasNewMessages
? 0
: (unreadBubbleSize - 9) *
room.notificationCount.toString().length +
@ -365,7 +394,8 @@ class ChatListItem extends StatelessWidget {
? Colors.white
: hasNotifications
? theme.colorScheme.onPrimary
: theme.colorScheme.onPrimaryContainer,
: theme
.colorScheme.onPrimaryContainer,
fontSize: 13,
),
)
@ -385,6 +415,7 @@ class ChatListItem extends StatelessWidget {
),
),
),
),
);
}
}

Loading…
Cancel
Save