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

Open private conversation from friends list

This commit is contained in:
2019-05-02 08:09:40 +02:00
parent eba12736e9
commit 21a60f423b
4 changed files with 85 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import 'package:comunic/models/friend.dart';
import 'package:comunic/ui/tiles/accepted_friend_tile.dart';
import 'package:comunic/ui/tiles/pending_friend_tile.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:comunic/utils/conversations_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
@ -111,6 +112,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
? AcceptedFriendTile(
friend: _friendsList[i],
user: _usersInfo.getUser(_friendsList[i].id),
onOpenPrivateConversation: _openPrivateConversation,
onSetFollowing: _setFollowingFriend,
onRequestDelete: _deleteFriend,
)
@ -135,16 +137,14 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
_loadList();
}
/// Update following status of a friend
Future<void> _setFollowingFriend(Friend friend, bool follow) async {
loading = true;
if(!await _friendsHelper.setFollowing(friend.id, follow))
if (!await _friendsHelper.setFollowing(friend.id, follow))
showSimpleSnack(context, tr("Could not update following status!"));
_loadList();
}
/// Handles deletion request of a friend
@ -182,4 +182,11 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
// Refresh list
_loadList();
}
/// Open a private conversation for a given [friend]
Future<void> _openPrivateConversation(Friend friend) async {
loading = true;
await openPrivateConversation(context, friend.id);
loading = false;
}
}

View File

@ -9,16 +9,18 @@ import 'package:flutter/material.dart';
///
/// @author Pierre HUBERT
enum _FriendMenuChoices { REMOVE, TOGGLE_FOLLOWING }
enum _FriendMenuChoices { REMOVE, TOGGLE_FOLLOWING, PRIVATE_CONVERSATION }
typedef OnRequestDeleteFriend = void Function(Friend);
typedef OnSetFollowing = void Function(Friend, bool);
typedef OnOpenPrivateConversation = void Function(Friend);
class AcceptedFriendTile extends StatelessWidget {
final Friend friend;
final User user;
final OnRequestDeleteFriend onRequestDelete;
final OnSetFollowing onSetFollowing;
final OnOpenPrivateConversation onOpenPrivateConversation;
const AcceptedFriendTile({
Key key,
@ -26,10 +28,12 @@ class AcceptedFriendTile extends StatelessWidget {
@required this.user,
@required this.onRequestDelete,
@required this.onSetFollowing,
@required this.onOpenPrivateConversation,
}) : assert(friend != null),
assert(user != null),
assert(onRequestDelete != null),
assert(onSetFollowing != null),
assert(onOpenPrivateConversation != null),
super(key: key);
@override
@ -49,6 +53,13 @@ class AcceptedFriendTile extends StatelessWidget {
),
trailing: PopupMenuButton<_FriendMenuChoices>(
itemBuilder: (c) => [
//Open a private conversation
PopupMenuItem(
child: Text(tr("Private conversation")),
value: _FriendMenuChoices.PRIVATE_CONVERSATION,
),
// Update following status
PopupMenuItem(
child: Row(
children: <Widget>[
@ -61,6 +72,8 @@ class AcceptedFriendTile extends StatelessWidget {
),
value: _FriendMenuChoices.TOGGLE_FOLLOWING,
),
// Remove the friend from the list
PopupMenuItem(
child: Text(tr("Remove")),
value: _FriendMenuChoices.REMOVE,
@ -75,6 +88,11 @@ class AcceptedFriendTile extends StatelessWidget {
if (value == null) return;
switch (value) {
// Open private conversation
case _FriendMenuChoices.PRIVATE_CONVERSATION:
onOpenPrivateConversation(friend);
break;
//Toggle following status
case _FriendMenuChoices.TOGGLE_FOLLOWING:
onSetFollowing(friend, !friend.following);