mebabl_social

Typed Flutter/Dart client for the Babilo/Mebabl Platform Social API. The SDK reuses the application's initialized MebablCore instance for API base URL, public Application JWT, authenticated User JWT, token storage and HTTP transport.

Requirements

  • Dart SDK >=3.8.0 <4.0.0
  • Flutter
  • mebabl_core: ^1.2.0
  • Register the signed-in mebabl_auth provider with MebablCore before using methods that require an Application User JWT.

Installation

dependencies:
  mebabl_core: ^1.2.0
  mebabl_social: ^1.3.0

For a local workspace, use a path dependency:

dependencies:
  mebabl_social:
    path: ../mebabl_social

Then run flutter pub get.

Initialization and authentication

final core = await MebablCore.initialize();
final auth = MebablAuthService(core: core);
core.addAuthProvider(auth);

// Default: use the User JWT for reads and writes.
final social = MebablSocialService(core: core);

// Optional: use the limited public Application JWT for endpoints whose
// backend policy is ApplicationPublicOrUser. Mutations and private endpoints
// continue to use the User JWT regardless of this setting.
final publicSocial = MebablSocialService(
  core: core,
  usePublicApplicationTokenForPublicReads: true,
);

The public-read option applies only to endpoints whose controller policy is ApplicationPublicOrUser: post/comment reactions, comments, comment reactions, post statistics, poll retrieval and hashtag discovery. These read endpoints still enforce post visibility, account privacy, block checks, application scope and rate limits on the backend. The option does not make the feed, followers, bookmarks, own privacy settings or mention inbox public.

Every write operation uses MebablAuthMode.user. A public Application JWT cannot create comments, reactions, shares, reposts, follows, bookmarks, polls, votes, privacy changes or mention-read updates. The Core package documents MebablAuthMode.application as the public Application-token policy and MebablAuthMode.user as the Application User JWT policy.

API coverage

Base path: /api/sdk/social.

Posts, reactions, comments and feed

SDK method HTTP method and route Authentication
getFeed GET /feed User
react POST /posts/{postId}/reactions User
removeReaction DELETE /posts/{postId}/reactions User
getReactions GET /posts/{postId}/reactions Public Application or User
createComment, replyToComment POST /posts/{postId}/comments User
getComments GET /posts/{postId}/comments Public Application or User
updateComment PATCH /comments/{commentId} User
deleteComment DELETE /comments/{commentId} User
getPostStats GET /posts/stats?postIds=... Public Application or User
share POST /posts/{postId}/shares User
repost POST /posts/{postId}/reposts User
removeRepost DELETE /posts/{postId}/reposts User
final reaction = await social.react(postId, type: SocialReactionType.love);
final comments = await social.getComments(postId, page: 1, pageSize: 30);
final reply = await social.replyToComment(
  postId,
  parentCommentId: comments.first.id,
  text: 'A reply',
);
final feed = await social.getFeed(page: 1, pageSize: 20);
final stats = await social.getPostStats([postId]);

getFeed, getMyBookmarks and getHashtagPosts return SocialPost. This is a Social API projection with visibility and SocialPostAttachment; it is separate from mebabl_content.Post. The API returns flat paginated comments; use SocialCommentTree.fromComments to project loaded pages into a local tree. Comment also exposes reactionCount and myReaction when the backend includes them.

Post reactions use Like, Love, Laugh, Wow, Sad and Angry. Like is the value counted by the current likes aggregate.

Comment reactions

SDK method HTTP method and route Authentication
reactToComment POST /comments/{commentId}/reactions User
removeCommentReaction DELETE /comments/{commentId}/reactions User
getCommentReactions GET /comments/{commentId}/reactions Public Application or User

Comment reaction values are Like, Love, Haha, Wow, Sad and Angry. They are distinct from post reactions (which use Laugh, not Haha).

Follow graph and mute

SDK method HTTP method and route Authentication
followUser POST /users/{targetUserId}/follow User
unfollowUser DELETE /users/{targetUserId}/follow User
getFollowers GET /users/{userId}/followers User
getFollowing GET /users/{userId}/following User
getSocialGraphStats GET /users/{userId}/social-stats User
getMyFollowRequests GET /me/follow-requests User
acceptFollowRequest POST /follow-requests/{followId}/accept User
declineFollowRequest POST /follow-requests/{followId}/decline User
muteUser POST /users/{targetUserId}/mute User
unmuteUser DELETE /users/{targetUserId}/mute User
getMyMutedUsers GET /me/muted-users User

Following a public account returns an Accepted relation. Following a private account returns a Pending follow request. Accept/decline methods require the followId returned by the incoming follow-request list, not the requester user ID.

final result = await social.followUser(targetUserId);
if (result.isPending) {
  // Wait for the private account owner to approve the request.
}
final followers = await social.getFollowers(targetUserId);
final graph = await social.getSocialGraphStats(targetUserId);

Bookmarks and profile privacy

SDK method HTTP method and route Authentication
bookmarkPost POST /posts/{postId}/bookmark User
removeBookmarkPost DELETE /posts/{postId}/bookmark User
getMyBookmarks GET /me/bookmarks User
getMyPrivacy GET /me/privacy User
updateMyPrivacy PUT /me/privacy User
await social.bookmarkPost(postId);
final savedPosts = await social.getMyBookmarks();

final settings = await social.updateMyPrivacy(
  isPrivateAccount: true,
  allowCommentsFrom: SocialAudience.followers,
  allowMentionsFrom: SocialAudience.followers,
  showFollowersList: false,
  showFollowingList: false,
);

getMyBookmarks returns readable post projections, not bookmark records. The backend rechecks current visibility; saving a post does not grant permanent access if its visibility or follow/block state later changes.

Audience values are SocialAudience.everyone, SocialAudience.followers and SocialAudience.nobody. updateMyPrivacy always sends isPrivateAccount and omits optional settings that are left null.

Mentions

SDK method HTTP method and route Authentication
getMyMentions GET /me/mentions User
markMentionRead POST /me/mentions/{mentionId}/read User
markAllMentionsRead POST /me/mentions/read-all User
final mentions = await social.getMyMentions(page: 1, pageSize: 30);
await social.markMentionRead(mentions.first.id);
// Or mark the whole inbox as read:
await social.markAllMentionsRead();

The inbox DTO includes the actor, content excerpt, post/comment target, read state and timestamps. The backend returns only mentions the signed-in user can still access; it does not return another user's inbox.

Hashtags

SDK method HTTP method and route Authentication
searchHashtags GET /hashtags/search?q=... Public Application or User
getTrendingHashtags GET /hashtags/trending?days=&take= Public Application or User
getHashtagPosts GET /hashtags/{tag}/posts Public Application or User
final matches = await social.searchHashtags('#بابل');
final trending = await social.getTrendingHashtags(days: 7, take: 20);
final posts = await social.getHashtagPosts('بابل', page: 1, pageSize: 20);

Search and hashtag-post page sizes are limited to 50. Trending days is 1-30 and take is 1-50. The service URL-encodes the hashtag path segment. The backend filters all results through the current application's visibility and block rules.

Polls

SDK method HTTP method and route Authentication
createPoll POST /posts/{postId}/poll User
getPostPoll GET /posts/{postId}/poll Public Application or User
castPollVote POST /polls/{pollId}/vote User
closePoll POST /polls/{pollId}/close User
final poll = await social.createPoll(
  postId,
  question: 'Which feature should come next?',
  options: ['Stories', 'Live', 'Groups'],
  allowsMultipleChoices: false,
  allowVoteChanges: true,
  hideResultsUntilVoted: true,
  closesAtUtc: DateTime.now().toUtc().add(const Duration(days: 3)),
);

final votedPoll = await social.castPollVote(
  poll.id,
  optionIds: [poll.options.first.id],
);

Poll questions are limited to 280 characters, options to 100 characters, and a poll must contain 2-10 distinct options. The client validates these limits for early feedback; the backend remains authoritative. SocialPoll.totalVotes, SocialPollOption.voteCount and percentage are nullable because the backend intentionally hides aggregate results until the viewer votes (except for the post owner). Voter identities are never included in the poll response.

Pagination and validation

Most Social list endpoints use page-number pagination starting at 1, with a maximum pageSize of 100. Hashtag search/post endpoints cap page size at 50. The service validates GUID route identifiers, page values, comment length, reaction strings, audience values, hashtag length and poll input before sending requests. These checks are for early client feedback and are not a security boundary; server-side authorization and validation remain authoritative.

Features not exposed as Social routes

This service intentionally follows the inspected SdkSocialController and its DTOs/handlers. It does not invent endpoints for social block/unblock, post creation/media upload, user search/mention suggestions, notification transport, chat delivery, story publishing or a SignalR Social stream. Those belong to their own SDK/API modules or require dedicated backend routes.

Error handling

HTTP/authentication failures are propagated by MebablCore as MebablException. SDK argument validation throws ArgumentError; malformed or unexpected response payloads throw FormatException. Do not treat a local tap as a successful mutation until the returned Future completes. The service does not perform hidden retries for social writes.