Compare commits
2 commits
main
...
krille/roo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d48da53134 | ||
|
|
e94368108a |
16 changed files with 316 additions and 487 deletions
|
|
@ -3205,5 +3205,14 @@
|
||||||
"takeAPhoto": "Take a photo",
|
"takeAPhoto": "Take a photo",
|
||||||
"recordAVideo": "Record a video",
|
"recordAVideo": "Record a video",
|
||||||
"optionalMessage": "(Optional) message...",
|
"optionalMessage": "(Optional) message...",
|
||||||
"notSupportedOnThisDevice": "Not supported on this device"
|
"notSupportedOnThisDevice": "Not supported on this device",
|
||||||
|
"noRoomFoundForAlias": "No room found with the alias {alias} on your server.",
|
||||||
|
"@noRoomFoundForAlias": {
|
||||||
|
"type": "String",
|
||||||
|
"placeholders": {
|
||||||
|
"alias": {
|
||||||
|
"type": "String"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import 'dart:async';
|
||||||
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:matrix/matrix_api_lite.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/themes.dart';
|
import 'package:fluffychat/config/themes.dart';
|
||||||
import 'package:fluffychat/pages/archive/archive.dart';
|
import 'package:fluffychat/pages/archive/archive.dart';
|
||||||
|
|
@ -35,6 +36,7 @@ import 'package:fluffychat/widgets/layouts/empty_page.dart';
|
||||||
import 'package:fluffychat/widgets/layouts/two_column_layout.dart';
|
import 'package:fluffychat/widgets/layouts/two_column_layout.dart';
|
||||||
import 'package:fluffychat/widgets/log_view.dart';
|
import 'package:fluffychat/widgets/log_view.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
import 'package:fluffychat/widgets/room_loader.dart';
|
||||||
import 'package:fluffychat/widgets/share_scaffold_dialog.dart';
|
import 'package:fluffychat/widgets/share_scaffold_dialog.dart';
|
||||||
|
|
||||||
abstract class AppRoutes {
|
abstract class AppRoutes {
|
||||||
|
|
@ -132,9 +134,15 @@ abstract class AppRoutes {
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
state,
|
state,
|
||||||
ChatPage(
|
RoomLoader(
|
||||||
roomId: state.pathParameters['roomid']!,
|
roomId: state.pathParameters['roomid']!,
|
||||||
eventId: state.uri.queryParameters['event'],
|
chunk: state.extra is PublicRoomsChunk
|
||||||
|
? state.extra as PublicRoomsChunk
|
||||||
|
: null,
|
||||||
|
builder: (context, room) => ChatPage(
|
||||||
|
room: room,
|
||||||
|
eventId: state.uri.queryParameters['event'],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
redirect: loggedOutRedirect,
|
redirect: loggedOutRedirect,
|
||||||
|
|
@ -331,10 +339,16 @@ abstract class AppRoutes {
|
||||||
return defaultPageBuilder(
|
return defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
state,
|
state,
|
||||||
ChatPage(
|
RoomLoader(
|
||||||
|
key: ValueKey(state.pathParameters['roomid']!),
|
||||||
roomId: state.pathParameters['roomid']!,
|
roomId: state.pathParameters['roomid']!,
|
||||||
shareItems: shareItems,
|
chunk: state.extra is PublicRoomsChunk
|
||||||
eventId: state.uri.queryParameters['event'],
|
? state.extra as PublicRoomsChunk
|
||||||
|
: null,
|
||||||
|
builder: (context, room) => ChatPage(
|
||||||
|
room: room,
|
||||||
|
eventId: state.uri.queryParameters['event'],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -376,8 +390,11 @@ abstract class AppRoutes {
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
state,
|
state,
|
||||||
ChatDetails(
|
RoomLoader(
|
||||||
roomId: state.pathParameters['roomid']!,
|
roomId: state.pathParameters['roomid']!,
|
||||||
|
builder: (context, room) => ChatDetails(
|
||||||
|
room: room,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
routes: [
|
routes: [
|
||||||
|
|
|
||||||
|
|
@ -44,48 +44,12 @@ import '../../utils/localized_exception_extension.dart';
|
||||||
import 'send_file_dialog.dart';
|
import 'send_file_dialog.dart';
|
||||||
import 'send_location_dialog.dart';
|
import 'send_location_dialog.dart';
|
||||||
|
|
||||||
class ChatPage extends StatelessWidget {
|
class ChatPage extends StatefulWidget {
|
||||||
final String roomId;
|
|
||||||
final List<ShareItem>? shareItems;
|
|
||||||
final String? eventId;
|
|
||||||
|
|
||||||
const ChatPage({
|
|
||||||
super.key,
|
|
||||||
required this.roomId,
|
|
||||||
this.eventId,
|
|
||||||
this.shareItems,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final room = Matrix.of(context).client.getRoomById(roomId);
|
|
||||||
if (room == null) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title: Text(L10n.of(context).oopsSomethingWentWrong)),
|
|
||||||
body: Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
child: Text(L10n.of(context).youAreNoLongerParticipatingInThisChat),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ChatPageWithRoom(
|
|
||||||
key: Key('chat_page_${roomId}_$eventId'),
|
|
||||||
room: room,
|
|
||||||
shareItems: shareItems,
|
|
||||||
eventId: eventId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ChatPageWithRoom extends StatefulWidget {
|
|
||||||
final Room room;
|
final Room room;
|
||||||
final List<ShareItem>? shareItems;
|
final List<ShareItem>? shareItems;
|
||||||
final String? eventId;
|
final String? eventId;
|
||||||
|
|
||||||
const ChatPageWithRoom({
|
const ChatPage({
|
||||||
super.key,
|
super.key,
|
||||||
required this.room,
|
required this.room,
|
||||||
this.shareItems,
|
this.shareItems,
|
||||||
|
|
@ -96,8 +60,7 @@ class ChatPageWithRoom extends StatefulWidget {
|
||||||
ChatController createState() => ChatController();
|
ChatController createState() => ChatController();
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChatController extends State<ChatPageWithRoom>
|
class ChatController extends State<ChatPage> with WidgetsBindingObserver {
|
||||||
with WidgetsBindingObserver {
|
|
||||||
Room get room => sendingClient.getRoomById(roomId) ?? widget.room;
|
Room get room => sendingClient.getRoomById(roomId) ?? widget.room;
|
||||||
|
|
||||||
late Client sendingClient;
|
late Client sendingClient;
|
||||||
|
|
@ -1332,7 +1295,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: ChatDetails(
|
child: ChatDetails(
|
||||||
roomId: roomId,
|
room: room,
|
||||||
embeddedCloseButton: IconButton(
|
embeddedCloseButton: IconButton(
|
||||||
icon: const Icon(Icons.close),
|
icon: const Icon(Icons.close),
|
||||||
onPressed: toggleDisplayChatDetailsColumn,
|
onPressed: toggleDisplayChatDetailsColumn,
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,9 @@ class ChatAppBarTitle extends StatelessWidget {
|
||||||
hoverColor: Colors.transparent,
|
hoverColor: Colors.transparent,
|
||||||
splashColor: Colors.transparent,
|
splashColor: Colors.transparent,
|
||||||
highlightColor: Colors.transparent,
|
highlightColor: Colors.transparent,
|
||||||
onTap: controller.isArchived
|
onTap: () => FluffyThemes.isThreeColumnMode(context)
|
||||||
? null
|
? controller.toggleDisplayChatDetailsColumn()
|
||||||
: () => FluffyThemes.isThreeColumnMode(context)
|
: context.go('/rooms/${room.id}/details'),
|
||||||
? controller.toggleDisplayChatDetailsColumn()
|
|
||||||
: context.go('/rooms/${room.id}/details'),
|
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Hero(
|
Hero(
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,10 @@ class ChatEventList extends StatelessWidget {
|
||||||
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (timeline.canRequestHistory) {
|
if (timeline.canRequestHistory &&
|
||||||
|
(timeline.room.membership == Membership.join ||
|
||||||
|
timeline.room.historyVisibility ==
|
||||||
|
HistoryVisibility.worldReadable)) {
|
||||||
return Builder(
|
return Builder(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
WidgetsBinding.instance
|
WidgetsBinding.instance
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import 'package:fluffychat/pages/chat/pinned_events.dart';
|
||||||
import 'package:fluffychat/pages/chat/reactions_picker.dart';
|
import 'package:fluffychat/pages/chat/reactions_picker.dart';
|
||||||
import 'package:fluffychat/pages/chat/reply_display.dart';
|
import 'package:fluffychat/pages/chat/reply_display.dart';
|
||||||
import 'package:fluffychat/utils/account_config.dart';
|
import 'package:fluffychat/utils/account_config.dart';
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
|
||||||
import 'package:fluffychat/widgets/chat_settings_popup_menu.dart';
|
import 'package:fluffychat/widgets/chat_settings_popup_menu.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';
|
||||||
|
|
@ -127,19 +126,15 @@ class ChatView extends StatelessWidget {
|
||||||
ChatSettingsPopupMenu(controller.room, true),
|
ChatSettingsPopupMenu(controller.room, true),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return [];
|
return [
|
||||||
|
ChatSettingsPopupMenu(controller.room, true),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
if (controller.room.membership == Membership.invite) {
|
|
||||||
showFutureLoadingDialog(
|
|
||||||
context: context,
|
|
||||||
future: () => controller.room.join(),
|
|
||||||
exceptionContext: ExceptionContext.joinRoom,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final bottomSheetPadding = FluffyThemes.isColumnMode(context) ? 16.0 : 8.0;
|
final bottomSheetPadding = FluffyThemes.isColumnMode(context) ? 16.0 : 8.0;
|
||||||
final scrollUpBannerEventId = controller.scrollUpBannerEventId;
|
final scrollUpBannerEventId = controller.scrollUpBannerEventId;
|
||||||
|
|
||||||
|
|
@ -300,6 +295,22 @@ class ChatView extends StatelessWidget {
|
||||||
child: ChatEventList(controller: controller),
|
child: ChatEventList(controller: controller),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (controller.room.membership != Membership.join &&
|
||||||
|
(controller.room.membership ==
|
||||||
|
Membership.invite ||
|
||||||
|
controller.room.joinRules ==
|
||||||
|
JoinRules.public))
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.all(bottomSheetPadding),
|
||||||
|
width: double.infinity,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () => showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: controller.room.join,
|
||||||
|
),
|
||||||
|
child: Text(L10n.of(context).joinRoom),
|
||||||
|
),
|
||||||
|
),
|
||||||
if (controller.room.canSendDefaultMessages &&
|
if (controller.room.canSendDefaultMessages &&
|
||||||
controller.room.membership == Membership.join)
|
controller.room.membership == Membership.join)
|
||||||
Container(
|
Container(
|
||||||
|
|
|
||||||
|
|
@ -14,17 +14,16 @@ import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
|
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
|
||||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
|
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
|
||||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
|
||||||
|
|
||||||
enum AliasActions { copy, delete, setCanonical }
|
enum AliasActions { copy, delete, setCanonical }
|
||||||
|
|
||||||
class ChatDetails extends StatefulWidget {
|
class ChatDetails extends StatefulWidget {
|
||||||
final String roomId;
|
final Room room;
|
||||||
final Widget? embeddedCloseButton;
|
final Widget? embeddedCloseButton;
|
||||||
|
|
||||||
const ChatDetails({
|
const ChatDetails({
|
||||||
super.key,
|
super.key,
|
||||||
required this.roomId,
|
required this.room,
|
||||||
this.embeddedCloseButton,
|
this.embeddedCloseButton,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -38,10 +37,8 @@ class ChatDetailsController extends State<ChatDetails> {
|
||||||
void toggleDisplaySettings() =>
|
void toggleDisplaySettings() =>
|
||||||
setState(() => displaySettings = !displaySettings);
|
setState(() => displaySettings = !displaySettings);
|
||||||
|
|
||||||
String? get roomId => widget.roomId;
|
|
||||||
|
|
||||||
void setDisplaynameAction() async {
|
void setDisplaynameAction() async {
|
||||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
final room = widget.room;
|
||||||
final input = await showTextInputDialog(
|
final input = await showTextInputDialog(
|
||||||
context: context,
|
context: context,
|
||||||
title: L10n.of(context).changeTheNameOfTheGroup,
|
title: L10n.of(context).changeTheNameOfTheGroup,
|
||||||
|
|
@ -66,7 +63,7 @@ class ChatDetailsController extends State<ChatDetails> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTopicAction() async {
|
void setTopicAction() async {
|
||||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
final room = widget.room;
|
||||||
final input = await showTextInputDialog(
|
final input = await showTextInputDialog(
|
||||||
context: context,
|
context: context,
|
||||||
title: L10n.of(context).setChatDescription,
|
title: L10n.of(context).setChatDescription,
|
||||||
|
|
@ -92,7 +89,7 @@ class ChatDetailsController extends State<ChatDetails> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void goToEmoteSettings() async {
|
void goToEmoteSettings() async {
|
||||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
final room = widget.room;
|
||||||
// okay, we need to test if there are any emote state events other than the default one
|
// okay, we need to test if there are any emote state events other than the default one
|
||||||
// if so, we need to be directed to a selection screen for which pack we want to look at
|
// if so, we need to be directed to a selection screen for which pack we want to look at
|
||||||
// otherwise, we just open the normal one.
|
// otherwise, we just open the normal one.
|
||||||
|
|
@ -106,7 +103,7 @@ class ChatDetailsController extends State<ChatDetails> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAvatarAction() async {
|
void setAvatarAction() async {
|
||||||
final room = Matrix.of(context).client.getRoomById(roomId!);
|
final room = widget.room;
|
||||||
final actions = [
|
final actions = [
|
||||||
if (PlatformInfos.isMobile)
|
if (PlatformInfos.isMobile)
|
||||||
AdaptiveModalAction(
|
AdaptiveModalAction(
|
||||||
|
|
@ -120,7 +117,7 @@ class ChatDetailsController extends State<ChatDetails> {
|
||||||
label: L10n.of(context).openGallery,
|
label: L10n.of(context).openGallery,
|
||||||
icon: const Icon(Icons.photo_outlined),
|
icon: const Icon(Icons.photo_outlined),
|
||||||
),
|
),
|
||||||
if (room?.avatar != null)
|
if (room.avatar != null)
|
||||||
AdaptiveModalAction(
|
AdaptiveModalAction(
|
||||||
value: AvatarAction.remove,
|
value: AvatarAction.remove,
|
||||||
label: L10n.of(context).delete,
|
label: L10n.of(context).delete,
|
||||||
|
|
@ -140,7 +137,7 @@ class ChatDetailsController extends State<ChatDetails> {
|
||||||
if (action == AvatarAction.remove) {
|
if (action == AvatarAction.remove) {
|
||||||
await showFutureLoadingDialog(
|
await showFutureLoadingDialog(
|
||||||
context: context,
|
context: context,
|
||||||
future: () => room!.setAvatar(null),
|
future: () => room.setAvatar(null),
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +169,7 @@ class ChatDetailsController extends State<ChatDetails> {
|
||||||
}
|
}
|
||||||
await showFutureLoadingDialog(
|
await showFutureLoadingDialog(
|
||||||
context: context,
|
context: context,
|
||||||
future: () => room!.setAvatar(file),
|
future: () => room.setAvatar(file),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
import 'package:fluffychat/widgets/chat_settings_popup_menu.dart';
|
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 '../../utils/url_launcher.dart';
|
import '../../utils/url_launcher.dart';
|
||||||
import '../../widgets/qr_code_viewer.dart';
|
import '../../widgets/qr_code_viewer.dart';
|
||||||
|
|
||||||
|
|
@ -25,17 +24,7 @@ class ChatDetailsView extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
final room = Matrix.of(context).client.getRoomById(controller.roomId!);
|
final room = controller.widget.room;
|
||||||
if (room == null) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text(L10n.of(context).oopsSomethingWentWrong),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Text(L10n.of(context).youAreNoLongerParticipatingInThisChat),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return StreamBuilder(
|
return StreamBuilder(
|
||||||
stream: room.client.onRoomState.stream
|
stream: room.client.onRoomState.stream
|
||||||
|
|
@ -163,7 +152,7 @@ class ChatDetailsView extends StatelessWidget {
|
||||||
onPressed: () => room.isDirectChat
|
onPressed: () => room.isDirectChat
|
||||||
? null
|
? null
|
||||||
: context.push(
|
: context.push(
|
||||||
'/rooms/${controller.roomId}/details/members',
|
'/rooms/${controller.widget.room.id}/details/members',
|
||||||
),
|
),
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
Icons.group_outlined,
|
Icons.group_outlined,
|
||||||
|
|
@ -335,7 +324,7 @@ class ChatDetailsView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () => context.push(
|
onTap: () => context.push(
|
||||||
'/rooms/${controller.roomId!}/details/members',
|
'/rooms/${controller.widget.room.id}/details/members',
|
||||||
),
|
),
|
||||||
trailing: const Icon(Icons.chevron_right_outlined),
|
trailing: const Icon(Icons.chevron_right_outlined),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -112,31 +112,6 @@ class ChatListController extends State<ChatList>
|
||||||
});
|
});
|
||||||
|
|
||||||
void onChatTap(Room room) async {
|
void onChatTap(Room room) async {
|
||||||
if (room.membership == Membership.invite) {
|
|
||||||
final joinResult = await showFutureLoadingDialog(
|
|
||||||
context: context,
|
|
||||||
future: () async {
|
|
||||||
final waitForRoom = room.client.waitForRoomInSync(
|
|
||||||
room.id,
|
|
||||||
join: true,
|
|
||||||
);
|
|
||||||
await room.join();
|
|
||||||
await waitForRoom;
|
|
||||||
},
|
|
||||||
exceptionContext: ExceptionContext.joinRoom,
|
|
||||||
);
|
|
||||||
if (joinResult.error != null) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (room.membership == Membership.ban) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(L10n.of(context).youHaveBeenBannedFromThisChat),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (room.membership == Membership.leave) {
|
if (room.membership == Membership.leave) {
|
||||||
context.go('/rooms/archive/${room.id}');
|
context.go('/rooms/archive/${room.id}');
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.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/config/app_config.dart';
|
||||||
|
|
@ -16,7 +17,6 @@ import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
||||||
import 'package:fluffychat/utils/stream_extension.dart';
|
import 'package:fluffychat/utils/stream_extension.dart';
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
import 'package:fluffychat/widgets/hover_builder.dart';
|
import 'package:fluffychat/widgets/hover_builder.dart';
|
||||||
import 'package:fluffychat/widgets/public_room_bottom_sheet.dart';
|
|
||||||
import '../../config/themes.dart';
|
import '../../config/themes.dart';
|
||||||
import '../../widgets/matrix.dart';
|
import '../../widgets/matrix.dart';
|
||||||
import 'chat_list_header.dart';
|
import 'chat_list_header.dart';
|
||||||
|
|
@ -344,14 +344,9 @@ class PublicRoomsHorizontalList extends StatelessWidget {
|
||||||
publicRooms[i].canonicalAlias?.localpart ??
|
publicRooms[i].canonicalAlias?.localpart ??
|
||||||
L10n.of(context).group,
|
L10n.of(context).group,
|
||||||
avatar: publicRooms[i].avatarUrl,
|
avatar: publicRooms[i].avatarUrl,
|
||||||
onPressed: () => showAdaptiveBottomSheet(
|
onPressed: () => context.go(
|
||||||
context: context,
|
'/rooms/${publicRooms[i].roomId}',
|
||||||
builder: (c) => PublicRoomBottomSheet(
|
extra: publicRooms[i],
|
||||||
roomAlias:
|
|
||||||
publicRooms[i].canonicalAlias ?? publicRooms[i].roomId,
|
|
||||||
outerContext: context,
|
|
||||||
chunk: publicRooms[i],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:matrix/matrix.dart' as sdk;
|
import 'package:matrix/matrix.dart' as sdk;
|
||||||
|
|
@ -10,7 +9,6 @@ import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/config/themes.dart';
|
import 'package:fluffychat/config/themes.dart';
|
||||||
import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
|
import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
|
||||||
import 'package:fluffychat/pages/chat_list/search_title.dart';
|
import 'package:fluffychat/pages/chat_list/search_title.dart';
|
||||||
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
import 'package:fluffychat/utils/stream_extension.dart';
|
import 'package:fluffychat/utils/stream_extension.dart';
|
||||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
|
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
|
||||||
|
|
@ -19,7 +17,6 @@ import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.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/public_room_bottom_sheet.dart';
|
|
||||||
|
|
||||||
enum AddRoomType { chat, subspace }
|
enum AddRoomType { chat, subspace }
|
||||||
|
|
||||||
|
|
@ -96,29 +93,6 @@ class _SpaceViewState extends State<SpaceView> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _joinChildRoom(SpaceRoomsChunk item) async {
|
|
||||||
final client = Matrix.of(context).client;
|
|
||||||
final space = client.getRoomById(widget.spaceId);
|
|
||||||
|
|
||||||
final joined = await showAdaptiveBottomSheet<bool>(
|
|
||||||
context: context,
|
|
||||||
builder: (_) => PublicRoomBottomSheet(
|
|
||||||
outerContext: context,
|
|
||||||
chunk: item,
|
|
||||||
via: space?.spaceChildren
|
|
||||||
.firstWhereOrNull(
|
|
||||||
(child) => child.roomId == item.roomId,
|
|
||||||
)
|
|
||||||
?.via,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (mounted && joined == true) {
|
|
||||||
setState(() {
|
|
||||||
_discoveredChildren.remove(item);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onSpaceAction(SpaceActions action) async {
|
void _onSpaceAction(SpaceActions action) async {
|
||||||
final space = Matrix.of(context).client.getRoomById(widget.spaceId);
|
final space = Matrix.of(context).client.getRoomById(widget.spaceId);
|
||||||
|
|
||||||
|
|
@ -499,7 +473,7 @@ class _SpaceViewState extends State<SpaceView> {
|
||||||
const VisualDensity(vertical: -0.5),
|
const VisualDensity(vertical: -0.5),
|
||||||
contentPadding:
|
contentPadding:
|
||||||
const EdgeInsets.symmetric(horizontal: 8),
|
const EdgeInsets.symmetric(horizontal: 8),
|
||||||
onTap: () => _joinChildRoom(item),
|
onTap: () => context.go('/rooms/${item.roomId}'),
|
||||||
leading: Avatar(
|
leading: Avatar(
|
||||||
mxContent: item.avatarUrl,
|
mxContent: item.avatarUrl,
|
||||||
name: displayname,
|
name: displayname,
|
||||||
|
|
|
||||||
84
lib/utils/room_from_public_rooms_chunk.dart
Normal file
84
lib/utils/room_from_public_rooms_chunk.dart
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
extension RoomFromPublicRoomsChunk on PublicRoomsChunk {
|
||||||
|
Room createRoom(Client client) {
|
||||||
|
final room = Room(
|
||||||
|
id: roomId,
|
||||||
|
client: client,
|
||||||
|
prev_batch: '',
|
||||||
|
membership: Membership.leave,
|
||||||
|
);
|
||||||
|
if (guestCanJoin) {
|
||||||
|
room.setState(
|
||||||
|
StrippedStateEvent(
|
||||||
|
stateKey: '',
|
||||||
|
type: EventTypes.GuestAccess,
|
||||||
|
content: {'guest_access': 'can_join'},
|
||||||
|
senderId: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (worldReadable) {
|
||||||
|
room.setState(
|
||||||
|
StrippedStateEvent(
|
||||||
|
stateKey: '',
|
||||||
|
type: EventTypes.HistoryVisibility,
|
||||||
|
content: {'history_visibility': 'world_readable'},
|
||||||
|
senderId: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (avatarUrl != null) {
|
||||||
|
room.setState(
|
||||||
|
StrippedStateEvent(
|
||||||
|
stateKey: '',
|
||||||
|
type: EventTypes.RoomAvatar,
|
||||||
|
content: {'url': avatarUrl.toString()},
|
||||||
|
senderId: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (canonicalAlias != null) {
|
||||||
|
room.setState(
|
||||||
|
StrippedStateEvent(
|
||||||
|
stateKey: '',
|
||||||
|
type: EventTypes.RoomCanonicalAlias,
|
||||||
|
content: {'alias': canonicalAlias},
|
||||||
|
senderId: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (joinRule != null) {
|
||||||
|
room.setState(
|
||||||
|
StrippedStateEvent(
|
||||||
|
stateKey: '',
|
||||||
|
type: EventTypes.RoomJoinRules,
|
||||||
|
content: {'join_rule': joinRule},
|
||||||
|
senderId: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
room.summary.mInvitedMemberCount = numJoinedMembers;
|
||||||
|
|
||||||
|
room.setState(
|
||||||
|
StrippedStateEvent(
|
||||||
|
stateKey: '',
|
||||||
|
type: EventTypes.RoomCreate,
|
||||||
|
content: {if (roomType != null) 'type': roomType},
|
||||||
|
senderId: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (name != null) {
|
||||||
|
room.setState(
|
||||||
|
StrippedStateEvent(
|
||||||
|
stateKey: '',
|
||||||
|
type: EventTypes.RoomName,
|
||||||
|
content: {'name': name},
|
||||||
|
senderId: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,7 +13,6 @@ import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
||||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.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/public_room_bottom_sheet.dart';
|
|
||||||
import 'platform_infos.dart';
|
import 'platform_infos.dart';
|
||||||
|
|
||||||
class UrlLauncher {
|
class UrlLauncher {
|
||||||
|
|
@ -134,92 +133,49 @@ class UrlLauncher {
|
||||||
if (identityParts == null) {
|
if (identityParts == null) {
|
||||||
return; // no match, nothing to do
|
return; // no match, nothing to do
|
||||||
}
|
}
|
||||||
if (identityParts.primaryIdentifier.sigil == '#' ||
|
|
||||||
identityParts.primaryIdentifier.sigil == '!') {
|
if (identityParts.primaryIdentifier.sigil == '!') {
|
||||||
|
final event = identityParts.secondaryIdentifier;
|
||||||
|
context.go(
|
||||||
|
'/${Uri(
|
||||||
|
pathSegments: ['rooms', identityParts.primaryIdentifier],
|
||||||
|
queryParameters: event != null ? {'event': event} : null,
|
||||||
|
)}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (identityParts.primaryIdentifier.sigil == '#') {
|
||||||
// we got a room! Let's open that one
|
// we got a room! Let's open that one
|
||||||
final roomIdOrAlias = identityParts.primaryIdentifier;
|
final roomIdOrAlias = identityParts.primaryIdentifier;
|
||||||
final event = identityParts.secondaryIdentifier;
|
final event = identityParts.secondaryIdentifier;
|
||||||
var room = matrix.client.getRoomByAlias(roomIdOrAlias) ??
|
var roomId = matrix.client.getRoomByAlias(roomIdOrAlias)?.id;
|
||||||
matrix.client.getRoomById(roomIdOrAlias);
|
|
||||||
var roomId = room?.id;
|
if (roomId == null && roomIdOrAlias.sigil == '#') {
|
||||||
// we make the servers a set and later on convert to a list, so that we can easily
|
|
||||||
// deduplicate servers added via alias lookup and query parameter
|
|
||||||
final servers = <String>{};
|
|
||||||
if (room == null && roomIdOrAlias.sigil == '#') {
|
|
||||||
// we were unable to find the room locally...so resolve it
|
// we were unable to find the room locally...so resolve it
|
||||||
final response = await showFutureLoadingDialog(
|
final response = await showFutureLoadingDialog(
|
||||||
context: context,
|
context: context,
|
||||||
future: () => matrix.client.getRoomIdByAlias(roomIdOrAlias),
|
future: () => matrix.client.getRoomIdByAlias(roomIdOrAlias),
|
||||||
);
|
);
|
||||||
if (response.error != null) {
|
roomId = response.result?.roomId;
|
||||||
return; // nothing to do, the alias doesn't exist
|
|
||||||
}
|
|
||||||
roomId = response.result!.roomId;
|
|
||||||
servers.addAll(response.result!.servers!);
|
|
||||||
room = matrix.client.getRoomById(roomId!);
|
|
||||||
}
|
}
|
||||||
servers.addAll(identityParts.via);
|
|
||||||
if (room != null) {
|
|
||||||
if (room.isSpace) {
|
|
||||||
// TODO: Implement navigate to space
|
|
||||||
context.go('/rooms/${room.id}');
|
|
||||||
|
|
||||||
return;
|
if (roomId == null) {
|
||||||
}
|
await showOkAlertDialog(
|
||||||
// we have the room, so....just open it
|
|
||||||
if (event != null) {
|
|
||||||
context.go(
|
|
||||||
'/${Uri(
|
|
||||||
pathSegments: ['rooms', room.id],
|
|
||||||
queryParameters: {'event': event},
|
|
||||||
)}',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
context.go('/rooms/${room.id}');
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
await showAdaptiveBottomSheet(
|
|
||||||
context: context,
|
context: context,
|
||||||
builder: (c) => PublicRoomBottomSheet(
|
message: L10n.of(context)
|
||||||
roomAlias: identityParts.primaryIdentifier,
|
.noRoomFoundForAlias(identityParts.primaryIdentifier),
|
||||||
outerContext: context,
|
title: L10n.of(context).nothingFound,
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (roomIdOrAlias.sigil == '!') {
|
context.go(
|
||||||
if (await showOkCancelAlertDialog(
|
'/${Uri(
|
||||||
useRootNavigator: false,
|
pathSegments: ['rooms', roomId],
|
||||||
context: context,
|
queryParameters: event != null ? {'event': event} : null,
|
||||||
title: 'Join room $roomIdOrAlias',
|
)}',
|
||||||
) ==
|
);
|
||||||
OkCancelResult.ok) {
|
|
||||||
roomId = roomIdOrAlias;
|
return;
|
||||||
final response = await showFutureLoadingDialog(
|
|
||||||
context: context,
|
|
||||||
future: () => matrix.client.joinRoom(
|
|
||||||
roomIdOrAlias,
|
|
||||||
serverName: servers.isNotEmpty ? servers.toList() : null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (response.error != null) return;
|
|
||||||
// wait for two seconds so that it probably came down /sync
|
|
||||||
await showFutureLoadingDialog(
|
|
||||||
context: context,
|
|
||||||
future: () => Future.delayed(const Duration(seconds: 2)),
|
|
||||||
);
|
|
||||||
if (event != null) {
|
|
||||||
context.go(
|
|
||||||
Uri(
|
|
||||||
pathSegments: ['rooms', response.result!],
|
|
||||||
queryParameters: {'event': event},
|
|
||||||
).toString(),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
context.go('/rooms/${response.result!}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (identityParts.primaryIdentifier.sigil == '@') {
|
} else if (identityParts.primaryIdentifier.sigil == '@') {
|
||||||
await showAdaptiveBottomSheet(
|
await showAdaptiveBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
|
|
|
||||||
|
|
@ -107,28 +107,30 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (widget.room.pushRuleState == PushRuleState.notify)
|
if (widget.room.membership == Membership.join) ...[
|
||||||
PopupMenuItem<ChatPopupMenuActions>(
|
if (widget.room.pushRuleState == PushRuleState.notify)
|
||||||
value: ChatPopupMenuActions.mute,
|
PopupMenuItem<ChatPopupMenuActions>(
|
||||||
child: Row(
|
value: ChatPopupMenuActions.mute,
|
||||||
children: [
|
child: Row(
|
||||||
const Icon(Icons.notifications_off_outlined),
|
children: [
|
||||||
const SizedBox(width: 12),
|
const Icon(Icons.notifications_off_outlined),
|
||||||
Text(L10n.of(context).muteChat),
|
const SizedBox(width: 12),
|
||||||
],
|
Text(L10n.of(context).muteChat),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
PopupMenuItem<ChatPopupMenuActions>(
|
||||||
|
value: ChatPopupMenuActions.unmute,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.notifications_on_outlined),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Text(L10n.of(context).unmuteChat),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
],
|
||||||
else
|
|
||||||
PopupMenuItem<ChatPopupMenuActions>(
|
|
||||||
value: ChatPopupMenuActions.unmute,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.notifications_on_outlined),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text(L10n.of(context).unmuteChat),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
PopupMenuItem<ChatPopupMenuActions>(
|
PopupMenuItem<ChatPopupMenuActions>(
|
||||||
value: ChatPopupMenuActions.search,
|
value: ChatPopupMenuActions.search,
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|
@ -139,16 +141,17 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
PopupMenuItem<ChatPopupMenuActions>(
|
if (widget.room.membership == Membership.join)
|
||||||
value: ChatPopupMenuActions.leave,
|
PopupMenuItem<ChatPopupMenuActions>(
|
||||||
child: Row(
|
value: ChatPopupMenuActions.leave,
|
||||||
children: [
|
child: Row(
|
||||||
const Icon(Icons.delete_outlined),
|
children: [
|
||||||
const SizedBox(width: 12),
|
const Icon(Icons.delete_outlined),
|
||||||
Text(L10n.of(context).leave),
|
const SizedBox(width: 12),
|
||||||
],
|
Text(L10n.of(context).leave),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -1,233 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
||||||
import 'package:flutter_linkify/flutter_linkify.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
|
||||||
import 'package:matrix/matrix.dart';
|
|
||||||
|
|
||||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
|
||||||
import 'package:fluffychat/utils/url_launcher.dart';
|
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
|
||||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
|
||||||
import 'package:fluffychat/widgets/qr_code_viewer.dart';
|
|
||||||
|
|
||||||
class PublicRoomBottomSheet extends StatelessWidget {
|
|
||||||
final String? roomAlias;
|
|
||||||
final BuildContext outerContext;
|
|
||||||
final PublicRoomsChunk? chunk;
|
|
||||||
final List<String>? via;
|
|
||||||
|
|
||||||
PublicRoomBottomSheet({
|
|
||||||
this.roomAlias,
|
|
||||||
required this.outerContext,
|
|
||||||
this.chunk,
|
|
||||||
this.via,
|
|
||||||
super.key,
|
|
||||||
}) {
|
|
||||||
assert(roomAlias != null || chunk != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _joinRoom(BuildContext context) async {
|
|
||||||
final client = Matrix.of(outerContext).client;
|
|
||||||
final chunk = this.chunk;
|
|
||||||
final knock = chunk?.joinRule == 'knock';
|
|
||||||
final result = await showFutureLoadingDialog<String>(
|
|
||||||
context: context,
|
|
||||||
future: () async {
|
|
||||||
if (chunk != null && client.getRoomById(chunk.roomId) != null) {
|
|
||||||
return chunk.roomId;
|
|
||||||
}
|
|
||||||
final roomId = chunk != null && knock
|
|
||||||
? await client.knockRoom(chunk.roomId, serverName: via)
|
|
||||||
: await client.joinRoom(
|
|
||||||
roomAlias ?? chunk!.roomId,
|
|
||||||
serverName: via,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!knock && client.getRoomById(roomId) == null) {
|
|
||||||
await client.waitForRoomInSync(roomId);
|
|
||||||
}
|
|
||||||
return roomId;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (knock) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (result.error == null) {
|
|
||||||
Navigator.of(context).pop<bool>(true);
|
|
||||||
// don't open the room if the joined room is a space
|
|
||||||
if (chunk?.roomType != 'm.space' &&
|
|
||||||
!client.getRoomById(result.result!)!.isSpace) {
|
|
||||||
outerContext.go('/rooms/${result.result!}');
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _testRoom(PublicRoomsChunk r) => r.canonicalAlias == roomAlias;
|
|
||||||
|
|
||||||
Future<PublicRoomsChunk> _search() async {
|
|
||||||
final chunk = this.chunk;
|
|
||||||
if (chunk != null) return chunk;
|
|
||||||
final query = await Matrix.of(outerContext).client.queryPublicRooms(
|
|
||||||
server: roomAlias!.domain,
|
|
||||||
filter: PublicRoomQueryFilter(
|
|
||||||
genericSearchTerm: roomAlias,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (!query.chunk.any(_testRoom)) {
|
|
||||||
throw (L10n.of(outerContext).noRoomsFound);
|
|
||||||
}
|
|
||||||
return query.chunk.firstWhere(_testRoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final roomAlias = this.roomAlias ?? chunk?.canonicalAlias;
|
|
||||||
final roomLink = roomAlias ?? chunk?.roomId;
|
|
||||||
return SafeArea(
|
|
||||||
child: Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text(
|
|
||||||
chunk?.name ?? roomAlias ?? chunk?.roomId ?? 'Unknown',
|
|
||||||
overflow: TextOverflow.fade,
|
|
||||||
),
|
|
||||||
leading: Center(
|
|
||||||
child: CloseButton(
|
|
||||||
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: roomAlias == null
|
|
||||||
? null
|
|
||||||
: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
||||||
child: IconButton(
|
|
||||||
icon: const Icon(Icons.qr_code_rounded),
|
|
||||||
onPressed: () => showQrCodeViewer(
|
|
||||||
context,
|
|
||||||
roomAlias,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: FutureBuilder<PublicRoomsChunk>(
|
|
||||||
future: _search(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
|
|
||||||
final profile = snapshot.data;
|
|
||||||
return ListView(
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: profile == null
|
|
||||||
? const Center(
|
|
||||||
child: CircularProgressIndicator.adaptive(),
|
|
||||||
)
|
|
||||||
: Avatar(
|
|
||||||
client: Matrix.of(outerContext).client,
|
|
||||||
mxContent: profile.avatarUrl,
|
|
||||||
name: profile.name ?? roomAlias,
|
|
||||||
size: Avatar.defaultSize * 3,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
TextButton.icon(
|
|
||||||
onPressed: roomLink != null
|
|
||||||
? () => FluffyShare.share(
|
|
||||||
roomLink,
|
|
||||||
context,
|
|
||||||
copyOnly: true,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.copy_outlined,
|
|
||||||
size: 14,
|
|
||||||
),
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
foregroundColor: theme.colorScheme.onSurface,
|
|
||||||
iconColor: theme.colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
label: Text(
|
|
||||||
roomLink ?? '...',
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextButton.icon(
|
|
||||||
onPressed: () {},
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.groups_3_outlined,
|
|
||||||
size: 14,
|
|
||||||
),
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
foregroundColor: theme.colorScheme.onSurface,
|
|
||||||
iconColor: theme.colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
label: Text(
|
|
||||||
L10n.of(context).countParticipants(
|
|
||||||
profile?.numJoinedMembers ?? 0,
|
|
||||||
),
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
||||||
child: ElevatedButton.icon(
|
|
||||||
onPressed: () => _joinRoom(context),
|
|
||||||
label: Text(
|
|
||||||
chunk?.joinRule == 'knock' &&
|
|
||||||
Matrix.of(outerContext)
|
|
||||||
.client
|
|
||||||
.getRoomById(chunk!.roomId) ==
|
|
||||||
null
|
|
||||||
? L10n.of(context).knock
|
|
||||||
: chunk?.roomType == 'm.space'
|
|
||||||
? L10n.of(context).joinSpace
|
|
||||||
: L10n.of(context).joinRoom,
|
|
||||||
),
|
|
||||||
icon: const Icon(Icons.navigate_next),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
if (profile?.topic?.isNotEmpty ?? false)
|
|
||||||
ListTile(
|
|
||||||
subtitle: SelectableLinkify(
|
|
||||||
text: profile!.topic!,
|
|
||||||
linkStyle: TextStyle(
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
decorationColor: theme.colorScheme.primary,
|
|
||||||
),
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: theme.textTheme.bodyMedium!.color,
|
|
||||||
),
|
|
||||||
options: const LinkifyOptions(humanize: false),
|
|
||||||
onOpen: (url) =>
|
|
||||||
UrlLauncher(context, url.url).launchUrl(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
88
lib/widgets/room_loader.dart
Normal file
88
lib/widgets/room_loader.dart
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
|
import 'package:fluffychat/utils/room_from_public_rooms_chunk.dart';
|
||||||
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
||||||
|
class RoomLoader extends StatelessWidget {
|
||||||
|
final String roomId;
|
||||||
|
final PublicRoomsChunk? chunk;
|
||||||
|
final Widget Function(BuildContext context, Room room) builder;
|
||||||
|
|
||||||
|
const RoomLoader({
|
||||||
|
required this.roomId,
|
||||||
|
required this.builder,
|
||||||
|
this.chunk,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
static final Map<String, Future<Room>> _roomLoaders = {};
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final client = Matrix.of(context).client;
|
||||||
|
final existingRoom = client.getRoomById(roomId);
|
||||||
|
|
||||||
|
if (existingRoom != null) {
|
||||||
|
return builder(context, existingRoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
final chunk = this.chunk;
|
||||||
|
if (chunk != null) {
|
||||||
|
return builder(context, chunk.createRoom(client));
|
||||||
|
}
|
||||||
|
|
||||||
|
final roomLoader =
|
||||||
|
_roomLoaders[roomId] ??= client.getRoomState(roomId).then((states) {
|
||||||
|
final room = Room(
|
||||||
|
id: roomId,
|
||||||
|
client: client,
|
||||||
|
prev_batch: '',
|
||||||
|
membership: Membership.leave,
|
||||||
|
);
|
||||||
|
states.forEach(room.setState);
|
||||||
|
return room;
|
||||||
|
});
|
||||||
|
|
||||||
|
return FutureBuilder(
|
||||||
|
key: ValueKey(roomId),
|
||||||
|
future: roomLoader,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final room = snapshot.data;
|
||||||
|
if (room != null) return builder(context, room);
|
||||||
|
final error = snapshot.error;
|
||||||
|
if (error != null) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: Center(
|
||||||
|
child: BackButton(onPressed: Navigator.of(context).pop),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: Column(
|
||||||
|
spacing: 8,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.search_off_outlined),
|
||||||
|
Text(error.toLocalizedString(context)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: Center(
|
||||||
|
child: BackButton(onPressed: Navigator.of(context).pop),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: const Center(
|
||||||
|
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue