MockChatClient class
In-memory ChatClient for testing and prototyping without a backend.
Stores rooms, users, and messages locally. Events are emitted synchronously when messages are sent. Use emitEvent to simulate server-side events.
- Implemented types
Constructors
- MockChatClient({required String currentUserId})
Properties
- attachments ↔ MockAttachmentsApi
-
File upload, download, and per-room attachment listing.
latefinaloverride-getter
- auth ↔ MockAuthApi
-
Authentication and server health checks.
latefinaloverride-getter
- connectionState → ChatConnectionState
-
Current connection state.
no setteroverride
- contacts ↔ MockContactsApi
-
Contact list, direct messages, blocking.
latefinaloverride-getter
- currentUserId → String
-
final
-
events
→ Stream<
ChatEvent> -
Stream of real-time events (messages, typing, presence, etc.).
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- members ↔ MockMembersApi
-
Room membership: invite, remove, ban, role management.
latefinaloverride-getter
- messages ↔ MockMessagesApi
-
Send, edit, delete messages; receipts, typing, threads, pins, search.
latefinaloverride-getter
- onOfflineMessageSent ← void Function(String roomId, String tempId, ChatMessage message)?
-
Optional callback invoked by clients with an offline queue when a
queued send completes after the connection is restored.
no getteroverride
- pendingOperationCount → int
-
Number of operations currently sitting in the offline queue, waiting
to be sent once the connection allows it.
no setteroverride
- presence ↔ MockPresenceApi
-
Online presence status for the current user and contacts.
latefinaloverride-getter
- rooms ↔ MockRoomsApi
-
Room lifecycle: create, list, discover, configure, mute, pin.
latefinaloverride-getter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stateChanges
→ Stream<
ChatConnectionState> -
Stream that emits whenever the connection state changes.
no setteroverride
- users ↔ MockUsersApi
-
User search, creation, update, and managed-user operations.
latefinaloverride-getter
Methods
-
addMessage(
String roomId, ChatMessage message) → void -
cancelOfflineSend(
String tempId) → int -
Drops whatever the offline queue is holding for the optimistic row
tempId, returning how many operations went.0on clients without an offline queue configured, and on a row that was never queued.override -
cancelPendingRequests(
[String reason = 'cancelled']) → void -
Cancels every in-flight REST request.
override
-
connect(
) → Future< void> -
Opens the real-time connection (WebSocket/SSE/polling) honoring
ChatConfig.realtimeMode.
override
-
disconnect(
) → Future< void> -
Closes the real-time connection without clearing state.
override
-
dispose(
) → Future< void> -
Releases all resources. The client must not be used after this call.
override
-
emitConnectionState(
ChatConnectionState state) → void -
Test helper: pushes a raw connection-state transition (e.g.
connecting/authenticating/reconnecting) without going through connect/disconnect — those two only ever emitconnected/disconnected. Lets tests exercise the intermediate states real transports report viastateChangesalone (no accompanyingChatEvent). -
emitEvent(
ChatEvent event) → void -
enqueueOfflineAttachment(
{required String roomId, required Uint8List bytes, required String mimeType, ChatFailure? causeFailure, String? fileName, MessageType messageType = MessageType.attachment, String? text, Map< String, dynamic> ? metadata, String? tempId, String? clientMessageId}) → void -
Queues an attachment upload+send for automatic retry once the
connection returns, instead of requiring the caller to re-drive the
whole upload manually.
override
-
flushPendingOperations(
) → Future< void> -
Forces an immediate drain attempt of the offline queue instead of
waiting for the next reconnect.
override
-
logout(
) → Future< void> -
Disconnects and clears all local state (rooms, messages, contacts).
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyTokenRotated(
) → Future< void> -
Notifies the server (via WebSocket) that the auth token has been rotated.
override
-
refresh(
) → Future< void> -
Force a refresh of the room list and (in
polling/manualmodes) pull new messages for any room that changed.override -
refreshRoom(
String roomId) → Future< void> -
Like refresh but scoped to a single room.
override
-
seedRoom(
ChatRoom room) → void -
Test helper: register a room directly in the mock store so subsequent
client.rooms.get(roomId)calls return a properRoomDetail. -
seedRoomMeta(
String roomId, {int? unread, bool? pinned, bool? muted}) → void -
Test/demo helper: seed chat-list metadata (unread badge, pinned,
muted) that the real backend computes/stores but the mock
ChatRoommodel doesn't carry. Null args leave the current value untouched. -
seedUser(
ChatUser user) → void -
Test helper: register a user directly in the mock store so subsequent
client.users.get(userId)calls return them. Pair with seedRoom when a test exercises the DM-draft hydration path. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited