chore: set active space via route instead of stream (#2744)
This commit is contained in:
parent
05942772b4
commit
d792e9fc86
9 changed files with 114 additions and 79 deletions
|
|
@ -38,6 +38,7 @@ import 'package:fluffychat/pangea/learning_settings/pages/settings_learning.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/constants/space_constants.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';
|
||||
|
|
@ -145,17 +146,23 @@ abstract class AppRoutes {
|
|||
pageBuilder: (context, state) => defaultPageBuilder(
|
||||
context,
|
||||
state,
|
||||
const JoinClassWithLink(),
|
||||
JoinClassWithLink(
|
||||
classCode: state.uri.queryParameters[SpaceConstants.classCode],
|
||||
),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/join_with_alias',
|
||||
pageBuilder: (context, state) => Matrix.of(context).client.isLogged()
|
||||
? chatListShellRouteBuilder(context, state, const JoinWithAlias())
|
||||
? chatListShellRouteBuilder(
|
||||
context,
|
||||
state,
|
||||
JoinWithAlias(alias: state.uri.queryParameters['alias']),
|
||||
)
|
||||
: defaultPageBuilder(
|
||||
context,
|
||||
state,
|
||||
const JoinWithAlias(),
|
||||
JoinWithAlias(alias: state.uri.queryParameters['alias']),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
|
|
@ -206,6 +213,10 @@ abstract class AppRoutes {
|
|||
? TwoColumnLayout(
|
||||
mainView: ChatList(
|
||||
activeChat: state.pathParameters['roomid'],
|
||||
// #Pangea
|
||||
activeSpaceId: state.uri.queryParameters['spaceId'],
|
||||
activeFilter: state.uri.queryParameters['filter'],
|
||||
// Pangea#
|
||||
displayNavigationRail:
|
||||
state.path?.startsWith('/rooms/settings') != true,
|
||||
),
|
||||
|
|
@ -224,7 +235,25 @@ abstract class AppRoutes {
|
|||
routes: [
|
||||
GoRoute(
|
||||
path: '/rooms',
|
||||
redirect: loggedOutRedirect,
|
||||
// #Pangea
|
||||
// redirect: loggedOutRedirect,
|
||||
redirect: (context, state) async {
|
||||
final resp = await loggedOutRedirect(context, state);
|
||||
final spaceId = state.uri.queryParameters['spaceId'];
|
||||
|
||||
if (resp != null ||
|
||||
!state.uri.queryParameters.containsKey('spaceId') ||
|
||||
spaceId == 'clear' ||
|
||||
!FluffyThemes.isColumnMode(context) ||
|
||||
(state.fullPath?.contains('details') ?? true)) {
|
||||
return resp;
|
||||
}
|
||||
|
||||
return !FluffyThemes.isColumnMode(context)
|
||||
? resp
|
||||
: '/rooms/$spaceId/details?spaceId=${spaceId ?? 'clear'}';
|
||||
},
|
||||
// Pangea#
|
||||
pageBuilder: (context, state) => defaultPageBuilder(
|
||||
context,
|
||||
state,
|
||||
|
|
@ -235,6 +264,10 @@ abstract class AppRoutes {
|
|||
// Pangea#
|
||||
: ChatList(
|
||||
activeChat: state.pathParameters['roomid'],
|
||||
// #Pangea
|
||||
activeSpaceId: state.uri.queryParameters['spaceId'],
|
||||
activeFilter: state.uri.queryParameters['filter'],
|
||||
// Pangea#
|
||||
),
|
||||
),
|
||||
routes: [
|
||||
|
|
@ -727,6 +760,10 @@ abstract class AppRoutes {
|
|||
? TwoColumnLayout(
|
||||
mainView: ChatList(
|
||||
activeChat: state.pathParameters['roomid'],
|
||||
// #Pangea
|
||||
activeSpaceId: state.uri.queryParameters['spaceId'],
|
||||
activeFilter: state.uri.queryParameters['filter'],
|
||||
// Pangea#
|
||||
displayNavigationRail:
|
||||
state.path?.startsWith('/rooms/settings') != true,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -358,14 +358,6 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
WidgetsBinding.instance.addObserver(this);
|
||||
// #Pangea
|
||||
if (!mounted) return;
|
||||
if (room.isSpace) {
|
||||
ErrorHandler.logError(
|
||||
e: "Space chat opened",
|
||||
s: StackTrace.current,
|
||||
data: {"roomId": roomId},
|
||||
);
|
||||
context.go("/rooms");
|
||||
}
|
||||
Future.delayed(const Duration(seconds: 1), () async {
|
||||
if (!mounted) return;
|
||||
debugPrint(
|
||||
|
|
@ -548,7 +540,8 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
var prevNumEvents = timeline!.events.length;
|
||||
await requestHistory();
|
||||
var numRequests = 0;
|
||||
while (timeline!.events.length > prevNumEvents &&
|
||||
while (timeline != null &&
|
||||
timeline!.events.length > prevNumEvents &&
|
||||
visibleEvents.length < 10 &&
|
||||
numRequests <= 5) {
|
||||
prevNumEvents = timeline!.events.length;
|
||||
|
|
@ -694,6 +687,14 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
super.didChangeDependencies();
|
||||
_router = GoRouter.of(context);
|
||||
_router.routeInformationProvider.addListener(_onRouteChanged);
|
||||
if (room.isSpace && _router.state.path == ":roomid") {
|
||||
ErrorHandler.logError(
|
||||
e: "Space chat opened",
|
||||
s: StackTrace.current,
|
||||
data: {"roomId": roomId},
|
||||
);
|
||||
context.go("/rooms");
|
||||
}
|
||||
}
|
||||
|
||||
void _onRouteChanged() {
|
||||
|
|
|
|||
|
|
@ -80,11 +80,19 @@ extension LocalizedActiveFilter on ActiveFilter {
|
|||
class ChatList extends StatefulWidget {
|
||||
static BuildContext? contextForVoip;
|
||||
final String? activeChat;
|
||||
// #Pangea
|
||||
final String? activeSpaceId;
|
||||
final String? activeFilter;
|
||||
// Pangea#
|
||||
final bool displayNavigationRail;
|
||||
|
||||
const ChatList({
|
||||
super.key,
|
||||
required this.activeChat,
|
||||
// #Pangea
|
||||
this.activeSpaceId,
|
||||
this.activeFilter,
|
||||
// Pangea#
|
||||
this.displayNavigationRail = false,
|
||||
});
|
||||
|
||||
|
|
@ -149,16 +157,9 @@ class ChatListController extends State<ChatList>
|
|||
future: () async {
|
||||
if (acceptInvite == OkCancelResult.ok) {
|
||||
await room.join();
|
||||
if (room.isSpace) {
|
||||
setActiveSpace(room.id);
|
||||
context.go(
|
||||
FluffyThemes.isColumnMode(context)
|
||||
? "/rooms/${room.id}/details"
|
||||
: "/rooms",
|
||||
);
|
||||
return;
|
||||
}
|
||||
context.go("/rooms/${room.id}");
|
||||
context.go(
|
||||
room.isSpace ? "/rooms?spaceId=${room.id}" : "/rooms/${room.id}",
|
||||
);
|
||||
return;
|
||||
}
|
||||
await room.leave();
|
||||
|
|
@ -472,7 +473,6 @@ class ChatListController extends State<ChatList>
|
|||
}
|
||||
|
||||
//#Pangea
|
||||
StreamSubscription? classStream;
|
||||
StreamSubscription? _invitedSpaceSubscription;
|
||||
StreamSubscription? _subscriptionStatusStream;
|
||||
StreamSubscription? _spaceChildSubscription;
|
||||
|
|
@ -507,20 +507,6 @@ class ChatListController extends State<ChatList>
|
|||
_checkTorBrowser();
|
||||
|
||||
//#Pangea
|
||||
classStream = MatrixState.pangeaController.classController.stateStream
|
||||
.listen((event) {
|
||||
if (!mounted || event is! Map<String, dynamic>) return;
|
||||
if (event.containsKey("activeSpaceId")) {
|
||||
final setSpaceID = event["activeSpaceId"];
|
||||
setSpaceID != null ? setActiveSpace(setSpaceID) : clearActiveSpace();
|
||||
if (setSpaceID != null) {
|
||||
context.push("/rooms/$setSpaceID/details");
|
||||
}
|
||||
} else if (event.containsKey("activeFilter")) {
|
||||
setActiveFilter(event["activeFilter"]);
|
||||
}
|
||||
});
|
||||
|
||||
_invitedSpaceSubscription = MatrixState
|
||||
.pangeaController.matrixState.client.onSync.stream
|
||||
.where((event) => event.rooms?.invite != null)
|
||||
|
|
@ -635,6 +621,15 @@ class ChatListController extends State<ChatList>
|
|||
);
|
||||
}
|
||||
});
|
||||
|
||||
_activeSpaceId =
|
||||
widget.activeSpaceId == 'clear' ? null : widget.activeSpaceId;
|
||||
|
||||
if (widget.activeFilter == 'groups') {
|
||||
activeFilter = AppConfig.separateChatTypes
|
||||
? ActiveFilter.groups
|
||||
: ActiveFilter.allChats;
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
super.initState();
|
||||
|
|
@ -644,15 +639,21 @@ class ChatListController extends State<ChatList>
|
|||
@override
|
||||
void didUpdateWidget(ChatList oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final params = GoRouterState.of(context).uri.queryParameters;
|
||||
if (!params.containsKey("filter") || params['filter'] != 'groups') return;
|
||||
if (widget.activeFilter != oldWidget.activeFilter &&
|
||||
widget.activeFilter == 'groups') {
|
||||
setActiveFilter(
|
||||
AppConfig.separateChatTypes
|
||||
? ActiveFilter.groups
|
||||
: ActiveFilter.allChats,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (widget.activeSpaceId != oldWidget.activeSpaceId &&
|
||||
widget.activeSpaceId != null) {
|
||||
widget.activeSpaceId == 'clear'
|
||||
? clearActiveSpace()
|
||||
: setActiveSpace(widget.activeSpaceId!);
|
||||
}
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
|
|
@ -662,7 +663,6 @@ class ChatListController extends State<ChatList>
|
|||
_intentFileStreamSubscription?.cancel();
|
||||
_intentUriStreamSubscription?.cancel();
|
||||
//#Pangea
|
||||
classStream?.cancel();
|
||||
_invitedSpaceSubscription?.cancel();
|
||||
_subscriptionStatusStream?.cancel();
|
||||
_spaceChildSubscription?.cancel();
|
||||
|
|
|
|||
|
|
@ -240,8 +240,7 @@ class NewGroupController extends State<NewGroup> {
|
|||
|
||||
// if a timeout happened, don't redirect to the space
|
||||
if (error != null) return;
|
||||
MatrixState.pangeaController.classController
|
||||
.setActiveSpaceIdInChatListController(spaceId);
|
||||
context.go("/rooms?spaceId=$spaceId");
|
||||
// Pangea#
|
||||
context.pop<String>(spaceId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -430,8 +430,7 @@ class PangeaChatDetailsView extends StatelessWidget {
|
|||
room.isSpace ? room.leaveSpace : room.leave,
|
||||
);
|
||||
if (!resp.isError) {
|
||||
MatrixState.pangeaController.classController
|
||||
.setActiveSpaceIdInChatListController(null);
|
||||
context.go("/rooms?spaceId=clear");
|
||||
}
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import 'package:get_storage/get_storage.dart';
|
|||
import 'package:go_router/go_router.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
||||
import 'package:fluffychat/pangea/common/constants/local.key.dart';
|
||||
import 'package:fluffychat/pangea/common/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
|
|
@ -34,14 +33,6 @@ class ClassController extends BaseController {
|
|||
_pangeaController = pangeaController;
|
||||
}
|
||||
|
||||
void setActiveFilterInChatListController(ActiveFilter filter) {
|
||||
setState({"activeFilter": filter});
|
||||
}
|
||||
|
||||
void setActiveSpaceIdInChatListController(String? classId) {
|
||||
setState({"activeSpaceId": classId});
|
||||
}
|
||||
|
||||
Future<void> joinCachedSpaceCode(BuildContext context) async {
|
||||
final String? classCode = linkBox.read(
|
||||
PLocalKey.cachedClassCodeToJoin,
|
||||
|
|
@ -83,7 +74,7 @@ class ClassController extends BaseController {
|
|||
Room? room = client.getRoomByAlias(alias) ?? client.getRoomById(alias);
|
||||
if (room != null) {
|
||||
room.isSpace
|
||||
? setActiveSpaceIdInChatListController(room.id)
|
||||
? context.go("/rooms?spaceId=${room.id}")
|
||||
: context.go("/rooms/${room.id}");
|
||||
return;
|
||||
}
|
||||
|
|
@ -100,7 +91,7 @@ class ClassController extends BaseController {
|
|||
}
|
||||
|
||||
room.isSpace
|
||||
? setActiveSpaceIdInChatListController(room.id)
|
||||
? context.go("/rooms?spaceId=${room.id}")
|
||||
: context.go("/rooms/${room.id}");
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +132,7 @@ class ClassController extends BaseController {
|
|||
);
|
||||
|
||||
if (alreadyJoined.isNotEmpty || inFoundClass) {
|
||||
setActiveSpaceIdInChatListController(alreadyJoined.first);
|
||||
context.go("/rooms?spaceId=${alreadyJoined.first}");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +192,7 @@ class ClassController extends BaseController {
|
|||
await room.requestParticipants();
|
||||
}
|
||||
|
||||
setActiveSpaceIdInChatListController(spaceID.result!);
|
||||
context.go("/rooms?spaceId=${room.id}");
|
||||
return spaceID;
|
||||
} catch (e, s) {
|
||||
ErrorHandler.logError(
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ import 'package:fluffychat/widgets/layouts/empty_page.dart';
|
|||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class JoinWithAlias extends StatefulWidget {
|
||||
const JoinWithAlias({super.key});
|
||||
final String? alias;
|
||||
const JoinWithAlias({super.key, this.alias});
|
||||
|
||||
@override
|
||||
State<JoinWithAlias> createState() => _JoinWithAliasState();
|
||||
|
|
@ -26,16 +27,13 @@ class _JoinWithAliasState extends State<JoinWithAlias> {
|
|||
}
|
||||
|
||||
Future<void> _joinRoom() async {
|
||||
final String? alias =
|
||||
GoRouterState.of(context).uri.queryParameters['alias'];
|
||||
|
||||
if (alias == null || alias.isEmpty) {
|
||||
if (widget.alias == null || widget.alias!.isEmpty) {
|
||||
context.go("/rooms");
|
||||
return;
|
||||
}
|
||||
|
||||
await MatrixState.pangeaController.classController.joinCachedRoomAlias(
|
||||
alias,
|
||||
widget.alias!,
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,13 @@ import 'package:go_router/go_router.dart';
|
|||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/common/constants/local.key.dart';
|
||||
import 'package:fluffychat/pangea/common/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/spaces/constants/space_constants.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
//if on home with classcode in url and not logged in, then save it soemhow and after llogin, join class automatically
|
||||
//if on home with classcode in url and logged in, then join class automatically
|
||||
class JoinClassWithLink extends StatefulWidget {
|
||||
const JoinClassWithLink({super.key});
|
||||
final String? classCode;
|
||||
const JoinClassWithLink({super.key, this.classCode});
|
||||
|
||||
@override
|
||||
State<JoinClassWithLink> createState() => _JoinClassWithLinkState();
|
||||
|
|
@ -19,19 +18,12 @@ class JoinClassWithLink extends StatefulWidget {
|
|||
|
||||
//PTODO - show class info in field so they know they're joining the right class
|
||||
class _JoinClassWithLinkState extends State<JoinClassWithLink> {
|
||||
String? classCode;
|
||||
final PangeaController pangeaController = MatrixState.pangeaController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
Future.delayed(Duration.zero, () async {
|
||||
classCode = GoRouterState.of(context)
|
||||
.uri
|
||||
.queryParameters[SpaceConstants.classCode];
|
||||
|
||||
if (classCode == null) {
|
||||
if (widget.classCode == null) {
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message:
|
||||
|
|
@ -42,7 +34,7 @@ class _JoinClassWithLinkState extends State<JoinClassWithLink> {
|
|||
}
|
||||
await MatrixState.pangeaController.classController.linkBox.write(
|
||||
PLocalKey.cachedClassCodeToJoin,
|
||||
classCode,
|
||||
widget.classCode,
|
||||
);
|
||||
context.go("/home");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ class PublicRoomDialog extends StatefulWidget {
|
|||
final List<String>? via;
|
||||
|
||||
const PublicRoomDialog({super.key, this.roomAlias, this.chunk, this.via});
|
||||
|
||||
// #Pangea
|
||||
@override
|
||||
State<PublicRoomDialog> createState() => PublicRoomDialogState();
|
||||
|
|
@ -39,6 +38,20 @@ class PublicRoomDialogState extends State<PublicRoomDialog> {
|
|||
|
||||
final TextEditingController _codeController = TextEditingController();
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (chunk != null) {
|
||||
final room = MatrixState.pangeaController.matrixState.client
|
||||
.getRoomById(chunk!.roomId);
|
||||
|
||||
if (room != null && room.membership == Membership.join) {
|
||||
context.go("/rooms?spaceId=${room.id}");
|
||||
Navigator.of(context).maybePop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_codeController.dispose();
|
||||
|
|
@ -95,6 +108,11 @@ class PublicRoomDialogState extends State<PublicRoomDialog> {
|
|||
!client.getRoomById(result.result!)!.isSpace) {
|
||||
context.go('/rooms/$roomId');
|
||||
}
|
||||
// #Pangea
|
||||
else {
|
||||
context.go('/rooms?spaceId=$roomId');
|
||||
}
|
||||
// Pangea#
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue