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

Update conversations list screen

This commit is contained in:
2021-04-06 18:04:16 +02:00
parent 22f27a24de
commit 0fb83079a6
5 changed files with 68 additions and 17 deletions

View File

@ -1,8 +1,11 @@
import 'package:comunic/enums/load_error_level.dart';
import 'package:comunic/helpers/conversations_helper.dart';
import 'package:comunic/helpers/events_helper.dart';
import 'package:comunic/helpers/groups_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/conversations_list.dart';
import 'package:comunic/lists/groups_list.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/conversation.dart';
import 'package:comunic/ui/routes/main_route/main_route.dart';
import 'package:comunic/ui/routes/update_conversation_route.dart';
@ -36,6 +39,8 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
final ConversationsHelper _conversationsHelper = ConversationsHelper();
final UsersHelper _usersHelper = UsersHelper();
ConversationsList _list;
UsersList _users;
GroupsList _groups;
LoadErrorLevel _error = LoadErrorLevel.NONE;
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
@ -72,8 +77,10 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
: await _conversationsHelper.downloadList();
assert(list != null);
//Get information about the members of the conversations
list.users = await _usersHelper.getList(list.allUsersID);
// Get information about the members of the conversations
_users = await _usersHelper.getList(list.allUsersID);
_groups = await GroupsHelper().getListOrThrow(list.allGroupsID);
setState(() => _list = list);
} catch (e, s) {
@ -124,6 +131,15 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
/// Handle conversation deletion request
Future<void> _requestLeaveConversation(Conversation conversation) async {
if (conversation.isGroupConversation) {
showAlert(
context: context,
title: tr("Group conversation"),
message: tr(
"This conversation is managed by a group. You can not leave it this way. If you do not want to receive notifications from this conversation anymore, you can stop following it in the conversation settings"));
return;
}
final result = await showConfirmDialog(
context: context,
message: conversation.isLastAdmin
@ -167,9 +183,13 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
physics: AlwaysScrollableScrollPhysics(),
controller: ScrollController(),
itemBuilder: (context, index) {
if (_list[index].isGroupConversation &&
!_list[index].following) return Container();
return ConversationTile(
conversation: _list.elementAt(index),
usersList: _list.users,
usersList: _users,
groupsList: _groups,
onOpen: (c) {
_openConversation(c.id);
},