mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 04:48:51 +00:00
Can respond to friendship requests from memberships bar
This commit is contained in:
parent
c5c544fb34
commit
263849266f
@ -30,4 +30,8 @@ class MembershipList extends AbstractList<Membership> {
|
||||
Set<int> get groupsId => where((f) => f.type == MembershipType.GROUP)
|
||||
.map((f) => f.groupID)
|
||||
.toSet();
|
||||
|
||||
/// Remove a friend membership from the list
|
||||
void removeFriend(int friendID) => remove(firstWhere(
|
||||
(f) => f.type == MembershipType.FRIEND && f.friend.id == friendID));
|
||||
}
|
||||
|
@ -8,12 +8,12 @@ import 'package:meta/meta.dart';
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class Friend extends CacheModel implements Comparable<Friend> {
|
||||
final bool accepted;
|
||||
bool accepted;
|
||||
final int lastActive;
|
||||
final bool following;
|
||||
final bool canPostTexts;
|
||||
|
||||
const Friend({
|
||||
Friend({
|
||||
@required int id,
|
||||
@required this.accepted,
|
||||
@required this.lastActive,
|
||||
@ -22,6 +22,8 @@ class Friend extends CacheModel implements Comparable<Friend> {
|
||||
}) : assert(id != null),
|
||||
assert(accepted != null),
|
||||
assert(lastActive != null),
|
||||
assert(following != null),
|
||||
assert(canPostTexts != null),
|
||||
super(id: id);
|
||||
|
||||
/// Check out whether friend is connected or not
|
||||
|
@ -1,10 +1,12 @@
|
||||
import 'package:comunic/helpers/conversations_helper.dart';
|
||||
import 'package:comunic/helpers/friends_helper.dart';
|
||||
import 'package:comunic/helpers/groups_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/helpers/webapp_helper.dart';
|
||||
import 'package:comunic/lists/groups_list.dart';
|
||||
import 'package:comunic/lists/memberships_list.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/friend.dart';
|
||||
import 'package:comunic/models/membership.dart';
|
||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||
import 'package:comunic/ui/widgets/group_icon_widget.dart';
|
||||
@ -92,13 +94,40 @@ class _MembershipsPanelState extends SafeState<MembershipsPanel> {
|
||||
Widget _buildFriendMembership(Membership membership) {
|
||||
final user = _usersList.getUser(membership.friend.id);
|
||||
final connected = membership.friend.isConnected;
|
||||
|
||||
Widget subtitle;
|
||||
|
||||
if (!membership.friend.accepted) {
|
||||
subtitle = RichText(
|
||||
text: TextSpan(children: [
|
||||
WidgetSpan(
|
||||
child: _RespondFriendshipRequestButton(
|
||||
friend: membership.friend,
|
||||
accept: true,
|
||||
text: tr("Accept"),
|
||||
color: Colors.green,
|
||||
onTap: _respondFriendshipRequest,
|
||||
)),
|
||||
TextSpan(text: " "),
|
||||
WidgetSpan(
|
||||
child: _RespondFriendshipRequestButton(
|
||||
friend: membership.friend,
|
||||
accept: false,
|
||||
text: tr("Reject"),
|
||||
color: Colors.red,
|
||||
onTap: _respondFriendshipRequest,
|
||||
)),
|
||||
]));
|
||||
} else
|
||||
subtitle = Text(
|
||||
connected ? tr("Online") : diffTimeFromNowToStr(membership.lastActive),
|
||||
style: TextStyle(color: connected ? Colors.green : null),
|
||||
);
|
||||
|
||||
return ListTile(
|
||||
leading: AccountImageWidget(user: user, width: _MembershipIconsWidth),
|
||||
title: Text(user.displayName),
|
||||
subtitle: Text(
|
||||
connected ? tr("Online") : diffTimeFromNowToStr(membership.lastActive),
|
||||
style: TextStyle(color: connected ? Colors.green : null),
|
||||
),
|
||||
subtitle: subtitle,
|
||||
);
|
||||
}
|
||||
|
||||
@ -124,4 +153,55 @@ class _MembershipsPanelState extends SafeState<MembershipsPanel> {
|
||||
subtitle: Text(diffTimeFromNowToStr(membership.lastActive)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Respond to a friendship request
|
||||
Future<void> _respondFriendshipRequest(Friend f, bool accept) async {
|
||||
try {
|
||||
if (!accept &&
|
||||
!await showConfirmDialog(
|
||||
context: Scaffold.of(context)
|
||||
.context, // Without this the text appears in white
|
||||
message:
|
||||
tr("Do you really want to reject this friendship request?")))
|
||||
return;
|
||||
|
||||
await FriendsHelper().respondRequest(f.id, accept);
|
||||
|
||||
setState(() {
|
||||
if (accept)
|
||||
f.accepted = true;
|
||||
else
|
||||
_membershipList.removeFriend(f.id);
|
||||
});
|
||||
_refreshKey.currentState.show();
|
||||
} catch (e, s) {
|
||||
print("Could not respond to friendship request! $e\n$s");
|
||||
showSimpleSnack(context, tr("Could not respond to friendship request!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _RespondFriendshipRequestButton extends StatelessWidget {
|
||||
final Friend friend;
|
||||
final bool accept;
|
||||
final String text;
|
||||
final Color color;
|
||||
final void Function(Friend, bool) onTap;
|
||||
|
||||
const _RespondFriendshipRequestButton({
|
||||
Key key,
|
||||
@required this.friend,
|
||||
@required this.accept,
|
||||
@required this.text,
|
||||
@required this.color,
|
||||
@required this.onTap,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: () => onTap(friend, accept),
|
||||
child: Text(text, style: TextStyle(color: color)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user