2021-04-15 13:03:14 +02:00
|
|
|
import 'dart:ui';
|
|
|
|
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:scroll_to_index/scroll_to_index.dart';
|
|
|
|
import 'package:swipe_to_action/swipe_to_action.dart';
|
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
2021-11-09 13:08:38 +01:00
|
|
|
import 'package:fluffychat/config/themes.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/chat/chat.dart';
|
2021-11-13 10:20:09 +01:00
|
|
|
import 'package:fluffychat/pages/chat/reactions_picker.dart';
|
|
|
|
import 'package:fluffychat/pages/chat/reply_display.dart';
|
2021-11-13 13:06:36 +01:00
|
|
|
import 'package:fluffychat/pages/chat/seen_by_row.dart';
|
2021-11-13 10:20:09 +01:00
|
|
|
import 'package:fluffychat/pages/chat/tombstone_display.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/user_bottom_sheet/user_bottom_sheet.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_locals.dart';
|
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
|
|
|
import 'package:fluffychat/utils/room_status_extension.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
|
|
|
import 'package:fluffychat/widgets/chat_settings_popup_menu.dart';
|
|
|
|
import 'package:fluffychat/widgets/connection_status_header.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
|
|
|
import 'package:fluffychat/widgets/unread_badge_back_button.dart';
|
2021-07-31 12:31:31 +02:00
|
|
|
import '../../utils/stream_extension.dart';
|
2021-11-13 10:20:09 +01:00
|
|
|
import 'chat_emoji_picker.dart';
|
|
|
|
import 'chat_input_row.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'events/message.dart';
|
2021-07-31 12:31:31 +02:00
|
|
|
|
2021-11-13 13:06:36 +01:00
|
|
|
enum _EventContextAction { info, report }
|
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
class ChatView extends StatelessWidget {
|
2021-04-15 13:03:14 +02:00
|
|
|
final ChatController controller;
|
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
const ChatView(this.controller, {Key key}) : super(key: key);
|
2021-04-15 13:03:14 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-09-19 13:48:23 +02:00
|
|
|
controller.matrix ??= Matrix.of(context);
|
2021-04-15 13:03:14 +02:00
|
|
|
final client = controller.matrix.client;
|
2021-09-19 13:48:23 +02:00
|
|
|
controller.sendingClient ??= client;
|
|
|
|
controller.room = controller.sendingClient.getRoomById(controller.roomId);
|
2021-04-15 13:03:14 +02:00
|
|
|
if (controller.room == null) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(L10n.of(context).oopsSomethingWentWrong),
|
|
|
|
),
|
|
|
|
body: Center(
|
|
|
|
child: Text(L10n.of(context).youAreNoLongerParticipatingInThisChat),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (controller.room.membership == Membership.invite) {
|
|
|
|
showFutureLoadingDialog(
|
|
|
|
context: context, future: () => controller.room.join());
|
|
|
|
}
|
2021-11-13 13:06:36 +01:00
|
|
|
final bottomSheetPadding = FluffyThemes.isColumnMode(context) ? 16.0 : 8.0;
|
2021-04-15 13:03:14 +02:00
|
|
|
|
2021-05-26 20:28:08 +02:00
|
|
|
return VWidgetGuard(
|
2021-08-28 18:31:37 +02:00
|
|
|
onSystemPop: (redirector) async {
|
|
|
|
if (controller.selectedEvents.isNotEmpty) {
|
|
|
|
controller.clearSelectedEvents();
|
|
|
|
redirector.stopRedirection();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: StreamBuilder(
|
|
|
|
stream: controller.room.onUpdate.stream
|
2021-10-14 18:09:30 +02:00
|
|
|
.rateLimit(const Duration(milliseconds: 250)),
|
2021-08-28 18:31:37 +02:00
|
|
|
builder: (context, snapshot) => Scaffold(
|
2021-05-26 20:50:15 +02:00
|
|
|
appBar: AppBar(
|
2021-08-12 21:10:26 +02:00
|
|
|
actionsIconTheme: IconThemeData(
|
|
|
|
color: controller.selectedEvents.isEmpty
|
|
|
|
? null
|
|
|
|
: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
leading: controller.selectMode
|
|
|
|
? IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.close),
|
2021-05-26 20:50:15 +02:00
|
|
|
onPressed: controller.clearSelectedEvents,
|
|
|
|
tooltip: L10n.of(context).close,
|
2021-08-12 21:10:26 +02:00
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2021-05-26 20:50:15 +02:00
|
|
|
)
|
|
|
|
: UnreadBadgeBackButton(roomId: controller.roomId),
|
|
|
|
titleSpacing: 0,
|
|
|
|
title: controller.selectedEvents.isEmpty
|
2021-08-28 18:31:37 +02:00
|
|
|
? ListTile(
|
|
|
|
leading: Avatar(
|
|
|
|
controller.room.avatar, controller.room.displayname),
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
onTap: controller.room.isDirectChat
|
|
|
|
? () => showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (c) => UserBottomSheet(
|
|
|
|
user: controller.room.getUserByMXIDSync(
|
|
|
|
controller.room.directChatMatrixID),
|
|
|
|
outerContext: context,
|
|
|
|
onMention: () => controller
|
|
|
|
.sendController.text +=
|
|
|
|
'${controller.room.getUserByMXIDSync(controller.room.directChatMatrixID).mention} ',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: () => VRouter.of(context).toSegments(
|
|
|
|
['rooms', controller.room.id, 'details']),
|
|
|
|
title: Text(
|
|
|
|
controller.room.getLocalizedDisplayname(
|
|
|
|
MatrixLocals(L10n.of(context))),
|
|
|
|
maxLines: 1),
|
|
|
|
subtitle: controller.room
|
|
|
|
.getLocalizedTypingText(context)
|
|
|
|
.isEmpty
|
|
|
|
? StreamBuilder<Object>(
|
|
|
|
stream: Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.onPresence
|
|
|
|
.stream
|
|
|
|
.where((p) =>
|
|
|
|
p.senderId ==
|
|
|
|
controller.room.directChatMatrixID)
|
2021-10-14 18:09:30 +02:00
|
|
|
.rateLimit(const Duration(seconds: 1)),
|
2021-08-28 18:31:37 +02:00
|
|
|
builder: (context, snapshot) => Text(
|
|
|
|
controller.room.getLocalizedStatus(context),
|
|
|
|
maxLines: 1,
|
|
|
|
//overflow: TextOverflow.ellipsis,
|
|
|
|
))
|
|
|
|
: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(Icons.edit_outlined,
|
|
|
|
color:
|
|
|
|
Theme.of(context).colorScheme.secondary,
|
|
|
|
size: 13),
|
2021-10-14 18:09:30 +02:00
|
|
|
const SizedBox(width: 4),
|
2021-08-28 18:31:37 +02:00
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
controller.room
|
|
|
|
.getLocalizedTypingText(context),
|
|
|
|
maxLines: 1,
|
|
|
|
style: TextStyle(
|
|
|
|
color:
|
|
|
|
Theme.of(context).colorScheme.secondary,
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-08-28 18:31:37 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
2021-08-12 21:10:26 +02:00
|
|
|
: Text(controller.selectedEvents.length.toString()),
|
2021-05-26 20:50:15 +02:00
|
|
|
actions: controller.selectMode
|
|
|
|
? <Widget>[
|
2021-09-19 13:48:23 +02:00
|
|
|
if (controller.canEditSelectedEvents)
|
2021-05-26 20:50:15 +02:00
|
|
|
IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.edit_outlined),
|
2021-05-26 20:50:15 +02:00
|
|
|
tooltip: L10n.of(context).edit,
|
|
|
|
onPressed: controller.editSelectedEventAction,
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-08-12 21:10:26 +02:00
|
|
|
IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.copy_outlined),
|
2021-08-12 21:10:26 +02:00
|
|
|
tooltip: L10n.of(context).copy,
|
|
|
|
onPressed: controller.copyEventsAction,
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
2021-08-12 21:10:26 +02:00
|
|
|
if (controller.canRedactSelectedEvents)
|
|
|
|
IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.delete_outlined),
|
2021-08-12 21:10:26 +02:00
|
|
|
tooltip: L10n.of(context).redactMessage,
|
|
|
|
onPressed: controller.redactEventsAction,
|
|
|
|
),
|
2021-11-13 13:06:36 +01:00
|
|
|
if (controller.selectedEvents.length == 1)
|
|
|
|
PopupMenuButton<_EventContextAction>(
|
|
|
|
onSelected: (action) {
|
|
|
|
switch (action) {
|
|
|
|
case _EventContextAction.info:
|
|
|
|
controller.showEventInfo();
|
|
|
|
controller.clearSelectedEvents();
|
|
|
|
break;
|
|
|
|
case _EventContextAction.report:
|
|
|
|
controller.reportEventAction();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
itemBuilder: (context) => [
|
|
|
|
PopupMenuItem(
|
|
|
|
value: _EventContextAction.info,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.info_outlined),
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
Text(L10n.of(context).messageInfo),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: _EventContextAction.report,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.report_outlined),
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
Text(L10n.of(context).reportMessage),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
]
|
|
|
|
: <Widget>[
|
|
|
|
if (controller.room.canSendDefaultStates)
|
|
|
|
IconButton(
|
|
|
|
tooltip: L10n.of(context).videoCall,
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.video_call_outlined),
|
2021-05-26 20:50:15 +02:00
|
|
|
onPressed: controller.startCallAction,
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
ChatSettingsPopupMenu(
|
|
|
|
controller.room, !controller.room.isDirectChat),
|
2021-04-15 13:03:14 +02:00
|
|
|
],
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
floatingActionButton: controller.showScrollDownButton
|
|
|
|
? Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 56.0),
|
|
|
|
child: FloatingActionButton(
|
|
|
|
onPressed: controller.scrollDown,
|
|
|
|
foregroundColor:
|
|
|
|
Theme.of(context).textTheme.bodyText2.color,
|
|
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
mini: true,
|
|
|
|
child: Icon(Icons.arrow_downward_outlined,
|
|
|
|
color: Theme.of(context).primaryColor),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
)
|
|
|
|
: null,
|
2021-11-13 19:22:11 +01:00
|
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
2021-05-26 20:50:15 +02:00
|
|
|
body: Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
if (Matrix.of(context).wallpaper != null)
|
|
|
|
Image.file(
|
|
|
|
Matrix.of(context).wallpaper,
|
|
|
|
width: double.infinity,
|
|
|
|
height: double.infinity,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
2021-11-13 13:06:36 +01:00
|
|
|
Column(
|
|
|
|
children: <Widget>[
|
|
|
|
TombstoneDisplay(controller),
|
|
|
|
Expanded(
|
|
|
|
child: FutureBuilder<bool>(
|
|
|
|
future: controller.getTimeline(),
|
|
|
|
builder: (BuildContext context, snapshot) {
|
|
|
|
if (controller.timeline == null) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator.adaptive(
|
|
|
|
strokeWidth: 2),
|
2021-08-28 18:31:37 +02:00
|
|
|
);
|
2021-11-13 13:06:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// create a map of eventId --> index to greatly improve performance of
|
|
|
|
// ListView's findChildIndexCallback
|
|
|
|
final thisEventsKeyMap = <String, int>{};
|
|
|
|
for (var i = 0;
|
|
|
|
i < controller.filteredEvents.length;
|
|
|
|
i++) {
|
|
|
|
thisEventsKeyMap[
|
|
|
|
controller.filteredEvents[i].eventId] = i;
|
|
|
|
}
|
|
|
|
return ListView.custom(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 16,
|
|
|
|
bottom: 4,
|
|
|
|
),
|
|
|
|
reverse: true,
|
|
|
|
controller: controller.scrollController,
|
|
|
|
keyboardDismissBehavior: PlatformInfos.isIOS
|
|
|
|
? ScrollViewKeyboardDismissBehavior.onDrag
|
|
|
|
: ScrollViewKeyboardDismissBehavior.manual,
|
|
|
|
childrenDelegate: SliverChildBuilderDelegate(
|
|
|
|
(BuildContext context, int i) {
|
|
|
|
return i == controller.filteredEvents.length + 1
|
|
|
|
? controller.timeline.isRequestingHistory
|
|
|
|
? const Center(
|
|
|
|
child: CircularProgressIndicator
|
|
|
|
.adaptive(strokeWidth: 2),
|
|
|
|
)
|
|
|
|
: controller.canLoadMore
|
|
|
|
? Center(
|
|
|
|
child: OutlinedButton(
|
|
|
|
style: OutlinedButton.styleFrom(
|
|
|
|
backgroundColor: Theme.of(
|
|
|
|
context)
|
|
|
|
.scaffoldBackgroundColor,
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
2021-11-13 13:06:36 +01:00
|
|
|
onPressed:
|
|
|
|
controller.requestHistory,
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context).loadMore),
|
2021-08-28 18:31:37 +02:00
|
|
|
),
|
2021-11-13 13:06:36 +01:00
|
|
|
)
|
|
|
|
: Container()
|
|
|
|
: i == 0
|
|
|
|
? SeenByRow(controller)
|
|
|
|
: AutoScrollTag(
|
|
|
|
key: ValueKey(controller
|
|
|
|
.filteredEvents[i - 1].eventId),
|
|
|
|
index: i - 1,
|
|
|
|
controller:
|
|
|
|
controller.scrollController,
|
|
|
|
child: Swipeable(
|
2021-05-26 20:50:15 +02:00
|
|
|
key: ValueKey(controller
|
|
|
|
.filteredEvents[i - 1].eventId),
|
2021-11-13 13:06:36 +01:00
|
|
|
background: const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: 12.0),
|
|
|
|
child: Center(
|
|
|
|
child:
|
|
|
|
Icon(Icons.reply_outlined),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
|
|
|
),
|
2021-11-13 13:06:36 +01:00
|
|
|
direction:
|
|
|
|
SwipeDirection.endToStart,
|
|
|
|
onSwipe: (direction) =>
|
|
|
|
controller.replyAction(
|
|
|
|
replyTo: controller
|
|
|
|
.filteredEvents[i - 1]),
|
|
|
|
child: Message(
|
|
|
|
controller
|
|
|
|
.filteredEvents[i - 1],
|
|
|
|
onInfoTab:
|
|
|
|
controller.showEventInfo,
|
|
|
|
onAvatarTab: (Event event) =>
|
|
|
|
showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (c) =>
|
|
|
|
UserBottomSheet(
|
|
|
|
user: event.sender,
|
|
|
|
outerContext: context,
|
|
|
|
onMention: () => controller
|
|
|
|
.sendController
|
|
|
|
.text +=
|
|
|
|
'${event.sender.mention} ',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
unfold: controller.unfold,
|
|
|
|
onSelect:
|
|
|
|
controller.onSelectMessage,
|
|
|
|
scrollToEventId: (String eventId) =>
|
|
|
|
controller.scrollToEventId(
|
|
|
|
eventId),
|
|
|
|
longPressSelect: controller
|
|
|
|
.selectedEvents.isEmpty,
|
|
|
|
selected: controller
|
|
|
|
.selectedEvents
|
|
|
|
.contains(controller
|
|
|
|
.filteredEvents[i - 1]),
|
|
|
|
timeline: controller.timeline,
|
|
|
|
nextEvent: i <
|
|
|
|
controller
|
|
|
|
.filteredEvents
|
|
|
|
.length
|
|
|
|
? controller.filteredEvents[i]
|
|
|
|
: null),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
childCount: controller.filteredEvents.length + 2,
|
|
|
|
findChildIndexCallback: (key) => controller
|
|
|
|
.findChildIndexCallback(key, thisEventsKeyMap),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
2021-11-13 13:06:36 +01:00
|
|
|
),
|
|
|
|
if (controller.room.canSendDefaultMessages &&
|
|
|
|
controller.room.membership == Membership.join)
|
2021-11-13 19:02:26 +01:00
|
|
|
Container(
|
2021-11-13 13:06:36 +01:00
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: bottomSheetPadding,
|
|
|
|
left: bottomSheetPadding,
|
|
|
|
right: bottomSheetPadding,
|
2021-11-06 11:18:32 +01:00
|
|
|
),
|
2021-11-13 19:02:26 +01:00
|
|
|
constraints: const BoxConstraints(
|
|
|
|
maxWidth: FluffyThemes.columnWidth * 2.5),
|
|
|
|
alignment: Alignment.center,
|
2021-11-13 13:06:36 +01:00
|
|
|
child: Material(
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
bottomLeft: Radius.circular(AppConfig.borderRadius),
|
|
|
|
bottomRight: Radius.circular(AppConfig.borderRadius),
|
|
|
|
),
|
|
|
|
elevation: 6,
|
|
|
|
shadowColor: Theme.of(context)
|
|
|
|
.secondaryHeaderColor
|
|
|
|
.withAlpha(100),
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
color: Theme.of(context).backgroundColor,
|
|
|
|
child: SafeArea(
|
2021-11-13 10:20:09 +01:00
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
const ConnectionStatusHeader(),
|
|
|
|
ReactionsPicker(controller),
|
|
|
|
ReplyDisplay(controller),
|
|
|
|
ChatInputRow(controller),
|
|
|
|
ChatEmojiPicker(controller),
|
|
|
|
],
|
2021-11-06 11:18:32 +01:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
),
|
2021-11-13 13:06:36 +01:00
|
|
|
),
|
|
|
|
],
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
],
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-08-28 18:31:37 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2021-04-15 13:03:14 +02:00
|
|
|
}
|
|
|
|
}
|