feat: Allow loading of multiple clients in main.dart
This commit is contained in:
parent
fe4dd064d1
commit
ec68d15586
26 changed files with 840 additions and 159 deletions
|
|
@ -32,6 +32,7 @@ import 'send_location_dialog.dart';
|
|||
import 'sticker_picker_dialog.dart';
|
||||
import '../utils/matrix_sdk_extensions.dart/filtered_timeline_extension.dart';
|
||||
import '../utils/matrix_sdk_extensions.dart/matrix_file_extension.dart';
|
||||
import '../utils/account_bundles.dart';
|
||||
|
||||
class Chat extends StatefulWidget {
|
||||
final Widget sideView;
|
||||
|
|
@ -45,6 +46,8 @@ class Chat extends StatefulWidget {
|
|||
class ChatController extends State<Chat> {
|
||||
Room room;
|
||||
|
||||
Client sendingClient;
|
||||
|
||||
Timeline timeline;
|
||||
|
||||
MatrixState matrix;
|
||||
|
|
@ -222,6 +225,14 @@ class ChatController extends State<Chat> {
|
|||
|
||||
TextEditingController sendController = TextEditingController();
|
||||
|
||||
void setSendingClient(Client c) => setState(() {
|
||||
sendingClient = c;
|
||||
});
|
||||
|
||||
void setActiveClient(Client c) => setState(() {
|
||||
Matrix.of(context).setActiveClient(c);
|
||||
});
|
||||
|
||||
Future<void> send() async {
|
||||
if (sendController.text.trim().isEmpty) return;
|
||||
var parseCommands = true;
|
||||
|
|
@ -447,19 +458,51 @@ class ChatController extends State<Chat> {
|
|||
for (final event in selectedEvents) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
event.status > 0 ? event.redactEvent() : event.remove());
|
||||
future: () async {
|
||||
if (event.status > 0) {
|
||||
if (event.canRedact) {
|
||||
await event.redactEvent();
|
||||
} else {
|
||||
final client = currentRoomBundle.firstWhere(
|
||||
(cl) => selectedEvents.first.senderId == cl.userID,
|
||||
orElse: () => null);
|
||||
if (client == null) {
|
||||
return;
|
||||
}
|
||||
final room = client.getRoomById(roomId);
|
||||
await Event.fromJson(event.toJson(), room).redactEvent();
|
||||
}
|
||||
} else {
|
||||
await event.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
setState(() => selectedEvents.clear());
|
||||
}
|
||||
|
||||
List<Client> get currentRoomBundle {
|
||||
final clients = matrix.currentBundle;
|
||||
clients.removeWhere((c) => c.getRoomById(roomId) == null);
|
||||
return clients;
|
||||
}
|
||||
|
||||
bool get canRedactSelectedEvents {
|
||||
final clients = matrix.currentBundle;
|
||||
for (final event in selectedEvents) {
|
||||
if (event.canRedact == false) return false;
|
||||
if (event.canRedact == false &&
|
||||
!(clients.any((cl) => event.senderId == cl.userID))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get canEditSelectedEvents {
|
||||
if (selectedEvents.length != 1 || selectedEvents.first.status < 1) {
|
||||
return false;
|
||||
}
|
||||
return currentRoomBundle
|
||||
.any((cl) => selectedEvents.first.senderId == cl.userID);
|
||||
}
|
||||
|
||||
void forwardEventsAction() async {
|
||||
if (selectedEvents.length == 1) {
|
||||
Matrix.of(context).shareContent = selectedEvents.first.content;
|
||||
|
|
@ -584,6 +627,13 @@ class ChatController extends State<Chat> {
|
|||
});
|
||||
|
||||
void editSelectedEventAction() {
|
||||
final client = currentRoomBundle.firstWhere(
|
||||
(cl) => selectedEvents.first.senderId == cl.userID,
|
||||
orElse: () => null);
|
||||
if (client == null) {
|
||||
return;
|
||||
}
|
||||
setSendingClient(client);
|
||||
setState(() {
|
||||
pendingText = sendController.text;
|
||||
editEvent = selectedEvents.first;
|
||||
|
|
@ -689,6 +739,19 @@ class ChatController extends State<Chat> {
|
|||
}
|
||||
|
||||
void onInputBarChanged(String text) {
|
||||
final clients = currentRoomBundle;
|
||||
for (final client in clients) {
|
||||
final prefix = client.sendPrefix;
|
||||
if ((prefix?.isNotEmpty ?? false) &&
|
||||
text.toLowerCase() == '${prefix.toLowerCase()} ') {
|
||||
setSendingClient(client);
|
||||
setState(() {
|
||||
inputText = '';
|
||||
sendController.text = '';
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
typingCoolDown?.cancel();
|
||||
typingCoolDown = Timer(Duration(seconds: 2), () {
|
||||
typingCoolDown = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue