Skip to content

feat: implement WebSocket connection and channel subscription functionality#8

Open
quytrandinh-ncc-asia wants to merge 5 commits into
mainfrom
feat/websocket-connection
Open

feat: implement WebSocket connection and channel subscription functionality#8
quytrandinh-ncc-asia wants to merge 5 commits into
mainfrom
feat/websocket-connection

Conversation

@quytrandinh-ncc-asia

@quytrandinh-ncc-asia quytrandinh-ncc-asia commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replace hardcoded test channel subscription with a store-driven flow where the transport task polls the ChannelList for pending subscription changes and executes leave/join transitions accordingly.

Changes

mezon-store

  • Added PendingSubscribe struct (clan_id, channel_id, channel_type, is_public)
  • Added pending_subscribe: Option field to ChannelList
  • Added ChannelType::as_proto_int() helper to convert enum to i32 for protobuf

mezon-client

  • Updated subscribe_channel signature to accept channel_type: i32, is_public: bool (replacing hardcoded 0, true)
  • Added fire-and-forget leave_channel method using direct adapter.send() without response tracking
  • Added TransportClient delegates for both methods

mezon-ui

  • ChannelSidebar.on_channel_click now sets ChannelList.pending_subscribe with real channel data (looks up Channel to get channel_type and is_public)
  • ChatLayout accepts Entity from constructor instead of creating internally
  • RootView accepts and threads Entity through to ChatLayout

mezon-app

  • Created ChannelList entity in run_app() before opening main window
  • Passed Entity to both open_main_window (→ UI tree) and spawn_transport_task
  • Transport task polls pending_subscribe every 500ms: if changed, sends ChannelLeave for old channel (fire-and-forget) then ChannelJoin for new
  • Removed hardcoded subscribe_channel call after get_account
  • On reconnect, resets subscription tracking to force re-subscribe on next poll cycle

Behavior

  • User clicks a channel → pending_subscribe set
  • Transport task (500ms poll) detects change → leaves old channel (if any) → joins new channel
  • Channel switches → leave old/join new happens automatically
  • WebSocket reconnects → resubscribes to currently selected channel
  • Uses real channel metadata (channel_type, is_public) instead of hardcoded values

All tests pass: cargo check -p mezon-app succeeds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants