1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 08:15:16 +00:00

Use the conversation messages cache before going online

This commit is contained in:
2019-04-27 09:24:29 +02:00
parent eaac6b1afa
commit 0579397ba7
4 changed files with 74 additions and 10 deletions

View File

@ -43,7 +43,7 @@ class _ConversationScreenState extends State<ConversationScreen> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
_loadMessages();
_initializeLoading();
}
void _setError(ErrorLevel err) => setState(() => _error = err);
@ -55,15 +55,27 @@ class _ConversationScreenState extends State<ConversationScreen> {
_setError(_messages == null ? ErrorLevel.MAJOR : ErrorLevel.MINOR);
}
/// Load the first conversations
Future<void> _initializeLoading() async {
await _loadMessages(false);
await _loadMessages(true);
}
/// Load a list of messages
Future<void> _loadMessages() async {
Future<void> _loadMessages(bool online) async {
//First, get the messages
final messages = await _conversationsHelper.getNewMessages(
conversationID: widget.conversationID,
lastMessageID: _messages == null ? 0 : _messages.lastMessageID);
lastMessageID: _messages == null ? 0 : _messages.lastMessageID,
online: online);
if (messages == null) return _errorLoading();
// In case we are offline and we did not get any message we do not do
// anything (we wait for the online request)
if(messages.length == 0 && !online)
return;
//Then get information about users
final usersToGet =
findMissingFromList(_usersInfo.usersID, messages.getUsersID());
@ -254,6 +266,9 @@ class _ConversationScreenState extends State<ConversationScreen> {
return Column(
children: <Widget>[
Container(
child: _error == ErrorLevel.MINOR ? _buildError() : null,
),
_buildMessagesList(),
Divider(),
_buildSendMessageForm()