From b2e97646cddb506a15d48debccbd8216ed726070 Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Thu, 11 Aug 2022 19:39:01 +0930 Subject: [PATCH] Fix accepting friend requests Fix "No Friends" flickering on tab change --- mobile/lib/views/main/friend/list.dart | 11 ++++++++++- .../lib/views/main/friend/request_list_item.dart | 2 +- mobile/lib/views/main/home.dart | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/mobile/lib/views/main/friend/list.dart b/mobile/lib/views/main/friend/list.dart index 82aa8be..ded6225 100644 --- a/mobile/lib/views/main/friend/list.dart +++ b/mobile/lib/views/main/friend/list.dart @@ -8,8 +8,15 @@ import '/components/custom_expandable_fab.dart'; import '/views/main/friend/list_item.dart'; class FriendList extends StatefulWidget { + final List friends; + final List friendRequests; + final Function callback; + const FriendList({ Key? key, + required this.friends, + required this.friendRequests, + required this.callback, }) : super(key: key); @override @@ -111,13 +118,15 @@ class _FriendListState extends State { @override void initState() { super.initState(); - initFriends(); + friends.addAll(widget.friends); + friendRequests.addAll(widget.friendRequests); } Future initFriends() async { friends = await getFriends(accepted: true); friendRequests = await getFriends(accepted: false); setState(() {}); + widget.callback(); } Widget headingOrNull(String heading) { diff --git a/mobile/lib/views/main/friend/request_list_item.dart b/mobile/lib/views/main/friend/request_list_item.dart index 07c7e24..21b81b0 100644 --- a/mobile/lib/views/main/friend/request_list_item.dart +++ b/mobile/lib/views/main/friend/request_list_item.dart @@ -102,7 +102,7 @@ class _FriendRequestListItemState extends State { final symmetricKey = AesHelper.deriveKey(generateRandomString(32)); String payloadJson = jsonEncode({ - 'user_id': widget.friend.userId, + 'user_id': widget.friend.friendId, 'friend_id': base64.encode(CryptoUtils.rsaEncrypt( Uint8List.fromList(profile.id.codeUnits), widget.friend.publicKey, diff --git a/mobile/lib/views/main/home.dart b/mobile/lib/views/main/home.dart index 46e5765..e740db0 100644 --- a/mobile/lib/views/main/home.dart +++ b/mobile/lib/views/main/home.dart @@ -33,7 +33,7 @@ class _HomeState extends State { int _selectedIndex = 0; List _widgetOptions = [ const ConversationList(conversations: [], friends: []), - const FriendList(), + FriendList(friends: const [], friendRequests: const [], callback: () {}), Profile( profile: MyProfile( id: '', @@ -154,6 +154,7 @@ class _HomeState extends State { conversations = await getConversations(); friends = await getFriends(accepted: true); + friendRequests = await getFriends(accepted: false); profile = await MyProfile.getProfile(); setState(() { @@ -162,13 +163,22 @@ class _HomeState extends State { conversations: conversations, friends: friends, ), - const FriendList(), + FriendList( + friends: friends, + friendRequests: friendRequests, + callback: initFriends, + ), Profile(profile: profile), ]; isLoading = false; }); } + Future initFriends() async { + friends = await getFriends(accepted: true); + friendRequests = await getFriends(accepted: false); + } + void _onItemTapped(int index) { setState(() { _selectedIndex = index;