feat: mention
This commit is contained in:
@@ -83,6 +83,8 @@ export type Post = {
|
||||
/** Whether the calling viewer has liked this post. Always false / absent
|
||||
* for anonymous viewers. */
|
||||
viewer_has_liked?: boolean;
|
||||
/** How many users are tagged on this post (drives the mentions icon). */
|
||||
mentions_count?: number;
|
||||
};
|
||||
|
||||
/** Result of a like / unlike toggle: the new viewer state + effective total. */
|
||||
@@ -169,6 +171,7 @@ export const posts = {
|
||||
source_url: string;
|
||||
source_title?: string;
|
||||
image_urls?: string[];
|
||||
mention_user_ids?: string[];
|
||||
}) {
|
||||
return call<Post>("/posts", {
|
||||
method: "POST",
|
||||
@@ -177,9 +180,35 @@ export const posts = {
|
||||
source_url: input.source_url,
|
||||
source_title: input.source_title ?? "",
|
||||
image_urls: input.image_urls ?? [],
|
||||
mention_user_ids: input.mention_user_ids ?? [],
|
||||
}),
|
||||
});
|
||||
},
|
||||
/** Prioritised mention suggestions (following → followers → others). Returns
|
||||
* one page; the popover loads more by `offset` until a short page. */
|
||||
mentionSuggest(q: string, opts: { limit?: number; offset?: number } = {}) {
|
||||
const params = new URLSearchParams({
|
||||
limit: String(opts.limit ?? 20),
|
||||
offset: String(opts.offset ?? 0),
|
||||
});
|
||||
if (q.trim()) params.set("q", q.trim());
|
||||
return call<UserSummary[]>(`/posts/mention-suggest?${params}`);
|
||||
},
|
||||
/** Users tagged on a post (insertion order). Public. */
|
||||
mentions(id: string) {
|
||||
return call<UserSummary[]>(`/posts/${id}/mentions`);
|
||||
},
|
||||
/** Tag a user on the post (author only, idempotent). */
|
||||
addMention(id: string, userId: string) {
|
||||
return call<void>(`/posts/${id}/mentions`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ user_id: userId }),
|
||||
});
|
||||
},
|
||||
/** Untag a user (author only). */
|
||||
removeMention(id: string, userId: string) {
|
||||
return call<void>(`/posts/${id}/mentions/${userId}`, { method: "DELETE" });
|
||||
},
|
||||
get(id: string) {
|
||||
return call<Post>(`/posts/${id}`);
|
||||
},
|
||||
@@ -412,6 +441,14 @@ export const profile = {
|
||||
});
|
||||
return call<Post[]>(`/u/${encodeURIComponent(handle)}/feed?${qs}`);
|
||||
},
|
||||
/** Posts that tag this user (the Mentions tab), newest first. */
|
||||
mentionsFeed(handle: string, limit = 30, offset = 0) {
|
||||
const qs = new URLSearchParams({
|
||||
limit: String(limit),
|
||||
offset: String(offset),
|
||||
});
|
||||
return call<Post[]>(`/u/${encodeURIComponent(handle)}/mentions?${qs}`);
|
||||
},
|
||||
};
|
||||
|
||||
// ─── Relationships (follow / block / report) ───────────────────────────────
|
||||
@@ -553,6 +590,9 @@ export const relationships = {
|
||||
|
||||
/** Lightweight user row in a followers / following list. */
|
||||
export type UserSummary = {
|
||||
/** Present where the caller needs it (mentions); absent in follower/like
|
||||
* lists that link by handle. */
|
||||
id?: string;
|
||||
handle: string;
|
||||
name: string;
|
||||
avatar_url: string | null;
|
||||
|
||||
Reference in New Issue
Block a user