From f74e2c0d527354072a5064d2dac8f73494ec8b49 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Tue, 11 Aug 2026 16:16:32 +0200 Subject: feat: chat notifications via hub, file delete, upload fix, cached display, inline thumbnails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend: - Chat store persists sender_name (SQLite migration, no more UUID display) - FILE_DELETE / FILE_DELETE_ACK MNP types — node admin can delete files - Node sends chat_notify to hub WS — hub creates notifications for offline members - Hub revocation.py handles chat_notify, creates per-member notifications Frontend: - Upload chunk size 64KB (was 1MB) — fixes WebRTC DataChannel max-message-size - Show cached files immediately while WebRTC connects - ChatImage component — inline image thumbnails in chat (download+decrypt) - File delete action in menu (group admin, with confirm dialog) - Member panel: "Owner" label instead of confusing "Group admin" - Create group page: hint about needing a node - Refresh index after chat attachment upload Co-Authored-By: Claude Opus 4.6 --- .../meshbay-hub/src/meshbay_hub/api/revocation.py | 36 ++++++++++++++++++++++ .../src/meshbay_node/transport/webrtc_server.py | 12 ++++++++ 2 files changed, 48 insertions(+) diff --git a/packages/meshbay-hub/src/meshbay_hub/api/revocation.py b/packages/meshbay-hub/src/meshbay_hub/api/revocation.py index 8f65f89..00258c1 100644 --- a/packages/meshbay-hub/src/meshbay_hub/api/revocation.py +++ b/packages/meshbay-hub/src/meshbay_hub/api/revocation.py @@ -99,6 +99,36 @@ def _sign_revocation(target: str, target_id: str, reason: str) -> str: # ── WebSocket endpoint ──────────────────────────────────────────────────────── @router.websocket("/v1/nodes/ws") +async def _handle_chat_notify(group_id: str, sender_name: str, sender_user_id: str) -> None: + """Node informs hub that a chat message was posted — create notifications for offline members.""" + if not group_id: + return + try: + from meshbay_hub.db.engine import get_session_factory + from meshbay_hub.db.models import GroupMember, Group + from meshbay_hub.api.notifications import create_notification + + async with get_session_factory()() as db: + group = await db.get(Group, group_id) + if not group: + return + result = await db.execute( + select(GroupMember.user_id).where(GroupMember.group_id == group_id) + ) + member_ids = [r[0] for r in result.all()] + for uid in member_ids: + if uid == sender_user_id: + continue + await create_notification( + db, uid, "chat_message", + f"{sender_name or 'Someone'} posted in {group.name}", + link=f"#/group/{group_id}", + ) + await db.commit() + except Exception as e: + log.warning("Chat notify failed: %s", e) + + async def node_websocket(ws: WebSocket): """ Persistent WebSocket connection for nodes. @@ -145,6 +175,12 @@ async def node_websocket(ws: WebSocket): elif msg.get("type") == "webrtc_answer": from meshbay_hub.api.signaling import handle_webrtc_answer handle_webrtc_answer(msg) + elif msg.get("type") == "chat_notify": + asyncio.ensure_future(_handle_chat_notify( + msg.get("group_id", ""), + msg.get("sender_name", ""), + decoded.get("sub", ""), + )) except WebSocketDisconnect: log.info("Node WS disconnected: %s", (node_id or "unknown")[:8]) diff --git a/packages/meshbay-node/src/meshbay_node/transport/webrtc_server.py b/packages/meshbay-node/src/meshbay_node/transport/webrtc_server.py index 15c8f66..1d10aa8 100644 --- a/packages/meshbay-node/src/meshbay_node/transport/webrtc_server.py +++ b/packages/meshbay-node/src/meshbay_node/transport/webrtc_server.py @@ -298,6 +298,18 @@ class WebRTCPeerSession: except Exception: pass + hub_ws = self._ctx.get("hub_ws") + if hub_ws and self._group_id: + try: + import json as _json + asyncio.ensure_future(hub_ws.send(_json.dumps({ + "type": "chat_notify", + "group_id": self._group_id, + "sender_name": sender_name, + }))) + except Exception: + pass + self._send({"type": "ack", "v": MNP_VERSION}) def _do_chat_history(self, msg: dict) -> None: -- cgit v1.2.3