fix: use moodStarShortcut+moodMap for liked state, warn on silent fail (v0.4.6)

FW_DEBUG=1 investigation revealed:
- wallmood can silently fail (200 OK, frozen modifDate, no state change) due to
  self-like restriction, unsupported post type (FAMILY_CREATED), or rate limit
- Response contains two complementary like indicators: moodStarShortcut (primary)
  and moodMap (secondary) — both must be checked
- liked: false with like=True now surfaces a warning instead of silently
  returning a misleading result
- SPEC.md documents silent-fail scenarios and dual indicator pattern

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-15 16:12:05 +02:00
parent da5be55070
commit 4cd0bdc499
4 changed files with 41 additions and 11 deletions
+20 -7
View File
@@ -532,14 +532,27 @@ def like_post(post_id: str, like: bool = True) -> str:
indent=2,
)
# Confirm the STAR is present in moodMap (server-side representation of a like).
now_liked = any("STAR" in moods for moods in mood_map.values())
# Two complementary indicators for the like state:
# - moodStarShortcut: direct boolean per-user flag on the post object (primary)
# - moodMap: dict of accountId → [mood types]; contains "STAR" when liked (secondary)
# Use both so either storage path is covered.
star_shortcut = wall_obj.get("moodStarShortcut") == "true"
star_in_map = any("STAR" in moods for moods in mood_map.values())
now_liked = star_shortcut or star_in_map
return json.dumps(
{"liked": now_liked, "id": post_id, "author": account_id},
ensure_ascii=False,
indent=2,
)
result: dict[str, Any] = {"liked": now_liked, "id": post_id, "author": account_id}
# Surface a warning when the like call apparently had no effect, so the
# caller can distinguish a successful like from a silent API rejection
# (e.g. rate limit, unsupported post type, or self-like restriction).
if not now_liked:
result["warning"] = (
"Like may not have been applied. "
"Possible causes: rate limit, unsupported post type (e.g. FAMILY_CREATED), "
"or self-like restriction."
)
return json.dumps(result, ensure_ascii=False, indent=2)
# ---------------------------------------------------------------------------