locality_social_cloud_friendlist 1.1.0 locality_social_cloud_friendlist: ^1.1.0 copied to clipboard
A simple friendlist based on Locality Social Cloud.
locality_social_cloud_friendlist #
A Flutter package based on Locality Social Cloud that provides a pub-sub based friend list system for sending and receiving friend requests between users. This package allows you to manage friend lists securely and efficiently, using SHA-256 for topic hashing and pub-sub mechanisms for event-driven updates.
Features #
- Send and receive friend requests between users.
- Manage friend lists via a pub-sub architecture.
- Automatically register and track friend lists.
- Securely generate unique friend list topics using SHA-256 hashing.
- Check the friend status between users easily.
Setup #
Configure your Locality Social Cloud and enter your appId and appSecret and connect the Cloud:
LocalitySocialCloud.configure(appId: '..', appSecret: '...=');
LoggedInUser loggedInUser = (await LocalitySocialCloud.auth('testuser1', 'pwd1')).loggedInUser!;
LocalityUser user1 = loggedInUser.user;
LocalityUser user2 = (await LocalitySocialCloud.auth('testuser2', 'pwd2')).loggedInUser!.user;
Usage #
Get the FriendList of a LocalityUser:
FriendList friendList1 = FriendListFacade.getFriendListOfUser(user1);
FriendList friendList2 = FriendListFacade.getFriendListOfUser(user2);
If you want to display the FriendList in the UI, you could use this style:
friendList1.addListener(() {
logger.info("These are all friends in the friendlist 1 after one throttled UI update: ");
for (var friendRequest in friendList1.friendRequests) {
....
}
});
The FriendList is a ThrottledProvider and can be easily be used together with the Provider package to display UI changes.
Let us say, you want to send a friend request only if you have not sent one so far. Then you can use the Timeline of the FriendList like this:
friendList1.timeline.whenSynchronized(() {
logger.info("The timelines are now synchronized of friendlist1.");
logger.info("Now we know whether the target user is our friend and we can send him a friend request if he is not.");
if (!friendList1.sentFriendRequestToUser(user2)) {
logger.info("Sending friend request ... ");
FriendListFacade.sendFriendRequest(user1, user2);
}
});
You can also check if they sent a friend request to each other like this:
friendList1.timeline.whenSynchronized(() {
if ( friendList1.isFriendsWithThisUser(user2) ) {
....
}
});
after initialization.
You can get a list of all the friends ( where they sent friend requests to each other ) like
friendList1.timeline.whenSynchronized(() {
List<LocalityUser> friends = friendList1.computeFriends();
});