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';
class FriendList extends StatefulWidget {
final List<Friend> friends;
final List<Friend> 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<FriendList> {
@override
void initState() {
super.initState();
initFriends();
friends.addAll(widget.friends);
friendRequests.addAll(widget.friendRequests);
}
Future<void> initFriends() async {
friends = await getFriends(accepted: true);
friendRequests = await getFriends(accepted: false);
setState(() {});
widget.callback();
}
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));
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,


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

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


Loading…
Cancel
Save