Skip to content

chore(chat): decompose ChatCoordinator into focused delegates#977

Merged
bmc08gt merged 10 commits into
code/cashfrom
chore/chat-coordinator-delegates
Jun 24, 2026
Merged

chore(chat): decompose ChatCoordinator into focused delegates#977
bmc08gt merged 10 commits into
code/cashfrom
chore/chat-coordinator-delegates

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Split the 735-line monolithic ChatCoordinator into three delegates using Kotlin interface delegation, following the SessionController pattern:

  • FeedSyncDelegate: feed sync, DB observation, ChatSummary projection
  • EventStreamDelegate: event stream, applyUpdate, gap tracking, reactions, typing indicators
  • MessagingDelegate: per-chat messaging, read pointers, paging, notifications

ChatCoordinator becomes an interface with sub-interfaces (FeedOperations, EventStreamOperations, MessagingOperations). RealChatCoordinator is the thin shell that wires delegates via Channel flows, handles lifecycle, and observes feature flags.

bmc08gt added 7 commits June 24, 2026 13:02
New Messaging RPCs: GetDelta, EditMessage, DeleteMessage, AddReaction,
RemoveReaction, GetReactors, GetReactionSummary, GetReactionSummaries.

New content types: ReplyContent, MediaContent, SystemContent, DeletedContent.
New models: Event, Mutation, EventBatch, ReactionSummary, EmojiReaction,
ReactionUpdate, Emoji, Reactor, MediaItem, MediaMetadata, MediaId.

ChatUpdate.new_messages deprecated in favor of EventBatch events.
Message gains last_edited_ts, event_sequence, reactions fields.
Metadata gains latest_event_sequence field.

Signed-off-by: Brandon McAnsh <[email protected]>
Full Api → Service → Repository → Controller scaffolding for:
GetDelta, EditMessage, DeleteMessage, AddReaction, RemoveReaction,
GetReactors, GetReactionSummary, GetReactionSummaries.

Domain model updates:
- ChatMetadata: +latestEventSequence
- ChatMessage: +lastEditedTs, eventSequence, reactions
- MessageContent: +Reply, Media, System, Deleted subtypes
- ChatUpdate: +events, reactionUpdates (newMessages deprecated)
- New models: Emoji, Reactor, EmojiReaction, ReactionSummary,
  ReactionUpdate, MediaId, MediaItem, MediaMetadata, ChatEvent,
  ChatMutation

Mapper updates for all new proto→domain and domain→proto conversions.
8 new error sealed classes matching proto response result enums.

Signed-off-by: Brandon McAnsh <[email protected]>
Add Room columns for eventSequence, lastEditedTs, reactions on
ChatMessageEntity and latestEventSequence on ChatMetadataEntity
(migration 20→21). ChatCoordinator now prefers ChatUpdate.events
over deprecated newMessages, supports delta-based catch-up on
reconnect via getDelta, and maintains an in-memory reaction overlay
from reactionUpdates. DAO upsert guards against stale writes using
event sequence LWW.

Add TODOs for UI handling

Signed-off-by: Brandon McAnsh <[email protected]>
Replace naive max-sequence cursor advancement with a contiguous-
frontier tracker. Out-of-order events are held in a pending set;
only the highest gapless sequence is persisted. If a gap is not
filled within 2s, getDelta backfills from the frontier. Prevents
permanently skipping events on reordered delivery, critical for
large group chats.

Signed-off-by: Brandon McAnsh <[email protected]>
…rialization

EventSequenceTrackerTest (14): gap detection, contiguous advancement,
out-of-order handling, resetTo, multi-chat isolation.
ChatCoordinatorEventsTest (10): events-vs-newMessages preference,
gap-aware cursor, reaction overlay LWW guard and pruning.
ChatTypeConvertersTest (12): ReactionSummary round-trip, nulls,
plus MessageContent/Status/UserProfile converters.
Split the 735-line monolithic ChatCoordinator into three delegates
using Kotlin interface delegation, following the SessionController
pattern:

- FeedSyncDelegate: feed sync, DB observation, ChatSummary projection
- EventStreamDelegate: event stream, applyUpdate, gap tracking,
  reactions, typing indicators
- MessagingDelegate: per-chat messaging, read pointers, paging,
  notifications

ChatCoordinator becomes an interface with sub-interfaces
(FeedOperations, EventStreamOperations, MessagingOperations).
RealChatCoordinator is the thin shell that wires delegates via
Channel<Event> flows, handles lifecycle, and observes feature flags.

Signed-off-by: Brandon McAnsh <[email protected]>
@github-actions github-actions Bot added the type: chore Maintenance, config, CI/CD label Jun 24, 2026
bmc08gt added 2 commits June 24, 2026 14:37
Cover editMessage, deleteMessage, addReaction, removeReaction,
getReactors, getReactionSummary, getReactionSummaries, and getDelta
with no-account-cluster, parameter-forwarding, and result-surfacing
tests. Wire up FakeChatMessagingRepository with tracked state for all
new repository methods.
Base automatically changed from feat/update-protos-chat to code/cash June 24, 2026 23:08
…inator-delegates

* origin/code/cash:
  feat(messaging): integrate updated chat protos with data layer and tests (#976)
  fix(streaming): stop reporting retryable ClosedSendChannelException to Bugsnag (#978)
  build: update release manifest

# Conflicts:
#	apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatCoordinator.kt
#	apps/flipcash/shared/chat/src/test/kotlin/com/flipcash/shared/chat/ChatCoordinatorEventsTest.kt
@bmc08gt bmc08gt merged commit f36c5e0 into code/cash Jun 24, 2026
3 checks passed
@github-actions github-actions Bot added the area: network gRPC, connectivity, API, exchange rates label Jun 24, 2026
@bmc08gt bmc08gt deleted the chore/chat-coordinator-delegates branch June 24, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: network gRPC, connectivity, API, exchange rates type: chore Maintenance, config, CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant