mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Update conversations list screen
This commit is contained in:
		@@ -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);
 | 
			
		||||
                      },
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
import 'package:comunic/helpers/conversations_helper.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';
 | 
			
		||||
@@ -21,6 +22,7 @@ enum _PopupMenuChoices { UPDATE, LEAVE }
 | 
			
		||||
class ConversationTile extends StatelessWidget {
 | 
			
		||||
  final Conversation conversation;
 | 
			
		||||
  final UsersList usersList;
 | 
			
		||||
  final GroupsList groupsList;
 | 
			
		||||
  final OpenConversationCallback onOpen;
 | 
			
		||||
  final RequestUpdateConversationCallback onRequestUpdate;
 | 
			
		||||
  final RequestLeaveConversationCallback onRequestLeave;
 | 
			
		||||
@@ -29,6 +31,7 @@ class ConversationTile extends StatelessWidget {
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.conversation,
 | 
			
		||||
    @required this.usersList,
 | 
			
		||||
    @required this.groupsList,
 | 
			
		||||
    @required this.onOpen,
 | 
			
		||||
    @required this.onRequestUpdate,
 | 
			
		||||
    @required this.onRequestLeave,
 | 
			
		||||
@@ -86,17 +89,24 @@ class ConversationTile extends StatelessWidget {
 | 
			
		||||
          children: <Widget>[
 | 
			
		||||
            _buildSubInformation(Icons.access_time,
 | 
			
		||||
                diffTimeFromNowToStr(conversation.lastActivity)),
 | 
			
		||||
            _buildSubInformation(
 | 
			
		||||
              Icons.group,
 | 
			
		||||
              conversation.members.length == 1
 | 
			
		||||
                  ? tr("1 member")
 | 
			
		||||
                  : tr(
 | 
			
		||||
                      "%num% members",
 | 
			
		||||
                      args: {
 | 
			
		||||
                        "num": conversation.members.length.toString(),
 | 
			
		||||
                      },
 | 
			
		||||
                    ),
 | 
			
		||||
            ),
 | 
			
		||||
            conversation.isGroupConversation
 | 
			
		||||
                ? _buildSubInformation(
 | 
			
		||||
                    Icons.link,
 | 
			
		||||
                    tr("Group: %group_name%", args: {
 | 
			
		||||
                      "group_name":
 | 
			
		||||
                          groupsList.getGroup(conversation.groupID).name
 | 
			
		||||
                    }))
 | 
			
		||||
                : _buildSubInformation(
 | 
			
		||||
                    Icons.group,
 | 
			
		||||
                    conversation.members.length == 1
 | 
			
		||||
                        ? tr("1 member")
 | 
			
		||||
                        : tr(
 | 
			
		||||
                            "%num% members",
 | 
			
		||||
                            args: {
 | 
			
		||||
                              "num": conversation.members.length.toString(),
 | 
			
		||||
                            },
 | 
			
		||||
                          ),
 | 
			
		||||
                  ),
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user