Browse Source

Fix accepting friend requests

Fix "No Friends" flickering on tab change
pull/1/head
Tovi Jaeschke-Rogers 2 years ago
parent
commit
b2e97646cd
3 changed files with 23 additions and 4 deletions
  1. +10
    -1
      mobile/lib/views/main/friend/list.dart
  2. +1
    -1
      mobile/lib/views/main/friend/request_list_item.dart
  3. +12
    -2
      mobile/lib/views/main/home.dart

+ 10
- 1
mobile/lib/views/main/friend/list.dart View File

@ -8,8 +8,15 @@ import '/components/custom_expandable_fab.dart';
import '/views/main/friend/list_item.dart'; import '/views/main/friend/list_item.dart';
class FriendList extends StatefulWidget { class FriendList extends StatefulWidget {
final List<Friend> friends;
final List<Friend> friendRequests;
final Function callback;
const FriendList({ const FriendList({
Key? key, Key? key,
required this.friends,
required this.friendRequests,
required this.callback,
}) : super(key: key); }) : super(key: key);
@override @override
@ -111,13 +118,15 @@ class _FriendListState extends State<FriendList> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
initFriends();
friends.addAll(widget.friends);
friendRequests.addAll(widget.friendRequests);
} }
Future<void> initFriends() async { Future<void> initFriends() async {
friends = await getFriends(accepted: true); friends = await getFriends(accepted: true);
friendRequests = await getFriends(accepted: false); friendRequests = await getFriends(accepted: false);
setState(() {}); setState(() {});
widget.callback();
} }
Widget headingOrNull(String heading) { Widget headingOrNull(String heading) {


+ 1
- 1
mobile/lib/views/main/friend/request_list_item.dart View File

@ -102,7 +102,7 @@ class _FriendRequestListItemState extends State<FriendRequestListItem> {
final symmetricKey = AesHelper.deriveKey(generateRandomString(32)); final symmetricKey = AesHelper.deriveKey(generateRandomString(32));
String payloadJson = jsonEncode({ String payloadJson = jsonEncode({
'user_id': widget.friend.userId,
'user_id': widget.friend.friendId,
'friend_id': base64.encode(CryptoUtils.rsaEncrypt( 'friend_id': base64.encode(CryptoUtils.rsaEncrypt(
Uint8List.fromList(profile.id.codeUnits), Uint8List.fromList(profile.id.codeUnits),
widget.friend.publicKey, widget.friend.publicKey,


+ 12
- 2
mobile/lib/views/main/home.dart View File

@ -33,7 +33,7 @@ class _HomeState extends State<Home> {
int _selectedIndex = 0; int _selectedIndex = 0;
List<Widget> _widgetOptions = <Widget>[ List<Widget> _widgetOptions = <Widget>[
const ConversationList(conversations: [], friends: []), const ConversationList(conversations: [], friends: []),
const FriendList(),
FriendList(friends: const [], friendRequests: const [], callback: () {}),
Profile( Profile(
profile: MyProfile( profile: MyProfile(
id: '', id: '',
@ -154,6 +154,7 @@ class _HomeState extends State<Home> {
conversations = await getConversations(); conversations = await getConversations();
friends = await getFriends(accepted: true); friends = await getFriends(accepted: true);
friendRequests = await getFriends(accepted: false);
profile = await MyProfile.getProfile(); profile = await MyProfile.getProfile();
setState(() { setState(() {
@ -162,13 +163,22 @@ class _HomeState extends State<Home> {
conversations: conversations, conversations: conversations,
friends: friends, friends: friends,
), ),
const FriendList(),
FriendList(
friends: friends,
friendRequests: friendRequests,
callback: initFriends,
),
Profile(profile: profile), Profile(profile: profile),
]; ];
isLoading = false; isLoading = false;
}); });
} }
Future<void> initFriends() async {
friends = await getFriends(accepted: true);
friendRequests = await getFriends(accepted: false);
}
void _onItemTapped(int index) { void _onItemTapped(int index) {
setState(() { setState(() {
_selectedIndex = index; _selectedIndex = index;


Loading…
Cancel
Save