Pinned group messages¶
Groups support one current pinned user message. Pinning is admin-controlled and persists a snapshot so the pin can be rendered even when the original history page is not loaded.
Main classes¶
Write side (:feature:conversationorchestration:groupstate / incoming):
PinGroupMessageWorkflow,UnpinGroupMessageWorkflow(GroupMessageCommand.PinMessage/UnpinMessage)SendCurrentGroupPinWorkflowReceiveGroupPinWorkflowGroupPinState,GroupPinRepository/GroupPinRepositoryImpl,GroupPinDataSource,GroupPinPacketCodec
Read side (:feature:chats):
GroupPinGroupPinReadRepository/GroupPinReadRepositoryImpl,GroupPinDataSourceGroupPinControllerLoadGroupPinnedAttachmentUseCaseGroupPinnedMessage(GroupPinnedMessageBar,PinnedMessageSheet),PinnedMessageParts
Pin sheet¶
Tapping the pin bar opens PinnedMessageSheet, a bottom sheet. Its header says who pinned the message and when ("Pinned by Chris · 1 Dec, 17:40", "Pinned by you · …", or only the time when the pinner is unknown), a divider separates it from the content. The content is shown directly on the sheet, never as a chat bubble, and without the author of the original message: pictures and videos in a two-column grid (after four tiles the last says how many more), files as rows, voice messages with their player, a contact as avatar, name and number, a location as map preview with coordinates, a poll with its options, the text last and selectable. Each part does its own action when tapped (viewer, open file, play, add contact, maps, vote), so it works from the pin alone. There is no "Show in chat", since a member who joined later has no message to jump to. Content taller than the screen scrolls below the fixed header and fades out at the bottom. Unpinning stays on the bar (the X, admins only).
Catch-up without switching¶
A pin or expense board changed several times while the app was closed arrives as several updates when the mailboxes are read. GroupConversationViewModel.pinState holds them back while the mailbox sync runs (heldWhile, ObserveMailboxSyncUseCase → MailboxSyncSource, set by MailboxPendingSynchronizer through MailboxSyncStateDataSource), so the bar shows only the newest instead of switching through all of them.
Who pinned¶
GroupPinUpdatedPacket.pinnedBySigningPublicKey names the admin who pinned the message by their group signing key; another admin may send the pin again later (to a new member), so it can differ from the signer. Older packets lack it and mean their signer (pinnerSigningPublicKey); it is part of the signed payload only when present, so their signatures stay valid. ReceiveGroupPinWorkflow resolves it like the message sender and stores GroupPinEntity.pinnedByContactId / isPinnedByMe (and the key, to send it on).
Snapshot model¶
PinGroupMessageWorkflow (FindPinTarget -> [ResolveSenderKey] -> AuthorizeAdmin -> PreparePin -> SavePin -> PublishPin) validates that the target is a readable group user message, resolves the sender signing key, builds GroupMessageContent from text plus message parts and stores the pin right away as unpublished, so it shows at once. PublishGroupPinWorkflow then queues it for the group under the administration lock and marks it published; a pin whose publish failed is published again when it is pinned again or after the next start (UnpublishedGroupStateRunner). A stored version never replaces a newer one that arrived meanwhile (GroupStateVersionPolicy).
sequenceDiagram
participant UI as GroupPinController
participant ORCH as ConversationOrchestrator
participant WF as PinGroupMessageWorkflow
participant R as GroupPinRepositoryImpl
participant OUT as ProtocolOutbox
UI->>ORCH: awaitResult(GroupMessageCommand.PinMessage)
ORCH->>WF: FindPinTarget / AuthorizeAdmin / PreparePin
WF->>OUT: CreatePinPackets / EnqueuePinPackets
WF->>R: SavePin (GroupPinEntity + encoded GroupMessageContent)
GroupPinEntity stores the message ID, sent/pinned/change timestamps, sender identity metadata and encoded message content. Unpinning (UnpinGroupMessageWorkflow) stores an unpinned state with a monotonically increasing changedAtEpochMilliseconds right away as unpublished and publishes it like a pin (PublishGroupPin); an unpin that was never published is published again instead of being reported as "nothing pinned". GroupPinEntity.publishPending marks a pin slot that is not queued yet.
Attachments¶
Pinned attachment loading uses the same message-part/blob infrastructure. LoadGroupPinnedAttachmentUseCase asks Attachments (MessageAttachmentRepository.loadBytes with the group ID); AttachmentContentDataSource checks through GroupPinnedAttachmentSource.isPinned (implemented by Chats' GroupPinDataSource, which searches top-level snapshot parts and nested PollDto.images) that the attachment belongs to the pin, then resolves the encrypted blob.
The filesystem cache does not need separate writePinned/readPinned APIs; “pinned” is a source context, not a different kind of attachment file.
Polls¶
Pinned polls are rendered through the normal PollMessageContent. GroupPinnedMessage forwards vote and close callbacks with the original message ID and poll ID, so a pin is interactive rather than a static screenshot.
A member who joined after the poll was pinned has the poll only in the pin. It still works there:
- The pin carries the votes cast so far. When a pin packet is created (
SharePinnedPollVotersUseCase, used byCreateGroupPinPacketsUseCase) the poll comes from the stored message when the device has it, and every voter is named by their group signing key (PinnedPollVoterPolicy), since contact IDs are local to each device. The receiver maps the keys back to its own contacts (LocalizePinnedPollVotersUseCase); an unknown key keeps counting, without a name. - A local vote or close finds the poll in the pin when the message is missing (
FindGroupPollHolderUseCasereturnsPollHolder.Pin), saves it there (SaveGroupPollUseCase,PinnedGroupPollRepository,GroupPinDao.replaceMessageContentIfVersion) and sends it like any vote, so members with the message apply it to theirs. - An incoming vote or close for a message this device does not have changes the pinned poll (
ApplyRemoteMessageOperationWorkflow:FindPinnedPoll) instead of waiting for a message that will never arrive; only operations for neither a stored nor a pinned poll are parked.
MessagePartSourceUi.GroupPin(groupId) gives pinned parts a stable source-aware instanceKey (group-pin:<groupId>:<partId>) without creating a parallel poll model.
Live vs snapshot state¶
The snapshot is required when the original history message is unavailable. When the corresponding message is already present in live conversation state, presentation should prefer that current message so reactions, poll votes and close state reflect ongoing updates rather than remaining frozen at pin time.