2020-01-05 11:27:03 +00:00
|
|
|
import 'dart:async';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'dart:io';
|
2020-10-03 11:11:07 +00:00
|
|
|
|
2024-03-05 09:11:49 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2020-02-09 14:15:29 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
|
|
|
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
2024-08-08 17:06:42 +00:00
|
|
|
import 'package:collection/collection.dart';
|
2021-11-28 10:43:36 +00:00
|
|
|
import 'package:desktop_drop/desktop_drop.dart';
|
2022-02-15 08:25:13 +00:00
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
2022-02-14 12:49:46 +00:00
|
|
|
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
2023-08-02 10:08:23 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:image_picker/image_picker.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-07-24 08:35:18 +00:00
|
|
|
import 'package:record/record.dart';
|
2020-09-19 17:21:33 +00:00
|
|
|
import 'package:scroll_to_index/scroll_to_index.dart';
|
2022-12-30 12:32:39 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2024-03-06 14:45:00 +00:00
|
|
|
import 'package:universal_html/html.dart' as html;
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2023-07-27 16:15:50 +00:00
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
2024-04-07 08:30:21 +00:00
|
|
|
import 'package:fluffychat/config/setting_keys.dart';
|
2023-08-12 11:37:42 +00:00
|
|
|
import 'package:fluffychat/config/themes.dart';
|
2021-11-09 20:32:16 +00:00
|
|
|
import 'package:fluffychat/pages/chat/chat_view.dart';
|
2021-11-13 12:06:36 +00:00
|
|
|
import 'package:fluffychat/pages/chat/event_info_dialog.dart';
|
2021-11-09 20:32:16 +00:00
|
|
|
import 'package:fluffychat/pages/chat/recording_dialog.dart';
|
2023-08-12 11:37:42 +00:00
|
|
|
import 'package:fluffychat/pages/chat_details/chat_details.dart';
|
2023-05-16 16:45:39 +00:00
|
|
|
import 'package:fluffychat/utils/error_reporter.dart';
|
2024-10-03 19:20:34 +00:00
|
|
|
import 'package:fluffychat/utils/file_selector.dart';
|
2022-12-30 16:54:01 +00:00
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
|
2024-07-28 07:52:27 +00:00
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/filtered_timeline_extension.dart';
|
2022-12-30 16:54:01 +00:00
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
2022-02-15 08:25:13 +00:00
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-11-09 20:32:16 +00:00
|
|
|
import '../../utils/account_bundles.dart';
|
|
|
|
import '../../utils/localized_exception_extension.dart';
|
2021-11-28 10:43:36 +00:00
|
|
|
import 'send_file_dialog.dart';
|
|
|
|
import 'send_location_dialog.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2023-03-25 14:06:12 +00:00
|
|
|
class ChatPage extends StatelessWidget {
|
2023-08-07 16:40:02 +00:00
|
|
|
final String roomId;
|
2024-01-03 12:37:36 +00:00
|
|
|
final String? shareText;
|
2024-04-17 07:26:22 +00:00
|
|
|
final String? eventId;
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2023-08-07 16:40:02 +00:00
|
|
|
const ChatPage({
|
2023-10-28 11:03:16 +00:00
|
|
|
super.key,
|
2023-08-07 16:40:02 +00:00
|
|
|
required this.roomId,
|
2024-04-17 07:26:22 +00:00
|
|
|
this.eventId,
|
2024-01-03 12:37:36 +00:00
|
|
|
this.shareText,
|
2023-10-28 11:03:16 +00:00
|
|
|
});
|
2023-03-25 14:06:12 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-08-07 16:40:02 +00:00
|
|
|
final room = Matrix.of(context).client.getRoomById(roomId);
|
2023-03-25 14:06:12 +00:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-08-12 11:37:42 +00:00
|
|
|
|
2024-04-07 08:30:21 +00:00
|
|
|
return ChatPageWithRoom(
|
2024-05-28 07:50:09 +00:00
|
|
|
key: Key('chat_page_${roomId}_$eventId'),
|
2024-04-07 08:30:21 +00:00
|
|
|
room: room,
|
|
|
|
shareText: shareText,
|
2024-04-17 07:26:22 +00:00
|
|
|
eventId: eventId,
|
2023-08-07 16:40:02 +00:00
|
|
|
);
|
2023-03-25 14:06:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChatPageWithRoom extends StatefulWidget {
|
|
|
|
final Room room;
|
2024-01-03 12:37:36 +00:00
|
|
|
final String? shareText;
|
2024-04-17 07:26:22 +00:00
|
|
|
final String? eventId;
|
2023-03-25 14:06:12 +00:00
|
|
|
|
|
|
|
const ChatPageWithRoom({
|
2023-10-28 11:03:16 +00:00
|
|
|
super.key,
|
2023-03-25 14:06:12 +00:00
|
|
|
required this.room,
|
2024-01-03 12:37:36 +00:00
|
|
|
this.shareText,
|
2024-04-17 07:26:22 +00:00
|
|
|
this.eventId,
|
2023-10-28 11:03:16 +00:00
|
|
|
});
|
2020-01-23 11:11:57 +00:00
|
|
|
|
2020-01-01 18:10:13 +00:00
|
|
|
@override
|
2021-04-15 11:03:14 +00:00
|
|
|
ChatController createState() => ChatController();
|
2020-01-01 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 08:41:52 +00:00
|
|
|
class ChatController extends State<ChatPageWithRoom>
|
|
|
|
with WidgetsBindingObserver {
|
2023-05-08 04:56:40 +00:00
|
|
|
Room get room => sendingClient.getRoomById(roomId) ?? widget.room;
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2023-03-25 13:58:51 +00:00
|
|
|
late Client sendingClient;
|
2021-09-19 11:48:23 +00:00
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
Timeline? timeline;
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2024-08-11 06:55:10 +00:00
|
|
|
late final String readMarkerEventId;
|
2023-03-23 14:02:32 +00:00
|
|
|
|
2023-03-25 14:06:12 +00:00
|
|
|
String get roomId => widget.room.id;
|
2021-05-23 11:11:55 +00:00
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
final AutoScrollController scrollController = AutoScrollController();
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2020-01-24 10:51:23 +00:00
|
|
|
FocusNode inputFocus = FocusNode();
|
2024-03-06 14:23:50 +00:00
|
|
|
StreamSubscription<html.Event>? onFocusSub;
|
2020-01-24 10:51:23 +00:00
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
Timer? typingCoolDown;
|
|
|
|
Timer? typingTimeout;
|
2020-01-05 11:27:03 +00:00
|
|
|
bool currentlyTyping = false;
|
2021-11-28 10:43:36 +00:00
|
|
|
bool dragging = false;
|
|
|
|
|
|
|
|
void onDragEntered(_) => setState(() => dragging = true);
|
2022-02-02 13:31:15 +00:00
|
|
|
|
2021-11-28 10:43:36 +00:00
|
|
|
void onDragExited(_) => setState(() => dragging = false);
|
2022-02-02 13:31:15 +00:00
|
|
|
|
2021-11-28 10:43:36 +00:00
|
|
|
void onDragDone(DropDoneDetails details) async {
|
|
|
|
setState(() => dragging = false);
|
2024-01-31 06:46:13 +00:00
|
|
|
if (details.files.isEmpty) return;
|
2022-07-10 07:26:16 +00:00
|
|
|
|
2023-10-29 08:32:06 +00:00
|
|
|
await showAdaptiveDialog(
|
2022-07-10 07:26:16 +00:00
|
|
|
context: context,
|
|
|
|
builder: (c) => SendFileDialog(
|
2024-09-22 13:45:41 +00:00
|
|
|
files: details.files,
|
2023-03-25 14:06:12 +00:00
|
|
|
room: room,
|
2024-09-22 17:18:08 +00:00
|
|
|
outerContext: context,
|
2022-07-10 07:26:16 +00:00
|
|
|
),
|
|
|
|
);
|
2021-11-28 10:43:36 +00:00
|
|
|
}
|
2020-01-05 11:27:03 +00:00
|
|
|
|
2021-12-27 14:35:25 +00:00
|
|
|
bool get canSaveSelectedEvent =>
|
|
|
|
selectedEvents.length == 1 &&
|
|
|
|
{
|
|
|
|
MessageTypes.Video,
|
|
|
|
MessageTypes.Image,
|
|
|
|
MessageTypes.Sticker,
|
|
|
|
MessageTypes.Audio,
|
|
|
|
MessageTypes.File,
|
|
|
|
}.contains(selectedEvents.single.messageType);
|
|
|
|
|
2022-08-21 06:42:02 +00:00
|
|
|
void saveSelectedEvent(context) => selectedEvents.single.saveFile(context);
|
2021-12-27 14:35:25 +00:00
|
|
|
|
2020-04-02 11:14:39 +00:00
|
|
|
List<Event> selectedEvents = [];
|
2020-02-09 14:15:29 +00:00
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
final Set<String> unfolded = {};
|
2020-11-22 18:34:19 +00:00
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
Event? replyEvent;
|
2020-02-09 14:15:29 +00:00
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
Event? editEvent;
|
2020-08-12 09:30:31 +00:00
|
|
|
|
2023-05-09 13:14:35 +00:00
|
|
|
bool _scrolledUp = false;
|
|
|
|
|
|
|
|
bool get showScrollDownButton =>
|
|
|
|
_scrolledUp || timeline?.allowNewEvent == false;
|
2020-02-09 15:58:49 +00:00
|
|
|
|
2020-02-09 14:15:29 +00:00
|
|
|
bool get selectMode => selectedEvents.isNotEmpty;
|
|
|
|
|
2020-02-14 13:34:28 +00:00
|
|
|
final int _loadHistoryCount = 100;
|
|
|
|
|
2020-10-23 15:45:22 +00:00
|
|
|
String pendingText = '';
|
|
|
|
|
2021-05-20 11:46:52 +00:00
|
|
|
bool showEmojiPicker = false;
|
|
|
|
|
2023-01-06 07:54:17 +00:00
|
|
|
void recreateChat() async {
|
|
|
|
final room = this.room;
|
2023-03-25 14:06:12 +00:00
|
|
|
final userId = room.directChatMatrixID;
|
|
|
|
if (userId == null) {
|
2023-01-06 07:54:17 +00:00
|
|
|
throw Exception(
|
2023-03-02 09:57:52 +00:00
|
|
|
'Try to recreate a room with is not a DM room. This should not be possible from the UI!',
|
|
|
|
);
|
2023-01-06 07:54:17 +00:00
|
|
|
}
|
2023-12-22 11:45:49 +00:00
|
|
|
await showFutureLoadingDialog(
|
2023-03-02 09:57:52 +00:00
|
|
|
context: context,
|
2023-12-22 11:45:49 +00:00
|
|
|
future: () => room.invite(userId),
|
2023-03-02 09:57:52 +00:00
|
|
|
);
|
2023-01-06 07:54:17 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 09:05:54 +00:00
|
|
|
void leaveChat() async {
|
|
|
|
final success = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: room.leave,
|
|
|
|
);
|
|
|
|
if (success.error != null) return;
|
2023-08-07 16:40:02 +00:00
|
|
|
context.go('/rooms');
|
2023-01-15 09:05:54 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 12:49:46 +00:00
|
|
|
EmojiPickerType emojiPickerType = EmojiPickerType.keyboard;
|
|
|
|
|
2023-12-26 17:19:33 +00:00
|
|
|
void requestHistory([_]) async {
|
2023-06-13 06:41:49 +00:00
|
|
|
Logs().v('Requesting history...');
|
2024-08-08 17:06:42 +00:00
|
|
|
await timeline?.requestHistory(historyCount: _loadHistoryCount);
|
2023-03-22 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void requestFuture() async {
|
2023-03-22 12:16:00 +00:00
|
|
|
final timeline = this.timeline;
|
|
|
|
if (timeline == null) return;
|
2023-06-13 06:41:49 +00:00
|
|
|
Logs().v('Requesting future...');
|
2023-12-26 18:12:31 +00:00
|
|
|
final mostRecentEventId = timeline.events.first.eventId;
|
|
|
|
await timeline.requestFuture(historyCount: _loadHistoryCount);
|
|
|
|
setReadMarker(eventId: mostRecentEventId);
|
2020-09-19 17:21:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _updateScrollController() {
|
2020-11-16 10:31:31 +00:00
|
|
|
if (!mounted) {
|
|
|
|
return;
|
|
|
|
}
|
2022-03-20 14:46:03 +00:00
|
|
|
if (!scrollController.hasClients) return;
|
2023-03-22 08:16:07 +00:00
|
|
|
if (timeline?.allowNewEvent == false ||
|
2023-05-09 13:14:35 +00:00
|
|
|
scrollController.position.pixels > 0 && _scrolledUp == false) {
|
|
|
|
setState(() => _scrolledUp = true);
|
2023-11-04 17:20:01 +00:00
|
|
|
} else if (scrollController.position.pixels <= 0 && _scrolledUp == true) {
|
2023-05-09 13:14:35 +00:00
|
|
|
setState(() => _scrolledUp = false);
|
2024-02-29 17:06:06 +00:00
|
|
|
setReadMarker();
|
2020-02-14 13:37:31 +00:00
|
|
|
}
|
2023-11-04 17:20:01 +00:00
|
|
|
|
|
|
|
if (scrollController.position.pixels == 0 ||
|
|
|
|
scrollController.position.pixels == 64) {
|
|
|
|
requestFuture();
|
|
|
|
}
|
2020-02-14 13:34:28 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 12:32:39 +00:00
|
|
|
void _loadDraft() async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
2024-01-03 12:37:36 +00:00
|
|
|
final draft = widget.shareText ?? prefs.getString('draft_$roomId');
|
2022-12-30 12:32:39 +00:00
|
|
|
if (draft != null && draft.isNotEmpty) {
|
|
|
|
sendController.text = draft;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-01 18:10:13 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2021-04-15 11:03:14 +00:00
|
|
|
scrollController.addListener(_updateScrollController);
|
2022-02-14 12:49:46 +00:00
|
|
|
inputFocus.addListener(_inputFocusListener);
|
2024-04-17 07:26:22 +00:00
|
|
|
|
2022-12-30 12:32:39 +00:00
|
|
|
_loadDraft();
|
2020-01-01 18:10:13 +00:00
|
|
|
super.initState();
|
2024-04-07 08:30:21 +00:00
|
|
|
_displayChatDetailsColumn = ValueNotifier(
|
|
|
|
Matrix.of(context).store.getBool(SettingKeys.displayChatDetailsColumn) ??
|
|
|
|
false,
|
|
|
|
);
|
2024-04-17 07:26:22 +00:00
|
|
|
|
2023-03-25 13:58:51 +00:00
|
|
|
sendingClient = Matrix.of(context).client;
|
2024-08-11 06:55:10 +00:00
|
|
|
readMarkerEventId = room.hasNewMessages ? room.fullyRead : '';
|
2024-02-29 17:06:06 +00:00
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2023-10-14 07:17:00 +00:00
|
|
|
_tryLoadTimeline();
|
2024-03-06 14:23:50 +00:00
|
|
|
if (kIsWeb) {
|
|
|
|
onFocusSub = html.window.onFocus.listen((_) => setReadMarker());
|
|
|
|
}
|
2023-10-14 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _tryLoadTimeline() async {
|
2024-05-28 07:50:09 +00:00
|
|
|
final initialEventId = widget.eventId;
|
|
|
|
loadTimelineFuture = _getTimeline();
|
2023-10-14 07:17:00 +00:00
|
|
|
try {
|
|
|
|
await loadTimelineFuture;
|
2024-05-28 07:50:09 +00:00
|
|
|
if (initialEventId != null) scrollToEventId(initialEventId);
|
|
|
|
|
2024-08-25 15:47:23 +00:00
|
|
|
var readMarkerEventIndex = readMarkerEventId.isEmpty
|
2024-08-11 06:55:10 +00:00
|
|
|
? -1
|
|
|
|
: timeline!.events
|
2024-08-25 15:47:23 +00:00
|
|
|
.where((e) => e.isVisibleInGui || e.eventId == readMarkerEventId)
|
2024-08-11 06:55:10 +00:00
|
|
|
.toList()
|
|
|
|
.indexWhere((e) => e.eventId == readMarkerEventId);
|
|
|
|
|
2024-08-25 15:47:23 +00:00
|
|
|
// Read marker is existing but not found in first events. Try a single
|
|
|
|
// requestHistory call before opening timeline on event context:
|
|
|
|
if (readMarkerEventId.isNotEmpty && readMarkerEventIndex == -1) {
|
|
|
|
await timeline?.requestHistory(historyCount: _loadHistoryCount);
|
|
|
|
readMarkerEventIndex = timeline!.events
|
|
|
|
.where((e) => e.isVisibleInGui || e.eventId == readMarkerEventId)
|
|
|
|
.toList()
|
|
|
|
.indexWhere((e) => e.eventId == readMarkerEventId);
|
|
|
|
}
|
|
|
|
|
2024-08-11 06:55:10 +00:00
|
|
|
if (readMarkerEventIndex > 1) {
|
|
|
|
Logs().v('Scroll up to visible event', readMarkerEventId);
|
|
|
|
scrollToEventId(readMarkerEventId, highlightEvent: false);
|
2023-10-14 07:17:00 +00:00
|
|
|
return;
|
2024-08-11 06:55:10 +00:00
|
|
|
} else if (readMarkerEventId.isNotEmpty && readMarkerEventIndex == -1) {
|
|
|
|
_showScrollUpMaterialBanner(readMarkerEventId);
|
2023-10-14 07:17:00 +00:00
|
|
|
}
|
2024-08-11 06:55:10 +00:00
|
|
|
|
2024-08-25 07:02:51 +00:00
|
|
|
// Mark room as read on first visit if requirements are fulfilled
|
|
|
|
setReadMarker();
|
|
|
|
|
2023-10-14 07:17:00 +00:00
|
|
|
if (!mounted) return;
|
|
|
|
} catch (e, s) {
|
|
|
|
ErrorReporter(context, 'Unable to load timeline').onErrorCallback(e, s);
|
|
|
|
rethrow;
|
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 07:17:00 +00:00
|
|
|
String? scrollUpBannerEventId;
|
|
|
|
|
|
|
|
void discardScrollUpBannerEventId() => setState(() {
|
|
|
|
scrollUpBannerEventId = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
void _showScrollUpMaterialBanner(String eventId) => setState(() {
|
|
|
|
scrollUpBannerEventId = eventId;
|
|
|
|
});
|
|
|
|
|
2020-01-05 11:27:03 +00:00
|
|
|
void updateView() {
|
2020-01-23 11:11:57 +00:00
|
|
|
if (!mounted) return;
|
2024-08-27 15:22:01 +00:00
|
|
|
setReadMarker();
|
2022-10-15 08:38:06 +00:00
|
|
|
setState(() {});
|
2021-02-25 08:11:17 +00:00
|
|
|
}
|
|
|
|
|
2023-03-25 14:23:14 +00:00
|
|
|
Future<void>? loadTimelineFuture;
|
2020-09-19 17:21:33 +00:00
|
|
|
|
2023-12-26 19:08:07 +00:00
|
|
|
int? animateInEventIndex;
|
|
|
|
|
|
|
|
void onInsert(int i) {
|
2024-08-11 06:55:10 +00:00
|
|
|
// setState will be called by updateView() anyway
|
|
|
|
animateInEventIndex = i;
|
|
|
|
}
|
|
|
|
|
2023-04-14 12:23:58 +00:00
|
|
|
Future<void> _getTimeline({
|
|
|
|
String? eventContextId,
|
|
|
|
}) async {
|
2023-03-25 14:23:14 +00:00
|
|
|
await Matrix.of(context).client.roomsLoading;
|
|
|
|
await Matrix.of(context).client.accountDataLoading;
|
2023-05-08 13:25:36 +00:00
|
|
|
if (eventContextId != null &&
|
|
|
|
(!eventContextId.isValidMatrixId || eventContextId.sigil != '\$')) {
|
2023-05-05 05:54:19 +00:00
|
|
|
eventContextId = null;
|
|
|
|
}
|
2023-04-14 12:23:58 +00:00
|
|
|
try {
|
2024-08-08 17:06:42 +00:00
|
|
|
timeline?.cancelSubscriptions();
|
2023-10-14 07:17:00 +00:00
|
|
|
timeline = await room.getTimeline(
|
|
|
|
onUpdate: updateView,
|
|
|
|
eventContextId: eventContextId,
|
2023-12-26 19:08:07 +00:00
|
|
|
onInsert: onInsert,
|
2023-10-14 07:17:00 +00:00
|
|
|
);
|
2023-05-31 07:22:14 +00:00
|
|
|
} catch (e, s) {
|
|
|
|
Logs().w('Unable to load timeline on event ID $eventContextId', e, s);
|
2023-04-14 12:23:58 +00:00
|
|
|
if (!mounted) return;
|
2023-12-26 19:08:07 +00:00
|
|
|
timeline = await room.getTimeline(
|
|
|
|
onUpdate: updateView,
|
|
|
|
onInsert: onInsert,
|
|
|
|
);
|
2023-04-14 12:23:58 +00:00
|
|
|
if (!mounted) return;
|
2023-05-31 07:22:14 +00:00
|
|
|
if (e is TimeoutException || e is IOException) {
|
2023-10-14 07:17:00 +00:00
|
|
|
_showScrollUpMaterialBanner(eventContextId!);
|
2023-05-31 07:22:14 +00:00
|
|
|
}
|
2023-04-14 12:23:58 +00:00
|
|
|
}
|
|
|
|
timeline!.requestKeys(onlineKeyBackupOnly: false);
|
2023-10-14 07:17:00 +00:00
|
|
|
if (room.markedUnread) room.markUnread(false);
|
2023-03-25 14:23:14 +00:00
|
|
|
|
2023-03-22 08:16:07 +00:00
|
|
|
return;
|
2022-02-17 20:12:47 +00:00
|
|
|
}
|
|
|
|
|
2023-12-26 17:51:53 +00:00
|
|
|
String? scrollToEventIdMarker;
|
|
|
|
|
2023-12-29 08:41:52 +00:00
|
|
|
@override
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
if (state != AppLifecycleState.resumed) return;
|
|
|
|
setReadMarker();
|
|
|
|
}
|
|
|
|
|
2022-02-17 20:12:47 +00:00
|
|
|
Future<void>? _setReadMarkerFuture;
|
|
|
|
|
2023-03-22 12:16:00 +00:00
|
|
|
void setReadMarker({String? eventId}) {
|
|
|
|
if (_setReadMarkerFuture != null) return;
|
2024-02-29 17:06:06 +00:00
|
|
|
if (_scrolledUp) return;
|
2023-10-14 07:17:00 +00:00
|
|
|
if (scrollUpBannerEventId != null) return;
|
2024-08-11 06:55:10 +00:00
|
|
|
|
2023-03-25 14:23:14 +00:00
|
|
|
if (eventId == null &&
|
2023-03-25 14:06:12 +00:00
|
|
|
!room.hasNewMessages &&
|
|
|
|
room.notificationCount == 0) {
|
2023-03-22 12:16:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-02-29 17:06:06 +00:00
|
|
|
|
|
|
|
// Do not send read markers when app is not in foreground
|
2024-03-05 09:11:49 +00:00
|
|
|
if (kIsWeb && !Matrix.of(context).webHasFocus) return;
|
|
|
|
if (!kIsWeb &&
|
2024-02-29 17:06:06 +00:00
|
|
|
WidgetsBinding.instance.lifecycleState != AppLifecycleState.resumed) {
|
|
|
|
return;
|
|
|
|
}
|
2023-03-22 12:16:00 +00:00
|
|
|
|
|
|
|
final timeline = this.timeline;
|
|
|
|
if (timeline == null || timeline.events.isEmpty) return;
|
|
|
|
|
2023-10-14 07:17:00 +00:00
|
|
|
Logs().d('Set read marker...', eventId);
|
2023-03-22 12:16:00 +00:00
|
|
|
// ignore: unawaited_futures
|
2024-01-20 08:13:53 +00:00
|
|
|
_setReadMarkerFuture = timeline
|
|
|
|
.setReadMarker(
|
|
|
|
eventId: eventId,
|
|
|
|
public: AppConfig.sendPublicReadReceipts,
|
|
|
|
)
|
|
|
|
.then((_) {
|
2023-03-22 12:16:00 +00:00
|
|
|
_setReadMarkerFuture = null;
|
|
|
|
});
|
2023-09-29 08:22:28 +00:00
|
|
|
if (eventId == null || eventId == timeline.room.lastEvent?.eventId) {
|
2023-08-06 19:13:37 +00:00
|
|
|
Matrix.of(context).backgroundPush?.cancelNotification(roomId);
|
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2020-02-22 07:27:08 +00:00
|
|
|
timeline?.cancelSubscriptions();
|
2020-01-23 11:11:57 +00:00
|
|
|
timeline = null;
|
2022-02-14 12:49:46 +00:00
|
|
|
inputFocus.removeListener(_inputFocusListener);
|
2024-03-06 14:23:50 +00:00
|
|
|
onFocusSub?.cancel();
|
2020-01-01 18:10:13 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2020-01-17 09:41:28 +00:00
|
|
|
TextEditingController sendController = TextEditingController();
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2023-03-25 13:58:51 +00:00
|
|
|
void setSendingClient(Client c) {
|
2023-05-08 04:56:40 +00:00
|
|
|
// first cancel typing with the old sending client
|
2021-09-21 07:13:02 +00:00
|
|
|
if (currentlyTyping) {
|
|
|
|
// no need to have the setting typing to false be blocking
|
|
|
|
typingCoolDown?.cancel();
|
|
|
|
typingCoolDown = null;
|
2023-03-25 14:06:12 +00:00
|
|
|
room.setTyping(false);
|
2021-09-21 07:13:02 +00:00
|
|
|
currentlyTyping = false;
|
|
|
|
}
|
2023-05-08 12:02:15 +00:00
|
|
|
// then cancel the old timeline
|
|
|
|
// fixes bug with read reciepts and quick switching
|
2023-05-16 16:45:39 +00:00
|
|
|
loadTimelineFuture = _getTimeline(eventContextId: room.fullyRead).onError(
|
|
|
|
ErrorReporter(
|
|
|
|
context,
|
|
|
|
'Unable to load timeline after changing sending Client',
|
|
|
|
).onErrorCallback,
|
|
|
|
);
|
2023-05-08 12:02:15 +00:00
|
|
|
|
2021-09-21 07:13:02 +00:00
|
|
|
// then set the new sending client
|
|
|
|
setState(() => sendingClient = c);
|
|
|
|
}
|
2021-09-19 11:48:23 +00:00
|
|
|
|
|
|
|
void setActiveClient(Client c) => setState(() {
|
|
|
|
Matrix.of(context).setActiveClient(c);
|
|
|
|
});
|
|
|
|
|
2021-06-13 22:03:06 +00:00
|
|
|
Future<void> send() async {
|
2021-01-16 18:44:46 +00:00
|
|
|
if (sendController.text.trim().isEmpty) return;
|
2022-12-30 17:24:34 +00:00
|
|
|
_storeInputTimeoutTimer?.cancel();
|
2022-12-30 12:32:39 +00:00
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
prefs.remove('draft_$roomId');
|
2021-06-13 22:03:06 +00:00
|
|
|
var parseCommands = true;
|
|
|
|
|
|
|
|
final commandMatch = RegExp(r'^\/(\w+)').firstMatch(sendController.text);
|
|
|
|
if (commandMatch != null &&
|
2023-05-08 04:56:40 +00:00
|
|
|
!sendingClient.commands.keys.contains(commandMatch[1]!.toLowerCase())) {
|
2022-01-29 11:35:03 +00:00
|
|
|
final l10n = L10n.of(context)!;
|
2021-06-13 22:03:06 +00:00
|
|
|
final dialogResult = await showOkCancelAlertDialog(
|
|
|
|
context: context,
|
|
|
|
title: l10n.commandInvalid,
|
2022-01-29 11:35:03 +00:00
|
|
|
message: l10n.commandMissing(commandMatch[0]!),
|
2021-06-13 22:03:06 +00:00
|
|
|
okLabel: l10n.sendAsText,
|
|
|
|
cancelLabel: l10n.cancel,
|
|
|
|
);
|
2022-01-29 11:35:03 +00:00
|
|
|
if (dialogResult == OkCancelResult.cancel) return;
|
2021-06-13 22:03:06 +00:00
|
|
|
parseCommands = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore: unawaited_futures
|
2023-03-25 14:06:12 +00:00
|
|
|
room.sendTextEvent(
|
2023-03-02 09:57:52 +00:00
|
|
|
sendController.text,
|
|
|
|
inReplyTo: replyEvent,
|
|
|
|
editEventId: editEvent?.eventId,
|
|
|
|
parseCommands: parseCommands,
|
|
|
|
);
|
2021-05-13 10:48:05 +00:00
|
|
|
sendController.value = TextEditingValue(
|
|
|
|
text: pendingText,
|
2021-10-14 16:09:30 +00:00
|
|
|
selection: const TextSelection.collapsed(offset: 0),
|
2021-05-13 10:48:05 +00:00
|
|
|
);
|
2020-02-23 07:52:28 +00:00
|
|
|
|
2020-08-12 09:30:31 +00:00
|
|
|
setState(() {
|
2023-12-23 06:38:45 +00:00
|
|
|
sendController.text = pendingText;
|
2023-12-25 17:07:19 +00:00
|
|
|
_inputTextIsEmpty = pendingText.isEmpty;
|
2020-08-12 09:30:31 +00:00
|
|
|
replyEvent = null;
|
|
|
|
editEvent = null;
|
2020-10-23 15:45:22 +00:00
|
|
|
pendingText = '';
|
2020-08-12 09:30:31 +00:00
|
|
|
});
|
2020-01-01 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void sendFileAction() async {
|
2024-10-03 19:20:34 +00:00
|
|
|
final files = await selectFiles(context, allowMultiple: true);
|
|
|
|
if (files.isEmpty) return;
|
2023-10-29 08:32:06 +00:00
|
|
|
await showAdaptiveDialog(
|
2020-10-04 15:01:54 +00:00
|
|
|
context: context,
|
2021-01-18 09:43:00 +00:00
|
|
|
builder: (c) => SendFileDialog(
|
2024-10-03 19:20:34 +00:00
|
|
|
files: files,
|
2023-03-25 14:06:12 +00:00
|
|
|
room: room,
|
2024-09-22 17:18:08 +00:00
|
|
|
outerContext: context,
|
2020-10-04 15:01:54 +00:00
|
|
|
),
|
|
|
|
);
|
2020-01-01 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 14:56:35 +00:00
|
|
|
void sendImageFromClipBoard(Uint8List? image) async {
|
2024-09-22 13:45:41 +00:00
|
|
|
if (image == null) return;
|
2023-10-29 08:32:06 +00:00
|
|
|
await showAdaptiveDialog(
|
2023-07-20 14:56:35 +00:00
|
|
|
context: context,
|
|
|
|
builder: (c) => SendFileDialog(
|
2024-09-22 13:45:41 +00:00
|
|
|
files: [XFile.fromData(image)],
|
2023-07-20 14:56:35 +00:00
|
|
|
room: room,
|
2024-09-22 17:18:08 +00:00
|
|
|
outerContext: context,
|
2023-07-20 14:56:35 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void sendImageAction() async {
|
2024-10-03 19:20:34 +00:00
|
|
|
final files = await selectFiles(
|
|
|
|
context,
|
|
|
|
allowMultiple: true,
|
2024-10-04 08:04:09 +00:00
|
|
|
type: FileSelectorType.images,
|
2022-07-10 07:26:16 +00:00
|
|
|
);
|
2024-10-03 19:20:34 +00:00
|
|
|
if (files.isEmpty) return;
|
2022-07-10 07:26:16 +00:00
|
|
|
|
2023-10-29 08:32:06 +00:00
|
|
|
await showAdaptiveDialog(
|
2020-10-04 15:01:54 +00:00
|
|
|
context: context,
|
2021-01-18 09:43:00 +00:00
|
|
|
builder: (c) => SendFileDialog(
|
2024-10-03 19:20:34 +00:00
|
|
|
files: files,
|
2023-03-25 14:06:12 +00:00
|
|
|
room: room,
|
2024-09-22 17:18:08 +00:00
|
|
|
outerContext: context,
|
2020-10-04 15:01:54 +00:00
|
|
|
),
|
|
|
|
);
|
2020-01-01 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void openCameraAction() async {
|
2021-07-18 10:17:56 +00:00
|
|
|
// Make sure the textfield is unfocused before opening the camera
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
2021-08-10 12:01:15 +00:00
|
|
|
final file = await ImagePicker().pickImage(source: ImageSource.camera);
|
2020-01-01 18:10:13 +00:00
|
|
|
if (file == null) return;
|
2024-09-22 13:45:41 +00:00
|
|
|
|
2023-10-29 08:32:06 +00:00
|
|
|
await showAdaptiveDialog(
|
2020-10-04 15:01:54 +00:00
|
|
|
context: context,
|
2021-01-18 09:43:00 +00:00
|
|
|
builder: (c) => SendFileDialog(
|
2024-09-22 13:45:41 +00:00
|
|
|
files: [file],
|
2023-03-25 14:06:12 +00:00
|
|
|
room: room,
|
2024-09-22 17:18:08 +00:00
|
|
|
outerContext: context,
|
2020-10-04 15:01:54 +00:00
|
|
|
),
|
|
|
|
);
|
2020-01-01 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 08:45:36 +00:00
|
|
|
void openVideoCameraAction() async {
|
|
|
|
// Make sure the textfield is unfocused before opening the camera
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
2023-10-28 09:47:31 +00:00
|
|
|
final file = await ImagePicker().pickVideo(
|
|
|
|
source: ImageSource.camera,
|
|
|
|
maxDuration: const Duration(minutes: 1),
|
|
|
|
);
|
2021-12-22 08:45:36 +00:00
|
|
|
if (file == null) return;
|
2024-09-22 13:45:41 +00:00
|
|
|
|
2023-10-29 08:32:06 +00:00
|
|
|
await showAdaptiveDialog(
|
2021-12-22 08:45:36 +00:00
|
|
|
context: context,
|
|
|
|
builder: (c) => SendFileDialog(
|
2024-09-22 13:45:41 +00:00
|
|
|
files: [file],
|
2023-03-25 14:06:12 +00:00
|
|
|
room: room,
|
2024-09-22 17:18:08 +00:00
|
|
|
outerContext: context,
|
2021-12-22 08:45:36 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void voiceMessageAction() async {
|
2023-02-13 14:38:08 +00:00
|
|
|
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
2022-06-20 13:35:22 +00:00
|
|
|
if (PlatformInfos.isAndroid) {
|
|
|
|
final info = await DeviceInfoPlugin().androidInfo;
|
2022-11-03 14:37:40 +00:00
|
|
|
if (info.version.sdkInt < 19) {
|
2022-06-20 13:35:22 +00:00
|
|
|
showOkAlertDialog(
|
|
|
|
context: context,
|
|
|
|
title: L10n.of(context)!.unsupportedAndroidVersion,
|
|
|
|
message: L10n.of(context)!.unsupportedAndroidVersionLong,
|
|
|
|
okLabel: L10n.of(context)!.close,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-07 12:37:22 +00:00
|
|
|
if (await AudioRecorder().hasPermission() == false) return;
|
2021-10-30 08:39:00 +00:00
|
|
|
final result = await showDialog<RecordingResult>(
|
2021-01-23 10:17:34 +00:00
|
|
|
context: context,
|
2022-12-30 11:53:42 +00:00
|
|
|
barrierDismissible: false,
|
2021-10-14 16:09:30 +00:00
|
|
|
builder: (c) => const RecordingDialog(),
|
2021-01-23 10:17:34 +00:00
|
|
|
);
|
2020-03-15 10:27:51 +00:00
|
|
|
if (result == null) return;
|
2024-08-05 11:21:12 +00:00
|
|
|
final audioFile = XFile(result.path);
|
2021-10-27 14:53:31 +00:00
|
|
|
final file = MatrixAudioFile(
|
2024-08-05 11:21:12 +00:00
|
|
|
bytes: await audioFile.readAsBytes(),
|
|
|
|
name: result.fileName ?? audioFile.path,
|
2021-10-27 14:53:31 +00:00
|
|
|
);
|
2023-03-25 14:06:12 +00:00
|
|
|
await room.sendFileEvent(
|
2022-03-30 09:46:24 +00:00
|
|
|
file,
|
|
|
|
inReplyTo: replyEvent,
|
|
|
|
extraContent: {
|
2021-10-27 14:53:31 +00:00
|
|
|
'info': {
|
|
|
|
...file.info,
|
2021-10-30 08:39:00 +00:00
|
|
|
'duration': result.duration,
|
2021-10-30 09:03:33 +00:00
|
|
|
},
|
2024-04-13 16:23:02 +00:00
|
|
|
'org.matrix.msc3245.voice': {},
|
2022-01-01 13:17:31 +00:00
|
|
|
'org.matrix.msc1767.audio': {
|
|
|
|
'duration': result.duration,
|
|
|
|
'waveform': result.waveform,
|
|
|
|
},
|
2022-03-30 09:46:24 +00:00
|
|
|
},
|
2023-02-13 14:38:08 +00:00
|
|
|
).catchError((e) {
|
|
|
|
scaffoldMessenger.showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(
|
|
|
|
(e as Object).toLocalizedString(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
});
|
2021-08-12 07:59:42 +00:00
|
|
|
setState(() {
|
|
|
|
replyEvent = null;
|
|
|
|
});
|
2020-03-15 10:27:51 +00:00
|
|
|
}
|
|
|
|
|
2024-02-25 15:14:12 +00:00
|
|
|
void hideEmojiPicker() {
|
|
|
|
setState(() => showEmojiPicker = false);
|
|
|
|
}
|
|
|
|
|
2022-02-14 12:49:46 +00:00
|
|
|
void emojiPickerAction() {
|
2022-02-17 08:18:50 +00:00
|
|
|
if (showEmojiPicker) {
|
|
|
|
inputFocus.requestFocus();
|
|
|
|
} else {
|
|
|
|
inputFocus.unfocus();
|
|
|
|
}
|
2022-02-14 12:49:46 +00:00
|
|
|
emojiPickerType = EmojiPickerType.keyboard;
|
|
|
|
setState(() => showEmojiPicker = !showEmojiPicker);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _inputFocusListener() {
|
2022-02-17 08:18:50 +00:00
|
|
|
if (showEmojiPicker && inputFocus.hasFocus) {
|
|
|
|
emojiPickerType = EmojiPickerType.keyboard;
|
|
|
|
setState(() => showEmojiPicker = false);
|
2022-02-14 12:49:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-01 07:53:43 +00:00
|
|
|
void sendLocationAction() async {
|
2023-10-29 08:32:06 +00:00
|
|
|
await showAdaptiveDialog(
|
2021-08-01 07:53:43 +00:00
|
|
|
context: context,
|
2023-03-25 14:06:12 +00:00
|
|
|
builder: (c) => SendLocationDialog(room: room),
|
2021-08-01 07:53:43 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
String _getSelectedEventString() {
|
2020-05-13 13:58:59 +00:00
|
|
|
var copyString = '';
|
2020-04-02 11:14:39 +00:00
|
|
|
if (selectedEvents.length == 1) {
|
2020-10-03 11:11:07 +00:00
|
|
|
return selectedEvents.first
|
2022-01-29 11:35:03 +00:00
|
|
|
.getDisplayEvent(timeline!)
|
2022-05-30 11:44:05 +00:00
|
|
|
.calcLocalizedBodyFallback(MatrixLocals(L10n.of(context)!));
|
2020-04-02 11:14:39 +00:00
|
|
|
}
|
2021-04-14 08:37:15 +00:00
|
|
|
for (final event in selectedEvents) {
|
2020-05-13 13:58:59 +00:00
|
|
|
if (copyString.isNotEmpty) copyString += '\n\n';
|
2022-05-30 11:44:05 +00:00
|
|
|
copyString += event.getDisplayEvent(timeline!).calcLocalizedBodyFallback(
|
2023-03-02 09:57:52 +00:00
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
withSenderNamePrefix: true,
|
|
|
|
);
|
2020-02-09 14:15:29 +00:00
|
|
|
}
|
|
|
|
return copyString;
|
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void copyEventsAction() {
|
|
|
|
Clipboard.setData(ClipboardData(text: _getSelectedEventString()));
|
2021-11-13 09:20:09 +00:00
|
|
|
setState(() {
|
|
|
|
showEmojiPicker = false;
|
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
2020-02-09 14:15:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void reportEventAction() async {
|
2021-02-01 20:26:02 +00:00
|
|
|
final event = selectedEvents.single;
|
|
|
|
final score = await showConfirmationDialog<int>(
|
2023-03-02 09:57:52 +00: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 20:26:02 +00:00
|
|
|
if (score == null) return;
|
|
|
|
final reason = await showTextInputDialog(
|
2023-03-02 09:57:52 +00:00
|
|
|
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 20:26:02 +00:00
|
|
|
if (reason == null || reason.single.isEmpty) return;
|
|
|
|
final result = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
2021-05-20 11:59:55 +00:00
|
|
|
future: () => Matrix.of(context).client.reportContent(
|
2022-01-29 11:35:03 +00:00
|
|
|
event.roomId!,
|
2021-02-01 20:26:02 +00:00
|
|
|
event.eventId,
|
2021-08-18 15:24:59 +00:00
|
|
|
reason: reason.single,
|
|
|
|
score: score,
|
2021-02-01 20:26:02 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
if (result.error != null) return;
|
2021-11-13 09:20:09 +00:00
|
|
|
setState(() {
|
|
|
|
showEmojiPicker = false;
|
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
2021-05-23 11:11:55 +00:00
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2023-03-02 09:57:52 +00:00
|
|
|
SnackBar(content: Text(L10n.of(context)!.contentHasBeenReported)),
|
|
|
|
);
|
2021-02-01 20:26:02 +00:00
|
|
|
}
|
|
|
|
|
2023-11-05 09:09:02 +00:00
|
|
|
void deleteErrorEventsAction() async {
|
|
|
|
try {
|
|
|
|
if (selectedEvents.any((event) => event.status != EventStatus.error)) {
|
|
|
|
throw Exception(
|
|
|
|
'Tried to delete failed to send events but one event is not failed to sent',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
for (final event in selectedEvents) {
|
2024-05-08 10:42:40 +00:00
|
|
|
await event.cancelSend();
|
2023-11-05 09:09:02 +00:00
|
|
|
}
|
2023-11-05 11:38:19 +00:00
|
|
|
setState(selectedEvents.clear);
|
2023-11-05 09:09:02 +00:00
|
|
|
} catch (e, s) {
|
|
|
|
ErrorReporter(
|
|
|
|
context,
|
|
|
|
'Error while delete error events action',
|
|
|
|
).onErrorCallback(e, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void redactEventsAction() async {
|
2023-09-28 07:04:13 +00:00
|
|
|
final reasonInput = selectedEvents.any((event) => event.status.isSent)
|
|
|
|
? await showTextInputDialog(
|
|
|
|
context: context,
|
|
|
|
title: L10n.of(context)!.redactMessage,
|
|
|
|
message: L10n.of(context)!.redactMessageDescription,
|
|
|
|
isDestructiveAction: true,
|
|
|
|
textFields: [
|
|
|
|
DialogTextField(
|
|
|
|
hintText: L10n.of(context)!.optionalRedactReason,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
okLabel: L10n.of(context)!.remove,
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
|
|
|
)
|
|
|
|
: <String>[];
|
2023-08-12 10:52:55 +00:00
|
|
|
if (reasonInput == null) return;
|
|
|
|
final reason = reasonInput.single.isEmpty ? null : reasonInput.single;
|
2021-04-14 08:37:15 +00:00
|
|
|
for (final event in selectedEvents) {
|
2020-12-25 08:58:34 +00:00
|
|
|
await showFutureLoadingDialog(
|
2023-03-02 09:57:52 +00:00
|
|
|
context: context,
|
|
|
|
future: () async {
|
|
|
|
if (event.status.isSent) {
|
|
|
|
if (event.canRedact) {
|
2023-08-12 10:52:55 +00:00
|
|
|
await event.redactEvent(reason: reason);
|
2021-09-19 11:48:23 +00:00
|
|
|
} else {
|
2023-03-02 09:57:52 +00:00
|
|
|
final client = currentRoomBundle.firstWhere(
|
|
|
|
(cl) => selectedEvents.first.senderId == cl!.userID,
|
|
|
|
orElse: () => null,
|
|
|
|
);
|
|
|
|
if (client == null) {
|
|
|
|
return;
|
|
|
|
}
|
2023-03-25 14:06:12 +00:00
|
|
|
final room = client.getRoomById(roomId)!;
|
2023-08-12 10:52:55 +00:00
|
|
|
await Event.fromJson(event.toJson(), room).redactEvent(
|
|
|
|
reason: reason,
|
|
|
|
);
|
2021-09-19 11:48:23 +00:00
|
|
|
}
|
2023-03-02 09:57:52 +00:00
|
|
|
} else {
|
2024-05-08 10:42:40 +00:00
|
|
|
await event.cancelSend();
|
2023-03-02 09:57:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2020-02-09 14:15:29 +00:00
|
|
|
}
|
2021-11-13 09:20:09 +00:00
|
|
|
setState(() {
|
|
|
|
showEmojiPicker = false;
|
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
2020-02-09 14:15:29 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
List<Client?> get currentRoomBundle {
|
2023-03-25 13:57:27 +00:00
|
|
|
final clients = Matrix.of(context).currentBundle!;
|
2023-03-25 14:06:12 +00:00
|
|
|
clients.removeWhere((c) => c!.getRoomById(roomId) == null);
|
2021-09-19 11:48:23 +00:00
|
|
|
return clients;
|
|
|
|
}
|
|
|
|
|
2020-02-09 14:15:29 +00:00
|
|
|
bool get canRedactSelectedEvents {
|
2023-01-08 11:32:35 +00:00
|
|
|
if (isArchived) return false;
|
2023-03-25 13:57:27 +00:00
|
|
|
final clients = Matrix.of(context).currentBundle;
|
2021-04-14 08:37:15 +00:00
|
|
|
for (final event in selectedEvents) {
|
2023-11-05 09:09:02 +00:00
|
|
|
if (!event.status.isSent) return false;
|
2021-09-19 11:48:23 +00:00
|
|
|
if (event.canRedact == false &&
|
2022-01-29 11:35:03 +00:00
|
|
|
!(clients!.any((cl) => event.senderId == cl!.userID))) return false;
|
2020-02-09 14:15:29 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-17 17:16:12 +00:00
|
|
|
bool get canPinSelectedEvents {
|
|
|
|
if (isArchived ||
|
|
|
|
!room.canChangeStateEvent(EventTypes.RoomPinnedEvents) ||
|
|
|
|
selectedEvents.length != 1 ||
|
|
|
|
!selectedEvents.single.status.isSent) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-11-06 13:25:56 +00:00
|
|
|
return true;
|
2023-08-17 17:16:12 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 11:48:23 +00:00
|
|
|
bool get canEditSelectedEvents {
|
2023-01-08 11:32:35 +00:00
|
|
|
if (isArchived ||
|
|
|
|
selectedEvents.length != 1 ||
|
|
|
|
!selectedEvents.first.status.isSent) {
|
2021-09-19 11:48:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return currentRoomBundle
|
2022-01-29 11:35:03 +00:00
|
|
|
.any((cl) => selectedEvents.first.senderId == cl!.userID);
|
2021-09-19 11:48:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void forwardEventsAction() async {
|
2020-02-09 14:15:29 +00:00
|
|
|
if (selectedEvents.length == 1) {
|
2022-08-06 09:41:06 +00:00
|
|
|
Matrix.of(context).shareContent =
|
|
|
|
selectedEvents.first.getDisplayEvent(timeline!).content;
|
2020-02-09 14:15:29 +00:00
|
|
|
} else {
|
|
|
|
Matrix.of(context).shareContent = {
|
2020-05-13 13:58:59 +00:00
|
|
|
'msgtype': 'm.text',
|
2021-04-15 11:03:14 +00:00
|
|
|
'body': _getSelectedEventString(),
|
2020-02-09 14:15:29 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
setState(() => selectedEvents.clear());
|
2023-08-07 16:40:02 +00:00
|
|
|
context.go('/rooms');
|
2020-02-09 14:15:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void sendAgainAction() {
|
2020-08-12 09:30:31 +00:00
|
|
|
final event = selectedEvents.first;
|
2021-10-25 08:46:58 +00:00
|
|
|
if (event.status.isError) {
|
2020-08-12 09:30:31 +00:00
|
|
|
event.sendAgain();
|
|
|
|
}
|
|
|
|
final allEditEvents = event
|
2022-01-29 11:35:03 +00:00
|
|
|
.aggregatedEvents(timeline!, RelationshipTypes.edit)
|
2021-10-25 08:46:58 +00:00
|
|
|
.where((e) => e.status.isError);
|
2020-08-12 09:30:31 +00:00
|
|
|
for (final e in allEditEvents) {
|
|
|
|
e.sendAgain();
|
|
|
|
}
|
2020-02-09 14:15:29 +00:00
|
|
|
setState(() => selectedEvents.clear());
|
|
|
|
}
|
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
void replyAction({Event? replyTo}) {
|
2020-02-09 14:15:29 +00:00
|
|
|
setState(() {
|
2020-10-17 09:15:55 +00:00
|
|
|
replyEvent = replyTo ?? selectedEvents.first;
|
2020-02-09 14:15:29 +00:00
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
2020-02-16 10:36:18 +00:00
|
|
|
inputFocus.requestFocus();
|
2020-02-09 14:15:29 +00:00
|
|
|
}
|
|
|
|
|
2024-07-28 07:54:07 +00:00
|
|
|
void scrollToEventId(
|
|
|
|
String eventId, {
|
|
|
|
bool highlightEvent = true,
|
|
|
|
}) async {
|
2024-08-08 17:06:42 +00:00
|
|
|
final foundEvent =
|
|
|
|
timeline!.events.firstWhereOrNull((event) => event.eventId == eventId);
|
|
|
|
|
|
|
|
final eventIndex = foundEvent == null
|
|
|
|
? -1
|
|
|
|
: timeline!.events
|
|
|
|
.where((event) => event.isVisibleInGui || event.eventId == eventId)
|
|
|
|
.toList()
|
|
|
|
.indexOf(foundEvent);
|
|
|
|
|
2020-09-19 17:21:33 +00:00
|
|
|
if (eventIndex == -1) {
|
2023-03-22 08:16:07 +00:00
|
|
|
setState(() {
|
|
|
|
timeline = null;
|
2023-05-09 13:14:35 +00:00
|
|
|
_scrolledUp = false;
|
2023-10-14 07:17:00 +00:00
|
|
|
loadTimelineFuture = _getTimeline(eventContextId: eventId).onError(
|
2023-05-16 16:45:39 +00:00
|
|
|
ErrorReporter(context, 'Unable to load timeline after scroll to ID')
|
|
|
|
.onErrorCallback,
|
2023-04-14 12:23:58 +00:00
|
|
|
);
|
2023-03-22 08:16:07 +00:00
|
|
|
});
|
2023-03-25 14:23:14 +00:00
|
|
|
await loadTimelineFuture;
|
2023-04-02 07:33:27 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
|
|
|
scrollToEventId(eventId);
|
|
|
|
});
|
2020-11-16 10:31:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-07-28 07:54:07 +00:00
|
|
|
if (highlightEvent) {
|
|
|
|
setState(() {
|
|
|
|
scrollToEventIdMarker = eventId;
|
|
|
|
});
|
|
|
|
}
|
2021-10-26 16:47:05 +00:00
|
|
|
await scrollController.scrollToIndex(
|
2024-07-28 07:52:27 +00:00
|
|
|
eventIndex + 1,
|
|
|
|
duration: FluffyThemes.animationDuration,
|
2023-11-04 17:20:01 +00:00
|
|
|
preferPosition: AutoScrollPosition.middle,
|
2021-10-26 16:47:05 +00:00
|
|
|
);
|
2020-09-19 17:21:33 +00:00
|
|
|
_updateScrollController();
|
|
|
|
}
|
|
|
|
|
2023-03-22 08:16:07 +00:00
|
|
|
void scrollDown() async {
|
|
|
|
if (!timeline!.allowNewEvent) {
|
|
|
|
setState(() {
|
|
|
|
timeline = null;
|
2023-05-09 13:14:35 +00:00
|
|
|
_scrolledUp = false;
|
2023-05-16 16:45:39 +00:00
|
|
|
loadTimelineFuture = _getTimeline().onError(
|
|
|
|
ErrorReporter(context, 'Unable to load timeline after scroll down')
|
|
|
|
.onErrorCallback,
|
|
|
|
);
|
2023-03-22 08:16:07 +00:00
|
|
|
});
|
2023-03-25 14:23:14 +00:00
|
|
|
await loadTimelineFuture;
|
2023-03-22 08:16:07 +00:00
|
|
|
}
|
|
|
|
scrollController.jumpTo(0);
|
|
|
|
}
|
2021-04-15 11:03:14 +00:00
|
|
|
|
2022-02-14 12:49:46 +00:00
|
|
|
void onEmojiSelected(_, Emoji? emoji) {
|
|
|
|
switch (emojiPickerType) {
|
|
|
|
case EmojiPickerType.reaction:
|
|
|
|
senEmojiReaction(emoji);
|
|
|
|
break;
|
|
|
|
case EmojiPickerType.keyboard:
|
|
|
|
typeEmoji(emoji);
|
2022-03-03 06:52:31 +00:00
|
|
|
onInputBarChanged(sendController.text);
|
2022-02-14 12:49:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void senEmojiReaction(Emoji? emoji) {
|
2021-05-20 11:46:52 +00:00
|
|
|
setState(() => showEmojiPicker = false);
|
2020-12-12 16:19:53 +00:00
|
|
|
if (emoji == null) return;
|
2020-12-19 15:12:47 +00:00
|
|
|
// make sure we don't send the same emoji twice
|
2023-07-13 10:46:10 +00:00
|
|
|
if (_allReactionEvents.any(
|
|
|
|
(e) => e.content.tryGetMap('m.relates_to')?['key'] == emoji.emoji,
|
|
|
|
)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-15 11:03:14 +00:00
|
|
|
return sendEmojiAction(emoji.emoji);
|
2020-12-12 16:19:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 12:49:46 +00: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 11:35:03 +00:00
|
|
|
late Iterable<Event> _allReactionEvents;
|
2021-05-20 11:46:52 +00:00
|
|
|
|
2022-02-14 12:49:46 +00: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 09:57:52 +00:00
|
|
|
TextPosition(offset: sendController.text.length),
|
|
|
|
);
|
2022-02-14 12:49:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 11:46:52 +00:00
|
|
|
|
2022-02-14 12:49:46 +00:00
|
|
|
void pickEmojiReactionAction(Iterable<Event> allReactionEvents) async {
|
2021-05-20 11:46:52 +00:00
|
|
|
_allReactionEvents = allReactionEvents;
|
2022-02-14 12:49:46 +00:00
|
|
|
emojiPickerType = EmojiPickerType.reaction;
|
2021-05-20 11:46:52 +00:00
|
|
|
setState(() => showEmojiPicker = true);
|
|
|
|
}
|
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
void sendEmojiAction(String? emoji) async {
|
2021-11-19 09:23:24 +00:00
|
|
|
final events = List<Event>.from(selectedEvents);
|
2020-12-12 16:19:53 +00:00
|
|
|
setState(() => selectedEvents.clear());
|
2021-11-19 09:23:24 +00:00
|
|
|
for (final event in events) {
|
2023-03-25 14:06:12 +00:00
|
|
|
await room.sendReaction(
|
2021-11-19 09:23:24 +00:00
|
|
|
event.eventId,
|
2022-01-29 11:35:03 +00:00
|
|
|
emoji!,
|
2021-11-19 09:23:24 +00:00
|
|
|
);
|
|
|
|
}
|
2020-12-12 16:19:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-20 11:46:52 +00:00
|
|
|
void clearSelectedEvents() => setState(() {
|
|
|
|
selectedEvents.clear();
|
|
|
|
showEmojiPicker = false;
|
|
|
|
});
|
2020-01-05 11:27:03 +00:00
|
|
|
|
2022-01-03 16:12:09 +00:00
|
|
|
void clearSingleSelectedEvent() {
|
|
|
|
if (selectedEvents.length <= 1) {
|
|
|
|
clearSelectedEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void editSelectedEventAction() {
|
2021-09-19 11:48:23 +00:00
|
|
|
final client = currentRoomBundle.firstWhere(
|
2023-03-02 09:57:52 +00:00
|
|
|
(cl) => selectedEvents.first.senderId == cl!.userID,
|
|
|
|
orElse: () => null,
|
|
|
|
);
|
2021-09-19 11:48:23 +00:00
|
|
|
if (client == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setSendingClient(client);
|
2021-04-15 11:03:14 +00:00
|
|
|
setState(() {
|
|
|
|
pendingText = sendController.text;
|
|
|
|
editEvent = selectedEvents.first;
|
2023-12-23 06:38:45 +00:00
|
|
|
sendController.text =
|
2023-03-02 09:57:52 +00:00
|
|
|
editEvent!.getDisplayEvent(timeline!).calcLocalizedBodyFallback(
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
withSenderNamePrefix: false,
|
|
|
|
hideReply: true,
|
|
|
|
);
|
2021-04-15 11:03:14 +00:00
|
|
|
selectedEvents.clear();
|
|
|
|
});
|
|
|
|
inputFocus.requestFocus();
|
|
|
|
}
|
2021-03-28 07:20:34 +00:00
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void goToNewRoomAction() async {
|
|
|
|
if (OkCancelResult.ok !=
|
|
|
|
await showOkCancelAlertDialog(
|
|
|
|
context: context,
|
2022-01-29 11:35:03 +00:00
|
|
|
title: L10n.of(context)!.goToTheNewRoom,
|
2023-03-25 14:06:12 +00:00
|
|
|
message: room
|
2022-01-29 11:35:03 +00:00
|
|
|
.getState(EventTypes.RoomTombstone)!
|
2021-04-15 11:03:14 +00:00
|
|
|
.parsedTombstoneContent
|
|
|
|
.body,
|
2022-01-29 11:35:03 +00:00
|
|
|
okLabel: L10n.of(context)!.ok,
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
2021-04-15 11:03:14 +00:00
|
|
|
)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final result = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
2023-03-25 14:06:12 +00:00
|
|
|
future: () => room.client.joinRoom(
|
|
|
|
room
|
2023-03-02 09:57:52 +00:00
|
|
|
.getState(EventTypes.RoomTombstone)!
|
|
|
|
.parsedTombstoneContent
|
|
|
|
.replacementRoom,
|
|
|
|
),
|
2021-04-15 11:03:14 +00:00
|
|
|
);
|
|
|
|
await showFutureLoadingDialog(
|
|
|
|
context: context,
|
2023-03-25 14:06:12 +00:00
|
|
|
future: room.leave,
|
2021-04-15 11:03:14 +00:00
|
|
|
);
|
|
|
|
if (result.error == null) {
|
2023-08-13 14:07:15 +00:00
|
|
|
context.go('/rooms/${result.result!}');
|
2021-04-15 11:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-07 09:18:51 +00:00
|
|
|
|
2021-04-15 11:03:14 +00: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 14:40:06 +00:00
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
int? findChildIndexCallback(Key key, Map<String, int> thisEventsKeyMap) {
|
2021-04-15 11:03:14 +00:00
|
|
|
// this method is called very often. As such, it has to be optimized for speed.
|
2021-10-14 16:09:30 +00:00
|
|
|
if (key is! ValueKey) {
|
2021-04-15 11:03:14 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-01-29 11:35:03 +00:00
|
|
|
final eventId = key.value;
|
2021-10-14 16:09:30 +00:00
|
|
|
if (eventId is! String) {
|
2021-04-15 11:03:14 +00: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 08:11:17 +00:00
|
|
|
|
2021-10-16 07:59:38 +00:00
|
|
|
void onInputBarSubmitted(_) {
|
2021-04-15 11:03:14 +00:00
|
|
|
send();
|
|
|
|
FocusScope.of(context).requestFocus(inputFocus);
|
|
|
|
}
|
2020-11-07 09:18:51 +00:00
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void onAddPopupMenuButtonSelected(String choice) {
|
|
|
|
if (choice == 'file') {
|
|
|
|
sendFileAction();
|
2021-07-23 12:24:52 +00:00
|
|
|
}
|
|
|
|
if (choice == 'image') {
|
2021-04-15 11:03:14 +00:00
|
|
|
sendImageAction();
|
|
|
|
}
|
|
|
|
if (choice == 'camera') {
|
|
|
|
openCameraAction();
|
|
|
|
}
|
2021-12-22 08:45:36 +00:00
|
|
|
if (choice == 'camera-video') {
|
|
|
|
openVideoCameraAction();
|
|
|
|
}
|
2021-08-01 07:53:43 +00:00
|
|
|
if (choice == 'location') {
|
|
|
|
sendLocationAction();
|
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
}
|
2020-08-12 09:30:31 +00:00
|
|
|
|
2022-02-14 17:44:37 +00: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 14:06:12 +00:00
|
|
|
final events = room.pinnedEventIds
|
2022-02-14 17:44:37 +00:00
|
|
|
..removeWhere((oldEvent) => oldEvent == eventId);
|
2022-02-15 11:47:22 +00:00
|
|
|
showFutureLoadingDialog(
|
|
|
|
context: context,
|
2023-03-25 14:06:12 +00:00
|
|
|
future: () => room.setPinnedEvents(events),
|
2022-02-15 11:47:22 +00:00
|
|
|
);
|
2022-02-14 17:44:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pinEvent() {
|
2022-02-16 11:11:25 +00:00
|
|
|
final pinnedEventIds = room.pinnedEventIds;
|
|
|
|
final selectedEventIds = selectedEvents.map((e) => e.eventId).toSet();
|
2022-02-17 13:02:17 +00:00
|
|
|
final unpin = selectedEventIds.length == 1 &&
|
|
|
|
pinnedEventIds.contains(selectedEventIds.single);
|
|
|
|
if (unpin) {
|
|
|
|
pinnedEventIds.removeWhere(selectedEventIds.contains);
|
|
|
|
} else {
|
|
|
|
pinnedEventIds.addAll(selectedEventIds);
|
|
|
|
}
|
2022-02-15 11:47:22 +00:00
|
|
|
showFutureLoadingDialog(
|
|
|
|
context: context,
|
2022-02-17 13:02:17 +00:00
|
|
|
future: () => room.setPinnedEvents(pinnedEventIds),
|
2022-02-14 17:44:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-30 12:32:39 +00:00
|
|
|
Timer? _storeInputTimeoutTimer;
|
|
|
|
static const Duration _storeInputTimeout = Duration(milliseconds: 500);
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void onInputBarChanged(String text) {
|
2023-12-24 07:14:13 +00:00
|
|
|
if (_inputTextIsEmpty != text.isEmpty) {
|
|
|
|
setState(() {
|
|
|
|
_inputTextIsEmpty = text.isEmpty;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-30 12:32:39 +00:00
|
|
|
_storeInputTimeoutTimer?.cancel();
|
|
|
|
_storeInputTimeoutTimer = Timer(_storeInputTimeout, () async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await prefs.setString('draft_$roomId', text);
|
|
|
|
});
|
2023-03-25 13:57:27 +00:00
|
|
|
if (text.endsWith(' ') && Matrix.of(context).hasComplexBundles) {
|
2021-09-21 07:08:18 +00:00
|
|
|
final clients = currentRoomBundle;
|
|
|
|
for (final client in clients) {
|
2022-01-29 11:35:03 +00:00
|
|
|
final prefix = client!.sendPrefix;
|
|
|
|
if ((prefix.isNotEmpty) &&
|
2021-09-21 07:08:18 +00:00
|
|
|
text.toLowerCase() == '${prefix.toLowerCase()} ') {
|
|
|
|
setSendingClient(client);
|
|
|
|
setState(() {
|
2023-12-25 17:07:19 +00:00
|
|
|
sendController.clear();
|
2021-09-21 07:08:18 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-09-19 11:48:23 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-27 16:15:50 +00:00
|
|
|
if (AppConfig.sendTypingNotifications) {
|
|
|
|
typingCoolDown?.cancel();
|
|
|
|
typingCoolDown = Timer(const Duration(seconds: 2), () {
|
|
|
|
typingCoolDown = null;
|
|
|
|
currentlyTyping = false;
|
|
|
|
room.setTyping(false);
|
|
|
|
});
|
|
|
|
typingTimeout ??= Timer(const Duration(seconds: 30), () {
|
|
|
|
typingTimeout = null;
|
|
|
|
currentlyTyping = false;
|
|
|
|
});
|
|
|
|
if (!currentlyTyping) {
|
|
|
|
currentlyTyping = true;
|
|
|
|
room.setTyping(
|
|
|
|
true,
|
|
|
|
timeout: const Duration(seconds: 30).inMilliseconds,
|
|
|
|
);
|
|
|
|
}
|
2021-04-15 11:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-12 09:30:31 +00:00
|
|
|
|
2023-12-23 06:38:45 +00:00
|
|
|
bool _inputTextIsEmpty = true;
|
|
|
|
|
2023-01-08 11:32:35 +00:00
|
|
|
bool get isArchived =>
|
2023-03-25 14:06:12 +00:00
|
|
|
{Membership.leave, Membership.ban}.contains(room.membership);
|
2023-01-08 11:32:35 +00:00
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
void showEventInfo([Event? event]) =>
|
2021-11-13 12:06:36 +00:00
|
|
|
(event ?? selectedEvents.single).showInfoDialog(context);
|
|
|
|
|
2022-02-15 08:25:13 +00:00
|
|
|
void onPhoneButtonTap() async {
|
|
|
|
// VoIP required Android SDK 21
|
|
|
|
if (PlatformInfos.isAndroid) {
|
|
|
|
DeviceInfoPlugin().androidInfo.then((value) {
|
2022-11-03 14:37:40 +00:00
|
|
|
if (value.version.sdkInt < 21) {
|
2022-02-15 08:25:13 +00:00
|
|
|
Navigator.pop(context);
|
2022-02-17 08:52:53 +00:00
|
|
|
showOkAlertDialog(
|
2022-02-15 08:25:13 +00:00
|
|
|
context: context,
|
2022-02-17 08:52:53 +00:00
|
|
|
title: L10n.of(context)!.unsupportedAndroidVersion,
|
|
|
|
message: L10n.of(context)!.unsupportedAndroidVersionLong,
|
|
|
|
okLabel: L10n.of(context)!.close,
|
2022-02-15 08:25:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-02-17 08:52:53 +00:00
|
|
|
final callType = await showModalActionSheet<CallType>(
|
|
|
|
context: context,
|
2022-02-17 14:07:29 +00:00
|
|
|
title: L10n.of(context)!.warning,
|
|
|
|
message: L10n.of(context)!.videoCallsBetaWarning,
|
2022-02-17 08:52:53 +00: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 08:25:13 +00:00
|
|
|
|
2024-04-30 12:49:10 +00:00
|
|
|
final voipPlugin = Matrix.of(context).voipPlugin;
|
|
|
|
try {
|
|
|
|
await voipPlugin!.voip.inviteToCall(room, callType);
|
|
|
|
} catch (e) {
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(content: Text(e.toLocalizedString(context))),
|
2022-02-15 08:25:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 11:03:14 +00:00
|
|
|
void cancelReplyEventAction() => setState(() {
|
|
|
|
if (editEvent != null) {
|
2023-12-23 06:38:45 +00:00
|
|
|
sendController.text = pendingText;
|
2021-04-15 11:03:14 +00:00
|
|
|
pendingText = '';
|
|
|
|
}
|
|
|
|
replyEvent = null;
|
|
|
|
editEvent = null;
|
|
|
|
});
|
2020-08-12 09:30:31 +00:00
|
|
|
|
2024-04-07 08:30:21 +00:00
|
|
|
late final ValueNotifier<bool> _displayChatDetailsColumn;
|
|
|
|
|
|
|
|
void toggleDisplayChatDetailsColumn() async {
|
|
|
|
await Matrix.of(context).store.setBool(
|
|
|
|
SettingKeys.displayChatDetailsColumn,
|
|
|
|
!_displayChatDetailsColumn.value,
|
|
|
|
);
|
|
|
|
_displayChatDetailsColumn.value = !_displayChatDetailsColumn.value;
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:30:31 +00:00
|
|
|
@override
|
2024-08-04 12:09:36 +00:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: ChatView(this),
|
|
|
|
),
|
|
|
|
AnimatedSize(
|
|
|
|
duration: FluffyThemes.animationDuration,
|
|
|
|
curve: FluffyThemes.animationCurve,
|
|
|
|
child: ValueListenableBuilder(
|
|
|
|
valueListenable: _displayChatDetailsColumn,
|
|
|
|
builder: (context, displayChatDetailsColumn, _) {
|
|
|
|
if (!FluffyThemes.isThreeColumnMode(context) ||
|
|
|
|
room.membership != Membership.join ||
|
|
|
|
!displayChatDetailsColumn) {
|
|
|
|
return const SizedBox(
|
|
|
|
height: double.infinity,
|
|
|
|
width: 0,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container(
|
|
|
|
width: FluffyThemes.columnWidth,
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
left: BorderSide(
|
|
|
|
width: 1,
|
|
|
|
color: theme.dividerColor,
|
2024-04-07 08:30:21 +00:00
|
|
|
),
|
|
|
|
),
|
2024-08-04 12:09:36 +00:00
|
|
|
),
|
|
|
|
child: ChatDetails(
|
|
|
|
roomId: roomId,
|
|
|
|
embeddedCloseButton: IconButton(
|
|
|
|
icon: const Icon(Icons.close),
|
|
|
|
onPressed: toggleDisplayChatDetailsColumn,
|
2024-04-07 08:30:21 +00:00
|
|
|
),
|
2024-08-04 12:09:36 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2024-04-07 08:30:21 +00:00
|
|
|
),
|
2024-08-04 12:09:36 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2020-08-12 09:30:31 +00:00
|
|
|
}
|
2022-02-14 12:49:46 +00:00
|
|
|
|
|
|
|
enum EmojiPickerType { reaction, keyboard }
|