nomadro/apps/api/services/social_svc/contract.py
Eric ffa456afdf Ship social join profile + SeaweedFS avatars, notify/coffee, and .com audience stack.
Pay-then-profile join desk with live card, S3 upload fallback, hydration-safe drafts; document on test9 README.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 02:25:05 +08:00

68 lines
2.1 KiB
Python

"""Nomadro Social IM — server contract (UI-agnostic).
Frontends (Web / 微信小程序 / future apps) MUST treat this as the only SoT.
No UI assumptions: display names, layouts, emoji pickers live entirely in clients.
Transport
---------
- REST: ``/api/social/v1/*``
- Realtime: Centrifugo channel ``social:{channelId}``
- Auth peer: header ``X-Social-Guest-Id`` (or ``?guest=``)
HTTP (chat core)
----------------
GET /health
GET /realtime/token?channel_id=
GET /channels/{id}/desc
GET /channels/{id}/messages?since=&before=&limit=&q=
POST /channels/{id}/messages body: {author, text?, clientId?, replyTo?, attachments?, mentions?}
PATCH /channels/{id}/messages/{msgId} body: {text} # edit
POST /channels/{id}/messages/{msgId}/recall
POST /channels/{id}/messages/{msgId}/react body: {emoji}
POST /channels/{id}/messages/{msgId}/pin body: {pinned?}
POST /channels/{id}/messages/{msgId}/report body: {reason?}
POST /channels/{id}/presence body: {nick?} # soft online heartbeat
POST /channels/{id}/notes body: {what: recv|read|kp, seq?}
POST /channels/{id}/upload multipart file → attachment descriptor
GET /files/{fileId} stream uploaded bytes
Centrifugo publications (JSON)
------------------------------
{"type":"chat.message","message":{…full message…}}
{"type":"chat.note","what":"recv|read|kp","seq":N,"guestId":"...","at":"..."}
Message fields
--------------
- ``seq``: monotonic int per channel (Tinode-inspired sync cursor)
- ``clientId``: client idempotency key (optional but recommended)
- ``replyTo``: {id, author, text, seq?}
- ``attachments``: [{id, kind, url, name, mime, size}]
- ``reactions``: {emoji: [guestId, …]}
- ``mentions``: [name, …]
- ``editedAt`` / ``recalled`` / ``pinned``
"""
from __future__ import annotations
IM_PROTOCOL = "nomadro.im.v1"
IM_FEATURES = (
"seq",
"clientId",
"since",
"before",
"note.recv",
"note.read",
"note.kp",
"centrifugo",
"replyTo",
"attachments",
"upload",
"recall",
"react",
"edit",
"pin",
"search",
"mentions",
"report",
"presence",
)