Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Friends

Vrekt edited this page Jan 26, 2020 · 3 revisions

The Friends class is a wrapper for FriendsPublicService and the XMPPProvider class provides friends XMPP support.

Getting all friends

            athena.friend().friends(false).forEach(friend -> {
                System.err.println(friend.accountId());
                System.err.println(friend.created());
            });

This method takes a parameter includePending if its true friend requests will be given also.

Friend profile

You can retrieve a friend profile via the Friend object or querying for it manually.

(For example)
            athena.friend().friends(false).forEach(friend -> {
                final var profile = friend.profile();
                System.err.println(profile.accountId());
                System.err.println(profile.displayName());
                System.err.println(profile.mutual());
            });

Or:

final var profile = athena.friend().friendProfile("accountId");

Adding/removing friends

athena.friend().add("accountID to add");
athena.friend().removeOrDecline("accountId");

Blocklist

final var list = athena.friend().blocked();
list.forEach(System.err::println);

Block/unblock

            athena.friend().block("accountId");
            athena.friend().unblock("accountId");

Retrieve friend summary

The friend summary is a list of all friends and their profile. You can also retrieve incoming and outgoing friend requests. As-well as the blocklist, suggested friends and settings.

            final var summary = athena.friend().summary();
            summary.friends().forEach(profile -> {
                // do something.
            });
            summary.incoming().forEach(friend -> System.err.println(friend.displayName()));
            final var specificProfile = summary.profileFromDisplayName("vrekt_");
            // do something..

Other stuff

Set a friend note

athena.friend().setFriendNote("accountId", "note");

Set a friend alias

athena.friend().setFriendAlias("accountId", "CoolFriend123");

You can remove both of these with:

athena.friend().removeFriendNote("accountId");
athena.friend().removeFriendAlias("accountId");

All of these methods can be accessed directly via the Friend object and the Profile object.

            final var profile = athena.friend().friendProfile("accountId");
            profile.setNote("note");
            profile.setAlias("alias");
            
            final var friend = athena.friend().friends(false).get(0);
            friend.setNote("note");
            friend.setAlias("alias");

Events

You can listen for events such as (friend request, friend request accepted/declined, and more) either via annotation or interface.

Each event has a special class where you can retrieve their account and also accept friend requests, for example:

    @FriendEvent
    public void onFriendAccepted(FriendAcceptedEvent event) {
        final var account = event.account();
        System.err.println("account " + account.displayName() + " accepted your friend request.");
    }

Or:

    @FriendEvent
    public void onFriendRequest(FriendRequestEvent event) {
        final var profile = event.accept();
        // do something...
    }

Here is an example of registering a FriendEventListener interface.

            athena.friend().registerEventListener(new FriendEventListener() {
                @Override
                public void friendRequest(FriendRequestEvent event) {
                    // TIP: you can accept with event.accept() which returns their profile.
                }

                @Override
                public void friendDeleted(FriendDeletedEvent event) {

                }

                @Override
                public void friendRejected(FriendRejectedEvent event) {

                }

                @Override
                public void friendAborted(FriendAbortedEvent event) {

                }

                @Override
                public void friendAccepted(FriendAcceptedEvent event) {

                }

                @Override
                public void blockListEntryRemoved(BlockListEntryApiObject blockListEntryApiObject) {

                }

                @Override
                public void blockListEntryRemoved(BlockListUpdate blockListUpdate) {

                }

                @Override
                public void blockListEntryAdded(BlockListEntryApiObject blockListEntryApiObject) {

                }

                @Override
                public void blockListEntryAdded(BlockListUpdate blockListUpdate) {

                }
            });

Here is an example of using the annotation event system. First you must register the event class that will contain the annotated methods.

athena.friend().registerEventListener(this);
// or...
athena.friend().registerEventListener(new MyEventListener());

And then you can create separate methods for handling different things. (Not all methods need to be present).

    @FriendEvent
    public void onFriendAccepted(FriendAcceptedEvent event) {
        System.err.println("account " + event.accountId() + " accepted your friend request.");
    }

    @FriendEvent
    public void onFriendRequest(FriendRequestEvent event) {
        final var profile = event.accept();
        // do something...
    }

And finally

You can change (or get) your friend settings.

final var settings = new FriendSettings("public"); // or "private"
athena.friend().setSettings(settings);
Clone this wiki locally