Skip to content

Commit

Permalink
TW-1011: Add StreamSubscription for listen lookupContact
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Dec 12, 2023
1 parent cdf9670 commit 574c686
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 45 deletions.
1 change: 1 addition & 0 deletions lib/pages/chat_draft/draft_chat_adaptive_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DraftChatAdaptiveScaffold extends StatelessWidget {
onBack: controller.hideRightColumn,
contact: _contact,
isInStack: isInStack,
isDraftInfo: true,
);
default:
return const SizedBox();
Expand Down
3 changes: 3 additions & 0 deletions lib/pages/chat_draft/draft_chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class DraftChatView extends StatelessWidget {
title: Row(
children: [
TwakeIconButton(
splashColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
tooltip: L10n.of(context)!.back,
icon: Icons.arrow_back,
onTap: () => context.pop(),
Expand Down
18 changes: 16 additions & 2 deletions lib/pages/chat_profile_info/chat_profile_info.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:dartz/dartz.dart' hide State;
import 'package:fluffychat/app_state/failure.dart';
import 'package:fluffychat/app_state/success.dart';
Expand All @@ -16,13 +18,15 @@ class ProfileInfo extends StatefulWidget {
final String? roomId;
final PresentationContact? contact;
final bool isInStack;
final bool isDraftInfo;

const ProfileInfo({
super.key,
required this.onBack,
required this.isInStack,
this.roomId,
this.contact,
required this.isDraftInfo,
});

@override
Expand All @@ -33,6 +37,8 @@ class ProfileInfoController extends State<ProfileInfo> {
final _lookupMatchContactInteractor =
getIt.get<LookupMatchContactInteractor>();

StreamSubscription? lookupContactNotifierSub;

final ValueNotifier<Either<Failure, Success>> lookupContactNotifier =
ValueNotifier<Either<Failure, Success>>(
const Right(LookupContactsInitial()),
Expand All @@ -46,16 +52,17 @@ class ProfileInfoController extends State<ProfileInfo> {
room?.unsafeGetUserFromMemoryOrFallback(room?.directChatMatrixID ?? '');

void lookupMatchContactAction() {
_lookupMatchContactInteractor
lookupContactNotifierSub = _lookupMatchContactInteractor
.execute(
val: user?.id ?? '',
val: widget.contact?.matrixId ?? user?.id ?? '',
)
.listen(
(event) => lookupContactNotifier.value = event,
);
}

void goToProfileShared() {
if (widget.isDraftInfo) return;
Navigator.of(context).pushNamed(
ProfileInfoRoutes.profileInfoShared,
arguments: widget.roomId,
Expand All @@ -68,6 +75,13 @@ class ProfileInfoController extends State<ProfileInfo> {
super.initState();
}

@override
void dispose() {
lookupContactNotifier.dispose();
lookupContactNotifierSub?.cancel();
super.dispose();
}

@override
Widget build(BuildContext context) {
return ProfileInfoView(this);
Expand Down
8 changes: 3 additions & 5 deletions lib/pages/chat_profile_info/chat_profile_info_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ import 'package:fluffychat/presentation/model/presentation_contact.dart';
class ProfileInfoRoutes {
static const String profileInfo = '/profileInfo';
static const String profileInfoShared = 'profileInfo/shared';

static final GlobalKey<NavigatorState> innerNavigatorProfileKey = GlobalKey(
debugLabel: 'innerNavigatorProfileKey',
);
}

class ProfileInfoNavigator extends StatelessWidget {
final VoidCallback? onBack;
final String? roomId;
final PresentationContact? contact;
final bool isInStack;
final bool isDraftInfo;

const ProfileInfoNavigator({
Key? key,
this.onBack,
this.roomId,
this.contact,
required this.isInStack,
this.isDraftInfo = false,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Navigator(
key: ProfileInfoRoutes.innerNavigatorProfileKey,
initialRoute: ProfileInfoRoutes.profileInfo,
onGenerateRoute: (route) => MaterialPageRoute(
builder: (context) {
Expand All @@ -41,6 +38,7 @@ class ProfileInfoNavigator extends StatelessWidget {
isInStack: isInStack,
roomId: roomId,
contact: contact,
isDraftInfo: isDraftInfo,
);

case ProfileInfoRoutes.profileInfoShared:
Expand Down
83 changes: 46 additions & 37 deletions lib/pages/chat_profile_info/chat_profile_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,27 @@ class ProfileInfoView extends StatelessWidget {
final user = controller.user;
final contact = controller.widget.contact;
return Scaffold(
backgroundColor: LinagoraSysColors.material().onPrimary,
appBar: AppBar(
backgroundColor: LinagoraSysColors.material().onPrimary,
automaticallyImplyLeading: false,
centerTitle: false,
leading: Padding(
padding: ChatProfileInfoStyle.backIconPadding,
child: IconButton(
splashColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onPressed: controller.widget.onBack,
icon: controller.widget.isInStack
? const Icon(Icons.arrow_back)
: const Icon(Icons.close),
),
),
leadingWidth: 40,
title: Text(
L10n.of(context)!.contactInfo,
style: Theme.of(context).textTheme.titleLarge,
title: Row(
children: [
Padding(
padding: ChatProfileInfoStyle.backIconPadding,
child: IconButton(
onPressed: controller.widget.onBack,
icon: controller.widget.isInStack
? const Icon(Icons.arrow_back)
: const Icon(Icons.close),
),
),
Text(
L10n.of(context)!.contactInfo,
style: Theme.of(context).textTheme.titleLarge,
),
],
),
),
body: SingleChildScrollView(
Expand All @@ -71,6 +73,7 @@ class ProfileInfoView extends StatelessWidget {
matrixId: contact.matrixId,
lookupContactNotifier: controller.lookupContactNotifier,
goToProfileShared: controller.goToProfileShared,
isDraftInfo: controller.widget.isDraftInfo,
),
);
}
Expand All @@ -80,6 +83,7 @@ class ProfileInfoView extends StatelessWidget {
matrixId: contact.matrixId,
lookupContactNotifier: controller.lookupContactNotifier,
goToProfileShared: controller.goToProfileShared,
isDraftInfo: controller.widget.isDraftInfo,
);
}
return _Information(
Expand All @@ -88,6 +92,7 @@ class ProfileInfoView extends StatelessWidget {
matrixId: user?.id,
lookupContactNotifier: controller.lookupContactNotifier,
goToProfileShared: controller.goToProfileShared,
isDraftInfo: controller.widget.isDraftInfo,
);
},
),
Expand All @@ -108,13 +113,15 @@ class _Information extends StatelessWidget {
this.matrixId,
required this.lookupContactNotifier,
this.goToProfileShared,
required this.isDraftInfo,
}) : super(key: key);

final Uri? avatarUri;
final String? displayName;
final String? matrixId;
final ValueNotifier<Either<Failure, Success>> lookupContactNotifier;
final Function()? goToProfileShared;
final bool isDraftInfo;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -244,29 +251,31 @@ class _Information extends StatelessWidget {
},
child: const SizedBox.shrink(),
),
InkWell(
splashColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: goToProfileShared,
child: Padding(
padding: ChatProfileInfoStyle.titleSharedMediaAndFilesPadding,
child: Row(
children: [
Text(
L10n.of(context)!.sharedMediaAndFiles,
style: Theme.of(context).textTheme.titleMedium,
),
const Spacer(),
Icon(
Icons.arrow_forward,
size: 18,
color: LinagoraSysColors.material().onSurface,
),
],
if (!isDraftInfo)
InkWell(
splashColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: goToProfileShared,
child: Padding(
padding:
ChatProfileInfoStyle.titleSharedMediaAndFilesPadding,
child: Row(
children: [
Text(
L10n.of(context)!.sharedMediaAndFiles,
style: Theme.of(context).textTheme.titleMedium,
),
const Spacer(),
Icon(
Icons.arrow_forward,
size: 18,
color: LinagoraSysColors.material().onSurface,
),
],
),
),
),
),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/mixins/go_to_direct_chat_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mixin GoToDraftChatMixin {
Matrix.of(context).client.userID) {
Router.neglect(
context,
() => context.push(
() => context.go(
'/$path/draftChat',
extra: {
PresentationContactConstant.receiverId:
Expand Down

0 comments on commit 574c686

Please sign in to comment.