mebabl_social 1.2.1
mebabl_social: ^1.2.1 copied to clipboard
Typed Flutter SDK for Mebabl Platform social interactions.
mebabl_social #
Typed Flutter SDK for the Mebabl Platform Social API. It reuses one initialized
MebablCore instance for the configured API base URL, user authentication,
token refresh integration, and HTTP transport.
Requirements #
- Dart SDK
>=3.8.0 <4.0.0 - Flutter
mebabl_core: ^1.2.0- An authenticated application-user session
- The signed-in
mebabl_authprovider must be registered withMebablCorebefore calling Social methods
Installation #
In the app's pubspec.yaml:
dependencies:
mebabl_core: ^1.2.0
mebabl_social: ^1.2.0
For a local monorepo/workspace, use a path dependency instead:
dependencies:
mebabl_social:
path: ../mebabl_social
Then run:
flutter pub get
Initialization #
Initialize Core and register the user auth provider before constructing Social:
final core = await MebablCore.initialize();
final auth = MebablAuthService(core: core);
core.addAuthProvider(auth);
final social = MebablSocialService(core: core);
All Social API requests explicitly use MebablAuthMode.user. An Application
JWT is not sufficient for these endpoints. Missing or expired user sessions
are handled by the configured Core/Auth integration.
Implemented backend contract #
The methods below map to the current SdkSocialController at
/api/sdk/social:
| Feature | SDK method | HTTP route |
|---|---|---|
| Create/change reaction | react |
POST /posts/{postId}/reactions |
| Remove own reaction | removeReaction |
DELETE /posts/{postId}/reactions |
| List reactions | getReactions |
GET /posts/{postId}/reactions?page=&pageSize= |
| Create comment/reply | createComment, replyToComment |
POST /posts/{postId}/comments |
| List comments | getComments |
GET /posts/{postId}/comments?page=&pageSize= |
| Edit comment | updateComment |
PATCH /comments/{commentId} |
| Delete comment | deleteComment |
DELETE /comments/{commentId} |
| Record share | share |
POST /posts/{postId}/shares |
| Create repost | repost |
POST /posts/{postId}/reposts |
| Remove own repost | removeRepost |
DELETE /posts/{postId}/reposts |
| Aggregated counters/current-user state | getPostStats |
GET /posts/stats?postIds={id1},{id2} |
The controller requires the ApplicationUser authorization policy. The
backend enforces application isolation, ownership, and permissions; client
validation is for early feedback and is not a security boundary.
Reactions #
final reaction = await social.react(
postId,
type: SocialReactionType.love,
);
final firstPage = await social.getReactions(
postId,
page: 1,
pageSize: 30,
);
await social.removeReaction(postId);
The backend keeps one active reaction per user and post. Calling react
again with a different type changes that user's reaction. The canonical Like
value is the one counted by the current likes aggregate; other values such as
Love, Laugh, Wow, Sad, and Angry are separate reaction types.
Reaction pages are ordered newest first by the backend. Page numbers start at 1; page size must be between 1 and 100. The endpoint returns a raw JSON array, not a total-count envelope.
Comments and replies #
final root = await social.createComment(
postId,
text: 'A top-level comment',
);
final reply = await social.replyToComment(
postId,
parentCommentId: root.id,
text: 'A reply to the comment',
);
final page1 = await social.getComments(
postId,
page: 1,
pageSize: 30,
);
final updated = await social.updateComment(
reply.id,
text: 'An updated reply',
);
await social.deleteComment(reply.id);
The backend accepts ParentCommentId and verifies that the parent belongs to
the same post. getComments returns a flat page. The response includes
parentCommentId and isDeleted; deleted comments have an empty text value
from the current handler.
To display a nested structure, combine the loaded pages and project them into a tree:
final allLoadedComments = [...page1, ...page2];
final roots = SocialCommentTree.fromComments(allLoadedComments);
for (final rootNode in roots) {
print(rootNode.comment.text);
for (final replyNode in rootNode.replies) {
print(replyNode.comment.text);
}
}
SocialCommentTree is a local projection only. It does not fetch additional
pages or change backend data. If a parent is not among the loaded comments, the
reply is returned as a root node so it is not lost.
Shares and reposts #
final shareEvent = await social.share(postId);
final repost = await social.repost(postId);
await social.removeRepost(postId);
share records a social share event for analytics and may create a backend
notification. It does not send a Chat message and does not invoke the native
Android/iOS share sheet. Sending a post in Chat is a separate feature of
mebabl_chat.
repost is idempotent for the authenticated user and post. removeRepost
only removes the current user's repost.
Aggregated statistics #
final stats = await social.getPostStats([
firstPostId,
secondPostId,
]);
for (final item in stats) {
print(item.likes);
print(item.comments);
print(item.shares);
print(item.reposts);
print(item.liked); // Current user's state.
print(item.reposted); // Current user's state.
}
The service removes duplicate IDs before sending the comma-separated query parameter. The backend accepts 1 to 100 IDs per request.
Features not exposed by the current backend contract #
This package intentionally does not invent API routes for functionality that
is not present in the inspected SdkSocialController and corresponding
Features/SdkSocial handlers. The following require backend endpoints and
server-side authorization/data models before they can be added to the SDK:
- Follow/unfollow users and follower/following lists.
- User mentions and mention search/suggestions.
- Save/unsave posts and saved-post lists.
- Social feed retrieval/ranking and post create/update/delete.
- Comment reactions.
- A paged response containing total counts or cursor pagination (the current Social controller exposes page-number pagination for comments and reactions).
- A Social-specific SignalR event stream. Social mutations currently create
notification outbox records where applicable; clients can consume those via
mebabl_notificationswhen the notification backend contract is available.
Post content, post media upload, and feed operations belong to their own API module and are not silently implemented through these interaction routes.
Error handling #
HTTP/authentication errors 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, so an
application should avoid blindly retrying non-idempotent comment/share actions
unless it has its own request strategy.