feat: bring back share link to join spaces (#1701)
This commit is contained in:
parent
8dd74d7e8a
commit
7c8f917370
5 changed files with 141 additions and 16 deletions
|
|
@ -34,6 +34,7 @@ import 'package:fluffychat/pangea/guard/p_vguard.dart';
|
|||
import 'package:fluffychat/pangea/login/pages/login_or_signup_view.dart';
|
||||
import 'package:fluffychat/pangea/login/pages/signup.dart';
|
||||
import 'package:fluffychat/pangea/login/pages/user_settings.dart';
|
||||
import 'package:fluffychat/pangea/spaces/utils/join_with_alias.dart';
|
||||
import 'package:fluffychat/pangea/spaces/utils/join_with_link.dart';
|
||||
import 'package:fluffychat/pangea/subscription/pages/settings_subscription.dart';
|
||||
import 'package:fluffychat/pangea/user/pages/find_partner.dart';
|
||||
|
|
@ -134,6 +135,20 @@ abstract class AppRoutes {
|
|||
const JoinClassWithLink(),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/join_with_alias',
|
||||
pageBuilder: (context, state) => defaultPageBuilder(
|
||||
context,
|
||||
state,
|
||||
const JoinWithAlias(),
|
||||
),
|
||||
redirect: (context, state) {
|
||||
if (Matrix.of(context).client.isLogged()) {
|
||||
return '/rooms/join_with_alias?alias=${state.uri.queryParameters['alias']}';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/user_age',
|
||||
pageBuilder: (context, state) => defaultPageBuilder(
|
||||
|
|
@ -209,6 +224,14 @@ abstract class AppRoutes {
|
|||
// ),
|
||||
// ],
|
||||
// ),
|
||||
GoRoute(
|
||||
path: '/join_with_alias',
|
||||
pageBuilder: (context, state) => defaultPageBuilder(
|
||||
context,
|
||||
state,
|
||||
const JoinWithAlias(),
|
||||
),
|
||||
),
|
||||
// Pangea#
|
||||
GoRoute(
|
||||
path: 'archive',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
class PLocalKey {
|
||||
static const String access = "access";
|
||||
static const String cachedClassCodeToJoin = "cachedclasscodetojoin";
|
||||
static const String cachedAliasToJoin = "cachedAliasToJoin";
|
||||
static const String beganWebPayment = "beganWebPayment";
|
||||
static const String dismissedPaywall = 'dismissedPaywall';
|
||||
static const String paywallBackoff = 'paywallBackoff';
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'dart:convert';
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
|
@ -23,6 +24,8 @@ class ClassController extends BaseController {
|
|||
_pangeaController = pangeaController;
|
||||
}
|
||||
|
||||
static final GetStorage _aliasStorage = GetStorage('alias_storage');
|
||||
|
||||
void setActiveSpaceIdInChatListController(String? classId) {
|
||||
setState({"activeSpaceId": classId});
|
||||
}
|
||||
|
|
@ -33,6 +36,8 @@ class ClassController extends BaseController {
|
|||
isAccountData: false,
|
||||
);
|
||||
|
||||
final String? alias = _aliasStorage.read(PLocalKey.cachedAliasToJoin);
|
||||
|
||||
if (classCode != null) {
|
||||
await joinClasswithCode(
|
||||
context,
|
||||
|
|
@ -43,9 +48,52 @@ class ClassController extends BaseController {
|
|||
PLocalKey.cachedClassCodeToJoin,
|
||||
isAccountData: false,
|
||||
);
|
||||
} else if (alias != null) {
|
||||
await joinCachedRoomAlias(alias, context);
|
||||
await _aliasStorage.remove(PLocalKey.cachedAliasToJoin);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> joinCachedRoomAlias(
|
||||
String alias,
|
||||
BuildContext context,
|
||||
) async {
|
||||
if (alias.isEmpty) {
|
||||
context.go("/rooms");
|
||||
return;
|
||||
}
|
||||
|
||||
final client = Matrix.of(context).client;
|
||||
if (!client.isLogged()) {
|
||||
await _aliasStorage.write(PLocalKey.cachedAliasToJoin, alias);
|
||||
context.go("/home");
|
||||
return;
|
||||
}
|
||||
|
||||
Room? room = client.getRoomByAlias(alias) ?? client.getRoomById(alias);
|
||||
if (room != null) {
|
||||
room.isSpace
|
||||
? context.push("/rooms/${room.id}/details")
|
||||
: context.go("/rooms/${room.id}");
|
||||
return;
|
||||
}
|
||||
|
||||
final roomID = await client.joinRoom(alias);
|
||||
room = client.getRoomById(roomID);
|
||||
if (room == null) {
|
||||
await client.waitForRoomInSync(roomID);
|
||||
room = client.getRoomById(roomID);
|
||||
if (room == null) {
|
||||
context.go("/rooms");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
room.isSpace
|
||||
? context.push("/rooms/${room.id}/details")
|
||||
: context.go("/rooms/${room.id}");
|
||||
}
|
||||
|
||||
Future<void> joinClasswithCode(
|
||||
BuildContext context,
|
||||
String classCode, {
|
||||
|
|
|
|||
45
lib/pangea/spaces/utils/join_with_alias.dart
Normal file
45
lib/pangea/spaces/utils/join_with_alias.dart
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/widgets/layouts/empty_page.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class JoinWithAlias extends StatefulWidget {
|
||||
const JoinWithAlias({super.key});
|
||||
|
||||
@override
|
||||
State<JoinWithAlias> createState() => _JoinWithAliasState();
|
||||
}
|
||||
|
||||
class _JoinWithAliasState extends State<JoinWithAlias> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async => _joinRoom(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _joinRoom() async {
|
||||
final String? alias =
|
||||
GoRouterState.of(context).uri.queryParameters['alias'];
|
||||
|
||||
if (alias == null || alias.isEmpty) {
|
||||
context.go("/rooms");
|
||||
return;
|
||||
}
|
||||
|
||||
await MatrixState.pangeaController.classController.joinCachedRoomAlias(
|
||||
alias,
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const EmptyPage();
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import 'package:go_router/go_router.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/common/config/environment.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||
import 'package:fluffychat/utils/url_launcher.dart';
|
||||
|
|
@ -140,22 +141,29 @@ class PublicRoomBottomSheetState extends State<PublicRoomBottomSheet> {
|
|||
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
||||
),
|
||||
),
|
||||
// #Pangea
|
||||
// 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,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// Pangea#
|
||||
actions: roomAlias == null
|
||||
? null
|
||||
: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.qr_code_rounded),
|
||||
// #Pangea
|
||||
// onPressed: () => showQrCodeViewer(
|
||||
// context,
|
||||
// roomAlias,
|
||||
// ),
|
||||
onPressed: () {
|
||||
FluffyShare.share(
|
||||
"${Environment.frontendURL}/#/join_with_alias?alias=${Uri.encodeComponent(roomAlias)}",
|
||||
context,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
// Pangea#
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: FutureBuilder<PublicRoomsChunk>(
|
||||
future: _search(),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue