2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2021-11-28 11:43:36 +01:00
|
|
|
import 'package:desktop_drop/desktop_drop.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
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: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-14 09:36:35 +01:00
|
|
|
import 'package:fluffychat/pages/chat/chat_app_bar_title.dart';
|
2022-06-28 16:51:29 +02:00
|
|
|
import 'package:fluffychat/pages/chat/chat_event_list.dart';
|
2022-02-14 13:49:46 +01:00
|
|
|
import 'package:fluffychat/pages/chat/encryption_button.dart';
|
2022-02-14 18:44:37 +01:00
|
|
|
import 'package:fluffychat/pages/chat/pinned_events.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';
|
|
|
|
import 'package:fluffychat/pages/chat/tombstone_display.dart';
|
2021-11-23 12:29:11 +01:00
|
|
|
import 'package:fluffychat/utils/sentry_controller.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
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-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;
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const ChatView(this.controller, {Key? key}) : super(key: key);
|
2021-04-15 13:03:14 +02:00
|
|
|
|
2022-02-02 14:31:15 +01:00
|
|
|
List<Widget> _appBarActions(BuildContext context) {
|
|
|
|
if (controller.selectMode) {
|
|
|
|
return [
|
|
|
|
if (controller.canEditSelectedEvents)
|
2021-11-14 09:36:35 +01:00
|
|
|
IconButton(
|
2022-02-02 14:31:15 +01:00
|
|
|
icon: const Icon(Icons.edit_outlined),
|
|
|
|
tooltip: L10n.of(context)!.edit,
|
|
|
|
onPressed: controller.editSelectedEventAction,
|
2021-11-14 09:36:35 +01:00
|
|
|
),
|
2022-02-02 14:31:15 +01:00
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.copy_outlined),
|
|
|
|
tooltip: L10n.of(context)!.copy,
|
|
|
|
onPressed: controller.copyEventsAction,
|
|
|
|
),
|
|
|
|
if (controller.canSaveSelectedEvent)
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.adaptive.share),
|
|
|
|
tooltip: L10n.of(context)!.share,
|
|
|
|
onPressed: controller.saveSelectedEvent,
|
|
|
|
),
|
|
|
|
if (controller.canRedactSelectedEvents)
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.delete_outlined),
|
|
|
|
tooltip: L10n.of(context)!.redactMessage,
|
|
|
|
onPressed: controller.redactEventsAction,
|
|
|
|
),
|
2022-02-14 18:44:37 +01:00
|
|
|
IconButton(
|
2022-02-15 12:47:19 +01:00
|
|
|
icon: const Icon(Icons.push_pin_outlined),
|
2022-02-14 18:44:37 +01:00
|
|
|
onPressed: controller.pinEvent,
|
|
|
|
tooltip: L10n.of(context)!.pinMessage,
|
|
|
|
),
|
2022-02-02 14:31:15 +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),
|
|
|
|
],
|
2021-11-14 09:36:35 +01:00
|
|
|
),
|
2022-02-02 14:31:15 +01:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: _EventContextAction.report,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
const Icon(
|
|
|
|
Icons.shield_outlined,
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
Text(L10n.of(context)!.reportMessage),
|
|
|
|
],
|
2021-11-14 09:36:35 +01:00
|
|
|
),
|
2022-02-02 14:31:15 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
return [
|
2022-02-19 11:58:21 +01:00
|
|
|
if (Matrix.of(context).voipPlugin != null &&
|
2022-02-17 21:38:37 +01:00
|
|
|
controller.room!.isDirectChat)
|
2022-02-17 15:07:29 +01:00
|
|
|
IconButton(
|
|
|
|
onPressed: controller.onPhoneButtonTap,
|
|
|
|
icon: const Icon(Icons.call_outlined),
|
|
|
|
tooltip: L10n.of(context)!.placeCall,
|
|
|
|
),
|
2022-02-14 13:49:46 +01:00
|
|
|
EncryptionButton(controller.room!),
|
2022-02-02 14:31:15 +01:00
|
|
|
ChatSettingsPopupMenu(controller.room!, !controller.room!.isDirectChat),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2021-11-14 09:36:35 +01:00
|
|
|
|
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);
|
2022-01-29 12:35:03 +01:00
|
|
|
final client = controller.matrix!.client;
|
2021-09-19 13:48:23 +02:00
|
|
|
controller.sendingClient ??= client;
|
2022-01-29 12:35:03 +01:00
|
|
|
controller.room = controller.sendingClient!.getRoomById(controller.roomId!);
|
2021-04-15 13:03:14 +02:00
|
|
|
if (controller.room == null) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-01-29 12:35:03 +01:00
|
|
|
title: Text(L10n.of(context)!.oopsSomethingWentWrong),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
|
|
|
body: Center(
|
2022-01-29 12:35:03 +01:00
|
|
|
child: Text(L10n.of(context)!.youAreNoLongerParticipatingInThisChat),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
if (controller.room!.membership == Membership.invite) {
|
2021-04-15 13:03:14 +02:00
|
|
|
showFutureLoadingDialog(
|
2022-01-29 12:35:03 +01:00
|
|
|
context: context, future: () => controller.room!.join());
|
2021-04-15 13:03:14 +02:00
|
|
|
}
|
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();
|
2022-03-03 07:52:31 +01:00
|
|
|
} else if (controller.showEmojiPicker) {
|
|
|
|
controller.emojiPickerAction();
|
|
|
|
redirector.stopRedirection();
|
2021-08-28 18:31:37 +02:00
|
|
|
}
|
|
|
|
},
|
2022-02-17 21:12:47 +01:00
|
|
|
child: GestureDetector(
|
|
|
|
onTapDown: controller.setReadMarker,
|
2022-03-13 10:55:52 +01:00
|
|
|
behavior: HitTestBehavior.opaque,
|
2022-02-17 21:12:47 +01:00
|
|
|
child: StreamBuilder(
|
|
|
|
stream: controller.room!.onUpdate.stream
|
|
|
|
.rateLimit(const Duration(milliseconds: 250)),
|
|
|
|
builder: (context, snapshot) => FutureBuilder<bool>(
|
|
|
|
future: controller.getTimeline(),
|
|
|
|
builder: (BuildContext context, snapshot) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-07-09 09:01:22 +02:00
|
|
|
elevation: 2,
|
2022-02-17 21:12:47 +01:00
|
|
|
actionsIconTheme: IconThemeData(
|
|
|
|
color: controller.selectedEvents.isEmpty
|
|
|
|
? null
|
|
|
|
: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
|
|
|
leading: controller.selectMode
|
|
|
|
? IconButton(
|
|
|
|
icon: const Icon(Icons.close),
|
|
|
|
onPressed: controller.clearSelectedEvents,
|
|
|
|
tooltip: L10n.of(context)!.close,
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
)
|
|
|
|
: UnreadBadgeBackButton(roomId: controller.roomId!),
|
|
|
|
titleSpacing: 0,
|
|
|
|
title: ChatAppBarTitle(controller),
|
|
|
|
actions: _appBarActions(context),
|
2022-02-02 14:31:15 +01:00
|
|
|
),
|
2022-02-17 21:12:47 +01:00
|
|
|
floatingActionButton: controller.showScrollDownButton &&
|
|
|
|
controller.selectedEvents.isEmpty
|
|
|
|
? Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 56.0),
|
|
|
|
child: FloatingActionButton(
|
|
|
|
onPressed: controller.scrollDown,
|
|
|
|
mini: true,
|
2022-05-18 08:54:50 +02:00
|
|
|
child: const Icon(Icons.arrow_downward_outlined),
|
2022-02-17 21:12:47 +01:00
|
|
|
),
|
2022-02-02 14:31:15 +01:00
|
|
|
)
|
2022-02-17 21:12:47 +01:00
|
|
|
: null,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
|
|
|
body: DropTarget(
|
|
|
|
onDragDone: controller.onDragDone,
|
|
|
|
onDragEntered: controller.onDragEntered,
|
|
|
|
onDragExited: controller.onDragExited,
|
|
|
|
child: Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
if (Matrix.of(context).wallpaper != null)
|
|
|
|
Image.file(
|
|
|
|
Matrix.of(context).wallpaper!,
|
|
|
|
width: double.infinity,
|
|
|
|
height: double.infinity,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
SafeArea(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
TombstoneDisplay(controller),
|
|
|
|
PinnedEvents(controller),
|
|
|
|
Expanded(
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: controller.clearSingleSelectedEvent,
|
|
|
|
child: Builder(
|
|
|
|
builder: (context) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
SentryController.captureException(
|
|
|
|
snapshot.error,
|
|
|
|
StackTrace.current,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (controller.timeline == null) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator
|
|
|
|
.adaptive(strokeWidth: 2),
|
|
|
|
);
|
|
|
|
}
|
2021-11-13 13:06:36 +01:00
|
|
|
|
2022-06-28 16:51:29 +02:00
|
|
|
return ChatEventList(
|
|
|
|
controller: controller,
|
2022-02-17 21:12:47 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
if (controller.room!.canSendDefaultMessages &&
|
|
|
|
controller.room!.membership == Membership.join)
|
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
bottom: bottomSheetPadding,
|
|
|
|
left: bottomSheetPadding,
|
|
|
|
right: bottomSheetPadding,
|
2022-02-02 14:31:15 +01:00
|
|
|
),
|
2022-02-17 21:12:47 +01:00
|
|
|
constraints: const BoxConstraints(
|
|
|
|
maxWidth: FluffyThemes.columnWidth * 2.5),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Material(
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
bottomLeft:
|
|
|
|
Radius.circular(AppConfig.borderRadius),
|
|
|
|
bottomRight:
|
|
|
|
Radius.circular(AppConfig.borderRadius),
|
|
|
|
),
|
2022-07-12 21:37:04 +02:00
|
|
|
elevation: 4,
|
2022-02-17 21:12:47 +01:00
|
|
|
shadowColor: Theme.of(context)
|
2022-07-12 21:37:04 +02:00
|
|
|
.colorScheme
|
|
|
|
.onBackground
|
|
|
|
.withAlpha(64),
|
2022-02-17 21:12:47 +01:00
|
|
|
clipBehavior: Clip.hardEdge,
|
2022-07-07 18:50:13 +02:00
|
|
|
color: Theme.of(context).brightness ==
|
|
|
|
Brightness.light
|
|
|
|
? Colors.white
|
|
|
|
: Colors.black,
|
2022-02-17 21:12:47 +01:00
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
const ConnectionStatusHeader(),
|
|
|
|
ReactionsPicker(controller),
|
|
|
|
ReplyDisplay(controller),
|
|
|
|
ChatInputRow(controller),
|
|
|
|
ChatEmojiPicker(controller),
|
|
|
|
],
|
|
|
|
),
|
2022-02-02 14:31:15 +01:00
|
|
|
),
|
|
|
|
),
|
2022-02-17 21:12:47 +01:00
|
|
|
],
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
2022-02-02 14:31:15 +01:00
|
|
|
),
|
2022-02-17 21:12:47 +01:00
|
|
|
if (controller.dragging)
|
|
|
|
Container(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.scaffoldBackgroundColor
|
|
|
|
.withOpacity(0.9),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: const Icon(
|
|
|
|
Icons.upload_outlined,
|
|
|
|
size: 100,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-11-27 10:33:21 +01:00
|
|
|
),
|
2022-02-17 21:12:47 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2021-08-28 18:31:37 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2021-04-15 13:03:14 +02:00
|
|
|
}
|
|
|
|
}
|