package peergos.shared.user;

import jsinterop.annotations.*;
import peergos.shared.social.*;
import peergos.shared.user.fs.*;

import java.util.*;
import java.util.stream.*;

@JsType
public class SocialState {
    public static final String FRIENDS_GROUP_NAME = "friends";
    public static final String FOLLOWERS_GROUP_NAME = "followers";

    public final List<FollowRequestWithCipherText> pendingIncoming;
    public final Set<String> pendingOutgoing;
    public final Map<String, FileWrapper> followerRoots;
    public final Set<FileWrapper> followingRoots;
    public final Map<String, FileWrapper> pendingOutgoingFollowRequests;
    public final Map<String, FriendAnnotation> friendAnnotations;
    public final Map<String, String> uidToGroupName, groupNameToUid;

    public SocialState(List<FollowRequestWithCipherText> pendingIncoming,
                       Set<String> pendingOutgoing,
                       Set<String> actualFollowers,
                       Map<String, FileWrapper> followerRoots,
                       Set<FileWrapper> followingRoots,
                       Map<String, FriendAnnotation> friendAnnotations,
                       Map<String, String> uidToGroupName) {
        this.pendingIncoming = pendingIncoming;
        this.pendingOutgoing = pendingOutgoing;
        this.pendingOutgoingFollowRequests = followerRoots.entrySet()
                .stream()
                .filter(e -> ! actualFollowers.contains(e.getKey()))
                .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
        Map<String, FileWrapper> actualFollowerRoots = followerRoots.entrySet()
                .stream()
                .filter(e -> actualFollowers.contains(e.getKey()))
                .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
        this.followerRoots = new TreeMap<>(actualFollowerRoots);
        TreeSet<FileWrapper> sortedByName = new TreeSet<>((a, b) -> a.getName().compareTo(b.getName()));
        sortedByName.addAll(followingRoots);
        this.followingRoots = sortedByName;
        this.friendAnnotations = friendAnnotations;
        this.uidToGroupName = uidToGroupName;
        this.groupNameToUid = uidToGroupName.entrySet()
                .stream()
                .collect(Collectors.toMap(e -> e.getValue(), e -> e.getKey()));
    }

    public Set<String> getFollowers() {
        return followerRoots.keySet();
    }

    public Set<String> getFollowing() {
        return followingRoots.stream().map(f -> f.getFileProperties().name).collect(Collectors.toSet());
    }

    public Set<String> getFriends() {
        HashSet<String> res = new HashSet<>(getFollowing());
        res.retainAll(getFollowers());
        return res;
    }

    public String getFriendsGroupUid() {
        return groupNameToUid.get(FRIENDS_GROUP_NAME);
    }

    public String getFollowersGroupUid() {
        return groupNameToUid.get(FOLLOWERS_GROUP_NAME);
    }
}

@@ -560,81 +560,8 @@
 ts;%0A
-    public final Map%3CString, FileWrapper%3E pendingOutgoingFollowRequests;%0A
     
@@ -1222,253 +1222,8 @@
 ng;%0A
-        this.pendingOutgoingFollowRequests = followerRoots.entrySet()%0A                .stream()%0A                .filter(e -%3E ! actualFollowers.contains(e.getKey()))%0A                .collect(Collectors.toMap(e -%3E e.getKey(), e -%3E e.getValue()));%0A
     

Remove unused member on SocialSate