isFollowed method

Future<bool> isFollowed(
  1. String followId,
  2. String actorId
)

Implementation

Future<bool> isFollowed(String followId, String actorId) async {
  ActorAPI actorAPI = ActorAPI();
  Actor actor = await actorAPI.getActor(actorId);
  Actor followActor = await actorAPI.getActor(followId);
  followId = followActor.id!;

  OrderedPagedCollection follows = await getFollowings(actor.following!);

  String url = follows.first!;

  do {
    Uri uri = Uri.parse(url);

    if (uri.authority != Config.domainName) {
      uri = uri.asProxyUri();
    }

    http.Response response = await http.get(
      uri,
      headers: <String, String>{"Accept": "application/json"},
    );

    var json = jsonDecode(utf8.decode(response.bodyBytes));

    OrderedCollectionPage collection = OrderedCollectionPage.fromJson(json);

    if (collection.orderedItems.isEmpty) {
      return false;
    }

    if (collection.orderedItems
        .where((element) => element == followId)
        .isNotEmpty) {
      return true;
    }

    url = collection.next!;
  } while (true);
}