Skip to content

Commit

Permalink
feat: enhance chat app bar from draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE authored and hoangdat committed Sep 26, 2023
1 parent bdb0d85 commit c5de42f
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 14 deletions.
9 changes: 9 additions & 0 deletions lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ abstract class AppRoutes {
final extra = state.extra as ChatRouterInputArgument;
switch (extra.type) {
case ChatRouterInputArgumentType.draft:
if (extra.data is String?) {
return NoTransitionPage(
child: Chat(
roomId: state.pathParameters['roomid']!,
key: Key(state.pathParameters['roomid']!),
roomName: extra.data as String?,
),
);
}
return NoTransitionPage(
child: Chat(
roomId: state.pathParameters['roomid']!,
Expand Down
8 changes: 6 additions & 2 deletions lib/domain/app_state/room/create_new_group_chat_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ class CreateNewGroupChatLoading extends Success {

class CreateNewGroupChatSuccess extends Success {
final String roomId;
final String? groupName;

const CreateNewGroupChatSuccess({required this.roomId});
const CreateNewGroupChatSuccess({
required this.roomId,
this.groupName,
});

@override
List<Object?> get props => [roomId];
List<Object?> get props => [roomId, groupName];
}

class CreateNewGroupChatFailed extends Failure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class CreateNewGroupChatInteractor {
);

if (roomId.isNotEmpty) {
yield Right(CreateNewGroupChatSuccess(roomId: roomId));
yield Right(
CreateNewGroupChatSuccess(
roomId: roomId,
groupName: createNewGroupChatRequest.groupName,
),
);
} else {
yield Left(
CreateNewGroupChatFailed(
Expand Down
4 changes: 4 additions & 0 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ class Chat extends StatefulWidget {
final String roomId;
final Widget? sideView;
final MatrixFile? shareFile;
final String? roomName;

const Chat({
Key? key,
this.sideView,
required this.roomId,
this.shareFile,
this.roomName,
}) : super(key: key);

@override
Expand Down Expand Up @@ -109,6 +111,8 @@ class ChatController extends State<Chat>

MatrixFile? get shareFile => widget.shareFile;

String? get roomName => widget.roomName;

String? get roomId => widget.roomId;

bool get isEmptyChat =>
Expand Down
17 changes: 10 additions & 7 deletions lib/pages/chat/chat_app_bar_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class ChatAppBarTitle extends StatelessWidget {
final TextEditingController sendController;
final Stream<ConnectivityResult> getStreamInstance;
final VoidCallback onPushDetails;
final String? roomName;

const ChatAppBarTitle({
Key? key,
required this.actions,
this.room,
this.roomName,
required this.selectedEvents,
required this.isArchived,
required this.sendController,
Expand Down Expand Up @@ -73,9 +75,10 @@ class ChatAppBarTitle extends StatelessWidget {
child: Avatar(
fontSize: ChatAppBarTitleStyle.avatarFontSize,
mxContent: room!.avatar,
name: room!.getLocalizedDisplayname(
MatrixLocals(L10n.of(context)!),
),
name: roomName ??
room!.getLocalizedDisplayname(
MatrixLocals(L10n.of(context)!),
),
size: ChatAppBarTitleStyle.avatarSize(context),
),
),
Expand All @@ -87,9 +90,10 @@ class ChatAppBarTitle extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
room!.getLocalizedDisplayname(
MatrixLocals(L10n.of(context)!),
),
roomName ??
room!.getLocalizedDisplayname(
MatrixLocals(L10n.of(context)!),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: ChatAppBarTitleStyle.appBarTitleStyle(context),
Expand All @@ -109,7 +113,6 @@ class ChatAppBarTitle extends StatelessWidget {
) {
final TextStyle? statusTextStyle =
ChatAppBarTitleStyle.statusTextStyle(context);

return StreamBuilder<ConnectivityResult>(
stream: getStreamInstance,
builder: (context, snapshot) {
Expand Down
1 change: 1 addition & 0 deletions lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class ChatView extends StatelessWidget {
.getStreamInstance(),
actions: _appBarActions(context),
onPushDetails: controller.onPushDetails,
roomName: controller.roomName,
);
},
),
Expand Down
2 changes: 2 additions & 0 deletions lib/pages/chat_draft/draft_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class DraftChatController extends State<DraftChat>
'/rooms/${room.id}/',
extra: ChatRouterInputArgument(
type: ChatRouterInputArgumentType.draft,
data: presentationContact?.displayName ??
presentationContact?.matrixId,
),
);
}
Expand Down
13 changes: 10 additions & 3 deletions lib/pages/new_group/new_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:fluffychat/pages/new_group/new_group_chat_info.dart';
import 'package:fluffychat/pages/new_group/new_group_info_controller.dart';
import 'package:fluffychat/presentation/mixins/common_media_picker_mixin.dart';
import 'package:fluffychat/presentation/mixins/single_image_picker_mixin.dart';
import 'package:fluffychat/presentation/model/chat/chat_router_input_argument.dart';
import 'package:fluffychat/presentation/model/presentation_contact.dart';
import 'package:fluffychat/utils/dialog/warning_dialog.dart';
import 'package:fluffychat/utils/platform_infos.dart';
Expand Down Expand Up @@ -273,7 +274,7 @@ class NewGroupController extends ContactsSelectionController<NewGroup>
'NewGroupController::_handleCreateNewGroupChatChatOnData() - success: $success',
);
if (success is CreateNewGroupChatSuccess) {
_goToRoom(context, success.roomId);
_goToRoom(success);
}
},
);
Expand All @@ -289,8 +290,14 @@ class NewGroupController extends ContactsSelectionController<NewGroup>
);
}

void _goToRoom(BuildContext context, String roomId) {
context.go("/rooms/$roomId");
void _goToRoom(CreateNewGroupChatSuccess success) {
context.go(
"/rooms/${success.roomId}",
extra: ChatRouterInputArgument(
type: ChatRouterInputArgumentType.draft,
data: success.groupName,
),
);
}

void _getImageOnWeb(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ packages:
description:
path: "."
ref: twake-supported
resolved-ref: f81a5a805f801902046c4c9442b0d960e4976e54
resolved-ref: a3d6992e4cf420f96fd855efc710af69e3562859
url: "[email protected]:linagora/matrix-dart-sdk.git"
source: git
version: "0.22.2"
Expand Down

0 comments on commit c5de42f

Please sign in to comment.