Skip to content

Commit fb4d254

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

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

lib/widgets/compose_box.dart

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ Future<void> _uploadFiles({
929929
required BuildContext context,
930930
required ComposeContentController contentController,
931931
required FocusNode contentFocusNode,
932+
bool shouldRequestFocus = true,
932933
required Iterable<FileToUpload> files,
933934
}) async {
934935
assert(context.mounted);
@@ -965,7 +966,7 @@ Future<void> _uploadFiles({
965966
zulipLocalizations);
966967
uploadsInProgress.add((tag, file));
967968
}
968-
if (!contentFocusNode.hasFocus) {
969+
if (shouldRequestFocus && !contentFocusNode.hasFocus) {
969970
contentFocusNode.requestFocus();
970971
}
971972

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

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

18741893
class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateMixin<ComposeBox> implements ComposeBoxState {
@@ -2021,6 +2040,19 @@ class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateM
20212040
});
20222041
}
20232042

2043+
@override
2044+
Future<void> uploadFiles({
2045+
required Iterable<FileToUpload> files,
2046+
required bool shouldRequestFocus,
2047+
}) async {
2048+
await _uploadFiles(
2049+
context: context,
2050+
contentController: controller.content,
2051+
contentFocusNode: controller.contentFocusNode,
2052+
shouldRequestFocus: shouldRequestFocus,
2053+
files: files);
2054+
}
2055+
20242056
@override
20252057
void onNewStore() {
20262058
final newStore = PerAccountStoreWidget.of(context);

0 commit comments

Comments
 (0)