mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 06:49:22 +00:00
Update conversations list screen
This commit is contained in:
parent
22f27a24de
commit
0fb83079a6
@ -1,6 +1,5 @@
|
|||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
|
|
||||||
import 'package:comunic/lists/users_list.dart';
|
|
||||||
import 'package:comunic/models/conversation.dart';
|
import 'package:comunic/models/conversation.dart';
|
||||||
|
|
||||||
/// Conversations list
|
/// Conversations list
|
||||||
@ -9,7 +8,6 @@ import 'package:comunic/models/conversation.dart';
|
|||||||
|
|
||||||
class ConversationsList extends ListBase<Conversation> {
|
class ConversationsList extends ListBase<Conversation> {
|
||||||
final List<Conversation> _list = [];
|
final List<Conversation> _list = [];
|
||||||
UsersList users;
|
|
||||||
|
|
||||||
set length(l) => _list.length = l;
|
set length(l) => _list.length = l;
|
||||||
|
|
||||||
@ -27,4 +25,9 @@ class ConversationsList extends ListBase<Conversation> {
|
|||||||
forEach((c) => c.members.forEach((member) => list.add(member.userID)));
|
forEach((c) => c.members.forEach((member) => list.add(member.userID)));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the entire lists of groups ID in this list
|
||||||
|
Set<int> get allGroupsID => where((element) => element.isGroupConversation)
|
||||||
|
.map((e) => e.groupID)
|
||||||
|
.toSet();
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,9 @@ class Conversation extends SerializableElement<Conversation> {
|
|||||||
bool get sawLastMessage => lastActivity <= membership.lastAccessTime;
|
bool get sawLastMessage => lastActivity <= membership.lastAccessTime;
|
||||||
|
|
||||||
/// Check out whether a conversation is managed or not
|
/// Check out whether a conversation is managed or not
|
||||||
bool get isManaged => groupID != null;
|
bool get isManaged => isGroupConversation;
|
||||||
|
|
||||||
|
bool get isGroupConversation => groupID != null;
|
||||||
|
|
||||||
bool get hasLogo => logoURL != null;
|
bool get hasLogo => logoURL != null;
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import 'package:comunic/enums/load_error_level.dart';
|
import 'package:comunic/enums/load_error_level.dart';
|
||||||
import 'package:comunic/helpers/conversations_helper.dart';
|
import 'package:comunic/helpers/conversations_helper.dart';
|
||||||
import 'package:comunic/helpers/events_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/helpers/users_helper.dart';
|
||||||
import 'package:comunic/lists/conversations_list.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/models/conversation.dart';
|
||||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
||||||
import 'package:comunic/ui/routes/update_conversation_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 ConversationsHelper _conversationsHelper = ConversationsHelper();
|
||||||
final UsersHelper _usersHelper = UsersHelper();
|
final UsersHelper _usersHelper = UsersHelper();
|
||||||
ConversationsList _list;
|
ConversationsList _list;
|
||||||
|
UsersList _users;
|
||||||
|
GroupsList _groups;
|
||||||
LoadErrorLevel _error = LoadErrorLevel.NONE;
|
LoadErrorLevel _error = LoadErrorLevel.NONE;
|
||||||
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
|
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
|
||||||
GlobalKey<RefreshIndicatorState>();
|
GlobalKey<RefreshIndicatorState>();
|
||||||
@ -72,8 +77,10 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
|
|||||||
: await _conversationsHelper.downloadList();
|
: await _conversationsHelper.downloadList();
|
||||||
assert(list != null);
|
assert(list != null);
|
||||||
|
|
||||||
//Get information about the members of the conversations
|
// Get information about the members of the conversations
|
||||||
list.users = await _usersHelper.getList(list.allUsersID);
|
_users = await _usersHelper.getList(list.allUsersID);
|
||||||
|
|
||||||
|
_groups = await GroupsHelper().getListOrThrow(list.allGroupsID);
|
||||||
|
|
||||||
setState(() => _list = list);
|
setState(() => _list = list);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
@ -124,6 +131,15 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
|
|||||||
|
|
||||||
/// Handle conversation deletion request
|
/// Handle conversation deletion request
|
||||||
Future<void> _requestLeaveConversation(Conversation conversation) async {
|
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(
|
final result = await showConfirmDialog(
|
||||||
context: context,
|
context: context,
|
||||||
message: conversation.isLastAdmin
|
message: conversation.isLastAdmin
|
||||||
@ -167,9 +183,13 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
|
|||||||
physics: AlwaysScrollableScrollPhysics(),
|
physics: AlwaysScrollableScrollPhysics(),
|
||||||
controller: ScrollController(),
|
controller: ScrollController(),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
if (_list[index].isGroupConversation &&
|
||||||
|
!_list[index].following) return Container();
|
||||||
|
|
||||||
return ConversationTile(
|
return ConversationTile(
|
||||||
conversation: _list.elementAt(index),
|
conversation: _list.elementAt(index),
|
||||||
usersList: _list.users,
|
usersList: _users,
|
||||||
|
groupsList: _groups,
|
||||||
onOpen: (c) {
|
onOpen: (c) {
|
||||||
_openConversation(c.id);
|
_openConversation(c.id);
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:comunic/helpers/conversations_helper.dart';
|
import 'package:comunic/helpers/conversations_helper.dart';
|
||||||
|
import 'package:comunic/lists/groups_list.dart';
|
||||||
import 'package:comunic/lists/users_list.dart';
|
import 'package:comunic/lists/users_list.dart';
|
||||||
import 'package:comunic/models/conversation.dart';
|
import 'package:comunic/models/conversation.dart';
|
||||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
||||||
@ -21,6 +22,7 @@ enum _PopupMenuChoices { UPDATE, LEAVE }
|
|||||||
class ConversationTile extends StatelessWidget {
|
class ConversationTile extends StatelessWidget {
|
||||||
final Conversation conversation;
|
final Conversation conversation;
|
||||||
final UsersList usersList;
|
final UsersList usersList;
|
||||||
|
final GroupsList groupsList;
|
||||||
final OpenConversationCallback onOpen;
|
final OpenConversationCallback onOpen;
|
||||||
final RequestUpdateConversationCallback onRequestUpdate;
|
final RequestUpdateConversationCallback onRequestUpdate;
|
||||||
final RequestLeaveConversationCallback onRequestLeave;
|
final RequestLeaveConversationCallback onRequestLeave;
|
||||||
@ -29,6 +31,7 @@ class ConversationTile extends StatelessWidget {
|
|||||||
Key key,
|
Key key,
|
||||||
@required this.conversation,
|
@required this.conversation,
|
||||||
@required this.usersList,
|
@required this.usersList,
|
||||||
|
@required this.groupsList,
|
||||||
@required this.onOpen,
|
@required this.onOpen,
|
||||||
@required this.onRequestUpdate,
|
@required this.onRequestUpdate,
|
||||||
@required this.onRequestLeave,
|
@required this.onRequestLeave,
|
||||||
@ -86,7 +89,14 @@ class ConversationTile extends StatelessWidget {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
_buildSubInformation(Icons.access_time,
|
_buildSubInformation(Icons.access_time,
|
||||||
diffTimeFromNowToStr(conversation.lastActivity)),
|
diffTimeFromNowToStr(conversation.lastActivity)),
|
||||||
_buildSubInformation(
|
conversation.isGroupConversation
|
||||||
|
? _buildSubInformation(
|
||||||
|
Icons.link,
|
||||||
|
tr("Group: %group_name%", args: {
|
||||||
|
"group_name":
|
||||||
|
groupsList.getGroup(conversation.groupID).name
|
||||||
|
}))
|
||||||
|
: _buildSubInformation(
|
||||||
Icons.group,
|
Icons.group,
|
||||||
conversation.members.length == 1
|
conversation.members.length == 1
|
||||||
? tr("1 member")
|
? tr("1 member")
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
|
||||||
import 'package:comunic/helpers/preferences_helper.dart';
|
import 'package:comunic/helpers/preferences_helper.dart';
|
||||||
import 'package:comunic/main.dart';
|
import 'package:comunic/main.dart';
|
||||||
import 'package:comunic/ui/routes/full_screen_image.dart';
|
import 'package:comunic/ui/routes/full_screen_image.dart';
|
||||||
import 'package:comunic/ui/widgets/dialogs/auto_sized_dialog_content_widget.dart';
|
import 'package:comunic/ui/widgets/dialogs/auto_sized_dialog_content_widget.dart';
|
||||||
|
import 'package:comunic/ui/widgets/dialogs/cancel_dialog_button.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_emoji/flutter_emoji.dart';
|
import 'package:flutter_emoji/flutter_emoji.dart';
|
||||||
@ -220,6 +222,20 @@ Future<bool> showConfirmDialog({
|
|||||||
return result != null && result;
|
return result != null && result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Show a simple alert dialog
|
||||||
|
Future<void> showAlert({
|
||||||
|
@required BuildContext context,
|
||||||
|
@required String message,
|
||||||
|
String title,
|
||||||
|
}) async =>
|
||||||
|
await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (c) => AlertDialog(
|
||||||
|
title: title == null ? null : Text(title),
|
||||||
|
content: Text(message),
|
||||||
|
actions: [CancelDialogButton()],
|
||||||
|
));
|
||||||
|
|
||||||
/// Smart [InputCounterWidgetBuilder] that show text limit only when some
|
/// Smart [InputCounterWidgetBuilder] that show text limit only when some
|
||||||
/// text has already been entered by the user
|
/// text has already been entered by the user
|
||||||
Widget smartInputCounterWidgetBuilder(
|
Widget smartInputCounterWidgetBuilder(
|
||||||
|
Loading…
Reference in New Issue
Block a user