2020-01-05 12:27:03 +01:00
|
|
|
import 'dart:async';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'dart:io';
|
2020-10-03 13:11:07 +02:00
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:flutter/scheduler.dart';
|
2020-02-09 15:15:29 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
|
|
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
2021-11-28 11:43:36 +01:00
|
|
|
import 'package:desktop_drop/desktop_drop.dart';
|
2022-02-15 09:25:13 +01:00
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
2022-02-14 13:49:46 +01:00
|
|
|
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
2023-03-18 17:02:12 +01:00
|
|
|
import 'package:file_picker/file_picker.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:image_picker/image_picker.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-07-24 10:35:18 +02:00
|
|
|
import 'package:record/record.dart';
|
2020-09-19 19:21:33 +02:00
|
|
|
import 'package:scroll_to_index/scroll_to_index.dart';
|
2022-12-30 13:32:39 +01:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2021-05-23 13:11:55 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/chat/chat_view.dart';
|
2021-11-13 13:06:36 +01:00
|
|
|
import 'package:fluffychat/pages/chat/event_info_dialog.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/chat/recording_dialog.dart';
|
2023-01-07 10:29:34 +01:00
|
|
|
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
2022-12-30 17:54:01 +01:00
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
|
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/ios_badge_client_extension.dart';
|
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
2022-02-15 09:25:13 +01:00
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import '../../utils/account_bundles.dart';
|
|
|
|
import '../../utils/localized_exception_extension.dart';
|
2022-12-30 17:54:01 +01:00
|
|
|
import '../../utils/matrix_sdk_extensions/matrix_file_extension.dart';
|
2021-11-28 11:43:36 +01:00
|
|
|
import 'send_file_dialog.dart';
|
|
|
|
import 'send_location_dialog.dart';
|
2021-07-23 14:24:52 +02:00
|
|
|
import 'sticker_picker_dialog.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2023-03-25 15:06:12 +01:00
|
|
|
class ChatPage extends StatelessWidget {
|
2022-01-29 12:35:03 +01:00
|
|
|
final Widget? sideView;
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2023-03-25 15:06:12 +01:00
|
|
|
const ChatPage({Key? key, this.sideView}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final roomId = context.vRouter.pathParameters['roomid'];
|
|
|
|
final room =
|
|
|
|
roomId == null ? null : Matrix.of(context).client.getRoomById(roomId);
|
|
|
|
if (room == null) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(title: Text(L10n.of(context)!.oopsSomethingWentWrong)),
|
|
|
|
body: Center(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child:
|
|
|
|
Text(L10n.of(context)!.youAreNoLongerParticipatingInThisChat),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return ChatPageWithRoom(sideView: sideView, room: room);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChatPageWithRoom extends StatefulWidget {
|
|
|
|
final Widget? sideView;
|
|
|
|
final Room room;
|
|
|
|
|
|
|
|
const ChatPageWithRoom({
|
|
|
|
Key? key,
|
|
|
|
required this.sideView,
|
|
|
|
required this.room,
|
|
|
|
}) : super(key: key);
|
2020-01-23 12:11:57 +01:00
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
@override
|
2021-04-15 13:03:14 +02:00
|
|
|
ChatController createState() => ChatController();
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
2023-03-25 15:06:12 +01:00
|
|
|
class ChatController extends State<ChatPageWithRoom> {
|
2023-05-08 06:56:40 +02:00
|
|
|
Room get room => sendingClient.getRoomById(roomId) ?? widget.room;
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2023-03-25 14:58:51 +01:00
|
|
|
late Client sendingClient;
|
2021-09-19 13:48:23 +02:00
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
Timeline? timeline;
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2023-03-23 15:02:32 +01:00
|
|
|
String? readMarkerEventId;
|
|
|
|
|
2023-03-25 15:06:12 +01:00
|
|
|
String get roomId => widget.room.id;
|
2021-05-23 13:11:55 +02:00
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
final AutoScrollController scrollController = AutoScrollController();
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2020-01-24 11:51:23 +01:00
|
|
|
FocusNode inputFocus = FocusNode();
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
Timer? typingCoolDown;
|
|
|
|
Timer? typingTimeout;
|
2020-01-05 12:27:03 +01:00
|
|
|
bool currentlyTyping = false;
|
2021-11-28 11:43:36 +01:00
|
|
|
bool dragging = false;
|
|
|
|
|
|
|
|
void onDragEntered(_) => setState(() => dragging = true);
|
2022-02-02 14:31:15 +01:00
|
|
|
|
2021-11-28 11:43:36 +01:00
|
|
|
void onDragExited(_) => setState(() => dragging = false);
|
2022-02-02 14:31:15 +01:00
|
|
|
|
2021-11-28 11:43:36 +01:00
|
|
|
void onDragDone(DropDoneDetails details) async {
|
|
|
|
setState(() => dragging = false);
|
2022-07-10 09:26:16 +02:00
|
|
|
final bytesList = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: () => Future.wait(
|
|
|
|
details.files.map(
|
|
|
|
(xfile) => xfile.readAsBytes(),
|
2021-11-28 11:43:36 +01:00
|
|
|
),
|
2022-07-10 09:26:16 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
if (bytesList.error != null) return;
|
|
|
|
|
|
|
|
final matrixFiles = <MatrixFile>[];
|
|
|
|
for (var i = 0; i < bytesList.result!.length; i++) {
|
2023-03-02 10:57:52 +01:00
|
|
|
matrixFiles.add(
|
|
|
|
MatrixFile(
|
|
|
|
bytes: bytesList.result![i],
|
|
|
|
name: details.files[i].name,
|
|
|
|
).detectFileType,
|
|
|
|
);
|
2021-11-28 11:43:36 +01:00
|
|
|
}
|
2022-07-10 09:26:16 +02:00
|
|
|
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
useRootNavigator: false,
|
|
|
|
builder: (c) => SendFileDialog(
|
|
|
|
files: matrixFiles,
|
2023-03-25 15:06:12 +01:00
|
|
|
room: room,
|
2022-07-10 09:26:16 +02:00
|
|
|
),
|
|
|
|
);
|
2021-11-28 11:43:36 +01:00
|
|
|
}
|
2020-01-05 12:27:03 +01:00
|
|
|
|
2021-12-27 15:35:25 +01:00
|
|
|
bool get canSaveSelectedEvent =>
|
|
|
|
selectedEvents.length == 1 &&
|
|
|
|
{
|
|
|
|
MessageTypes.Video,
|
|
|
|
MessageTypes.Image,
|
|
|
|
MessageTypes.Sticker,
|
|
|
|
MessageTypes.Audio,
|
|
|
|
MessageTypes.File,
|
|
|
|
}.contains(selectedEvents.single.messageType);
|
|
|
|
|
2022-08-21 08:42:02 +02:00
|
|
|
void saveSelectedEvent(context) => selectedEvents.single.saveFile(context);
|
2021-12-27 15:35:25 +01:00
|
|
|
|
2020-04-02 13:14:39 +02:00
|
|
|
List<Event> selectedEvents = [];
|
2020-02-09 15:15:29 +01:00
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
final Set<String> unfolded = {};
|
2020-11-22 19:34:19 +01:00
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
Event? replyEvent;
|
2020-02-09 15:15:29 +01:00
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
Event? editEvent;
|
2020-08-12 11:30:31 +02:00
|
|
|
|
2020-02-09 16:58:49 +01:00
|
|
|
bool showScrollDownButton = false;
|
|
|
|
|
2020-02-09 15:15:29 +01:00
|
|
|
bool get selectMode => selectedEvents.isNotEmpty;
|
|
|
|
|
2020-02-14 14:34:28 +01:00
|
|
|
final int _loadHistoryCount = 100;
|
|
|
|
|
2020-05-13 15:58:59 +02:00
|
|
|
String inputText = '';
|
2020-02-22 09:03:44 +01:00
|
|
|
|
2020-10-23 17:45:22 +02:00
|
|
|
String pendingText = '';
|
|
|
|
|
2021-05-20 13:46:52 +02:00
|
|
|
bool showEmojiPicker = false;
|
|
|
|
|
2023-01-06 08:54:17 +01:00
|
|
|
void recreateChat() async {
|
|
|
|
final room = this.room;
|
2023-03-25 15:06:12 +01:00
|
|
|
final userId = room.directChatMatrixID;
|
|
|
|
if (userId == null) {
|
2023-01-06 08:54:17 +01:00
|
|
|
throw Exception(
|
2023-03-02 10:57:52 +01:00
|
|
|
'Try to recreate a room with is not a DM room. This should not be possible from the UI!',
|
|
|
|
);
|
2023-01-06 08:54:17 +01:00
|
|
|
}
|
|
|
|
final success = await showFutureLoadingDialog(
|
2023-03-02 10:57:52 +01:00
|
|
|
context: context,
|
|
|
|
future: () async {
|
|
|
|
final client = room.client;
|
|
|
|
final waitForSync = client.onSync.stream
|
|
|
|
.firstWhere((s) => s.rooms?.leave?.containsKey(room.id) ?? false);
|
|
|
|
await room.leave();
|
|
|
|
await waitForSync;
|
|
|
|
return await client.startDirectChat(userId);
|
|
|
|
},
|
|
|
|
);
|
2023-01-06 08:54:17 +01:00
|
|
|
final roomId = success.result;
|
|
|
|
if (roomId == null) return;
|
|
|
|
VRouter.of(context).toSegments(['rooms', roomId]);
|
|
|
|
}
|
|
|
|
|
2023-01-15 10:05:54 +01:00
|
|
|
void leaveChat() async {
|
|
|
|
final success = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: room.leave,
|
|
|
|
);
|
|
|
|
if (success.error != null) return;
|
|
|
|
VRouter.of(context).to('/rooms');
|
|
|
|
}
|
|
|
|
|
2022-02-14 13:49:46 +01:00
|
|
|
EmojiPickerType emojiPickerType = EmojiPickerType.keyboard;
|
|
|
|
|
2020-02-14 14:34:28 +01:00
|
|
|
void requestHistory() async {
|
2023-03-22 09:16:07 +01:00
|
|
|
if (!timeline!.canRequestHistory) return;
|
|
|
|
try {
|
|
|
|
await timeline!.requestHistory(historyCount: _loadHistoryCount);
|
|
|
|
} catch (err) {
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(
|
|
|
|
(err).toLocalizedString(context),
|
2021-06-06 17:56:01 +02:00
|
|
|
),
|
2023-03-22 09:16:07 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void requestFuture() async {
|
2023-03-22 13:16:00 +01:00
|
|
|
final timeline = this.timeline;
|
|
|
|
if (timeline == null) return;
|
|
|
|
if (!timeline.canRequestFuture) return;
|
2023-03-22 09:16:07 +01:00
|
|
|
try {
|
2023-03-22 13:16:00 +01:00
|
|
|
final mostRecentEventId = timeline.events.first.eventId;
|
|
|
|
await timeline.requestFuture(historyCount: _loadHistoryCount);
|
|
|
|
setReadMarker(eventId: mostRecentEventId);
|
2023-03-22 09:16:07 +01:00
|
|
|
} catch (err) {
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(
|
|
|
|
(err).toLocalizedString(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
rethrow;
|
2020-09-19 19:21:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _updateScrollController() {
|
2020-11-16 11:31:31 +01:00
|
|
|
if (!mounted) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-17 21:12:47 +01:00
|
|
|
setReadMarker();
|
2022-03-20 15:46:03 +01:00
|
|
|
if (!scrollController.hasClients) return;
|
2021-04-15 13:03:14 +02:00
|
|
|
if (scrollController.position.pixels ==
|
2023-03-22 09:16:07 +01:00
|
|
|
scrollController.position.maxScrollExtent) {
|
2020-09-19 19:21:33 +02:00
|
|
|
requestHistory();
|
2023-03-22 09:16:07 +01:00
|
|
|
} else if (scrollController.position.pixels == 0) {
|
|
|
|
requestFuture();
|
2020-09-19 19:21:33 +02:00
|
|
|
}
|
2023-03-22 09:16:07 +01:00
|
|
|
if (timeline?.allowNewEvent == false ||
|
|
|
|
scrollController.position.pixels > 0 && showScrollDownButton == false) {
|
2020-09-19 19:21:33 +02:00
|
|
|
setState(() => showScrollDownButton = true);
|
2021-04-15 13:03:14 +02:00
|
|
|
} else if (scrollController.position.pixels == 0 &&
|
2020-09-19 19:21:33 +02:00
|
|
|
showScrollDownButton == true) {
|
|
|
|
setState(() => showScrollDownButton = false);
|
2020-02-14 14:37:31 +01:00
|
|
|
}
|
2020-02-14 14:34:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-30 13:32:39 +01:00
|
|
|
void _loadDraft() async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
final draft = prefs.getString('draft_$roomId');
|
|
|
|
if (draft != null && draft.isNotEmpty) {
|
|
|
|
sendController.text = draft;
|
|
|
|
setState(() => inputText = draft);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
2021-04-15 13:03:14 +02:00
|
|
|
scrollController.addListener(_updateScrollController);
|
2022-02-14 13:49:46 +01:00
|
|
|
inputFocus.addListener(_inputFocusListener);
|
2022-12-30 13:32:39 +01:00
|
|
|
_loadDraft();
|
2020-01-01 19:10:13 +01:00
|
|
|
super.initState();
|
2023-03-25 14:58:51 +01:00
|
|
|
sendingClient = Matrix.of(context).client;
|
2023-03-25 15:23:14 +01:00
|
|
|
readMarkerEventId = room.fullyRead;
|
|
|
|
loadTimelineFuture = _getTimeline();
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
2020-01-05 12:27:03 +01:00
|
|
|
void updateView() {
|
2020-01-23 12:11:57 +01:00
|
|
|
if (!mounted) return;
|
2022-10-15 10:38:06 +02:00
|
|
|
setState(() {});
|
2021-02-25 09:11:17 +01:00
|
|
|
}
|
|
|
|
|
2023-03-25 15:23:14 +01:00
|
|
|
Future<void>? loadTimelineFuture;
|
2020-09-19 19:21:33 +02:00
|
|
|
|
2023-04-14 14:23:58 +02:00
|
|
|
Future<void> _getTimeline({
|
|
|
|
String? eventContextId,
|
|
|
|
Duration timeout = const Duration(seconds: 5),
|
|
|
|
}) async {
|
2023-03-25 15:23:14 +01:00
|
|
|
await Matrix.of(context).client.roomsLoading;
|
|
|
|
await Matrix.of(context).client.accountDataLoading;
|
2023-04-14 14:23:58 +02:00
|
|
|
eventContextId ??= room.fullyRead;
|
2023-05-05 07:54:19 +02:00
|
|
|
if (!eventContextId.isValidMatrixId || eventContextId.sigil != '\$') {
|
|
|
|
eventContextId = null;
|
|
|
|
}
|
2023-04-14 14:23:58 +02:00
|
|
|
try {
|
|
|
|
timeline = await room
|
|
|
|
.getTimeline(
|
|
|
|
onUpdate: updateView,
|
|
|
|
eventContextId: eventContextId,
|
|
|
|
)
|
|
|
|
.timeout(timeout);
|
|
|
|
} on TimeoutException catch (_) {
|
|
|
|
if (!mounted) return;
|
|
|
|
timeline = await room.getTimeline(onUpdate: updateView);
|
|
|
|
if (!mounted) return;
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(L10n.of(context)!.jumpToLastReadMessage),
|
|
|
|
action: SnackBarAction(
|
|
|
|
label: L10n.of(context)!.jump,
|
|
|
|
onPressed: () => scrollToEventId(eventContextId!),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
timeline!.requestKeys(onlineKeyBackupOnly: false);
|
|
|
|
if (timeline!.events.isNotEmpty) {
|
2023-03-25 15:23:14 +01:00
|
|
|
if (room.markedUnread) room.markUnread(false);
|
|
|
|
setReadMarker();
|
2020-01-24 12:05:37 +01:00
|
|
|
}
|
2023-03-25 15:23:14 +01:00
|
|
|
|
|
|
|
// when the scroll controller is attached we want to scroll to an event id, if specified
|
|
|
|
// and update the scroll controller...which will trigger a request history, if the
|
|
|
|
// "load more" button is visible on the screen
|
|
|
|
SchedulerBinding.instance.addPostFrameCallback((_) async {
|
|
|
|
if (mounted) {
|
|
|
|
final event = VRouter.of(context).queryParameters['event'];
|
|
|
|
if (event != null) {
|
|
|
|
scrollToEventId(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-03-22 09:16:07 +01:00
|
|
|
return;
|
2022-02-17 21:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void>? _setReadMarkerFuture;
|
|
|
|
|
2023-03-22 13:16:00 +01:00
|
|
|
void setReadMarker({String? eventId}) {
|
|
|
|
if (_setReadMarkerFuture != null) return;
|
2023-03-25 15:23:14 +01:00
|
|
|
if (eventId == null &&
|
2023-03-25 15:06:12 +01:00
|
|
|
!room.hasNewMessages &&
|
|
|
|
room.notificationCount == 0) {
|
2023-03-22 13:16:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Matrix.of(context).webHasFocus) return;
|
|
|
|
|
|
|
|
final timeline = this.timeline;
|
|
|
|
if (timeline == null || timeline.events.isEmpty) return;
|
|
|
|
|
|
|
|
eventId ??= timeline.events.first.eventId;
|
|
|
|
Logs().v('Set read marker...', eventId);
|
|
|
|
// ignore: unawaited_futures
|
|
|
|
_setReadMarkerFuture = timeline.setReadMarker(eventId).then((_) {
|
|
|
|
_setReadMarkerFuture = null;
|
|
|
|
});
|
2023-03-25 15:06:12 +01:00
|
|
|
room.client.updateIosBadge();
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2020-02-22 08:27:08 +01:00
|
|
|
timeline?.cancelSubscriptions();
|
2020-01-23 12:11:57 +01:00
|
|
|
timeline = null;
|
2022-02-14 13:49:46 +01:00
|
|
|
inputFocus.removeListener(_inputFocusListener);
|
2020-01-01 19:10:13 +01:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2020-01-17 10:41:28 +01:00
|
|
|
TextEditingController sendController = TextEditingController();
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2023-03-25 14:58:51 +01:00
|
|
|
void setSendingClient(Client c) {
|
2023-05-08 06:56:40 +02:00
|
|
|
// first cancel typing with the old sending client
|
2021-09-21 09:13:02 +02:00
|
|
|
if (currentlyTyping) {
|
|
|
|
// no need to have the setting typing to false be blocking
|
|
|
|
typingCoolDown?.cancel();
|
|
|
|
typingCoolDown = null;
|
2023-03-25 15:06:12 +01:00
|
|
|
room.setTyping(false);
|
2021-09-21 09:13:02 +02:00
|
|
|
currentlyTyping = false;
|
|
|
|
}
|
2023-05-08 14:02:15 +02:00
|
|
|
// then cancel the old timeline
|
|
|
|
// fixes bug with read reciepts and quick switching
|
|
|
|
loadTimelineFuture = _getTimeline(eventContextId: room.fullyRead);
|
|
|
|
|
2021-09-21 09:13:02 +02:00
|
|
|
// then set the new sending client
|
|
|
|
setState(() => sendingClient = c);
|
|
|
|
}
|
2021-09-19 13:48:23 +02:00
|
|
|
|
|
|
|
void setActiveClient(Client c) => setState(() {
|
|
|
|
Matrix.of(context).setActiveClient(c);
|
|
|
|
});
|
|
|
|
|
2021-06-14 00:03:06 +02:00
|
|
|
Future<void> send() async {
|
2021-01-16 19:44:46 +01:00
|
|
|
if (sendController.text.trim().isEmpty) return;
|
2022-12-30 18:24:34 +01:00
|
|
|
_storeInputTimeoutTimer?.cancel();
|
2022-12-30 13:32:39 +01:00
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
prefs.remove('draft_$roomId');
|
2021-06-14 00:03:06 +02:00
|
|
|
var parseCommands = true;
|
|
|
|
|
|
|
|
final commandMatch = RegExp(r'^\/(\w+)').firstMatch(sendController.text);
|
|
|
|
if (commandMatch != null &&
|
2023-05-08 06:56:40 +02:00
|
|
|
!sendingClient.commands.keys.contains(commandMatch[1]!.toLowerCase())) {
|
2022-01-29 12:35:03 +01:00
|
|
|
final l10n = L10n.of(context)!;
|
2021-06-14 00:03:06 +02:00
|
|
|
final dialogResult = await showOkCancelAlertDialog(
|
|
|
|
context: context,
|
|
|
|
useRootNavigator: false,
|
|
|
|
title: l10n.commandInvalid,
|
2022-01-29 12:35:03 +01:00
|
|
|
message: l10n.commandMissing(commandMatch[0]!),
|
2021-06-14 00:03:06 +02:00
|
|
|
okLabel: l10n.sendAsText,
|
|
|
|
cancelLabel: l10n.cancel,
|
|
|
|
);
|
2022-01-29 12:35:03 +01:00
|
|
|
if (dialogResult == OkCancelResult.cancel) return;
|
2021-06-14 00:03:06 +02:00
|
|
|
parseCommands = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore: unawaited_futures
|
2023-03-25 15:06:12 +01:00
|
|
|
room.sendTextEvent(
|
2023-03-02 10:57:52 +01:00
|
|
|
sendController.text,
|
|
|
|
inReplyTo: replyEvent,
|
|
|
|
editEventId: editEvent?.eventId,
|
|
|
|
parseCommands: parseCommands,
|
|
|
|
);
|
2021-05-13 12:48:05 +02:00
|
|
|
sendController.value = TextEditingValue(
|
|
|
|
text: pendingText,
|
2021-10-14 18:09:30 +02:00
|
|
|
selection: const TextSelection.collapsed(offset: 0),
|
2021-05-13 12:48:05 +02:00
|
|
|
);
|
2020-02-23 08:52:28 +01:00
|
|
|
|
2020-08-12 11:30:31 +02:00
|
|
|
setState(() {
|
2020-10-23 17:45:22 +02:00
|
|
|
inputText = pendingText;
|
2020-08-12 11:30:31 +02:00
|
|
|
replyEvent = null;
|
|
|
|
editEvent = null;
|
2020-10-23 17:45:22 +02:00
|
|
|
pendingText = '';
|
2020-08-12 11:30:31 +02:00
|
|
|
});
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void sendFileAction() async {
|
2023-03-18 17:02:12 +01:00
|
|
|
final result = await FilePicker.platform.pickFiles(
|
|
|
|
allowMultiple: true,
|
|
|
|
withData: true,
|
2022-07-10 09:26:16 +02:00
|
|
|
);
|
2023-03-18 17:02:12 +01:00
|
|
|
if (result == null || result.files.isEmpty) return;
|
2020-09-04 12:56:25 +02:00
|
|
|
await showDialog(
|
2020-10-04 17:01:54 +02:00
|
|
|
context: context,
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-01-18 10:43:00 +01:00
|
|
|
builder: (c) => SendFileDialog(
|
2023-03-18 17:02:12 +01:00
|
|
|
files: result.files
|
2023-03-02 10:57:52 +01:00
|
|
|
.map(
|
|
|
|
(xfile) => MatrixFile(
|
2023-03-18 17:02:12 +01:00
|
|
|
bytes: xfile.bytes!,
|
|
|
|
name: xfile.name,
|
2023-03-02 10:57:52 +01:00
|
|
|
).detectFileType,
|
|
|
|
)
|
2022-07-10 09:26:16 +02:00
|
|
|
.toList(),
|
2023-03-25 15:06:12 +01:00
|
|
|
room: room,
|
2020-10-04 17:01:54 +02:00
|
|
|
),
|
|
|
|
);
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void sendImageAction() async {
|
2023-03-18 17:02:12 +01:00
|
|
|
final result = await FilePicker.platform.pickFiles(
|
|
|
|
type: FileType.image,
|
|
|
|
withData: true,
|
|
|
|
allowMultiple: true,
|
2022-07-10 09:26:16 +02:00
|
|
|
);
|
2023-03-18 17:02:12 +01:00
|
|
|
if (result == null || result.files.isEmpty) return;
|
2022-07-10 09:26:16 +02:00
|
|
|
|
2020-09-04 12:56:25 +02:00
|
|
|
await showDialog(
|
2020-10-04 17:01:54 +02:00
|
|
|
context: context,
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-01-18 10:43:00 +01:00
|
|
|
builder: (c) => SendFileDialog(
|
2023-03-18 17:02:12 +01:00
|
|
|
files: result.files
|
2023-03-02 10:57:52 +01:00
|
|
|
.map(
|
|
|
|
(xfile) => MatrixFile(
|
2023-03-18 17:02:12 +01:00
|
|
|
bytes: xfile.bytes!,
|
|
|
|
name: xfile.name,
|
2023-03-02 10:57:52 +01:00
|
|
|
).detectFileType,
|
|
|
|
)
|
2022-07-10 09:26:16 +02:00
|
|
|
.toList(),
|
2023-03-25 15:06:12 +01:00
|
|
|
room: room,
|
2020-10-04 17:01:54 +02:00
|
|
|
),
|
|
|
|
);
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void openCameraAction() async {
|
2021-07-18 12:17:56 +02:00
|
|
|
// Make sure the textfield is unfocused before opening the camera
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
2021-08-10 14:01:15 +02:00
|
|
|
final file = await ImagePicker().pickImage(source: ImageSource.camera);
|
2020-01-01 19:10:13 +01:00
|
|
|
if (file == null) return;
|
2020-10-04 17:01:54 +02:00
|
|
|
final bytes = await file.readAsBytes();
|
2020-09-04 12:56:25 +02:00
|
|
|
await showDialog(
|
2020-10-04 17:01:54 +02:00
|
|
|
context: context,
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-01-18 10:43:00 +01:00
|
|
|
builder: (c) => SendFileDialog(
|
2022-07-10 09:26:16 +02:00
|
|
|
files: [
|
|
|
|
MatrixImageFile(
|
|
|
|
bytes: bytes,
|
|
|
|
name: file.path,
|
|
|
|
)
|
|
|
|
],
|
2023-03-25 15:06:12 +01:00
|
|
|
room: room,
|
2020-10-04 17:01:54 +02:00
|
|
|
),
|
|
|
|
);
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
2021-12-22 09:45:36 +01:00
|
|
|
void openVideoCameraAction() async {
|
|
|
|
// Make sure the textfield is unfocused before opening the camera
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
final file = await ImagePicker().pickVideo(source: ImageSource.camera);
|
|
|
|
if (file == null) return;
|
|
|
|
final bytes = await file.readAsBytes();
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
useRootNavigator: false,
|
|
|
|
builder: (c) => SendFileDialog(
|
2022-07-10 09:26:16 +02:00
|
|
|
files: [
|
|
|
|
MatrixVideoFile(
|
|
|
|
bytes: bytes,
|
|
|
|
name: file.path,
|
|
|
|
)
|
|
|
|
],
|
2023-03-25 15:06:12 +01:00
|
|
|
room: room,
|
2021-12-22 09:45:36 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-23 14:24:52 +02:00
|
|
|
void sendStickerAction() async {
|
2023-01-07 10:29:34 +01:00
|
|
|
final sticker = await showAdaptiveBottomSheet<ImagePackImageContent>(
|
2021-07-23 14:24:52 +02:00
|
|
|
context: context,
|
2023-03-25 15:06:12 +01:00
|
|
|
builder: (c) => StickerPickerDialog(room: room),
|
2021-07-23 14:24:52 +02:00
|
|
|
);
|
|
|
|
if (sticker == null) return;
|
|
|
|
final eventContent = <String, dynamic>{
|
|
|
|
'body': sticker.body,
|
|
|
|
if (sticker.info != null) 'info': sticker.info,
|
|
|
|
'url': sticker.url.toString(),
|
|
|
|
};
|
|
|
|
// send the sticker
|
2023-03-25 15:06:12 +01:00
|
|
|
await room.sendEvent(
|
2022-05-27 15:16:44 +02:00
|
|
|
eventContent,
|
|
|
|
type: EventTypes.Sticker,
|
2021-07-23 14:24:52 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void voiceMessageAction() async {
|
2023-02-13 15:38:08 +01:00
|
|
|
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
2022-06-20 15:35:22 +02:00
|
|
|
if (PlatformInfos.isAndroid) {
|
|
|
|
final info = await DeviceInfoPlugin().androidInfo;
|
2022-11-03 15:37:40 +01:00
|
|
|
if (info.version.sdkInt < 19) {
|
2022-06-20 15:35:22 +02:00
|
|
|
showOkAlertDialog(
|
|
|
|
context: context,
|
|
|
|
title: L10n.of(context)!.unsupportedAndroidVersion,
|
|
|
|
message: L10n.of(context)!.unsupportedAndroidVersionLong,
|
|
|
|
okLabel: L10n.of(context)!.close,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 10:35:18 +02:00
|
|
|
if (await Record().hasPermission() == false) return;
|
2021-10-30 10:39:00 +02:00
|
|
|
final result = await showDialog<RecordingResult>(
|
2021-01-23 11:17:34 +01:00
|
|
|
context: context,
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2022-12-30 12:53:42 +01:00
|
|
|
barrierDismissible: false,
|
2021-10-14 18:09:30 +02:00
|
|
|
builder: (c) => const RecordingDialog(),
|
2021-01-23 11:17:34 +01:00
|
|
|
);
|
2020-03-15 11:27:51 +01:00
|
|
|
if (result == null) return;
|
2021-10-30 10:39:00 +02:00
|
|
|
final audioFile = File(result.path);
|
2021-10-27 16:53:31 +02:00
|
|
|
final file = MatrixAudioFile(
|
|
|
|
bytes: audioFile.readAsBytesSync(),
|
|
|
|
name: audioFile.path,
|
|
|
|
);
|
2023-03-25 15:06:12 +01:00
|
|
|
await room.sendFileEvent(
|
2022-03-30 11:46:24 +02:00
|
|
|
file,
|
|
|
|
inReplyTo: replyEvent,
|
|
|
|
extraContent: {
|
2021-10-27 16:53:31 +02:00
|
|
|
'info': {
|
|
|
|
...file.info,
|
2021-10-30 10:39:00 +02:00
|
|
|
'duration': result.duration,
|
2021-10-30 11:03:33 +02:00
|
|
|
},
|
|
|
|
'org.matrix.msc3245.voice': {},
|
2022-01-01 14:17:31 +01:00
|
|
|
'org.matrix.msc1767.audio': {
|
|
|
|
'duration': result.duration,
|
|
|
|
'waveform': result.waveform,
|
|
|
|
},
|
2022-03-30 11:46:24 +02:00
|
|
|
},
|
2023-02-13 15:38:08 +01:00
|
|
|
).catchError((e) {
|
|
|
|
scaffoldMessenger.showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(
|
|
|
|
(e as Object).toLocalizedString(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
});
|
2021-08-12 09:59:42 +02:00
|
|
|
setState(() {
|
|
|
|
replyEvent = null;
|
|
|
|
});
|
2020-03-15 11:27:51 +01:00
|
|
|
}
|
|
|
|
|
2022-02-14 13:49:46 +01:00
|
|
|
void emojiPickerAction() {
|
2022-02-17 09:18:50 +01:00
|
|
|
if (showEmojiPicker) {
|
|
|
|
inputFocus.requestFocus();
|
|
|
|
} else {
|
|
|
|
inputFocus.unfocus();
|
|
|
|
}
|
2022-02-14 13:49:46 +01:00
|
|
|
emojiPickerType = EmojiPickerType.keyboard;
|
|
|
|
setState(() => showEmojiPicker = !showEmojiPicker);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _inputFocusListener() {
|
2022-02-17 09:18:50 +01:00
|
|
|
if (showEmojiPicker && inputFocus.hasFocus) {
|
|
|
|
emojiPickerType = EmojiPickerType.keyboard;
|
|
|
|
setState(() => showEmojiPicker = false);
|
2022-02-14 13:49:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-01 09:53:43 +02:00
|
|
|
void sendLocationAction() async {
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
useRootNavigator: false,
|
2023-03-25 15:06:12 +01:00
|
|
|
builder: (c) => SendLocationDialog(room: room),
|
2021-08-01 09:53:43 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
String _getSelectedEventString() {
|
2020-05-13 15:58:59 +02:00
|
|
|
var copyString = '';
|
2020-04-02 13:14:39 +02:00
|
|
|
if (selectedEvents.length == 1) {
|
2020-10-03 13:11:07 +02:00
|
|
|
return selectedEvents.first
|
2022-01-29 12:35:03 +01:00
|
|
|
.getDisplayEvent(timeline!)
|
2022-05-30 13:44:05 +02:00
|
|
|
.calcLocalizedBodyFallback(MatrixLocals(L10n.of(context)!));
|
2020-04-02 13:14:39 +02:00
|
|
|
}
|
2021-04-14 10:37:15 +02:00
|
|
|
for (final event in selectedEvents) {
|
2020-05-13 15:58:59 +02:00
|
|
|
if (copyString.isNotEmpty) copyString += '\n\n';
|
2022-05-30 13:44:05 +02:00
|
|
|
copyString += event.getDisplayEvent(timeline!).calcLocalizedBodyFallback(
|
2023-03-02 10:57:52 +01:00
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
withSenderNamePrefix: true,
|
|
|
|
);
|
2020-02-09 15:15:29 +01:00
|
|
|
}
|
|
|
|
return copyString;
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void copyEventsAction() {
|
|
|
|
Clipboard.setData(ClipboardData(text: _getSelectedEventString()));
|
2021-11-13 10:20:09 +01:00
|
|
|
setState(() {
|
|
|
|
showEmojiPicker = false;
|
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
2020-02-09 15:15:29 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void reportEventAction() async {
|
2021-02-01 21:26:02 +01:00
|
|
|
final event = selectedEvents.single;
|
|
|
|
final score = await showConfirmationDialog<int>(
|
2023-03-02 10:57:52 +01:00
|
|
|
context: context,
|
|
|
|
title: L10n.of(context)!.reportMessage,
|
|
|
|
message: L10n.of(context)!.howOffensiveIsThisContent,
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
|
|
|
okLabel: L10n.of(context)!.ok,
|
|
|
|
actions: [
|
|
|
|
AlertDialogAction(
|
|
|
|
key: -100,
|
|
|
|
label: L10n.of(context)!.extremeOffensive,
|
|
|
|
),
|
|
|
|
AlertDialogAction(
|
|
|
|
key: -50,
|
|
|
|
label: L10n.of(context)!.offensive,
|
|
|
|
),
|
|
|
|
AlertDialogAction(
|
|
|
|
key: 0,
|
|
|
|
label: L10n.of(context)!.inoffensive,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2021-02-01 21:26:02 +01:00
|
|
|
if (score == null) return;
|
|
|
|
final reason = await showTextInputDialog(
|
2023-03-02 10:57:52 +01:00
|
|
|
useRootNavigator: false,
|
|
|
|
context: context,
|
|
|
|
title: L10n.of(context)!.whyDoYouWantToReportThis,
|
|
|
|
okLabel: L10n.of(context)!.ok,
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
|
|
|
textFields: [DialogTextField(hintText: L10n.of(context)!.reason)],
|
|
|
|
);
|
2021-02-01 21:26:02 +01:00
|
|
|
if (reason == null || reason.single.isEmpty) return;
|
|
|
|
final result = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
2021-05-20 13:59:55 +02:00
|
|
|
future: () => Matrix.of(context).client.reportContent(
|
2022-01-29 12:35:03 +01:00
|
|
|
event.roomId!,
|
2021-02-01 21:26:02 +01:00
|
|
|
event.eventId,
|
2021-08-18 17:24:59 +02:00
|
|
|
reason: reason.single,
|
|
|
|
score: score,
|
2021-02-01 21:26:02 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
if (result.error != null) return;
|
2021-11-13 10:20:09 +01:00
|
|
|
setState(() {
|
|
|
|
showEmojiPicker = false;
|
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
2021-05-23 13:11:55 +02:00
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2023-03-02 10:57:52 +01:00
|
|
|
SnackBar(content: Text(L10n.of(context)!.contentHasBeenReported)),
|
|
|
|
);
|
2021-02-01 21:26:02 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void redactEventsAction() async {
|
2021-04-14 10:37:15 +02:00
|
|
|
final confirmed = await showOkCancelAlertDialog(
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2020-11-14 10:08:13 +01:00
|
|
|
context: context,
|
2022-01-29 12:35:03 +01:00
|
|
|
title: L10n.of(context)!.messageWillBeRemovedWarning,
|
|
|
|
okLabel: L10n.of(context)!.remove,
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
2020-11-14 10:08:13 +01:00
|
|
|
) ==
|
|
|
|
OkCancelResult.ok;
|
2020-02-09 15:15:29 +01:00
|
|
|
if (!confirmed) return;
|
2021-04-14 10:37:15 +02:00
|
|
|
for (final event in selectedEvents) {
|
2020-12-25 09:58:34 +01:00
|
|
|
await showFutureLoadingDialog(
|
2023-03-02 10:57:52 +01:00
|
|
|
context: context,
|
|
|
|
future: () async {
|
|
|
|
if (event.status.isSent) {
|
|
|
|
if (event.canRedact) {
|
|
|
|
await event.redactEvent();
|
2021-09-19 13:48:23 +02:00
|
|
|
} else {
|
2023-03-02 10:57:52 +01:00
|
|
|
final client = currentRoomBundle.firstWhere(
|
|
|
|
(cl) => selectedEvents.first.senderId == cl!.userID,
|
|
|
|
orElse: () => null,
|
|
|
|
);
|
|
|
|
if (client == null) {
|
|
|
|
return;
|
|
|
|
}
|
2023-03-25 15:06:12 +01:00
|
|
|
final room = client.getRoomById(roomId)!;
|
2023-03-02 10:57:52 +01:00
|
|
|
await Event.fromJson(event.toJson(), room).redactEvent();
|
2021-09-19 13:48:23 +02:00
|
|
|
}
|
2023-03-02 10:57:52 +01:00
|
|
|
} else {
|
|
|
|
await event.remove();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2020-02-09 15:15:29 +01:00
|
|
|
}
|
2021-11-13 10:20:09 +01:00
|
|
|
setState(() {
|
|
|
|
showEmojiPicker = false;
|
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
2020-02-09 15:15:29 +01:00
|
|
|
}
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
List<Client?> get currentRoomBundle {
|
2023-03-25 14:57:27 +01:00
|
|
|
final clients = Matrix.of(context).currentBundle!;
|
2023-03-25 15:06:12 +01:00
|
|
|
clients.removeWhere((c) => c!.getRoomById(roomId) == null);
|
2021-09-19 13:48:23 +02:00
|
|
|
return clients;
|
|
|
|
}
|
|
|
|
|
2020-02-09 15:15:29 +01:00
|
|
|
bool get canRedactSelectedEvents {
|
2023-01-08 12:32:35 +01:00
|
|
|
if (isArchived) return false;
|
2023-03-25 14:57:27 +01:00
|
|
|
final clients = Matrix.of(context).currentBundle;
|
2021-04-14 10:37:15 +02:00
|
|
|
for (final event in selectedEvents) {
|
2021-09-19 13:48:23 +02:00
|
|
|
if (event.canRedact == false &&
|
2022-01-29 12:35:03 +01:00
|
|
|
!(clients!.any((cl) => event.senderId == cl!.userID))) return false;
|
2020-02-09 15:15:29 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-19 13:48:23 +02:00
|
|
|
bool get canEditSelectedEvents {
|
2023-01-08 12:32:35 +01:00
|
|
|
if (isArchived ||
|
|
|
|
selectedEvents.length != 1 ||
|
|
|
|
!selectedEvents.first.status.isSent) {
|
2021-09-19 13:48:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return currentRoomBundle
|
2022-01-29 12:35:03 +01:00
|
|
|
.any((cl) => selectedEvents.first.senderId == cl!.userID);
|
2021-09-19 13:48:23 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void forwardEventsAction() async {
|
2020-02-09 15:15:29 +01:00
|
|
|
if (selectedEvents.length == 1) {
|
2022-08-06 11:41:06 +02:00
|
|
|
Matrix.of(context).shareContent =
|
|
|
|
selectedEvents.first.getDisplayEvent(timeline!).content;
|
2020-02-09 15:15:29 +01:00
|
|
|
} else {
|
|
|
|
Matrix.of(context).shareContent = {
|
2020-05-13 15:58:59 +02:00
|
|
|
'msgtype': 'm.text',
|
2021-04-15 13:03:14 +02:00
|
|
|
'body': _getSelectedEventString(),
|
2020-02-09 15:15:29 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
setState(() => selectedEvents.clear());
|
2021-07-08 17:10:20 +02:00
|
|
|
VRouter.of(context).to('/rooms');
|
2020-02-09 15:15:29 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void sendAgainAction() {
|
2020-08-12 11:30:31 +02:00
|
|
|
final event = selectedEvents.first;
|
2021-10-25 10:46:58 +02:00
|
|
|
if (event.status.isError) {
|
2020-08-12 11:30:31 +02:00
|
|
|
event.sendAgain();
|
|
|
|
}
|
|
|
|
final allEditEvents = event
|
2022-01-29 12:35:03 +01:00
|
|
|
.aggregatedEvents(timeline!, RelationshipTypes.edit)
|
2021-10-25 10:46:58 +02:00
|
|
|
.where((e) => e.status.isError);
|
2020-08-12 11:30:31 +02:00
|
|
|
for (final e in allEditEvents) {
|
|
|
|
e.sendAgain();
|
|
|
|
}
|
2020-02-09 15:15:29 +01:00
|
|
|
setState(() => selectedEvents.clear());
|
|
|
|
}
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
void replyAction({Event? replyTo}) {
|
2020-02-09 15:15:29 +01:00
|
|
|
setState(() {
|
2020-10-17 11:15:55 +02:00
|
|
|
replyEvent = replyTo ?? selectedEvents.first;
|
2020-02-09 15:15:29 +01:00
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
2020-02-16 11:36:18 +01:00
|
|
|
inputFocus.requestFocus();
|
2020-02-09 15:15:29 +01:00
|
|
|
}
|
|
|
|
|
2023-04-02 09:33:27 +02:00
|
|
|
void scrollToEventId(String eventId) async {
|
|
|
|
final eventIndex = timeline!.events.indexWhere((e) => e.eventId == eventId);
|
2020-09-19 19:21:33 +02:00
|
|
|
if (eventIndex == -1) {
|
2023-03-22 09:16:07 +01:00
|
|
|
setState(() {
|
|
|
|
timeline = null;
|
2023-04-14 14:23:58 +02:00
|
|
|
loadTimelineFuture = _getTimeline(
|
|
|
|
eventContextId: eventId,
|
|
|
|
timeout: const Duration(seconds: 30),
|
|
|
|
);
|
2023-03-22 09:16:07 +01:00
|
|
|
});
|
2023-03-25 15:23:14 +01:00
|
|
|
await loadTimelineFuture;
|
2023-04-02 09:33:27 +02:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
|
|
|
scrollToEventId(eventId);
|
|
|
|
});
|
2020-11-16 11:31:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-10-26 18:47:05 +02:00
|
|
|
await scrollController.scrollToIndex(
|
|
|
|
eventIndex,
|
|
|
|
preferPosition: AutoScrollPosition.middle,
|
|
|
|
);
|
2020-09-19 19:21:33 +02:00
|
|
|
_updateScrollController();
|
|
|
|
}
|
|
|
|
|
2023-03-22 09:16:07 +01:00
|
|
|
void scrollDown() async {
|
|
|
|
if (!timeline!.allowNewEvent) {
|
|
|
|
setState(() {
|
|
|
|
timeline = null;
|
2023-03-25 15:23:14 +01:00
|
|
|
loadTimelineFuture = _getTimeline();
|
2023-03-22 09:16:07 +01:00
|
|
|
});
|
2023-03-25 15:23:14 +01:00
|
|
|
await loadTimelineFuture;
|
2023-03-22 13:16:00 +01:00
|
|
|
setReadMarker(eventId: timeline!.events.first.eventId);
|
2023-03-22 09:16:07 +01:00
|
|
|
}
|
|
|
|
scrollController.jumpTo(0);
|
|
|
|
}
|
2021-04-15 13:03:14 +02:00
|
|
|
|
2022-02-14 13:49:46 +01:00
|
|
|
void onEmojiSelected(_, Emoji? emoji) {
|
|
|
|
switch (emojiPickerType) {
|
|
|
|
case EmojiPickerType.reaction:
|
|
|
|
senEmojiReaction(emoji);
|
|
|
|
break;
|
|
|
|
case EmojiPickerType.keyboard:
|
|
|
|
typeEmoji(emoji);
|
2022-03-03 07:52:31 +01:00
|
|
|
onInputBarChanged(sendController.text);
|
2022-02-14 13:49:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void senEmojiReaction(Emoji? emoji) {
|
2021-05-20 13:46:52 +02:00
|
|
|
setState(() => showEmojiPicker = false);
|
2020-12-12 17:19:53 +01:00
|
|
|
if (emoji == null) return;
|
2020-12-19 16:12:47 +01:00
|
|
|
// make sure we don't send the same emoji twice
|
2021-05-20 13:46:52 +02:00
|
|
|
if (_allReactionEvents
|
2020-12-19 16:12:47 +01:00
|
|
|
.any((e) => e.content['m.relates_to']['key'] == emoji.emoji)) return;
|
2021-04-15 13:03:14 +02:00
|
|
|
return sendEmojiAction(emoji.emoji);
|
2020-12-12 17:19:53 +01:00
|
|
|
}
|
|
|
|
|
2023-01-08 12:32:35 +01:00
|
|
|
void forgetRoom() async {
|
|
|
|
final result = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
2023-03-25 15:06:12 +01:00
|
|
|
future: room.forget,
|
2023-01-08 12:32:35 +01:00
|
|
|
);
|
|
|
|
if (result.error != null) return;
|
|
|
|
VRouter.of(context).to('/archive');
|
|
|
|
}
|
|
|
|
|
2022-02-14 13:49:46 +01:00
|
|
|
void typeEmoji(Emoji? emoji) {
|
|
|
|
if (emoji == null) return;
|
|
|
|
final text = sendController.text;
|
|
|
|
final selection = sendController.selection;
|
|
|
|
final newText = sendController.text.isEmpty
|
|
|
|
? emoji.emoji
|
|
|
|
: text.replaceRange(selection.start, selection.end, emoji.emoji);
|
|
|
|
sendController.value = TextEditingValue(
|
|
|
|
text: newText,
|
|
|
|
selection: TextSelection.collapsed(
|
|
|
|
// don't forget an UTF-8 combined emoji might have a length > 1
|
|
|
|
offset: selection.baseOffset + emoji.emoji.length,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
late Iterable<Event> _allReactionEvents;
|
2021-05-20 13:46:52 +02:00
|
|
|
|
2022-02-14 13:49:46 +01:00
|
|
|
void emojiPickerBackspace() {
|
|
|
|
switch (emojiPickerType) {
|
|
|
|
case EmojiPickerType.reaction:
|
|
|
|
setState(() => showEmojiPicker = false);
|
|
|
|
break;
|
|
|
|
case EmojiPickerType.keyboard:
|
|
|
|
sendController
|
|
|
|
..text = sendController.text.characters.skipLast(1).toString()
|
|
|
|
..selection = TextSelection.fromPosition(
|
2023-03-02 10:57:52 +01:00
|
|
|
TextPosition(offset: sendController.text.length),
|
|
|
|
);
|
2022-02-14 13:49:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 13:46:52 +02:00
|
|
|
|
2022-02-14 13:49:46 +01:00
|
|
|
void pickEmojiReactionAction(Iterable<Event> allReactionEvents) async {
|
2021-05-20 13:46:52 +02:00
|
|
|
_allReactionEvents = allReactionEvents;
|
2022-02-14 13:49:46 +01:00
|
|
|
emojiPickerType = EmojiPickerType.reaction;
|
2021-05-20 13:46:52 +02:00
|
|
|
setState(() => showEmojiPicker = true);
|
|
|
|
}
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
void sendEmojiAction(String? emoji) async {
|
2021-11-19 10:23:24 +01:00
|
|
|
final events = List<Event>.from(selectedEvents);
|
2020-12-12 17:19:53 +01:00
|
|
|
setState(() => selectedEvents.clear());
|
2021-11-19 10:23:24 +01:00
|
|
|
for (final event in events) {
|
2023-03-25 15:06:12 +01:00
|
|
|
await room.sendReaction(
|
2021-11-19 10:23:24 +01:00
|
|
|
event.eventId,
|
2022-01-29 12:35:03 +01:00
|
|
|
emoji!,
|
2021-11-19 10:23:24 +01:00
|
|
|
);
|
|
|
|
}
|
2020-12-12 17:19:53 +01:00
|
|
|
}
|
|
|
|
|
2021-05-20 13:46:52 +02:00
|
|
|
void clearSelectedEvents() => setState(() {
|
|
|
|
selectedEvents.clear();
|
|
|
|
showEmojiPicker = false;
|
|
|
|
});
|
2020-01-05 12:27:03 +01:00
|
|
|
|
2022-01-03 17:12:09 +01:00
|
|
|
void clearSingleSelectedEvent() {
|
|
|
|
if (selectedEvents.length <= 1) {
|
|
|
|
clearSelectedEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void editSelectedEventAction() {
|
2021-09-19 13:48:23 +02:00
|
|
|
final client = currentRoomBundle.firstWhere(
|
2023-03-02 10:57:52 +01:00
|
|
|
(cl) => selectedEvents.first.senderId == cl!.userID,
|
|
|
|
orElse: () => null,
|
|
|
|
);
|
2021-09-19 13:48:23 +02:00
|
|
|
if (client == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setSendingClient(client);
|
2021-04-15 13:03:14 +02:00
|
|
|
setState(() {
|
|
|
|
pendingText = sendController.text;
|
|
|
|
editEvent = selectedEvents.first;
|
2023-03-02 10:57:52 +01:00
|
|
|
inputText = sendController.text =
|
|
|
|
editEvent!.getDisplayEvent(timeline!).calcLocalizedBodyFallback(
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
withSenderNamePrefix: false,
|
|
|
|
hideReply: true,
|
|
|
|
);
|
2021-04-15 13:03:14 +02:00
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
|
|
|
inputFocus.requestFocus();
|
|
|
|
}
|
2021-03-28 09:20:34 +02:00
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void goToNewRoomAction() async {
|
|
|
|
if (OkCancelResult.ok !=
|
|
|
|
await showOkCancelAlertDialog(
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-04-15 13:03:14 +02:00
|
|
|
context: context,
|
2022-01-29 12:35:03 +01:00
|
|
|
title: L10n.of(context)!.goToTheNewRoom,
|
2023-03-25 15:06:12 +01:00
|
|
|
message: room
|
2022-01-29 12:35:03 +01:00
|
|
|
.getState(EventTypes.RoomTombstone)!
|
2021-04-15 13:03:14 +02:00
|
|
|
.parsedTombstoneContent
|
|
|
|
.body,
|
2022-01-29 12:35:03 +01:00
|
|
|
okLabel: L10n.of(context)!.ok,
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
2021-04-15 13:03:14 +02:00
|
|
|
)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final result = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
2023-03-25 15:06:12 +01:00
|
|
|
future: () => room.client.joinRoom(
|
|
|
|
room
|
2023-03-02 10:57:52 +01:00
|
|
|
.getState(EventTypes.RoomTombstone)!
|
|
|
|
.parsedTombstoneContent
|
|
|
|
.replacementRoom,
|
|
|
|
),
|
2021-04-15 13:03:14 +02:00
|
|
|
);
|
|
|
|
await showFutureLoadingDialog(
|
|
|
|
context: context,
|
2023-03-25 15:06:12 +01:00
|
|
|
future: room.leave,
|
2021-04-15 13:03:14 +02:00
|
|
|
);
|
|
|
|
if (result.error == null) {
|
2022-01-29 12:35:03 +01:00
|
|
|
VRouter.of(context).toSegments(['rooms', result.result!]);
|
2021-04-15 13:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
2020-11-07 10:18:51 +01:00
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void onSelectMessage(Event event) {
|
|
|
|
if (!event.redacted) {
|
|
|
|
if (selectedEvents.contains(event)) {
|
|
|
|
setState(
|
|
|
|
() => selectedEvents.remove(event),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
setState(
|
|
|
|
() => selectedEvents.add(event),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
selectedEvents.sort(
|
|
|
|
(a, b) => a.originServerTs.compareTo(b.originServerTs),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-11-08 15:40:06 +01:00
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
int? findChildIndexCallback(Key key, Map<String, int> thisEventsKeyMap) {
|
2021-04-15 13:03:14 +02:00
|
|
|
// this method is called very often. As such, it has to be optimized for speed.
|
2021-10-14 18:09:30 +02:00
|
|
|
if (key is! ValueKey) {
|
2021-04-15 13:03:14 +02:00
|
|
|
return null;
|
|
|
|
}
|
2022-01-29 12:35:03 +01:00
|
|
|
final eventId = key.value;
|
2021-10-14 18:09:30 +02:00
|
|
|
if (eventId is! String) {
|
2021-04-15 13:03:14 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
// first fetch the last index the event was at
|
|
|
|
final index = thisEventsKeyMap[eventId];
|
|
|
|
if (index == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
// we need to +1 as 0 is the typing thing at the bottom
|
|
|
|
return index + 1;
|
|
|
|
}
|
2021-02-25 09:11:17 +01:00
|
|
|
|
2021-10-16 09:59:38 +02:00
|
|
|
void onInputBarSubmitted(_) {
|
2021-04-15 13:03:14 +02:00
|
|
|
send();
|
|
|
|
FocusScope.of(context).requestFocus(inputFocus);
|
|
|
|
}
|
2020-11-07 10:18:51 +01:00
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void onAddPopupMenuButtonSelected(String choice) {
|
|
|
|
if (choice == 'file') {
|
|
|
|
sendFileAction();
|
2021-07-23 14:24:52 +02:00
|
|
|
}
|
|
|
|
if (choice == 'image') {
|
2021-04-15 13:03:14 +02:00
|
|
|
sendImageAction();
|
|
|
|
}
|
|
|
|
if (choice == 'camera') {
|
|
|
|
openCameraAction();
|
|
|
|
}
|
2021-12-22 09:45:36 +01:00
|
|
|
if (choice == 'camera-video') {
|
|
|
|
openVideoCameraAction();
|
|
|
|
}
|
2021-07-23 14:24:52 +02:00
|
|
|
if (choice == 'sticker') {
|
|
|
|
sendStickerAction();
|
|
|
|
}
|
2021-08-01 09:53:43 +02:00
|
|
|
if (choice == 'location') {
|
|
|
|
sendLocationAction();
|
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
2020-08-12 11:30:31 +02:00
|
|
|
|
2022-02-14 18:44:37 +01:00
|
|
|
unpinEvent(String eventId) async {
|
|
|
|
final response = await showOkCancelAlertDialog(
|
|
|
|
context: context,
|
|
|
|
title: L10n.of(context)!.unpin,
|
|
|
|
message: L10n.of(context)!.confirmEventUnpin,
|
|
|
|
okLabel: L10n.of(context)!.unpin,
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
|
|
|
);
|
|
|
|
if (response == OkCancelResult.ok) {
|
2023-03-25 15:06:12 +01:00
|
|
|
final events = room.pinnedEventIds
|
2022-02-14 18:44:37 +01:00
|
|
|
..removeWhere((oldEvent) => oldEvent == eventId);
|
2022-02-15 12:47:22 +01:00
|
|
|
showFutureLoadingDialog(
|
|
|
|
context: context,
|
2023-03-25 15:06:12 +01:00
|
|
|
future: () => room.setPinnedEvents(events),
|
2022-02-15 12:47:22 +01:00
|
|
|
);
|
2022-02-14 18:44:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pinEvent() {
|
2022-02-16 12:11:25 +01:00
|
|
|
final pinnedEventIds = room.pinnedEventIds;
|
|
|
|
final selectedEventIds = selectedEvents.map((e) => e.eventId).toSet();
|
2022-02-17 14:02:17 +01:00
|
|
|
final unpin = selectedEventIds.length == 1 &&
|
|
|
|
pinnedEventIds.contains(selectedEventIds.single);
|
|
|
|
if (unpin) {
|
|
|
|
pinnedEventIds.removeWhere(selectedEventIds.contains);
|
|
|
|
} else {
|
|
|
|
pinnedEventIds.addAll(selectedEventIds);
|
|
|
|
}
|
2022-02-15 12:47:22 +01:00
|
|
|
showFutureLoadingDialog(
|
|
|
|
context: context,
|
2022-02-17 14:02:17 +01:00
|
|
|
future: () => room.setPinnedEvents(pinnedEventIds),
|
2022-02-14 18:44:37 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-30 13:32:39 +01:00
|
|
|
Timer? _storeInputTimeoutTimer;
|
|
|
|
static const Duration _storeInputTimeout = Duration(milliseconds: 500);
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void onInputBarChanged(String text) {
|
2022-12-30 13:32:39 +01:00
|
|
|
_storeInputTimeoutTimer?.cancel();
|
|
|
|
_storeInputTimeoutTimer = Timer(_storeInputTimeout, () async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await prefs.setString('draft_$roomId', text);
|
|
|
|
});
|
2022-02-17 21:12:47 +01:00
|
|
|
setReadMarker();
|
2023-03-25 14:57:27 +01:00
|
|
|
if (text.endsWith(' ') && Matrix.of(context).hasComplexBundles) {
|
2021-09-21 09:08:18 +02:00
|
|
|
final clients = currentRoomBundle;
|
|
|
|
for (final client in clients) {
|
2022-01-29 12:35:03 +01:00
|
|
|
final prefix = client!.sendPrefix;
|
|
|
|
if ((prefix.isNotEmpty) &&
|
2021-09-21 09:08:18 +02:00
|
|
|
text.toLowerCase() == '${prefix.toLowerCase()} ') {
|
|
|
|
setSendingClient(client);
|
|
|
|
setState(() {
|
|
|
|
inputText = '';
|
|
|
|
sendController.text = '';
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-09-19 13:48:23 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-15 13:03:14 +02:00
|
|
|
typingCoolDown?.cancel();
|
2021-10-14 18:09:30 +02:00
|
|
|
typingCoolDown = Timer(const Duration(seconds: 2), () {
|
2021-04-15 13:03:14 +02:00
|
|
|
typingCoolDown = null;
|
|
|
|
currentlyTyping = false;
|
2023-03-25 15:06:12 +01:00
|
|
|
room.setTyping(false);
|
2021-04-15 13:03:14 +02:00
|
|
|
});
|
2021-10-14 18:09:30 +02:00
|
|
|
typingTimeout ??= Timer(const Duration(seconds: 30), () {
|
2021-04-15 13:03:14 +02:00
|
|
|
typingTimeout = null;
|
|
|
|
currentlyTyping = false;
|
|
|
|
});
|
|
|
|
if (!currentlyTyping) {
|
|
|
|
currentlyTyping = true;
|
2023-03-25 15:06:12 +01:00
|
|
|
room.setTyping(true, timeout: const Duration(seconds: 30).inMilliseconds);
|
2021-04-15 13:03:14 +02:00
|
|
|
}
|
2021-05-20 13:33:06 +02:00
|
|
|
setState(() => inputText = text);
|
2021-04-15 13:03:14 +02:00
|
|
|
}
|
2020-08-12 11:30:31 +02:00
|
|
|
|
2023-01-08 12:32:35 +01:00
|
|
|
bool get isArchived =>
|
2023-03-25 15:06:12 +01:00
|
|
|
{Membership.leave, Membership.ban}.contains(room.membership);
|
2023-01-08 12:32:35 +01:00
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
void showEventInfo([Event? event]) =>
|
2021-11-13 13:06:36 +01:00
|
|
|
(event ?? selectedEvents.single).showInfoDialog(context);
|
|
|
|
|
2022-02-15 09:25:13 +01:00
|
|
|
void onPhoneButtonTap() async {
|
|
|
|
// VoIP required Android SDK 21
|
|
|
|
if (PlatformInfos.isAndroid) {
|
|
|
|
DeviceInfoPlugin().androidInfo.then((value) {
|
2022-11-03 15:37:40 +01:00
|
|
|
if (value.version.sdkInt < 21) {
|
2022-02-15 09:25:13 +01:00
|
|
|
Navigator.pop(context);
|
2022-02-17 09:52:53 +01:00
|
|
|
showOkAlertDialog(
|
2022-02-15 09:25:13 +01:00
|
|
|
context: context,
|
2022-02-17 09:52:53 +01:00
|
|
|
title: L10n.of(context)!.unsupportedAndroidVersion,
|
|
|
|
message: L10n.of(context)!.unsupportedAndroidVersionLong,
|
|
|
|
okLabel: L10n.of(context)!.close,
|
2022-02-15 09:25:13 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-02-17 09:52:53 +01:00
|
|
|
final callType = await showModalActionSheet<CallType>(
|
|
|
|
context: context,
|
2022-02-17 15:07:29 +01:00
|
|
|
title: L10n.of(context)!.warning,
|
|
|
|
message: L10n.of(context)!.videoCallsBetaWarning,
|
2022-02-17 09:52:53 +01:00
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
|
|
|
actions: [
|
|
|
|
SheetAction(
|
|
|
|
label: L10n.of(context)!.voiceCall,
|
|
|
|
icon: Icons.phone_outlined,
|
|
|
|
key: CallType.kVoice,
|
|
|
|
),
|
|
|
|
SheetAction(
|
|
|
|
label: L10n.of(context)!.videoCall,
|
|
|
|
icon: Icons.video_call_outlined,
|
|
|
|
key: CallType.kVideo,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
if (callType == null) return;
|
2022-02-15 09:25:13 +01:00
|
|
|
|
|
|
|
final success = await showFutureLoadingDialog(
|
2023-03-02 10:57:52 +01:00
|
|
|
context: context,
|
|
|
|
future: () =>
|
|
|
|
Matrix.of(context).voipPlugin!.voip.requestTurnServerCredentials(),
|
|
|
|
);
|
2022-02-15 09:25:13 +01:00
|
|
|
if (success.result != null) {
|
|
|
|
final voipPlugin = Matrix.of(context).voipPlugin;
|
2023-01-26 09:47:30 +01:00
|
|
|
try {
|
2023-03-25 15:06:12 +01:00
|
|
|
await voipPlugin!.voip.inviteToCall(room.id, callType);
|
2023-01-26 09:47:30 +01:00
|
|
|
} catch (e) {
|
2022-02-15 09:25:13 +01:00
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2023-01-26 09:47:30 +01:00
|
|
|
SnackBar(content: Text(e.toLocalizedString(context))),
|
2022-02-15 09:25:13 +01:00
|
|
|
);
|
2023-01-26 09:47:30 +01:00
|
|
|
}
|
2022-02-15 09:25:13 +01:00
|
|
|
} else {
|
|
|
|
await showOkAlertDialog(
|
|
|
|
context: context,
|
|
|
|
title: L10n.of(context)!.unavailable,
|
|
|
|
okLabel: L10n.of(context)!.next,
|
|
|
|
useRootNavigator: false,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:03:14 +02:00
|
|
|
void cancelReplyEventAction() => setState(() {
|
|
|
|
if (editEvent != null) {
|
|
|
|
inputText = sendController.text = pendingText;
|
|
|
|
pendingText = '';
|
|
|
|
}
|
|
|
|
replyEvent = null;
|
|
|
|
editEvent = null;
|
|
|
|
});
|
2020-08-12 11:30:31 +02:00
|
|
|
|
|
|
|
@override
|
2021-05-23 18:46:15 +02:00
|
|
|
Widget build(BuildContext context) => ChatView(this);
|
2020-08-12 11:30:31 +02:00
|
|
|
}
|
2022-02-14 13:49:46 +01:00
|
|
|
|
|
|
|
enum EmojiPickerType { reaction, keyboard }
|