Message History and Presence
Relevant source files
The following files were used as context for generating this wiki page:
The "Message History and Presence" module within the tauri-plugin-centrifugo project provides the structures and API interfaces necessary for retrieving historical publications and real-time client state from Centrifugo channels. These features allow developers to synchronize application state for late-joining clients and monitor active users within specific communication channels.
While the data models and frontend API bindings for these features are fully defined, the current Rust implementation in the plugin core marks several of these backend commands as NotImplemented, as they are not yet directly supported by the underlying tokio-centrifuge library.
Sources: src/commands.rs:135-191, guest-js/index.ts:108-124
Message History
Message history allows clients to retrieve previously published messages from a channel's cache. This is critical for features like chat history or state recovery after a temporary disconnection.
Architecture and Data Flow
The history system relies on specific request structures that define the range and order of messages to be retrieved. The plugin defines these structures in both Rust and TypeScript to ensure type safety across the FFI boundary.
The following sequence diagram illustrates the intended flow of a history request from the frontend to the Centrifugo server:
Explanation: The diagram shows the current state where the frontend initiates a history request, but the Rust backend returns a NotImplemented error.
Sources: guest-js/index.ts:114-116, src/commands.rs:170-184, src/models.rs:107-117
History Data Structures
The system uses the HistoryRequest to filter data and HistoryResponse to return the resulting list of publications.
| Field | Type | Description |
|---|---|---|
channel | string | The target channel name for history retrieval. |
limit | number (optional) | Maximum number of messages to return. |
since | string (optional) | Message ID/Stream position to start from. |
reverse | boolean (optional) | Whether to return messages in reverse chronological order. |
Sources: guest-js/index.ts:31-36, src/models.rs:107-117
The history response contains an array of PublicationData objects, which include the base64-encoded message payload and the source channel.
Sources: src/models.rs:242-251
Presence Information
Presence features provide visibility into who is currently connected to a specific channel. This includes both raw client lists and aggregated statistics.
Presence vs. Presence Stats
The plugin distinguishes between detailed presence (identifying specific clients) and presence statistics (counts of users and clients).
- Presence: Returns a list of unique client identifiers.
- Presence Stats: Returns the count of total clients and total unique users (one user may have multiple client connections).
Explanation: The flow shows how presence requests are branched into detailed client lists or simplified statistical counts.
Sources: src/commands.rs:135-168, guest-js/index.ts:108-112
API Implementation Details
The frontend provides asynchronous functions that invoke the corresponding Tauri commands. Currently, these commands are defined in src/commands.rs but return placeholders.
/**
* Get presence information for channel
*/
export async function presence(request: PresenceRequest): Promise<string[]> {
return await invoke('plugin:centrifugo|presence', { request })
}
/**
* Get presence statistics for channel
*/
export async function presenceStats(request: PresenceStatsRequest): Promise<[number, number]> {
return await invoke('plugin:centrifugo|presence_stats', { request })
}
Sources: guest-js/index.ts:108-112
Protocol Definition (Protobuf)
The underlying communication with the Centrifugo server can be performed via Protobuf. The api.proto file defines the service methods for History and Presence that the plugin aims to support.
| Service Method | Request Message | Response Message | Description |
|---|---|---|---|
Presence | PresenceRequest | PresenceResponse | Returns a map of ClientInfo objects. |
PresenceStats | PresenceStatsRequest | PresenceStatsResponse | Returns num_clients and num_users. |
History | HistoryRequest | HistoryResponse | Returns a list of Publication messages. |
Sources: examples/server/proto/api.proto:11-13, examples/server/proto/api.proto:230-264
The Protobuf Publication message is more complex than the internal PublicationData used for frontend events, as it includes ClientInfo, offset, and tags.
Sources: examples/server/proto/api.proto:258-264
Summary of Feature Status
The following table summarizes the implementation status of Message History and Presence features as of the current version:
| Feature | Frontend API | Data Models | Backend Implementation |
|---|---|---|---|
| History Retrieval | ✅ Available | ✅ Defined | ❌ Not Implemented |
| Presence List | ✅ Available | ✅ Defined | ❌ Not Implemented |
| Presence Stats | ✅ Available | ✅ Defined | ❌ Not Implemented |
| History Removal | ❌ Missing | ❌ Missing | ❌ Not Implemented |
Sources: src/commands.rs:135-184, README.md:200-210
The Message History and Presence systems are architected to provide essential real-time awareness and state synchronization. While the Rust backend currently lacks the functional logic for these features, the presence of comprehensive data models and frontend bindings indicates a planned roadmap for full integration with the Centrifugo server's capabilities.