Skip to content

Commit 45f3f48

Browse files
compose [nfc]: Expose uploadFiles on ComposeBoxState
This will be used soon to allow uploading files directly via using `MessageListPageState`.
1 parent 997b930 commit 45f3f48

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

lib/widgets/compose_box.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ class FileToUpload {
928928
Future<void> _uploadFiles({
929929
required BuildContext context,
930930
required ComposeContentController contentController,
931-
required FocusNode contentFocusNode,
931+
required FocusNode? contentFocusNode,
932932
required Iterable<FileToUpload> files,
933933
}) async {
934934
assert(context.mounted);
@@ -965,7 +965,7 @@ Future<void> _uploadFiles({
965965
zulipLocalizations);
966966
uploadsInProgress.add((tag, file));
967967
}
968-
if (!contentFocusNode.hasFocus) {
968+
if (contentFocusNode != null && !contentFocusNode.hasFocus) {
969969
contentFocusNode.requestFocus();
970970
}
971971

@@ -1869,6 +1869,24 @@ abstract class ComposeBoxState extends State<ComposeBox> {
18691869

18701870
/// Switch the compose box back to regular non-edit mode, with no content.
18711871
void endEditInteraction();
1872+
1873+
/// Uploads the provided files, populating the compose box with their links.
1874+
///
1875+
/// If any of the file is larger than maximum file size allowed by the
1876+
/// server, an error dialog is shown mentioning their names and actual
1877+
/// file sizes.
1878+
///
1879+
/// While uploading, a placeholder link is inserted in the compose box and
1880+
/// if [contentFocusNode] is non-null it will be focused. And then after
1881+
/// uploading completes successfully the placeholder link will be replaced
1882+
/// with an actual link.
1883+
///
1884+
/// If there is an error while uploading a file, then an error dialog is
1885+
/// shown mentioning the corresponding file name.
1886+
Future<void> uploadFiles({
1887+
required Iterable<FileToUpload> files,
1888+
required FocusNode? contentFocusNode,
1889+
});
18721890
}
18731891

18741892
class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateMixin<ComposeBox> implements ComposeBoxState {
@@ -2021,6 +2039,18 @@ class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateM
20212039
});
20222040
}
20232041

2042+
@override
2043+
Future<void> uploadFiles({
2044+
required Iterable<FileToUpload> files,
2045+
required FocusNode? contentFocusNode,
2046+
}) async {
2047+
await _uploadFiles(
2048+
context: context,
2049+
contentController: controller.content,
2050+
contentFocusNode: contentFocusNode,
2051+
files: files);
2052+
}
2053+
20242054
@override
20252055
void onNewStore() {
20262056
final newStore = PerAccountStoreWidget.of(context);

0 commit comments

Comments
 (0)