-
Notifications
You must be signed in to change notification settings - Fork 3
Friends
The Friends
class is a wrapper for FriendsPublicService
and the XMPPProvider
class provides friends XMPP support.
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.
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");
athena.friend().add("accountID to add");
athena.friend().removeOrDecline("accountId");
final var list = athena.friend().blocked();
list.forEach(System.err::println);
athena.friend().block("accountId");
athena.friend().unblock("accountId");
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..
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");
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...
}
You can change (or get) your friend settings.
final var settings = new FriendSettings("public"); // or "private"
athena.friend().setSettings(settings);