feat: QR Code viewer for mxid sharing
Signed-off-by: Krille <c.kussowski@famedly.com>
This commit is contained in:
parent
0687c0a496
commit
dbf3eccc93
7 changed files with 492 additions and 339 deletions
|
|
@ -5,7 +5,6 @@ import 'package:flutter_linkify/flutter_linkify.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
|
||||||
import 'package:fluffychat/pages/chat_details/chat_details.dart';
|
import 'package:fluffychat/pages/chat_details/chat_details.dart';
|
||||||
import 'package:fluffychat/pages/chat_details/participant_list_item.dart';
|
import 'package:fluffychat/pages/chat_details/participant_list_item.dart';
|
||||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||||
|
|
@ -15,6 +14,7 @@ import 'package:fluffychat/widgets/chat_settings_popup_menu.dart';
|
||||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
import '../../utils/url_launcher.dart';
|
import '../../utils/url_launcher.dart';
|
||||||
|
import '../../widgets/qr_code_viewer.dart';
|
||||||
|
|
||||||
class ChatDetailsView extends StatelessWidget {
|
class ChatDetailsView extends StatelessWidget {
|
||||||
final ChatDetailsController controller;
|
final ChatDetailsController controller;
|
||||||
|
|
@ -60,10 +60,10 @@ class ChatDetailsView extends StatelessWidget {
|
||||||
if (room.canonicalAlias.isNotEmpty)
|
if (room.canonicalAlias.isNotEmpty)
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: L10n.of(context).share,
|
tooltip: L10n.of(context).share,
|
||||||
icon: Icon(Icons.adaptive.share_outlined),
|
icon: const Icon(Icons.qr_code_rounded),
|
||||||
onPressed: () => FluffyShare.share(
|
onPressed: () => showQrCodeViewer(
|
||||||
AppConfig.inviteLinkPrefix + room.canonicalAlias,
|
|
||||||
context,
|
context,
|
||||||
|
room.canonicalAlias,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (controller.widget.embeddedCloseButton == null)
|
if (controller.widget.embeddedCloseButton == null)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import 'package:fluffychat/utils/url_launcher.dart';
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
import '../../widgets/qr_code_viewer.dart';
|
||||||
|
|
||||||
class NewPrivateChatView extends StatelessWidget {
|
class NewPrivateChatView extends StatelessWidget {
|
||||||
final NewPrivateChatController controller;
|
final NewPrivateChatController controller;
|
||||||
|
|
@ -25,6 +26,7 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
final searchResponse = controller.searchResponse;
|
final searchResponse = controller.searchResponse;
|
||||||
|
final userId = Matrix.of(context).client.userID!;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
scrolledUnderElevation: 0,
|
scrolledUnderElevation: 0,
|
||||||
|
|
@ -157,26 +159,35 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(64.0),
|
padding: const EdgeInsets.symmetric(
|
||||||
child: ConstrainedBox(
|
horizontal: 64.0,
|
||||||
constraints: const BoxConstraints(maxHeight: 256),
|
vertical: 24.0,
|
||||||
child: Material(
|
),
|
||||||
borderRadius: BorderRadius.circular(12),
|
child: Material(
|
||||||
elevation: 10,
|
borderRadius:
|
||||||
color: Colors.white,
|
BorderRadius.circular(AppConfig.borderRadius),
|
||||||
shadowColor: theme.appBarTheme.shadowColor,
|
color: theme.colorScheme.primaryContainer,
|
||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
|
child: InkWell(
|
||||||
|
borderRadius:
|
||||||
|
BorderRadius.circular(AppConfig.borderRadius),
|
||||||
|
onTap: () => showQrCodeViewer(
|
||||||
|
context,
|
||||||
|
userId,
|
||||||
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(32.0),
|
||||||
child: PrettyQrView.data(
|
child: ConstrainedBox(
|
||||||
data:
|
constraints:
|
||||||
'https://matrix.to/#/${Matrix.of(context).client.userID}',
|
const BoxConstraints(maxWidth: 256),
|
||||||
decoration: PrettyQrDecoration(
|
child: PrettyQrView.data(
|
||||||
shape: PrettyQrSmoothSymbol(
|
data: 'https://matrix.to/#/$userId',
|
||||||
roundFactor: 1,
|
decoration: PrettyQrDecoration(
|
||||||
color: theme.brightness == Brightness.light
|
shape: PrettyQrSmoothSymbol(
|
||||||
? theme.colorScheme.primary
|
roundFactor: 1,
|
||||||
: theme.colorScheme.onPrimary,
|
color:
|
||||||
|
theme.colorScheme.onPrimaryContainer,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import 'package:fluffychat/utils/fluffy_share.dart';
|
||||||
import 'package:fluffychat/utils/url_launcher.dart';
|
import 'package:fluffychat/utils/url_launcher.dart';
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
import 'package:fluffychat/widgets/presence_builder.dart';
|
import 'package:fluffychat/widgets/presence_builder.dart';
|
||||||
|
import 'package:fluffychat/widgets/qr_code_viewer.dart';
|
||||||
import '../../widgets/matrix.dart';
|
import '../../widgets/matrix.dart';
|
||||||
import 'user_bottom_sheet.dart';
|
import 'user_bottom_sheet.dart';
|
||||||
|
|
||||||
|
|
@ -30,348 +31,340 @@ class UserBottomSheetView extends StatelessWidget {
|
||||||
final client = Matrix.of(controller.widget.outerContext).client;
|
final client = Matrix.of(controller.widget.outerContext).client;
|
||||||
final profileSearchError = controller.widget.profileSearchError;
|
final profileSearchError = controller.widget.profileSearchError;
|
||||||
final dmRoomId = client.getDirectChatFromUserId(userId);
|
final dmRoomId = client.getDirectChatFromUserId(userId);
|
||||||
return SafeArea(
|
return Scaffold(
|
||||||
child: Scaffold(
|
appBar: AppBar(
|
||||||
appBar: AppBar(
|
leading: Center(
|
||||||
leading: Center(
|
child: CloseButton(
|
||||||
child: CloseButton(
|
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
||||||
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
centerTitle: false,
|
|
||||||
title: Text(displayname),
|
|
||||||
actions: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
||||||
child: IconButton(
|
|
||||||
onPressed: () => FluffyShare.share(
|
|
||||||
'https://matrix.to/#/$userId',
|
|
||||||
context,
|
|
||||||
),
|
|
||||||
icon: Icon(Icons.adaptive.share_outlined),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
body: StreamBuilder<Object>(
|
centerTitle: false,
|
||||||
stream: user?.room.client.onSync.stream.where(
|
title: Text(displayname),
|
||||||
(syncUpdate) =>
|
actions: [
|
||||||
syncUpdate.rooms?.join?[user.room.id]?.timeline?.events?.any(
|
Padding(
|
||||||
(state) => state.type == EventTypes.RoomPowerLevels,
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
) ??
|
child: IconButton(
|
||||||
false,
|
onPressed: () => showQrCodeViewer(context, userId),
|
||||||
|
icon: const Icon(Icons.qr_code_outlined),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
builder: (context, snapshot) {
|
],
|
||||||
final theme = Theme.of(context);
|
),
|
||||||
return ListView(
|
body: StreamBuilder<Object>(
|
||||||
children: [
|
stream: user?.room.client.onSync.stream.where(
|
||||||
if (user?.membership == Membership.knock)
|
(syncUpdate) =>
|
||||||
Padding(
|
syncUpdate.rooms?.join?[user.room.id]?.timeline?.events?.any(
|
||||||
padding: const EdgeInsets.all(12.0),
|
(state) => state.type == EventTypes.RoomPowerLevels,
|
||||||
child: Material(
|
) ??
|
||||||
color: theme.colorScheme.surfaceContainerHigh,
|
false,
|
||||||
borderRadius:
|
),
|
||||||
BorderRadius.circular(AppConfig.borderRadius),
|
builder: (context, snapshot) {
|
||||||
child: ListTile(
|
final theme = Theme.of(context);
|
||||||
minVerticalPadding: 16,
|
return ListView(
|
||||||
title: Padding(
|
children: [
|
||||||
padding: const EdgeInsets.only(bottom: 12.0),
|
if (user?.membership == Membership.knock)
|
||||||
child: Text(
|
Padding(
|
||||||
L10n.of(context)
|
padding: const EdgeInsets.all(12.0),
|
||||||
.userWouldLikeToChangeTheChat(displayname),
|
child: Material(
|
||||||
),
|
color: theme.colorScheme.surfaceContainerHigh,
|
||||||
),
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||||
subtitle: Row(
|
child: ListTile(
|
||||||
children: [
|
minVerticalPadding: 16,
|
||||||
TextButton.icon(
|
title: Padding(
|
||||||
style: TextButton.styleFrom(
|
padding: const EdgeInsets.only(bottom: 12.0),
|
||||||
backgroundColor: theme.colorScheme.surface,
|
child: Text(
|
||||||
foregroundColor: theme.colorScheme.primary,
|
L10n.of(context)
|
||||||
),
|
.userWouldLikeToChangeTheChat(displayname),
|
||||||
onPressed: controller.knockAccept,
|
|
||||||
icon: const Icon(Icons.check_outlined),
|
|
||||||
label: Text(L10n.of(context).accept),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
TextButton.icon(
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
backgroundColor:
|
|
||||||
theme.colorScheme.errorContainer,
|
|
||||||
foregroundColor:
|
|
||||||
theme.colorScheme.onErrorContainer,
|
|
||||||
),
|
|
||||||
onPressed: controller.knockDecline,
|
|
||||||
icon: const Icon(Icons.cancel_outlined),
|
|
||||||
label: Text(L10n.of(context).decline),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
subtitle: Row(
|
||||||
),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: Avatar(
|
|
||||||
client:
|
|
||||||
Matrix.of(controller.widget.outerContext).client,
|
|
||||||
mxContent: avatarUrl,
|
|
||||||
name: displayname,
|
|
||||||
size: Avatar.defaultSize * 2.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
TextButton.icon(
|
TextButton.icon(
|
||||||
onPressed: () => FluffyShare.share(
|
|
||||||
userId,
|
|
||||||
context,
|
|
||||||
copyOnly: true,
|
|
||||||
),
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.copy_outlined,
|
|
||||||
size: 14,
|
|
||||||
),
|
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
foregroundColor: theme.colorScheme.onSurface,
|
backgroundColor: theme.colorScheme.surface,
|
||||||
),
|
foregroundColor: theme.colorScheme.primary,
|
||||||
label: Text(
|
|
||||||
userId,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
),
|
||||||
|
onPressed: controller.knockAccept,
|
||||||
|
icon: const Icon(Icons.check_outlined),
|
||||||
|
label: Text(L10n.of(context).accept),
|
||||||
),
|
),
|
||||||
PresenceBuilder(
|
const SizedBox(width: 12),
|
||||||
userId: userId,
|
TextButton.icon(
|
||||||
client: client,
|
style: TextButton.styleFrom(
|
||||||
builder: (context, presence) {
|
backgroundColor: theme.colorScheme.errorContainer,
|
||||||
if (presence == null ||
|
foregroundColor:
|
||||||
(presence.presence == PresenceType.offline &&
|
theme.colorScheme.onErrorContainer,
|
||||||
presence.lastActiveTimestamp == null)) {
|
),
|
||||||
return const SizedBox.shrink();
|
onPressed: controller.knockDecline,
|
||||||
}
|
icon: const Icon(Icons.cancel_outlined),
|
||||||
|
label: Text(L10n.of(context).decline),
|
||||||
final dotColor = presence.presence.isOnline
|
|
||||||
? Colors.green
|
|
||||||
: presence.presence.isUnavailable
|
|
||||||
? Colors.orange
|
|
||||||
: Colors.grey;
|
|
||||||
|
|
||||||
final lastActiveTimestamp =
|
|
||||||
presence.lastActiveTimestamp;
|
|
||||||
|
|
||||||
return Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
Container(
|
|
||||||
width: 8,
|
|
||||||
height: 8,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: dotColor,
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
if (presence.currentlyActive == true)
|
|
||||||
Text(
|
|
||||||
L10n.of(context).currentlyActive,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: theme.textTheme.bodySmall,
|
|
||||||
)
|
|
||||||
else if (lastActiveTimestamp != null)
|
|
||||||
Text(
|
|
||||||
L10n.of(context).lastActiveAgo(
|
|
||||||
lastActiveTimestamp
|
|
||||||
.localizedTimeShort(context),
|
|
||||||
),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: theme.textTheme.bodySmall,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
PresenceBuilder(
|
Row(
|
||||||
userId: userId,
|
children: [
|
||||||
client: client,
|
|
||||||
builder: (context, presence) {
|
|
||||||
final status = presence?.statusMsg;
|
|
||||||
if (status == null || status.isEmpty) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
return ListTile(
|
|
||||||
title: SelectableLinkify(
|
|
||||||
text: status,
|
|
||||||
style: const TextStyle(fontSize: 16),
|
|
||||||
options: const LinkifyOptions(humanize: false),
|
|
||||||
linkStyle: const TextStyle(
|
|
||||||
color: Colors.blueAccent,
|
|
||||||
decorationColor: Colors.blueAccent,
|
|
||||||
),
|
|
||||||
onOpen: (url) =>
|
|
||||||
UrlLauncher(context, url.url).launchUrl(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (userId != client.userID)
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.all(16.0),
|
||||||
horizontal: 16.0,
|
child: Avatar(
|
||||||
vertical: 8.0,
|
client: Matrix.of(controller.widget.outerContext).client,
|
||||||
),
|
mxContent: avatarUrl,
|
||||||
child: ElevatedButton.icon(
|
name: displayname,
|
||||||
onPressed: () => controller.participantAction(
|
size: Avatar.defaultSize * 2.5,
|
||||||
UserBottomSheetAction.message,
|
|
||||||
),
|
|
||||||
icon: const Icon(Icons.forum_outlined),
|
|
||||||
label: Text(
|
|
||||||
dmRoomId == null
|
|
||||||
? L10n.of(context).startConversation
|
|
||||||
: L10n.of(context).sendAMessage,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (controller.widget.onMention != null)
|
Expanded(
|
||||||
ListTile(
|
child: Column(
|
||||||
leading: const Icon(Icons.alternate_email_outlined),
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
title: Text(L10n.of(context).mention),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
onTap: () => controller
|
children: [
|
||||||
.participantAction(UserBottomSheetAction.mention),
|
TextButton.icon(
|
||||||
),
|
onPressed: () => FluffyShare.share(
|
||||||
if (user != null) ...[
|
userId,
|
||||||
Divider(color: theme.dividerColor),
|
context,
|
||||||
ListTile(
|
copyOnly: true,
|
||||||
title: Text(L10n.of(context).userRole),
|
|
||||||
leading: const Icon(Icons.admin_panel_settings_outlined),
|
|
||||||
trailing: Material(
|
|
||||||
borderRadius:
|
|
||||||
BorderRadius.circular(AppConfig.borderRadius / 2),
|
|
||||||
color: theme.colorScheme.onInverseSurface,
|
|
||||||
child: DropdownButton<int>(
|
|
||||||
onChanged: user.canChangeUserPowerLevel ||
|
|
||||||
// Workaround until https://github.com/famedly/matrix-dart-sdk/pull/1765
|
|
||||||
(user.room.canChangePowerLevel &&
|
|
||||||
user.id == user.room.client.userID)
|
|
||||||
? controller.setPowerLevel
|
|
||||||
: null,
|
|
||||||
value: {0, 50, 100}.contains(user.powerLevel)
|
|
||||||
? user.powerLevel
|
|
||||||
: null,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
||||||
borderRadius:
|
|
||||||
BorderRadius.circular(AppConfig.borderRadius / 2),
|
|
||||||
underline: const SizedBox.shrink(),
|
|
||||||
items: [
|
|
||||||
DropdownMenuItem(
|
|
||||||
value: 0,
|
|
||||||
child: Text(
|
|
||||||
L10n.of(context).userLevel(
|
|
||||||
user.powerLevel < 50 ? user.powerLevel : 0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
DropdownMenuItem(
|
icon: const Icon(
|
||||||
value: 50,
|
Icons.copy_outlined,
|
||||||
child: Text(
|
size: 14,
|
||||||
L10n.of(context).moderatorLevel(
|
|
||||||
user.powerLevel >= 50 && user.powerLevel < 100
|
|
||||||
? user.powerLevel
|
|
||||||
: 50,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
DropdownMenuItem(
|
style: TextButton.styleFrom(
|
||||||
value: 100,
|
foregroundColor: theme.colorScheme.onSurface,
|
||||||
child: Text(
|
|
||||||
L10n.of(context).adminLevel(
|
|
||||||
user.powerLevel >= 100 ? user.powerLevel : 100,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
DropdownMenuItem(
|
label: Text(
|
||||||
value: null,
|
userId,
|
||||||
child: Text(L10n.of(context).custom),
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
PresenceBuilder(
|
||||||
|
userId: userId,
|
||||||
|
client: client,
|
||||||
|
builder: (context, presence) {
|
||||||
|
if (presence == null ||
|
||||||
|
(presence.presence == PresenceType.offline &&
|
||||||
|
presence.lastActiveTimestamp == null)) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
final dotColor = presence.presence.isOnline
|
||||||
|
? Colors.green
|
||||||
|
: presence.presence.isUnavailable
|
||||||
|
? Colors.orange
|
||||||
|
: Colors.grey;
|
||||||
|
|
||||||
|
final lastActiveTimestamp =
|
||||||
|
presence.lastActiveTimestamp;
|
||||||
|
|
||||||
|
return Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Container(
|
||||||
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: dotColor,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
if (presence.currentlyActive == true)
|
||||||
|
Text(
|
||||||
|
L10n.of(context).currentlyActive,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: theme.textTheme.bodySmall,
|
||||||
|
)
|
||||||
|
else if (lastActiveTimestamp != null)
|
||||||
|
Text(
|
||||||
|
L10n.of(context).lastActiveAgo(
|
||||||
|
lastActiveTimestamp
|
||||||
|
.localizedTimeShort(context),
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: theme.textTheme.bodySmall,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
|
PresenceBuilder(
|
||||||
|
userId: userId,
|
||||||
|
client: client,
|
||||||
|
builder: (context, presence) {
|
||||||
|
final status = presence?.statusMsg;
|
||||||
|
if (status == null || status.isEmpty) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
return ListTile(
|
||||||
|
title: SelectableLinkify(
|
||||||
|
text: status,
|
||||||
|
style: const TextStyle(fontSize: 16),
|
||||||
|
options: const LinkifyOptions(humanize: false),
|
||||||
|
linkStyle: const TextStyle(
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
decorationColor: Colors.blueAccent,
|
||||||
|
),
|
||||||
|
onOpen: (url) =>
|
||||||
|
UrlLauncher(context, url.url).launchUrl(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
if (userId != client.userID)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16.0,
|
||||||
|
vertical: 8.0,
|
||||||
|
),
|
||||||
|
child: ElevatedButton.icon(
|
||||||
|
onPressed: () => controller.participantAction(
|
||||||
|
UserBottomSheetAction.message,
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.forum_outlined),
|
||||||
|
label: Text(
|
||||||
|
dmRoomId == null
|
||||||
|
? L10n.of(context).startConversation
|
||||||
|
: L10n.of(context).sendAMessage,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (controller.widget.onMention != null)
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.alternate_email_outlined),
|
||||||
|
title: Text(L10n.of(context).mention),
|
||||||
|
onTap: () => controller
|
||||||
|
.participantAction(UserBottomSheetAction.mention),
|
||||||
|
),
|
||||||
|
if (user != null) ...[
|
||||||
Divider(color: theme.dividerColor),
|
Divider(color: theme.dividerColor),
|
||||||
if (user != null && user.canKick)
|
ListTile(
|
||||||
ListTile(
|
title: Text(L10n.of(context).userRole),
|
||||||
textColor: theme.colorScheme.error,
|
leading: const Icon(Icons.admin_panel_settings_outlined),
|
||||||
iconColor: theme.colorScheme.error,
|
trailing: Material(
|
||||||
title: Text(L10n.of(context).kickFromChat),
|
borderRadius:
|
||||||
leading: const Icon(Icons.exit_to_app_outlined),
|
BorderRadius.circular(AppConfig.borderRadius / 2),
|
||||||
onTap: () => controller
|
color: theme.colorScheme.onInverseSurface,
|
||||||
.participantAction(UserBottomSheetAction.kick),
|
child: DropdownButton<int>(
|
||||||
),
|
onChanged: user.canChangeUserPowerLevel ||
|
||||||
if (user != null &&
|
// Workaround until https://github.com/famedly/matrix-dart-sdk/pull/1765
|
||||||
user.canBan &&
|
(user.room.canChangePowerLevel &&
|
||||||
user.membership != Membership.ban)
|
user.id == user.room.client.userID)
|
||||||
ListTile(
|
? controller.setPowerLevel
|
||||||
textColor: theme.colorScheme.onErrorContainer,
|
: null,
|
||||||
iconColor: theme.colorScheme.onErrorContainer,
|
value: {0, 50, 100}.contains(user.powerLevel)
|
||||||
title: Text(L10n.of(context).banFromChat),
|
? user.powerLevel
|
||||||
leading: const Icon(Icons.warning_sharp),
|
: null,
|
||||||
onTap: () =>
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
controller.participantAction(UserBottomSheetAction.ban),
|
borderRadius:
|
||||||
)
|
BorderRadius.circular(AppConfig.borderRadius / 2),
|
||||||
else if (user != null &&
|
underline: const SizedBox.shrink(),
|
||||||
user.canBan &&
|
items: [
|
||||||
user.membership == Membership.ban)
|
DropdownMenuItem(
|
||||||
ListTile(
|
value: 0,
|
||||||
title: Text(L10n.of(context).unbanFromChat),
|
child: Text(
|
||||||
leading: const Icon(Icons.warning_outlined),
|
L10n.of(context).userLevel(
|
||||||
onTap: () => controller
|
user.powerLevel < 50 ? user.powerLevel : 0,
|
||||||
.participantAction(UserBottomSheetAction.unban),
|
),
|
||||||
),
|
),
|
||||||
if (user != null && user.id != client.userID)
|
),
|
||||||
ListTile(
|
DropdownMenuItem(
|
||||||
textColor: theme.colorScheme.onErrorContainer,
|
value: 50,
|
||||||
iconColor: theme.colorScheme.onErrorContainer,
|
child: Text(
|
||||||
title: Text(L10n.of(context).reportUser),
|
L10n.of(context).moderatorLevel(
|
||||||
leading: const Icon(Icons.gavel_outlined),
|
user.powerLevel >= 50 && user.powerLevel < 100
|
||||||
onTap: () => controller
|
? user.powerLevel
|
||||||
.participantAction(UserBottomSheetAction.report),
|
: 50,
|
||||||
),
|
),
|
||||||
if (profileSearchError != null)
|
),
|
||||||
ListTile(
|
),
|
||||||
leading: const Icon(
|
DropdownMenuItem(
|
||||||
Icons.warning_outlined,
|
value: 100,
|
||||||
color: Colors.orange,
|
child: Text(
|
||||||
),
|
L10n.of(context).adminLevel(
|
||||||
subtitle: Text(
|
user.powerLevel >= 100 ? user.powerLevel : 100,
|
||||||
L10n.of(context).profileNotFound,
|
),
|
||||||
style: const TextStyle(color: Colors.orange),
|
),
|
||||||
|
),
|
||||||
|
DropdownMenuItem(
|
||||||
|
value: null,
|
||||||
|
child: Text(L10n.of(context).custom),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (userId != client.userID &&
|
),
|
||||||
!client.ignoredUsers.contains(userId))
|
|
||||||
ListTile(
|
|
||||||
textColor: theme.colorScheme.onErrorContainer,
|
|
||||||
iconColor: theme.colorScheme.onErrorContainer,
|
|
||||||
leading: const Icon(Icons.block_outlined),
|
|
||||||
title: Text(L10n.of(context).block),
|
|
||||||
onTap: () => controller
|
|
||||||
.participantAction(UserBottomSheetAction.ignore),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
Divider(color: theme.dividerColor),
|
||||||
},
|
if (user != null && user.canKick)
|
||||||
),
|
ListTile(
|
||||||
|
textColor: theme.colorScheme.error,
|
||||||
|
iconColor: theme.colorScheme.error,
|
||||||
|
title: Text(L10n.of(context).kickFromChat),
|
||||||
|
leading: const Icon(Icons.exit_to_app_outlined),
|
||||||
|
onTap: () =>
|
||||||
|
controller.participantAction(UserBottomSheetAction.kick),
|
||||||
|
),
|
||||||
|
if (user != null &&
|
||||||
|
user.canBan &&
|
||||||
|
user.membership != Membership.ban)
|
||||||
|
ListTile(
|
||||||
|
textColor: theme.colorScheme.onErrorContainer,
|
||||||
|
iconColor: theme.colorScheme.onErrorContainer,
|
||||||
|
title: Text(L10n.of(context).banFromChat),
|
||||||
|
leading: const Icon(Icons.warning_sharp),
|
||||||
|
onTap: () =>
|
||||||
|
controller.participantAction(UserBottomSheetAction.ban),
|
||||||
|
)
|
||||||
|
else if (user != null &&
|
||||||
|
user.canBan &&
|
||||||
|
user.membership == Membership.ban)
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10n.of(context).unbanFromChat),
|
||||||
|
leading: const Icon(Icons.warning_outlined),
|
||||||
|
onTap: () =>
|
||||||
|
controller.participantAction(UserBottomSheetAction.unban),
|
||||||
|
),
|
||||||
|
if (user != null && user.id != client.userID)
|
||||||
|
ListTile(
|
||||||
|
textColor: theme.colorScheme.onErrorContainer,
|
||||||
|
iconColor: theme.colorScheme.onErrorContainer,
|
||||||
|
title: Text(L10n.of(context).reportUser),
|
||||||
|
leading: const Icon(Icons.gavel_outlined),
|
||||||
|
onTap: () => controller
|
||||||
|
.participantAction(UserBottomSheetAction.report),
|
||||||
|
),
|
||||||
|
if (profileSearchError != null)
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(
|
||||||
|
Icons.warning_outlined,
|
||||||
|
color: Colors.orange,
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
L10n.of(context).profileNotFound,
|
||||||
|
style: const TextStyle(color: Colors.orange),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (userId != client.userID &&
|
||||||
|
!client.ignoredUsers.contains(userId))
|
||||||
|
ListTile(
|
||||||
|
textColor: theme.colorScheme.onErrorContainer,
|
||||||
|
iconColor: theme.colorScheme.onErrorContainer,
|
||||||
|
leading: const Icon(Icons.block_outlined),
|
||||||
|
title: Text(L10n.of(context).block),
|
||||||
|
onTap: () => controller
|
||||||
|
.participantAction(UserBottomSheetAction.ignore),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import 'package:fluffychat/utils/url_launcher.dart';
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
import 'package:fluffychat/widgets/qr_code_viewer.dart';
|
||||||
|
|
||||||
class PublicRoomBottomSheet extends StatelessWidget {
|
class PublicRoomBottomSheet extends StatelessWidget {
|
||||||
final String? roomAlias;
|
final String? roomAlias;
|
||||||
|
|
@ -98,16 +99,17 @@ class PublicRoomBottomSheet extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
Padding(
|
if (roomAlias != null)
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
Padding(
|
||||||
child: IconButton(
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
icon: Icon(Icons.adaptive.share_outlined),
|
child: IconButton(
|
||||||
onPressed: () => FluffyShare.share(
|
icon: Icon(Icons.adaptive.share_outlined),
|
||||||
'https://matrix.to/#/${roomAlias ?? chunk?.roomId}',
|
onPressed: () => showQrCodeViewer(
|
||||||
context,
|
context,
|
||||||
|
roomAlias,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: FutureBuilder<PublicRoomsChunk>(
|
body: FutureBuilder<PublicRoomsChunk>(
|
||||||
|
|
|
||||||
138
lib/widgets/qr_code_viewer.dart
Normal file
138
lib/widgets/qr_code_viewer.dart
Normal file
|
|
@ -0,0 +1,138 @@
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:image/image.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:pretty_qr_code/pretty_qr_code.dart';
|
||||||
|
import 'package:qr_image/qr_image.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
|
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||||
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
|
||||||
|
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||||
|
import '../config/themes.dart';
|
||||||
|
|
||||||
|
Future<void> showQrCodeViewer(
|
||||||
|
BuildContext context,
|
||||||
|
String content,
|
||||||
|
) =>
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => QrCodeViewer(content: content),
|
||||||
|
);
|
||||||
|
|
||||||
|
class QrCodeViewer extends StatelessWidget {
|
||||||
|
final String content;
|
||||||
|
|
||||||
|
const QrCodeViewer({required this.content, super.key});
|
||||||
|
|
||||||
|
void _save(BuildContext context) async {
|
||||||
|
final imageResult = await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () async {
|
||||||
|
final inviteLink = 'https://matrix.to/#/$content';
|
||||||
|
final image = QRImage(
|
||||||
|
inviteLink,
|
||||||
|
size: 256,
|
||||||
|
radius: 1,
|
||||||
|
).generate();
|
||||||
|
return compute(encodePng, image);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
final bytes = imageResult.result;
|
||||||
|
if (bytes == null) return;
|
||||||
|
if (!context.mounted) return;
|
||||||
|
|
||||||
|
MatrixImageFile(
|
||||||
|
bytes: bytes,
|
||||||
|
name: 'QR_Code_$content.png',
|
||||||
|
mimeType: 'image/png',
|
||||||
|
).save(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final inviteLink = 'https://matrix.to/#/$content';
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.black.withOpacity(0.5),
|
||||||
|
extendBodyBehindAppBar: true,
|
||||||
|
appBar: AppBar(
|
||||||
|
elevation: 0,
|
||||||
|
leading: IconButton(
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
backgroundColor: Colors.black.withOpacity(0.5),
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.close),
|
||||||
|
onPressed: Navigator.of(context).pop,
|
||||||
|
color: Colors.white,
|
||||||
|
tooltip: L10n.of(context).close,
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
backgroundColor: Colors.black.withOpacity(0.5),
|
||||||
|
),
|
||||||
|
icon: Icon(Icons.adaptive.share_outlined),
|
||||||
|
onPressed: () => FluffyShare.share(
|
||||||
|
inviteLink,
|
||||||
|
context,
|
||||||
|
),
|
||||||
|
color: Colors.white,
|
||||||
|
tooltip: L10n.of(context).share,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
IconButton(
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
backgroundColor: Colors.black.withOpacity(0.5),
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.download_outlined),
|
||||||
|
onPressed: () => _save(context),
|
||||||
|
color: Colors.white,
|
||||||
|
tooltip: L10n.of(context).downloadFile,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.all(32.0),
|
||||||
|
padding: const EdgeInsets.all(32.0),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
ConstrainedBox(
|
||||||
|
constraints:
|
||||||
|
const BoxConstraints(maxWidth: FluffyThemes.columnWidth),
|
||||||
|
child: PrettyQrView.data(
|
||||||
|
data: inviteLink,
|
||||||
|
decoration: PrettyQrDecoration(
|
||||||
|
shape: PrettyQrSmoothSymbol(
|
||||||
|
roundFactor: 1,
|
||||||
|
color: theme.colorScheme.onPrimaryContainer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8.0),
|
||||||
|
SelectableText(
|
||||||
|
content,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
color: theme.colorScheme.onPrimaryContainer,
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1554,6 +1554,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.1"
|
version: "1.0.1"
|
||||||
|
qr_image:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: qr_image
|
||||||
|
sha256: c3cd2ac2c6cd6b14604c97b45c477b18988b6518f72120fa04418fc54e3b0d76
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
quiver:
|
quiver:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ dependencies:
|
||||||
provider: ^6.0.2
|
provider: ^6.0.2
|
||||||
punycode: ^1.0.0
|
punycode: ^1.0.0
|
||||||
qr_code_scanner: ^1.0.1
|
qr_code_scanner: ^1.0.1
|
||||||
|
qr_image: ^1.0.0
|
||||||
receive_sharing_intent: ^1.8.1
|
receive_sharing_intent: ^1.8.1
|
||||||
record: ^5.1.2
|
record: ^5.1.2
|
||||||
scroll_to_index: ^3.0.1
|
scroll_to_index: ^3.0.1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue