mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 06:49:22 +00:00
File update system
This commit is contained in:
parent
ec4ca238de
commit
701d5d3c27
@ -309,12 +309,12 @@ class ConversationsHelper {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check for image
|
// Check for file
|
||||||
if (message.hasImage) request.addPickedFile("image", message.image);
|
if (message.hasFile) request.addBytesFile("file", message.file);
|
||||||
|
|
||||||
//Send the message
|
//Send the message
|
||||||
APIResponse response;
|
APIResponse response;
|
||||||
if (!message.hasImage)
|
if (!message.hasFile)
|
||||||
response = await request.exec();
|
response = await request.exec();
|
||||||
else
|
else
|
||||||
response = await request.execWithFiles();
|
response = await request.execWithFiles();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:comunic/models/api_request.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
/// New conversation message model
|
/// New conversation message model
|
||||||
@ -10,14 +10,16 @@ import 'package:meta/meta.dart';
|
|||||||
class NewConversationMessage {
|
class NewConversationMessage {
|
||||||
final int conversationID;
|
final int conversationID;
|
||||||
final String message;
|
final String message;
|
||||||
final PickedFile image;
|
final BytesFile file;
|
||||||
|
|
||||||
NewConversationMessage(
|
NewConversationMessage({
|
||||||
{@required this.conversationID, @required this.message, this.image})
|
@required this.conversationID,
|
||||||
: assert(conversationID != null),
|
@required this.message,
|
||||||
assert(image != null || message != null);
|
this.file,
|
||||||
|
}) : assert(conversationID != null),
|
||||||
|
assert(file != null || message != null);
|
||||||
|
|
||||||
bool get hasMessage => message != null;
|
bool get hasMessage => message != null;
|
||||||
|
|
||||||
bool get hasImage => image != null;
|
bool get hasFile => file != null;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import 'package:comunic/helpers/server_config_helper.dart';
|
|||||||
import 'package:comunic/helpers/users_helper.dart';
|
import 'package:comunic/helpers/users_helper.dart';
|
||||||
import 'package:comunic/lists/conversation_messages_list.dart';
|
import 'package:comunic/lists/conversation_messages_list.dart';
|
||||||
import 'package:comunic/lists/users_list.dart';
|
import 'package:comunic/lists/users_list.dart';
|
||||||
|
import 'package:comunic/models/api_request.dart';
|
||||||
import 'package:comunic/models/conversation.dart';
|
import 'package:comunic/models/conversation.dart';
|
||||||
import 'package:comunic/models/conversation_message.dart';
|
import 'package:comunic/models/conversation_message.dart';
|
||||||
import 'package:comunic/models/new_conversation_message.dart';
|
import 'package:comunic/models/new_conversation_message.dart';
|
||||||
@ -17,6 +18,7 @@ import 'package:comunic/ui/widgets/scroll_watcher.dart';
|
|||||||
import 'package:comunic/utils/files_utils.dart';
|
import 'package:comunic/utils/files_utils.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:comunic/utils/list_utils.dart';
|
import 'package:comunic/utils/list_utils.dart';
|
||||||
|
import 'package:comunic/utils/log_utils.dart';
|
||||||
import 'package:comunic/utils/ui_utils.dart';
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@ -48,12 +50,20 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
ConversationMessagesList _messages;
|
ConversationMessagesList _messages;
|
||||||
UsersList _usersInfo = UsersList();
|
UsersList _usersInfo = UsersList();
|
||||||
ErrorLevel _error = ErrorLevel.NONE;
|
ErrorLevel _error = ErrorLevel.NONE;
|
||||||
bool _isMessageValid = false;
|
|
||||||
bool _isSendingMessage = false;
|
bool _isSendingMessage = false;
|
||||||
TextEditingController _textEditingController = TextEditingController();
|
TextEditingController _textEditingController = TextEditingController();
|
||||||
ScrollWatcher _scrollController;
|
ScrollWatcher _scrollController;
|
||||||
_OlderMessagesLevel _loadingOlderMessages = _OlderMessagesLevel.NONE;
|
_OlderMessagesLevel _loadingOlderMessages = _OlderMessagesLevel.NONE;
|
||||||
|
|
||||||
|
String get textMessage => _textEditingController.text;
|
||||||
|
|
||||||
|
bool get _isMessageValid =>
|
||||||
|
textMessage.length >=
|
||||||
|
ServerConfigurationHelper.config.conversationsPolicy.minMessageLen &&
|
||||||
|
textMessage.length <
|
||||||
|
ServerConfigurationHelper.config.conversationsPolicy.maxMessageLen;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -213,21 +223,31 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
|
|
||||||
/// Pick and send an image
|
/// Pick and send an image
|
||||||
Future<void> _sendImage(BuildContext context) async {
|
Future<void> _sendImage(BuildContext context) async {
|
||||||
|
try {
|
||||||
final image = await pickImage(context);
|
final image = await pickImage(context);
|
||||||
|
|
||||||
if (image == null) return null;
|
if (image == null) return;
|
||||||
|
|
||||||
_submitMessage(
|
await _sendFileMessage(BytesFile(
|
||||||
|
image.path.split("/").last,
|
||||||
|
await image.readAsBytes(),
|
||||||
|
));
|
||||||
|
} catch (e, s) {
|
||||||
|
logError(e, s);
|
||||||
|
showSimpleSnack(context, tr("Failed to send image!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Send a file message
|
||||||
|
Future<void> _sendFileMessage(BytesFile file) async {
|
||||||
|
await _submitMessage(
|
||||||
context,
|
context,
|
||||||
NewConversationMessage(
|
NewConversationMessage(
|
||||||
conversationID: widget.conversationID,
|
conversationID: widget.conversationID,
|
||||||
message: null,
|
message: null,
|
||||||
image: image,
|
file: file,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// In case a message was already written in the input
|
|
||||||
_updatedText(_textEditingController.text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a new text message
|
/// Send a new text message
|
||||||
@ -265,18 +285,9 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updatedText(String text) {
|
|
||||||
setState(() {
|
|
||||||
_isMessageValid = text.length > 2;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear send message form
|
/// Clear send message form
|
||||||
void _clearSendMessageForm() {
|
void _clearSendMessageForm() {
|
||||||
setState(() {
|
setState(() => _textEditingController = TextEditingController());
|
||||||
_textEditingController = TextEditingController();
|
|
||||||
_isMessageValid = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if a message is the last message of a user or not
|
/// Check if a message is the last message of a user or not
|
||||||
@ -352,7 +363,7 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
margin: new EdgeInsets.symmetric(horizontal: 4.0),
|
margin: new EdgeInsets.symmetric(horizontal: 4.0),
|
||||||
child: new IconButton(
|
child: new IconButton(
|
||||||
icon: new Icon(
|
icon: new Icon(
|
||||||
Icons.photo_camera,
|
Icons.add,
|
||||||
color: _isSendingMessage
|
color: _isSendingMessage
|
||||||
? Theme.of(context).disabledColor
|
? Theme.of(context).disabledColor
|
||||||
: Theme.of(context).accentColor,
|
: Theme.of(context).accentColor,
|
||||||
@ -366,7 +377,8 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
child: new TextField(
|
child: new TextField(
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
maxLength: 200,
|
maxLength: ServerConfigurationHelper
|
||||||
|
.config.conversationsPolicy.maxMessageLen,
|
||||||
maxLengthEnforced: true,
|
maxLengthEnforced: true,
|
||||||
|
|
||||||
// Show max length only when there is some text already typed
|
// Show max length only when there is some text already typed
|
||||||
@ -374,7 +386,7 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
|
|||||||
|
|
||||||
enabled: !_isSendingMessage,
|
enabled: !_isSendingMessage,
|
||||||
controller: _textEditingController,
|
controller: _textEditingController,
|
||||||
onChanged: _updatedText,
|
onChanged: (s) => setState(() {}),
|
||||||
onSubmitted: _isMessageValid
|
onSubmitted: _isMessageValid
|
||||||
? (s) => _submitTextMessage(context, s)
|
? (s) => _submitTextMessage(context, s)
|
||||||
: null,
|
: null,
|
||||||
|
Loading…
Reference in New Issue
Block a user