refactor: Update to Dart 3.10 with . shorthands
This commit is contained in:
parent
75a37f3f7c
commit
1ea649f01e
167 changed files with 3351 additions and 3912 deletions
|
|
@ -182,14 +182,14 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
|
||||
void enterThread(String eventId) => setState(() {
|
||||
activeThreadId = eventId;
|
||||
selectedEvents.clear();
|
||||
});
|
||||
activeThreadId = eventId;
|
||||
selectedEvents.clear();
|
||||
});
|
||||
|
||||
void closeThread() => setState(() {
|
||||
activeThreadId = null;
|
||||
selectedEvents.clear();
|
||||
});
|
||||
activeThreadId = null;
|
||||
selectedEvents.clear();
|
||||
});
|
||||
|
||||
void recreateChat() async {
|
||||
final room = this.room;
|
||||
|
|
@ -266,9 +266,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
closeIconColor: theme.colorScheme.onErrorContainer,
|
||||
content: Text(
|
||||
L10n.of(context).otherPartyNotLoggedIn,
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.onErrorContainer,
|
||||
),
|
||||
style: TextStyle(color: theme.colorScheme.onErrorContainer),
|
||||
),
|
||||
showCloseIcon: true,
|
||||
),
|
||||
|
|
@ -306,11 +304,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
return KeyEventResult.handled;
|
||||
} else if (evt.logicalKey.keyLabel == 'Enter' && evt is KeyDownEvent) {
|
||||
final currentLineNum = sendController.text
|
||||
.substring(
|
||||
0,
|
||||
sendController.selection.baseOffset,
|
||||
)
|
||||
final currentLineNum =
|
||||
sendController.text
|
||||
.substring(0, sendController.selection.baseOffset)
|
||||
.split('\n')
|
||||
.length -
|
||||
1;
|
||||
|
|
@ -357,10 +353,11 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
sendingClient = Matrix.of(context).client;
|
||||
final lastEventThreadId =
|
||||
room.lastEvent?.relationshipType == RelationshipTypes.thread
|
||||
? room.lastEvent?.relationshipEventId
|
||||
: null;
|
||||
readMarkerEventId =
|
||||
room.hasNewMessages ? lastEventThreadId ?? room.fullyRead : '';
|
||||
? room.lastEvent?.relationshipEventId
|
||||
: null;
|
||||
readMarkerEventId = room.hasNewMessages
|
||||
? lastEventThreadId ?? room.fullyRead
|
||||
: '';
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_tryLoadTimeline();
|
||||
if (kIsWeb) {
|
||||
|
|
@ -402,11 +399,11 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
var readMarkerEventIndex = readMarkerEventId.isEmpty
|
||||
? -1
|
||||
: timeline!.events
|
||||
.filterByVisibleInGui(
|
||||
exceptionEventId: readMarkerEventId,
|
||||
threadId: activeThreadId,
|
||||
)
|
||||
.indexWhere((e) => e.eventId == readMarkerEventId);
|
||||
.filterByVisibleInGui(
|
||||
exceptionEventId: readMarkerEventId,
|
||||
threadId: activeThreadId,
|
||||
)
|
||||
.indexWhere((e) => e.eventId == readMarkerEventId);
|
||||
|
||||
// Read marker is existing but not found in first events. Try a single
|
||||
// requestHistory call before opening timeline on event context:
|
||||
|
|
@ -441,12 +438,12 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
String? scrollUpBannerEventId;
|
||||
|
||||
void discardScrollUpBannerEventId() => setState(() {
|
||||
scrollUpBannerEventId = null;
|
||||
});
|
||||
scrollUpBannerEventId = null;
|
||||
});
|
||||
|
||||
void _showScrollUpMaterialBanner(String eventId) => setState(() {
|
||||
scrollUpBannerEventId = eventId;
|
||||
});
|
||||
scrollUpBannerEventId = eventId;
|
||||
});
|
||||
|
||||
void updateView() {
|
||||
if (!mounted) return;
|
||||
|
|
@ -463,9 +460,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
animateInEventIndex = i;
|
||||
}
|
||||
|
||||
Future<void> _getTimeline({
|
||||
String? eventContextId,
|
||||
}) async {
|
||||
Future<void> _getTimeline({String? eventContextId}) async {
|
||||
await Matrix.of(context).client.roomsLoading;
|
||||
await Matrix.of(context).client.accountDataLoading;
|
||||
if (eventContextId != null &&
|
||||
|
|
@ -534,12 +529,12 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
// ignore: unawaited_futures
|
||||
_setReadMarkerFuture = timeline
|
||||
.setReadMarker(
|
||||
eventId: eventId,
|
||||
public: AppSettings.sendPublicReadReceipts.value,
|
||||
)
|
||||
eventId: eventId,
|
||||
public: AppSettings.sendPublicReadReceipts.value,
|
||||
)
|
||||
.then((_) {
|
||||
_setReadMarkerFuture = null;
|
||||
});
|
||||
_setReadMarkerFuture = null;
|
||||
});
|
||||
if (eventId == null || eventId == timeline.room.lastEvent?.eventId) {
|
||||
Matrix.of(context).backgroundPush?.cancelNotification(roomId);
|
||||
}
|
||||
|
|
@ -579,8 +574,8 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
|
||||
void setActiveClient(Client c) => setState(() {
|
||||
Matrix.of(context).setActiveClient(c);
|
||||
});
|
||||
Matrix.of(context).setActiveClient(c);
|
||||
});
|
||||
|
||||
Future<void> send() async {
|
||||
if (sendController.text.trim().isEmpty) return;
|
||||
|
|
@ -627,11 +622,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
|
||||
void sendFileAction({FileSelectorType type = FileSelectorType.any}) async {
|
||||
final files = await selectFiles(
|
||||
context,
|
||||
allowMultiple: true,
|
||||
type: type,
|
||||
);
|
||||
final files = await selectFiles(context, allowMultiple: true, type: type);
|
||||
if (files.isEmpty) return;
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
|
|
@ -722,31 +713,26 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
setState(() {
|
||||
replyEvent = null;
|
||||
});
|
||||
room.sendFileEvent(
|
||||
file,
|
||||
inReplyTo: replyEvent,
|
||||
threadRootEventId: activeThreadId,
|
||||
extraContent: {
|
||||
'info': {
|
||||
...file.info,
|
||||
'duration': duration,
|
||||
},
|
||||
'org.matrix.msc3245.voice': {},
|
||||
'org.matrix.msc1767.audio': {
|
||||
'duration': duration,
|
||||
'waveform': waveform,
|
||||
},
|
||||
},
|
||||
).catchError((e) {
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
(e as Object).toLocalizedString(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
return null;
|
||||
});
|
||||
room
|
||||
.sendFileEvent(
|
||||
file,
|
||||
inReplyTo: replyEvent,
|
||||
threadRootEventId: activeThreadId,
|
||||
extraContent: {
|
||||
'info': {...file.info, 'duration': duration},
|
||||
'org.matrix.msc3245.voice': {},
|
||||
'org.matrix.msc1767.audio': {
|
||||
'duration': duration,
|
||||
'waveform': waveform,
|
||||
},
|
||||
},
|
||||
)
|
||||
.catchError((e) {
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(content: Text((e as Object).toLocalizedString(context))),
|
||||
);
|
||||
return null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -785,7 +771,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
for (final event in selectedEvents) {
|
||||
if (copyString.isNotEmpty) copyString += '\n\n';
|
||||
copyString += event.getDisplayEvent(timeline!).calcLocalizedBodyFallback(
|
||||
copyString += event
|
||||
.getDisplayEvent(timeline!)
|
||||
.calcLocalizedBodyFallback(
|
||||
MatrixLocals(L10n.of(context)),
|
||||
withSenderNamePrefix: true,
|
||||
);
|
||||
|
|
@ -813,14 +801,8 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
value: -100,
|
||||
label: L10n.of(context).extremeOffensive,
|
||||
),
|
||||
AdaptiveModalAction(
|
||||
value: -50,
|
||||
label: L10n.of(context).offensive,
|
||||
),
|
||||
AdaptiveModalAction(
|
||||
value: 0,
|
||||
label: L10n.of(context).inoffensive,
|
||||
),
|
||||
AdaptiveModalAction(value: -50, label: L10n.of(context).offensive),
|
||||
AdaptiveModalAction(value: 0, label: L10n.of(context).inoffensive),
|
||||
],
|
||||
);
|
||||
if (score == null) return;
|
||||
|
|
@ -835,11 +817,11 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
final result = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.reportEvent(
|
||||
event.roomId!,
|
||||
event.eventId,
|
||||
reason: reason,
|
||||
score: score,
|
||||
),
|
||||
event.roomId!,
|
||||
event.eventId,
|
||||
reason: reason,
|
||||
score: score,
|
||||
),
|
||||
);
|
||||
if (result.error != null) return;
|
||||
setState(() {
|
||||
|
|
@ -905,9 +887,10 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
return;
|
||||
}
|
||||
final room = client.getRoomById(roomId)!;
|
||||
await Event.fromJson(event.toJson(), room).redactEvent(
|
||||
reason: reason,
|
||||
);
|
||||
await Event.fromJson(
|
||||
event.toJson(),
|
||||
room,
|
||||
).redactEvent(reason: reason);
|
||||
}
|
||||
} else {
|
||||
await event.cancelSend();
|
||||
|
|
@ -957,8 +940,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
!selectedEvents.first.status.isSent) {
|
||||
return false;
|
||||
}
|
||||
return currentRoomBundle
|
||||
.any((cl) => selectedEvents.first.senderId == cl!.userID);
|
||||
return currentRoomBundle.any(
|
||||
(cl) => selectedEvents.first.senderId == cl!.userID,
|
||||
);
|
||||
}
|
||||
|
||||
void forwardEventsAction() async {
|
||||
|
|
@ -966,9 +950,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
final timeline = this.timeline;
|
||||
if (timeline == null) return;
|
||||
|
||||
final forwardEvents = List<Event>.from(selectedEvents)
|
||||
.map((event) => event.getDisplayEvent(timeline))
|
||||
.toList();
|
||||
final forwardEvents = List<Event>.from(
|
||||
selectedEvents,
|
||||
).map((event) => event.getDisplayEvent(timeline)).toList();
|
||||
|
||||
await showScaffoldDialog(
|
||||
context: context,
|
||||
|
|
@ -1004,29 +988,29 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
inputFocus.requestFocus();
|
||||
}
|
||||
|
||||
void scrollToEventId(
|
||||
String eventId, {
|
||||
bool highlightEvent = true,
|
||||
}) async {
|
||||
final foundEvent =
|
||||
timeline!.events.firstWhereOrNull((event) => event.eventId == eventId);
|
||||
void scrollToEventId(String eventId, {bool highlightEvent = true}) async {
|
||||
final foundEvent = timeline!.events.firstWhereOrNull(
|
||||
(event) => event.eventId == eventId,
|
||||
);
|
||||
|
||||
final eventIndex = foundEvent == null
|
||||
? -1
|
||||
: timeline!.events
|
||||
.filterByVisibleInGui(
|
||||
exceptionEventId: eventId,
|
||||
threadId: activeThreadId,
|
||||
)
|
||||
.indexOf(foundEvent);
|
||||
.filterByVisibleInGui(
|
||||
exceptionEventId: eventId,
|
||||
threadId: activeThreadId,
|
||||
)
|
||||
.indexOf(foundEvent);
|
||||
|
||||
if (eventIndex == -1) {
|
||||
setState(() {
|
||||
timeline = null;
|
||||
_scrolledUp = false;
|
||||
loadTimelineFuture = _getTimeline(eventContextId: eventId).onError(
|
||||
ErrorReporter(context, 'Unable to load timeline after scroll to ID')
|
||||
.onErrorCallback,
|
||||
ErrorReporter(
|
||||
context,
|
||||
'Unable to load timeline after scroll to ID',
|
||||
).onErrorCallback,
|
||||
);
|
||||
});
|
||||
await loadTimelineFuture;
|
||||
|
|
@ -1054,8 +1038,10 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
timeline = null;
|
||||
_scrolledUp = false;
|
||||
loadTimelineFuture = _getTimeline().onError(
|
||||
ErrorReporter(context, 'Unable to load timeline after scroll down')
|
||||
.onErrorCallback,
|
||||
ErrorReporter(
|
||||
context,
|
||||
'Unable to load timeline after scroll down',
|
||||
).onErrorCallback,
|
||||
);
|
||||
});
|
||||
await loadTimelineFuture;
|
||||
|
|
@ -1093,9 +1079,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
|
||||
void clearSelectedEvents() => setState(() {
|
||||
selectedEvents.clear();
|
||||
showEmojiPicker = false;
|
||||
});
|
||||
selectedEvents.clear();
|
||||
showEmojiPicker = false;
|
||||
});
|
||||
|
||||
void clearSingleSelectedEvent() {
|
||||
if (selectedEvents.length <= 1) {
|
||||
|
|
@ -1115,12 +1101,13 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
setState(() {
|
||||
pendingText = sendController.text;
|
||||
editEvent = selectedEvents.first;
|
||||
sendController.text =
|
||||
editEvent!.getDisplayEvent(timeline!).calcLocalizedBodyFallback(
|
||||
MatrixLocals(L10n.of(context)),
|
||||
withSenderNamePrefix: false,
|
||||
hideReply: true,
|
||||
);
|
||||
sendController.text = editEvent!
|
||||
.getDisplayEvent(timeline!)
|
||||
.calcLocalizedBodyFallback(
|
||||
MatrixLocals(L10n.of(context)),
|
||||
withSenderNamePrefix: false,
|
||||
hideReply: true,
|
||||
);
|
||||
selectedEvents.clear();
|
||||
});
|
||||
inputFocus.requestFocus();
|
||||
|
|
@ -1145,22 +1132,15 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
if (!mounted) return;
|
||||
context.go('/rooms/${result.result!}');
|
||||
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: room.leave,
|
||||
);
|
||||
await showFutureLoadingDialog(context: context, future: room.leave);
|
||||
}
|
||||
|
||||
void onSelectMessage(Event event) {
|
||||
if (!event.redacted) {
|
||||
if (selectedEvents.contains(event)) {
|
||||
setState(
|
||||
() => selectedEvents.remove(event),
|
||||
);
|
||||
setState(() => selectedEvents.remove(event));
|
||||
} else {
|
||||
setState(
|
||||
() => selectedEvents.add(event),
|
||||
);
|
||||
setState(() => selectedEvents.add(event));
|
||||
}
|
||||
selectedEvents.sort(
|
||||
(a, b) => a.originServerTs.compareTo(b.originServerTs),
|
||||
|
|
@ -1243,7 +1223,8 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
void pinEvent() {
|
||||
final pinnedEventIds = room.pinnedEventIds;
|
||||
final selectedEventIds = selectedEvents.map((e) => e.eventId).toSet();
|
||||
final unpin = selectedEventIds.length == 1 &&
|
||||
final unpin =
|
||||
selectedEventIds.length == 1 &&
|
||||
pinnedEventIds.contains(selectedEventIds.single);
|
||||
if (unpin) {
|
||||
pinnedEventIds.removeWhere(selectedEventIds.contains);
|
||||
|
|
@ -1353,20 +1334,20 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
try {
|
||||
await voipPlugin!.voip.inviteToCall(room, callType);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(e.toLocalizedString(context))),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(e.toLocalizedString(context))));
|
||||
}
|
||||
}
|
||||
|
||||
void cancelReplyEventAction() => setState(() {
|
||||
if (editEvent != null) {
|
||||
sendController.text = pendingText;
|
||||
pendingText = '';
|
||||
}
|
||||
replyEvent = null;
|
||||
editEvent = null;
|
||||
});
|
||||
if (editEvent != null) {
|
||||
sendController.text = pendingText;
|
||||
pendingText = '';
|
||||
}
|
||||
replyEvent = null;
|
||||
editEvent = null;
|
||||
});
|
||||
|
||||
late final ValueNotifier<bool> _displayChatDetailsColumn;
|
||||
|
||||
|
|
@ -1382,38 +1363,30 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
final theme = Theme.of(context);
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ChatView(this),
|
||||
),
|
||||
Expanded(child: ChatView(this)),
|
||||
ValueListenableBuilder(
|
||||
valueListenable: _displayChatDetailsColumn,
|
||||
builder: (context, displayChatDetailsColumn, _) =>
|
||||
!FluffyThemes.isThreeColumnMode(context) ||
|
||||
room.membership != Membership.join ||
|
||||
!displayChatDetailsColumn
|
||||
? const SizedBox(
|
||||
height: double.infinity,
|
||||
width: 0,
|
||||
)
|
||||
: Container(
|
||||
width: FluffyThemes.columnWidth,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
left: BorderSide(
|
||||
width: 1,
|
||||
color: theme.dividerColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: ChatDetails(
|
||||
roomId: roomId,
|
||||
embeddedCloseButton: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: toggleDisplayChatDetailsColumn,
|
||||
),
|
||||
),
|
||||
room.membership != Membership.join ||
|
||||
!displayChatDetailsColumn
|
||||
? const SizedBox(height: double.infinity, width: 0)
|
||||
: Container(
|
||||
width: FluffyThemes.columnWidth,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
left: BorderSide(width: 1, color: theme.dividerColor),
|
||||
),
|
||||
),
|
||||
child: ChatDetails(
|
||||
roomId: roomId,
|
||||
embeddedCloseButton: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: toggleDisplayChatDetailsColumn,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue