2021-04-15 13:03:14 +02:00
|
|
|
import 'dart:ui';
|
|
|
|
|
2021-05-20 13:46:52 +02:00
|
|
|
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-05-22 08:57:49 +02:00
|
|
|
import 'package:fluffychat/pages/chat.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';
|
|
|
|
import 'package:fluffychat/widgets/input_bar.dart';
|
|
|
|
import 'package:fluffychat/widgets/unread_badge_back_button.dart';
|
2021-04-15 13:03:14 +02:00
|
|
|
|
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/encryption_button.dart';
|
2021-05-22 09:24:39 +02:00
|
|
|
import 'package:fluffychat/widgets/event_content/message.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-05-22 09:24:39 +02:00
|
|
|
import 'package:fluffychat/widgets/event_content/reply_content.dart';
|
2021-05-22 08:57:49 +02:00
|
|
|
import 'package:fluffychat/pages/user_bottom_sheet.dart';
|
2021-04-15 13:03:14 +02:00
|
|
|
import 'package:fluffychat/config/app_emojis.dart';
|
2021-05-22 09:24:39 +02:00
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_locals.dart';
|
2021-04-15 13:03:14 +02:00
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
|
|
|
import 'package:fluffychat/utils/room_status_extension.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:scroll_to_index/scroll_to_index.dart';
|
|
|
|
import 'package:swipe_to_action/swipe_to_action.dart';
|
2021-05-23 13:11:55 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
2021-04-15 13:03:14 +02:00
|
|
|
|
2021-07-31 12:31:31 +02:00
|
|
|
import '../../utils/stream_extension.dart';
|
|
|
|
|
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) {
|
|
|
|
controller.matrix = Matrix.of(context);
|
|
|
|
final client = controller.matrix.client;
|
2021-05-23 13:11:55 +02:00
|
|
|
controller.room ??= client.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-05-26 20:28:08 +02:00
|
|
|
return VWidgetGuard(
|
2021-05-26 20:50:15 +02:00
|
|
|
onSystemPop: (redirector) async {
|
|
|
|
if (controller.selectedEvents.isNotEmpty) {
|
|
|
|
controller.clearSelectedEvents();
|
|
|
|
redirector.stopRedirection();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: controller.selectMode
|
|
|
|
? IconButton(
|
|
|
|
icon: Icon(Icons.close),
|
|
|
|
onPressed: controller.clearSelectedEvents,
|
|
|
|
tooltip: L10n.of(context).close,
|
|
|
|
)
|
|
|
|
: UnreadBadgeBackButton(roomId: controller.roomId),
|
|
|
|
titleSpacing: 0,
|
|
|
|
title: controller.selectedEvents.isEmpty
|
|
|
|
? StreamBuilder(
|
2021-07-31 12:31:31 +02:00
|
|
|
stream: controller.room.onUpdate.stream
|
|
|
|
.rateLimit(Duration(milliseconds: 250)),
|
2021-05-26 20:50:15 +02:00
|
|
|
builder: (context, snapshot) => 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 +=
|
2021-07-20 17:54:48 +02:00
|
|
|
'${controller.room.getUserByMXIDSync(controller.room.directChatMatrixID).mention} ',
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
)
|
|
|
|
: () => VRouter.of(context)
|
2021-07-08 17:10:20 +02:00
|
|
|
.to('/rooms/${controller.room.id}/details'),
|
2021-05-26 20:50:15 +02:00
|
|
|
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 ==
|
2021-07-31 12:31:31 +02:00
|
|
|
controller.room.directChatMatrixID)
|
|
|
|
.rateLimit(Duration(seconds: 1)),
|
2021-05-26 20:50:15 +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),
|
|
|
|
SizedBox(width: 4),
|
|
|
|
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-05-26 20:50:15 +02:00
|
|
|
))
|
|
|
|
: Text(L10n.of(context).numberSelected(
|
|
|
|
controller.selectedEvents.length.toString())),
|
|
|
|
actions: controller.selectMode
|
|
|
|
? <Widget>[
|
|
|
|
if (controller.selectedEvents.length == 1 &&
|
|
|
|
controller.selectedEvents.first.status > 0 &&
|
|
|
|
controller.selectedEvents.first.senderId ==
|
|
|
|
client.userID)
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.edit_outlined),
|
|
|
|
tooltip: L10n.of(context).edit,
|
|
|
|
onPressed: controller.editSelectedEventAction,
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
PopupMenuButton(
|
|
|
|
onSelected: controller.onEventActionPopupMenuSelected,
|
|
|
|
itemBuilder: (_) => [
|
|
|
|
PopupMenuItem(
|
|
|
|
value: 'copy',
|
|
|
|
child: Text(L10n.of(context).copy),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
if (controller.canRedactSelectedEvents)
|
|
|
|
PopupMenuItem(
|
|
|
|
value: 'redact',
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context).redactMessage,
|
|
|
|
style: TextStyle(color: Colors.orange),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (controller.selectedEvents.length == 1)
|
|
|
|
PopupMenuItem(
|
|
|
|
value: 'report',
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context).reportMessage,
|
|
|
|
style: TextStyle(color: Colors.red),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
]
|
|
|
|
: <Widget>[
|
|
|
|
if (controller.room.canSendDefaultStates)
|
|
|
|
IconButton(
|
|
|
|
tooltip: L10n.of(context).videoCall,
|
|
|
|
icon: Icon(Icons.video_call_outlined),
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
SafeArea(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
if (controller.room.getState(EventTypes.RoomTombstone) !=
|
|
|
|
null)
|
|
|
|
Container(
|
|
|
|
height: 72,
|
|
|
|
child: Material(
|
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
|
|
|
child: ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
foregroundColor:
|
|
|
|
Theme.of(context).colorScheme.secondary,
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).backgroundColor,
|
|
|
|
child: Icon(Icons.upgrade_outlined),
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
controller.room
|
|
|
|
.getState(EventTypes.RoomTombstone)
|
|
|
|
.parsedTombstoneContent
|
|
|
|
.body,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
subtitle: Text(L10n.of(context).goToTheNewRoom),
|
|
|
|
onTap: controller.goToNewRoomAction,
|
|
|
|
),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
Expanded(
|
|
|
|
child: FutureBuilder<bool>(
|
|
|
|
future: controller.getTimeline(),
|
|
|
|
builder: (BuildContext context, snapshot) {
|
|
|
|
if (controller.timeline == null) {
|
|
|
|
return Center(
|
2021-06-20 14:36:01 +02:00
|
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
2021-05-26 20:50:15 +02:00
|
|
|
);
|
|
|
|
}
|
2021-04-15 13:03:14 +02:00
|
|
|
|
2021-05-26 20:50:15 +02: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;
|
|
|
|
}
|
2021-04-15 13:03:14 +02:00
|
|
|
|
2021-05-26 20:50:15 +02:00
|
|
|
return ListView.custom(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: 16,
|
|
|
|
bottom: 4,
|
|
|
|
),
|
|
|
|
reverse: true,
|
|
|
|
controller: controller.scrollController,
|
|
|
|
childrenDelegate: SliverChildBuilderDelegate(
|
|
|
|
(BuildContext context, int i) {
|
|
|
|
return i == controller.filteredEvents.length + 1
|
|
|
|
? controller.timeline.isRequestingHistory
|
2021-06-20 14:08:34 +02:00
|
|
|
? LinearProgressIndicator()
|
2021-05-26 20:50:15 +02:00
|
|
|
: controller.canLoadMore
|
2021-06-20 14:05:47 +02:00
|
|
|
? Center(
|
2021-06-20 14:27:07 +02:00
|
|
|
child: OutlinedButton(
|
2021-06-20 14:05:47 +02:00
|
|
|
onPressed:
|
|
|
|
controller.requestHistory,
|
2021-06-20 14:27:07 +02:00
|
|
|
child: Text(L10n.of(context)
|
|
|
|
.loadMore),
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
2021-06-20 14:27:07 +02:00
|
|
|
)
|
2021-05-26 20:50:15 +02:00
|
|
|
: Container()
|
|
|
|
: i == 0
|
|
|
|
? StreamBuilder(
|
2021-07-31 12:31:31 +02:00
|
|
|
stream: controller
|
|
|
|
.room.onUpdate.stream
|
|
|
|
.rateLimit(Duration(
|
|
|
|
milliseconds: 250)),
|
2021-05-26 20:50:15 +02:00
|
|
|
builder: (_, __) {
|
|
|
|
final seenByText = controller.room
|
|
|
|
.getLocalizedSeenByText(
|
|
|
|
context,
|
|
|
|
controller.timeline,
|
|
|
|
controller.filteredEvents,
|
|
|
|
controller.unfolded,
|
|
|
|
);
|
|
|
|
return AnimatedContainer(
|
|
|
|
height:
|
|
|
|
seenByText.isEmpty ? 0 : 24,
|
|
|
|
duration: seenByText.isEmpty
|
|
|
|
? Duration(milliseconds: 0)
|
|
|
|
: Duration(
|
|
|
|
milliseconds: 300),
|
|
|
|
alignment: controller
|
|
|
|
.filteredEvents
|
|
|
|
.first
|
|
|
|
.senderId ==
|
|
|
|
client.userID
|
|
|
|
? Alignment.topRight
|
|
|
|
: Alignment.topLeft,
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: 8,
|
|
|
|
right: 8,
|
|
|
|
bottom: 8,
|
|
|
|
),
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: 4),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.scaffoldBackgroundColor
|
|
|
|
.withOpacity(0.8),
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(
|
|
|
|
4),
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
seenByText,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow:
|
|
|
|
TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.secondary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
: AutoScrollTag(
|
|
|
|
key: ValueKey(controller
|
|
|
|
.filteredEvents[i - 1].eventId),
|
|
|
|
index: i - 1,
|
|
|
|
controller:
|
|
|
|
controller.scrollController,
|
|
|
|
child: Swipeable(
|
|
|
|
key: ValueKey(controller
|
|
|
|
.filteredEvents[i - 1]
|
|
|
|
.eventId),
|
|
|
|
background: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: 12.0),
|
|
|
|
child: Center(
|
|
|
|
child: Icon(
|
|
|
|
Icons.reply_outlined),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
direction:
|
|
|
|
SwipeDirection.endToStart,
|
|
|
|
onSwipe: (direction) =>
|
|
|
|
controller.replyAction(
|
|
|
|
replyTo: controller
|
|
|
|
.filteredEvents[
|
|
|
|
i - 1]),
|
|
|
|
child: Message(
|
|
|
|
controller
|
|
|
|
.filteredEvents[i - 1],
|
|
|
|
onAvatarTab: (Event event) =>
|
|
|
|
showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (c) =>
|
|
|
|
UserBottomSheet(
|
|
|
|
user: event.sender,
|
|
|
|
outerContext: context,
|
|
|
|
onMention: () => controller
|
|
|
|
.sendController
|
|
|
|
.text +=
|
2021-07-20 17:54:48 +02:00
|
|
|
'${event.sender.mention} ',
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
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 >= 2
|
|
|
|
? controller.filteredEvents[i - 2]
|
|
|
|
: null),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
|
|
|
);
|
2021-05-26 20:50:15 +02:00
|
|
|
},
|
|
|
|
childCount: controller.filteredEvents.length + 2,
|
|
|
|
findChildIndexCallback: (key) =>
|
|
|
|
controller.findChildIndexCallback(
|
|
|
|
key, thisEventsKeyMap),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2021-06-20 09:03:22 +02:00
|
|
|
ConnectionStatusHeader(),
|
2021-05-26 20:50:15 +02:00
|
|
|
if (!controller.showEmojiPicker)
|
|
|
|
AnimatedContainer(
|
|
|
|
duration: Duration(milliseconds: 300),
|
|
|
|
height: (controller.editEvent == null &&
|
|
|
|
controller.replyEvent == null &&
|
|
|
|
controller.room.canSendDefaultMessages &&
|
|
|
|
controller.selectedEvents.length == 1)
|
|
|
|
? 56
|
|
|
|
: 0,
|
|
|
|
child: Material(
|
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
|
|
|
child: Builder(builder: (context) {
|
|
|
|
if (!(controller.editEvent == null &&
|
|
|
|
controller.replyEvent == null &&
|
|
|
|
controller.selectedEvents.length == 1)) {
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
final emojis = List<String>.from(AppEmojis.emojis);
|
|
|
|
final allReactionEvents = controller
|
|
|
|
.selectedEvents.first
|
|
|
|
.aggregatedEvents(controller.timeline,
|
|
|
|
RelationshipTypes.reaction)
|
|
|
|
?.where((event) =>
|
|
|
|
event.senderId ==
|
|
|
|
event.room.client.userID &&
|
|
|
|
event.type == 'm.reaction');
|
2021-04-15 13:03:14 +02:00
|
|
|
|
2021-05-26 20:50:15 +02:00
|
|
|
allReactionEvents.forEach((event) {
|
|
|
|
try {
|
|
|
|
emojis.remove(
|
|
|
|
event.content['m.relates_to']['key']);
|
|
|
|
} catch (_) {}
|
|
|
|
});
|
|
|
|
return ListView.builder(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
itemCount: emojis.length + 1,
|
|
|
|
itemBuilder: (c, i) => i == emojis.length
|
|
|
|
? InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
onTap: () => controller
|
|
|
|
.pickEmojiAction(allReactionEvents),
|
|
|
|
child: Container(
|
|
|
|
width: 56,
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Icon(Icons.add_outlined),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
onTap: () =>
|
|
|
|
controller.sendEmojiAction(emojis[i]),
|
|
|
|
child: Container(
|
|
|
|
width: 56,
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
emojis[i],
|
|
|
|
style: TextStyle(fontSize: 30),
|
|
|
|
),
|
|
|
|
),
|
2021-05-20 13:46:52 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
);
|
|
|
|
}),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
AnimatedContainer(
|
|
|
|
duration: Duration(milliseconds: 300),
|
|
|
|
height: controller.editEvent != null ||
|
|
|
|
controller.replyEvent != null
|
|
|
|
? 56
|
|
|
|
: 0,
|
|
|
|
child: Material(
|
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
IconButton(
|
|
|
|
tooltip: L10n.of(context).close,
|
|
|
|
icon: Icon(Icons.close),
|
|
|
|
onPressed: controller.cancelReplyEventAction,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: controller.replyEvent != null
|
|
|
|
? ReplyContent(controller.replyEvent,
|
|
|
|
timeline: controller.timeline)
|
|
|
|
: _EditContent(controller.editEvent
|
|
|
|
?.getDisplayEvent(controller.timeline)),
|
|
|
|
),
|
|
|
|
],
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
Divider(
|
|
|
|
height: 1,
|
|
|
|
thickness: 1,
|
2021-05-20 13:46:52 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
if (controller.room.canSendDefaultMessages &&
|
|
|
|
controller.room.membership == Membership.join &&
|
|
|
|
!controller.showEmojiPicker)
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: controller.selectMode
|
|
|
|
? <Widget>[
|
|
|
|
Container(
|
|
|
|
height: 56,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: controller.forwardEventsAction,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(Icons
|
|
|
|
.keyboard_arrow_left_outlined),
|
|
|
|
Text(L10n.of(context).forward),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
controller.selectedEvents.length == 1
|
|
|
|
? controller.selectedEvents.first
|
|
|
|
.getDisplayEvent(
|
|
|
|
controller.timeline)
|
|
|
|
.status >
|
|
|
|
0
|
|
|
|
? Container(
|
|
|
|
height: 56,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed:
|
|
|
|
controller.replyAction,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
|
|
|
L10n.of(context).reply),
|
|
|
|
Icon(Icons
|
|
|
|
.keyboard_arrow_right),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Container(
|
|
|
|
height: 56,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed:
|
|
|
|
controller.sendAgainAction,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Text(L10n.of(context)
|
|
|
|
.tryToSendAgain),
|
|
|
|
SizedBox(width: 4),
|
|
|
|
Icon(Icons.send_outlined,
|
|
|
|
size: 16),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Container(),
|
|
|
|
]
|
|
|
|
: <Widget>[
|
|
|
|
AnimatedContainer(
|
|
|
|
duration: Duration(milliseconds: 200),
|
|
|
|
height: 56,
|
|
|
|
width:
|
|
|
|
controller.inputText.isEmpty ? 56 : 0,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
decoration: BoxDecoration(),
|
|
|
|
child: PopupMenuButton<String>(
|
|
|
|
icon: Icon(Icons.add_outlined),
|
|
|
|
onSelected: controller
|
|
|
|
.onAddPopupMenuButtonSelected,
|
|
|
|
itemBuilder: (BuildContext context) =>
|
|
|
|
<PopupMenuEntry<String>>[
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
value: 'file',
|
|
|
|
child: ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
backgroundColor: Colors.green,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
child: Icon(
|
|
|
|
Icons.attachment_outlined),
|
2021-05-20 13:33:06 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
title:
|
|
|
|
Text(L10n.of(context).sendFile),
|
|
|
|
contentPadding: EdgeInsets.all(0),
|
2021-05-20 13:33:06 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
value: 'image',
|
|
|
|
child: ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
backgroundColor: Colors.blue,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
child: Icon(Icons.image_outlined),
|
2021-05-20 13:33:06 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
title: Text(
|
|
|
|
L10n.of(context).sendImage),
|
|
|
|
contentPadding: EdgeInsets.all(0),
|
2021-05-20 13:33:06 +02:00
|
|
|
),
|
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
if (PlatformInfos.isMobile)
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
value: 'camera',
|
|
|
|
child: ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
backgroundColor: Colors.purple,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
child: Icon(
|
|
|
|
Icons.camera_alt_outlined),
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
L10n.of(context).openCamera),
|
|
|
|
contentPadding: EdgeInsets.all(0),
|
|
|
|
),
|
|
|
|
),
|
2021-07-24 10:52:54 +02:00
|
|
|
if (controller.room
|
|
|
|
.getImagePacks(
|
|
|
|
ImagePackUsage.sticker)
|
|
|
|
.isNotEmpty)
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
value: 'sticker',
|
|
|
|
child: ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
backgroundColor: Colors.orange,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
child: Icon(Icons
|
|
|
|
.emoji_emotions_outlined),
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
L10n.of(context).sendSticker),
|
|
|
|
contentPadding: EdgeInsets.all(0),
|
2021-07-23 14:24:52 +02:00
|
|
|
),
|
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
if (PlatformInfos.isMobile)
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
value: 'voice',
|
|
|
|
child: ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
child: Icon(
|
|
|
|
Icons.mic_none_outlined),
|
|
|
|
),
|
|
|
|
title: Text(L10n.of(context)
|
|
|
|
.voiceMessage),
|
|
|
|
contentPadding: EdgeInsets.all(0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: EncryptionButton(controller.room),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 4.0),
|
|
|
|
child: InputBar(
|
|
|
|
room: controller.room,
|
|
|
|
minLines: 1,
|
2021-05-28 22:44:20 +02:00
|
|
|
maxLines: 8,
|
2021-05-26 20:50:15 +02:00
|
|
|
autofocus: !PlatformInfos.isMobile,
|
2021-05-28 22:44:20 +02:00
|
|
|
keyboardType: TextInputType.multiline,
|
2021-05-26 20:50:15 +02:00
|
|
|
onSubmitted:
|
|
|
|
controller.onInputBarSubmitted,
|
|
|
|
focusNode: controller.inputFocus,
|
|
|
|
controller: controller.sendController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText:
|
|
|
|
L10n.of(context).writeAMessage,
|
|
|
|
hintMaxLines: 1,
|
|
|
|
border: InputBorder.none,
|
|
|
|
enabledBorder: InputBorder.none,
|
|
|
|
filled: false,
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
onChanged: controller.onInputBarChanged,
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
if (PlatformInfos.isMobile &&
|
|
|
|
controller.inputText.isEmpty)
|
|
|
|
Container(
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: IconButton(
|
|
|
|
tooltip: L10n.of(context).voiceMessage,
|
|
|
|
icon: Icon(Icons.mic_none_outlined),
|
|
|
|
onPressed:
|
|
|
|
controller.voiceMessageAction,
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
if (!PlatformInfos.isMobile ||
|
|
|
|
controller.inputText.isNotEmpty)
|
|
|
|
Container(
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: IconButton(
|
|
|
|
icon: Icon(Icons.send_outlined),
|
|
|
|
onPressed: controller.send,
|
|
|
|
tooltip: L10n.of(context).send,
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
AnimatedContainer(
|
|
|
|
duration: Duration(milliseconds: 300),
|
|
|
|
height: controller.showEmojiPicker
|
|
|
|
? MediaQuery.of(context).size.height / 2
|
|
|
|
: 0,
|
|
|
|
child: controller.showEmojiPicker
|
|
|
|
? EmojiPicker(
|
|
|
|
onEmojiSelected: controller.onEmojiSelected,
|
|
|
|
onBackspacePressed: controller.cancelEmojiPicker,
|
|
|
|
)
|
|
|
|
: null,
|
2021-05-20 13:46:52 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
],
|
2021-05-20 13:46:52 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
|
|
|
],
|
2021-04-15 13:03:14 +02:00
|
|
|
),
|
2021-05-26 20:50:15 +02:00
|
|
|
));
|
2021-04-15 13:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _EditContent extends StatelessWidget {
|
|
|
|
final Event event;
|
|
|
|
|
|
|
|
_EditContent(this.event);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (event == null) {
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
return Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(
|
|
|
|
Icons.edit,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
Container(width: 15.0),
|
|
|
|
Text(
|
|
|
|
event?.getLocalizedBody(
|
|
|
|
MatrixLocals(L10n.of(context)),
|
|
|
|
withSenderNamePrefix: false,
|
|
|
|
hideReply: true,
|
|
|
|
) ??
|
|
|
|
'',
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 1,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).textTheme.bodyText2.color,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|