Skip to content

Commit

Permalink
fixup! fixup! fixup! TW-1456: optionnal duration param added to snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-Z committed Mar 28, 2024
1 parent f87a045 commit daab3b3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/pages/chat_details/participant_list_item/participant_list_item_style.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_body.dart';
import 'package:fluffychat/pages/profile_info/profile_info_page.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
import 'package:fluffychat/widgets/avatar/avatar.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -148,7 +149,9 @@ class ParticipantListItem extends StatelessWidget {
Expanded(
child: TextButton.icon(
onPressed: () {
bottomSheetContext.pop();
if (PlatformInfos.isMobile) {
bottomSheetContext.pop();
}
Navigator.of(context).push(
CupertinoPageRoute(
builder: (ctx) => ProfileInfoPage(
Expand Down Expand Up @@ -210,7 +213,6 @@ class ParticipantListItem extends StatelessWidget {
),
ProfileInfoBody(
user: member,
parentContext: context,
onNewChatOpen: () {
dialogContext.pop();
},
Expand Down
55 changes: 47 additions & 8 deletions lib/pages/profile_info/profile_info_body/profile_info_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import 'package:fluffychat/domain/app_state/contact/lookup_match_contact_state.d
import 'package:fluffychat/domain/usecase/contacts/lookup_match_contact_interactor.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_body_view.dart';
import 'package:fluffychat/presentation/mixins/go_to_direct_chat_mixin.dart';
import 'package:fluffychat/presentation/model/presentation_contact_constant.dart';
import 'package:fluffychat/presentation/model/search/presentation_search.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
Expand All @@ -19,23 +21,19 @@ import 'package:matrix/matrix.dart';
class ProfileInfoBody extends StatefulWidget {
const ProfileInfoBody({
required this.user,
required this.parentContext,
this.onNewChatOpen,
Key? key,
}) : super(key: key);

final User? user;

final BuildContext parentContext;

final void Function()? onNewChatOpen;

@override
State<ProfileInfoBody> createState() => ProfileInfoBodyController();
}

class ProfileInfoBodyController extends State<ProfileInfoBody>
with GoToDraftChatMixin {
class ProfileInfoBodyController extends State<ProfileInfoBody> {
final _lookupMatchContactInteractor =
getIt.get<LookupMatchContactInteractor>();

Expand All @@ -48,8 +46,6 @@ class ProfileInfoBodyController extends State<ProfileInfoBody>

User? get user => widget.user;

BuildContext get parentContext => widget.parentContext;

bool get isOwnProfile => user?.id == user?.room.client.userID;

void lookupMatchContactAction() {
Expand All @@ -66,8 +62,13 @@ class ProfileInfoBodyController extends State<ProfileInfoBody>
void openNewChat() {
if (user == null) return;
final roomId = Matrix.of(context).client.getDirectChatFromUserId(user!.id);

if (roomId == null) {
goToDraftChat(
if (!PlatformInfos.isMobile && widget.onNewChatOpen != null) {
widget.onNewChatOpen!();
}

_goToDraftChat(
context: context,
path: "rooms",
contactPresentationSearch: user!.toContactPresentationSearch(),
Expand All @@ -84,6 +85,44 @@ class ProfileInfoBodyController extends State<ProfileInfoBody>
}
}

void _goToDraftChat({
required BuildContext context,
required String path,
required ContactPresentationSearch contactPresentationSearch,
}) {
if (contactPresentationSearch.matrixId !=
Matrix.of(context).client.userID) {
Router.neglect(
context,
() => PlatformInfos.isMobile
? context.push(
'/$path/draftChat',
extra: {
PresentationContactConstant.receiverId:
contactPresentationSearch.matrixId ?? '',
PresentationContactConstant.email:
contactPresentationSearch.email ?? '',
PresentationContactConstant.displayName:
contactPresentationSearch.displayName ?? '',
PresentationContactConstant.status: '',
},
)
: context.go(
'/$path/draftChat',
extra: {
PresentationContactConstant.receiverId:
contactPresentationSearch.matrixId ?? '',
PresentationContactConstant.email:
contactPresentationSearch.email ?? '',
PresentationContactConstant.displayName:
contactPresentationSearch.displayName ?? '',
PresentationContactConstant.status: '',
},
),
);
}
}

@override
void initState() {
lookupMatchContactAction();
Expand Down
1 change: 0 additions & 1 deletion lib/pages/profile_info/profile_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class ProfileInfoView extends StatelessWidget {
),
body: ProfileInfoBody(
user: controller.user,
parentContext: context,
),
);
}
Expand Down

0 comments on commit daab3b3

Please sign in to comment.