Message workflows¶
Generated by ./gradlew workflowCatalog from :feature:conversationorchestration:message. Do not edit by hand.
Writing, changing, reading and retrying Direct and Group messages, polls and forwarding.
Diagram legend: boxes are Steps, arrow labels are the Outcome a step reported, [*] is the start or a successful completion, Rejected ends the workflow with a ConversationFailure.
| Workflow | Started by | Command | Lock |
|---|---|---|---|
DeleteDirectMessageWorkflow |
Chats (ConversationOrchestrator) |
DirectConversationCommand.DeleteMessage |
— |
DeleteOwnDirectMessageWorkflow |
orchestration (engine.run) |
MessageCommand.DeleteOwnDirectMessage |
directReleaseLockKey(command.target.contactId) |
DeliverDirectMessageWorkflow |
orchestration (engine.run) |
MessageCommand.DeliverDirectMessage |
— |
EditDirectMessageWorkflow |
Chats (ConversationOrchestrator) |
DirectConversationCommand.EditMessage |
— |
EditOwnDirectMessageWorkflow |
orchestration (engine.run) |
MessageCommand.EditOwnDirectMessage |
directReleaseLockKey(command.target.contactId) |
MarkDirectConversationReadWorkflow |
Chats (ConversationOrchestrator) |
DirectConversationCommand.MarkConversationRead |
— |
RetryDirectMessageWorkflow |
Chats (ConversationOrchestrator) |
DirectConversationCommand.RetryMessage |
— |
SendDirectIndicatorWorkflow |
Chats (ConversationOrchestrator) |
DirectConversationCommand.SendIndicator |
— |
SendDirectMessageWorkflow |
Chats (ConversationOrchestrator) |
DirectConversationCommand.SendMessage |
— |
ToggleDirectReactionWorkflow |
Chats (ConversationOrchestrator) |
DirectConversationCommand.ToggleReaction |
— |
ActivateAuthorizedConversationWorkflow |
orchestration (engine.run) |
MessageCommand.ActivateAuthorizedConversation |
— |
DiscardWaitingDirectMessagesWorkflow |
orchestration (engine.run) |
MessageCommand.DiscardWaitingDirectMessages |
directReleaseLockKey(command.contactId) |
ReleaseWaitingDirectMessagesWorkflow |
orchestration (engine.run) |
MessageCommand.ReleaseWaitingDirectMessages |
directReleaseLockKey(command.contactId) |
StoreWaitingDirectMessageWorkflow |
orchestration (engine.run) |
MessageCommand.StoreWaitingDirectMessage |
directReleaseLockKey(command.contactId) |
ForwardMessageWorkflow |
Chats (ConversationOrchestrator) |
ForwardMessage |
— |
CloseGroupPollWorkflow |
Chats (ConversationOrchestrator) |
GroupMessageCommand.ClosePoll |
— |
DeleteGroupMessageWorkflow |
Chats (ConversationOrchestrator) |
GroupMessageCommand.DeleteMessage |
— |
DeleteUnsentGroupMessageWorkflow |
orchestration (engine.run) |
MessageCommand.DeleteUnsentGroupMessage |
groupSendLockKey(command.groupId) |
EditGroupMessageWorkflow |
Chats (ConversationOrchestrator) |
GroupMessageCommand.EditMessage |
— |
EditUnsentGroupMessageWorkflow |
orchestration (engine.run) |
MessageCommand.EditUnsentGroupMessage |
groupSendLockKey(command.groupId) |
FlushQueuedGroupMessagesWorkflow |
orchestration (engine.run) |
MessageCommand.FlushQueuedGroupMessages |
groupSendLockKey(command.groupId) |
MarkGroupConversationReadWorkflow |
Chats (ConversationOrchestrator) |
GroupMessageCommand.MarkConversationRead |
— |
RetryGroupMessageWorkflow |
Chats (ConversationOrchestrator) |
GroupMessageCommand.RetryMessage |
— |
SendGroupIndicatorWorkflow |
Chats (ConversationOrchestrator) |
GroupMessageCommand.SendIndicator |
— |
SendGroupMessageWorkflow |
Chats (ConversationOrchestrator) |
GroupMessageCommand.SendMessage |
groupSendLockKey(command.groupId) |
ToggleGroupReactionWorkflow |
Chats (ConversationOrchestrator) |
GroupMessageCommand.ToggleReaction |
— |
VoteGroupPollWorkflow |
Chats (ConversationOrchestrator) |
GroupMessageCommand.VotePoll |
— |
direct¶
DeleteDirectMessageWorkflow¶
- Kind: public — Chats submits
DirectConversationCommand.DeleteMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/DeleteDirectMessageWorkflow.kt - Lock: none
- Uses:
WorkflowEngine,DirectConversationRepository,FindDeletableDirectMessageUseCase,RequireDirectChatAuthorizationUseCase,SendDirectOperationUseCase,DiscardDirectMessagesUseCase
FindConversation -> FindOwnMessage -> (DeleteWaitingMessage) | (CheckAuthorization -> SendDelete -> DiscardMessage).
A message still waiting for authorization was never sent, so it is deleted locally only; that delete runs as
[MessageCommand.DeleteOwnDirectMessage] under the contact's release lock, which checks the message again, so a
release never revives it. A sent message cannot become waiting again, so its delete takes no lock.
stateDiagram-v2
[*] --> FindConversation
FindConversation --> FindOwnMessage : ConversationFound
FindOwnMessage --> DeleteWaitingMessage : MessageNeverSent
FindOwnMessage --> CheckAuthorization : MessageSent
DeleteWaitingMessage --> [*] : WaitingMessageDeleted
CheckAuthorization --> SendDelete : Authorized
SendDelete --> DiscardMessage : DeleteSent
DiscardMessage --> [*] : MessageDiscarded
DeleteOwnDirectMessageWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.DeleteOwnDirectMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/DeleteOwnDirectMessageWorkflow.kt - Lock:
directReleaseLockKey(command.target.contactId) - Uses:
FindDeletableDirectMessageUseCase,RequireDirectChatAuthorizationUseCase,SendDirectOperationUseCase,DiscardDirectMessagesUseCase
FindOwnMessage -> (DiscardMessage) | (CheckAuthorization -> SendDelete -> DiscardMessage).
Runs only for a message that was still waiting when the public delete looked at it. The workflow holds the
contact's release lock, so a waiting message cannot be released (and written back) between the check and the
local delete; one that was released just before gets a normal delete.
stateDiagram-v2
[*] --> FindOwnMessage
FindOwnMessage --> DiscardMessage : MessageNeverSent
FindOwnMessage --> CheckAuthorization : MessageSent
CheckAuthorization --> SendDelete : Authorized
SendDelete --> DiscardMessage : DeleteSent
DiscardMessage --> [*] : MessageDiscarded
DeliverDirectMessageWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.DeliverDirectMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/DeliverDirectMessageWorkflow.kt - Lock: none
- Uses:
DirectConversationRepository,FindDirectAuthorizationBlockUseCase,LoadDirectRecipientUseCase,StoreOutgoingDirectMessageUseCase,DiscardDirectMessagesUseCase,CreateDirectMessagePacketUseCase,ProtocolOutbox,RecordPacketSendFailureUseCase,KeepUnsentDirectMessageUseCase
FindConversation -> CheckAuthorization -> LoadRecipient -> StoreMessage -> CreatePacket -> EnqueuePacket.
A packet that cannot be created or linked to the message discards the stored message again, unless only its
attachment could not go out yet ([UnsentMessagePolicy]): then the message stays, failed, to be sent again. A
packet the outbox rejects keeps the message and marks it failed so the user can retry.
stateDiagram-v2
[*] --> FindConversation
FindConversation --> CheckAuthorization : ConversationFound
CheckAuthorization --> Rejected : AuthorizationMissing
CheckAuthorization --> LoadRecipient : Authorized
LoadRecipient --> StoreMessage : RecipientLoaded
StoreMessage --> CreatePacket : MessageStored
CreatePacket --> EnqueuePacket : PacketCreated
CreatePacket --> DiscardMessage : PacketPreparationFailed
CreatePacket --> KeepUnsent : PacketPreparationFailed
DiscardMessage --> Rejected : MessageDiscarded
KeepUnsent --> Rejected : MessageKeptUnsent
EnqueuePacket --> MarkSendFailed : EnqueueFailed
EnqueuePacket --> [*] : PacketEnqueued
MarkSendFailed --> Rejected : SendFailureRecorded
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject
EditDirectMessageWorkflow¶
- Kind: public — Chats submits
DirectConversationCommand.EditMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/EditDirectMessageWorkflow.kt - Lock: none
- Uses:
WorkflowEngine,DirectConversationRepository,DirectMessageRepository,FindEditableDirectMessageUseCase,RequireDirectChatAuthorizationUseCase,SendDirectOperationUseCase
FindConversation -> FindEditableMessage -> (EditWaitingMessage) | (CheckAuthorization -> SendEdit -> ReplaceText).
A message still waiting for authorization was never sent, so it is edited locally only; that edit runs as
[MessageCommand.EditOwnDirectMessage] under the contact's release lock, which checks the message again, so a
release never sends the old text. A sent message cannot become waiting again, so its edit takes no lock and never
waits for a release or a send to the same contact.
stateDiagram-v2
[*] --> FindConversation
FindConversation --> FindEditableMessage : ConversationFound
FindEditableMessage --> CheckAuthorization : MessageSent
FindEditableMessage --> EditWaitingMessage : MessageWaitingForAuthorization
EditWaitingMessage --> [*] : WaitingMessageEdited
CheckAuthorization --> SendEdit : Authorized
SendEdit --> ReplaceText : EditSent
ReplaceText --> [*] : TextReplaced
EditOwnDirectMessageWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.EditOwnDirectMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/EditOwnDirectMessageWorkflow.kt - Lock:
directReleaseLockKey(command.target.contactId) - Uses:
DirectMessageRepository,FindEditableDirectMessageUseCase,RequireDirectChatAuthorizationUseCase,SendDirectOperationUseCase
FindEditableMessage -> (ReplaceText) | (CheckAuthorization -> SendEdit -> ReplaceText).
Runs only for a message that was still waiting when the public edit looked at it. A message still waiting for
authorization was never sent, so it is edited locally only. The workflow holds the contact's release lock, so a
waiting message cannot be released with its old text between the check and the edit; one that was released
just before gets a normal edit.
stateDiagram-v2
[*] --> FindEditableMessage
FindEditableMessage --> CheckAuthorization : MessageSent
FindEditableMessage --> ReplaceText : MessageWaitingForAuthorization
CheckAuthorization --> SendEdit : Authorized
SendEdit --> ReplaceText : EditSent
ReplaceText --> [*] : TextReplaced
MarkDirectConversationReadWorkflow¶
- Kind: public — Chats submits
DirectConversationCommand.MarkConversationRead - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/MarkDirectConversationReadWorkflow.kt - Lock: none
- Uses:
ConversationUnseenCountRepository,DirectConversationRepository,DirectMessageRepository,FindDirectAuthorizationBlockUseCase,AcknowledgeIncomingMessageUseCase
ClearUnseenCount -> FindConversation -> FindUnreadMessages -> CheckAuthorization -> (AcknowledgeMessage)* .
Read receipts are opportunistic: while authorization is missing (e.g. during onboarding) the
receipts stay pending in the database and are sent the next time the chat is read.
stateDiagram-v2
[*] --> ClearUnseenCount
ClearUnseenCount --> FindConversation : UnseenCountCleared
FindConversation --> FindUnreadMessages : ConversationFound
FindUnreadMessages --> CheckAuthorization : UnreadMessagesFound
FindUnreadMessages --> [*] : UnreadMessagesFound
CheckAuthorization --> AcknowledgeMessage : Authorized
CheckAuthorization --> [*] : Authorized
CheckAuthorization --> [*] : ReceiptsDeferred
AcknowledgeMessage --> AcknowledgeMessage : MessageAcknowledged
AcknowledgeMessage --> [*] : MessageAcknowledged
RetryDirectMessageWorkflow¶
- Kind: public — Chats submits
DirectConversationCommand.RetryMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/RetryDirectMessageWorkflow.kt - Lock: none
- Uses:
DirectConversationRepository,FindRetryableDirectMessageUseCase,CreateDirectMessagePacketUseCase,ProtocolOutbox,RequireDirectChatAuthorizationUseCase,RecordRetryRequestedUseCase
FindRetryableMessage -> FindConversation -> CheckAuthorization -> FindPacket
-> (ResendPacket | CreatePacket -> EnqueuePacket) -> RecordRetry.
A message whose packet never reached the outbox, or is no longer in it, gets a new packet; resending a packet
the outbox does not know would do nothing and leave the message queued forever.
stateDiagram-v2
[*] --> FindRetryableMessage
FindRetryableMessage --> FindConversation : RetryableMessageFound
FindConversation --> CheckAuthorization : ConversationFound
CheckAuthorization --> FindPacket : Authorized
FindPacket --> ResendPacket : PacketInOutbox
FindPacket --> CreatePacket : PacketMissing
ResendPacket --> RecordRetry : PacketResent
CreatePacket --> EnqueuePacket : PacketCreated
EnqueuePacket --> RecordRetry : PacketResent
RecordRetry --> [*] : RetryRecorded
SendDirectIndicatorWorkflow¶
- Kind: public — Chats submits
DirectConversationCommand.SendIndicator - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/SendDirectIndicatorWorkflow.kt - Lock: none
- Uses:
SendConversationIndicatorUseCase
stateDiagram-v2
[*] --> SendIndicator
SendIndicator --> [*] : IndicatorSent
SendDirectMessageWorkflow¶
- Kind: public — Chats submits
DirectConversationCommand.SendMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/SendDirectMessageWorkflow.kt - Lock: none
- Uses:
WorkflowEngine,RequireDirectChatAuthorizationUseCase,InspectDirectInvitationUseCase,DirectReauthorizationPort,DirectConversationRepository
ValidateContent -> CheckAuthorization -> [InspectInvitation -> RequestReauthorization] -> ResolveConversation
-> DeliverMessage | (QueueMessage [-> DeliverMessage]).
An authorized contact gets the message immediately. Without authorization the message waits in
WAITING_FOR_AUTHORIZATION, and the workflow starts a fresh invitation when none is pending.
The workflow takes no lock, so a message is stored and shown at once even while an earlier message to the same
contact still uploads its attachments. Only QueueMessage ([MessageCommand.StoreWaitingDirectMessage]) holds the
contact's release lock: otherwise a release could run between "authorization missing" and storing the waiting
message, find nothing, and leave it waiting until the next identity event. When it finds the contact authorized
meanwhile, the message is delivered normally instead.
stateDiagram-v2
[*] --> ValidateContent
ValidateContent --> CheckAuthorization : ContentValidated
CheckAuthorization --> InspectInvitation : AuthorizationMissing
CheckAuthorization --> ResolveConversation : Authorized
CheckAuthorization --> Rejected : ContactBlocked
CheckAuthorization --> ResolveConversation : IdentityChangePending
InspectInvitation --> ResolveConversation : InvitationPending
InspectInvitation --> RequestReauthorization : InvitationRetryable
InspectInvitation --> Rejected : InvitationUnavailable
RequestReauthorization --> ResolveConversation : ReauthorizationFailed
RequestReauthorization --> ResolveConversation : Reauthorized
ResolveConversation --> DeliverMessage : ConversationResolved
ResolveConversation --> QueueMessage : ConversationResolved
DeliverMessage --> [*] : MessageDelivered
QueueMessage --> DeliverMessage : AuthorizedWhileQueuing
QueueMessage --> [*] : MessageQueued
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject
ToggleDirectReactionWorkflow¶
- Kind: public — Chats submits
DirectConversationCommand.ToggleReaction - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/ToggleDirectReactionWorkflow.kt - Lock: none
- Uses:
DirectConversationRepository,FindDirectMessageUseCase,ToggleLocalReactionUseCase,RequireDirectChatAuthorizationUseCase,SendDirectOperationUseCase
stateDiagram-v2
[*] --> FindConversation
FindConversation --> CheckAuthorization : ConversationFound
CheckAuthorization --> FindMessage : Authorized
FindMessage --> ToggleReaction : MessageFound
ToggleReaction --> SendReaction : ReactionChanged
SendReaction --> [*] : ReactionSent
direct.authorization¶
ActivateAuthorizedConversationWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.ActivateAuthorizedConversation - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/authorization/ActivateAuthorizedConversationWorkflow.kt - Lock: none
- Uses:
WorkflowEngine,DirectConversationRepository
stateDiagram-v2
[*] --> EnsureConversation
EnsureConversation --> ReleaseWaitingMessages : ConversationReady
ReleaseWaitingMessages --> [*] : WaitingMessagesReleased
DiscardWaitingDirectMessagesWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.DiscardWaitingDirectMessages - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/authorization/DiscardWaitingDirectMessagesWorkflow.kt - Lock:
directReleaseLockKey(command.contactId) - Uses:
DirectMessageRepository,DiscardDirectMessagesUseCase
stateDiagram-v2
[*] --> FindWaitingMessages
FindWaitingMessages --> DiscardMessages : WaitingMessagesFound
FindWaitingMessages --> [*] : WaitingMessagesFound
DiscardMessages --> [*] : MessagesDiscarded
ReleaseWaitingDirectMessagesWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.ReleaseWaitingDirectMessages - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/authorization/ReleaseWaitingDirectMessagesWorkflow.kt - Lock:
directReleaseLockKey(command.contactId) - Uses:
DirectMessageRepository,FindDirectAuthorizationBlockUseCase,DiscardExpiredWaitingDirectMessagesUseCase,ReleaseWaitingDirectMessageUseCase,RestoreWaitingDirectMessageUseCase,ProtocolOutbox,RecordPacketSendFailureUseCase
FindWaitingMessages -> CheckAuthorization -> DiscardExpiredMessages
-> (PrepareRelease [-> EnqueuePacket [-> MarkSendFailed -> RestoreWaitingMessage]])* .
Release is opportunistic: onboarding, invitation acceptance and restart reconciliation may
all try before keys exist. Missing authorization defers the work instead of failing. A message
whose packet could not reach the outbox goes back to waiting so a later release retries it.
Storing a new waiting message and editing or deleting one share the lock, so none of them works on a contact's
waiting messages while they are released. PrepareRelease still reads each message again and skips one that is
gone or no longer waiting.
stateDiagram-v2
[*] --> FindWaitingMessages
FindWaitingMessages --> CheckAuthorization : WaitingMessagesFound
FindWaitingMessages --> [*] : WaitingMessagesFound
CheckAuthorization --> DiscardExpiredMessages : Authorized
CheckAuthorization --> [*] : ReleaseDeferred
DiscardExpiredMessages --> PrepareRelease : ExpiredMessagesDiscarded
DiscardExpiredMessages --> [*] : ExpiredMessagesDiscarded
PrepareRelease --> EnqueuePacket : ReleasePrepared
PrepareRelease --> PrepareRelease : ReleaseSkipped
PrepareRelease --> [*] : ReleaseSkipped
EnqueuePacket --> MarkSendFailed : EnqueueFailed
EnqueuePacket --> PrepareRelease : PacketEnqueued
EnqueuePacket --> [*] : PacketEnqueued
MarkSendFailed --> RestoreWaitingMessage : SendFailureRecorded
RestoreWaitingMessage --> PrepareRelease : WaitingMessageRestored
RestoreWaitingMessage --> [*] : WaitingMessageRestored
StoreWaitingDirectMessageWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.StoreWaitingDirectMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/direct/authorization/StoreWaitingDirectMessageWorkflow.kt - Lock:
directReleaseLockKey(command.contactId) - Uses:
FindDirectAuthorizationBlockUseCase,DirectConversationRepository,LoadDirectRecipientUseCase,StoreOutgoingDirectMessageUseCase
CheckAuthorization -> (FindConversation -> LoadRecipient -> StoreWaitingMessage).
Holds the contact's release lock and checks authorization again under it with the same rule the release uses:
either the contact became authorized meanwhile and nothing is stored (the caller sends the message normally), or
the message is stored as waiting before any later release can look for it. Only messages for contacts without
authorization take the lock, so authorized sends never wait for each other.
stateDiagram-v2
[*] --> CheckAuthorization
CheckAuthorization --> [*] : AuthorizedMeanwhile
CheckAuthorization --> FindConversation : StillUnauthorized
FindConversation --> LoadRecipient : ConversationFound
LoadRecipient --> StoreWaitingMessage : RecipientLoaded
StoreWaitingMessage --> [*] : MessageStored
forward¶
ForwardMessageWorkflow¶
- Kind: public — Chats submits
ForwardMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/forward/ForwardMessageWorkflow.kt - Lock: none
- Uses:
WorkflowEngine,DirectConversationRepository,ConversationUnseenCountRepository
ValidateParts -> (FindContact ->) SendDirectMessage -> (FindDirectConversation ->) IncrementUnseen
ValidateParts -> SendGroupMessage -> IncrementUnseen
stateDiagram-v2
[*] --> ValidateParts
ValidateParts --> FindContact : PartsValid
ValidateParts --> SendDirectMessage : PartsValid
ValidateParts --> SendGroupMessage : PartsValid
FindContact --> SendDirectMessage : ContactFound
SendDirectMessage --> FindDirectConversation : DirectMessageSent
SendDirectMessage --> IncrementUnseen : DirectMessageSent
FindDirectConversation --> IncrementUnseen : DirectConversationFound
SendGroupMessage --> IncrementUnseen : GroupMessageSent
IncrementUnseen --> [*] : UnseenIncremented
group¶
CloseGroupPollWorkflow¶
- Kind: public — Chats submits
GroupMessageCommand.ClosePoll - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/CloseGroupPollWorkflow.kt - Lock: none
- Uses:
CheckGroupMessageAccessUseCase,FindGroupPollHolderUseCase,CheckPollClosePermissionUseCase,FindGroupRecipientsUseCase,FindGroupPollUseCase,SaveGroupPollUseCase,EncryptGroupOperationUseCase,EnqueueGroupPacketsUseCase
CheckMembership -> FindPollHolder -> CheckClosePermission -> FindRecipients -> FindPoll -> EncryptClose
-> EnqueueClose -> SaveClosedPoll.
Only the poll creator or a group admin may close a poll. The poll is closed locally only after the close is
queued: a failed send leaves it open, so a retry closes and sends again. A poll this device only has in the
group's pin ([PollHolder.Pin]) is closed there.
stateDiagram-v2
[*] --> CheckMembership
CheckMembership --> FindPollHolder : MembershipActive
CheckMembership --> Rejected : MembershipInactive
FindPollHolder --> CheckClosePermission : PollHolderFound
CheckClosePermission --> FindRecipients : CloseAllowed
CheckClosePermission --> Rejected : CloseNotAllowed
FindRecipients --> FindPoll : RecipientsFound
FindPoll --> EncryptClose : PollFound
EncryptClose --> EnqueueClose : CloseEncrypted
EnqueueClose --> SaveClosedPoll : CloseEnqueued
SaveClosedPoll --> [*] : ClosedPollSaved
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject
DeleteGroupMessageWorkflow¶
- Kind: public — Chats submits
GroupMessageCommand.DeleteMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/DeleteGroupMessageWorkflow.kt - Lock: none
- Uses:
WorkflowEngine,CheckGroupMessageAccessUseCase,FindDeletableGroupMessageUseCase,FindGroupRecipientsUseCase,EncryptGroupOperationUseCase,EnqueueGroupPacketsUseCase,DiscardGroupMessagesUseCase
CheckMembership -> FindOwnMessage -> FindRecipients -> (EncryptDelete -> EnqueueDelete -> DiscardMessage)
| DeleteUnsentMessage.
A message nobody can receive or that is still queued unsent is deleted locally only, so it is never flushed.
Only that local delete ([MessageCommand.DeleteUnsentGroupMessage]) takes the group send lock, so a running flush
cannot send it while it is deleted. The delete of a message members already have takes no lock.
stateDiagram-v2
[*] --> CheckMembership
CheckMembership --> FindOwnMessage : MembershipActive
CheckMembership --> Rejected : MembershipInactive
FindOwnMessage --> FindRecipients : OwnMessageFound
FindRecipients --> DeleteUnsentMessage : RecipientsFound
FindRecipients --> EncryptDelete : RecipientsFound
EncryptDelete --> EnqueueDelete : DeleteEncrypted
EnqueueDelete --> DiscardMessage : DeleteEnqueued
DiscardMessage --> [*] : MessageDiscarded
DeleteUnsentMessage --> [*] : UnsentMessageDeleted
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject
DeleteUnsentGroupMessageWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.DeleteUnsentGroupMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/DeleteUnsentGroupMessageWorkflow.kt - Lock:
groupSendLockKey(command.groupId) - Uses:
FindDeletableGroupMessageUseCase,FindGroupRecipientsUseCase,EncryptGroupOperationUseCase,EnqueueGroupPacketsUseCase,DiscardGroupMessagesUseCase
FindOwnMessage -> FindRecipients -> [EncryptDelete -> EnqueueDelete] -> DiscardMessage.
Runs only for a message nobody had received when the public delete looked at it. It holds the group send lock and
checks the recipients again, so a running flush either finished (and the delete is sent like any other) or never
sends the message.
stateDiagram-v2
[*] --> FindOwnMessage
FindOwnMessage --> FindRecipients : OwnMessageFound
FindRecipients --> DiscardMessage : RecipientsFound
FindRecipients --> EncryptDelete : RecipientsFound
EncryptDelete --> EnqueueDelete : DeleteEncrypted
EnqueueDelete --> DiscardMessage : DeleteEnqueued
DiscardMessage --> [*] : MessageDiscarded
EditGroupMessageWorkflow¶
- Kind: public — Chats submits
GroupMessageCommand.EditMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/EditGroupMessageWorkflow.kt - Lock: none
- Uses:
WorkflowEngine,GroupMessageRepository,CheckGroupMessageAccessUseCase,FindEditableGroupMessageUseCase,FindGroupRecipientsUseCase,EncryptGroupOperationUseCase,EnqueueGroupPacketsUseCase
CheckMembership -> FindEditableMessage -> FindRecipients -> (EncryptEdit -> EnqueueEdit -> ReplaceText)
| EditUnsentMessage.
A message nobody can receive or that is still queued unsent is edited locally only; the flush sends the new
text. Only that local edit ([MessageCommand.EditUnsentGroupMessage]) takes the group send lock, so a running
flush never sends the text from before the edit. The edit of a message members already have takes no lock and
never waits for a send or flush of the group.
stateDiagram-v2
[*] --> CheckMembership
CheckMembership --> FindEditableMessage : MembershipActive
CheckMembership --> Rejected : MembershipInactive
FindEditableMessage --> FindRecipients : MessageEditable
FindRecipients --> EditUnsentMessage : RecipientsFound
FindRecipients --> EncryptEdit : RecipientsFound
EncryptEdit --> EnqueueEdit : EditEncrypted
EnqueueEdit --> ReplaceText : EditEnqueued
ReplaceText --> [*] : TextReplaced
EditUnsentMessage --> [*] : UnsentMessageEdited
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject
EditUnsentGroupMessageWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.EditUnsentGroupMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/EditUnsentGroupMessageWorkflow.kt - Lock:
groupSendLockKey(command.groupId) - Uses:
GroupMessageRepository,FindEditableGroupMessageUseCase,FindGroupRecipientsUseCase,EncryptGroupOperationUseCase,EnqueueGroupPacketsUseCase
FindEditableMessage -> FindRecipients -> [EncryptEdit -> EnqueueEdit] -> ReplaceText.
Runs only for a message nobody had received when the public edit looked at it. It holds the group send lock and
checks the recipients again, so a running flush either finished (and the edit is sent like any other) or sends the
new text later; it never sends the text from before the edit.
stateDiagram-v2
[*] --> FindEditableMessage
FindEditableMessage --> FindRecipients : MessageEditable
FindRecipients --> EncryptEdit : RecipientsFound
FindRecipients --> ReplaceText : RecipientsFound
EncryptEdit --> EnqueueEdit : EditEncrypted
EnqueueEdit --> ReplaceText : EditEnqueued
ReplaceText --> [*] : TextReplaced
FlushQueuedGroupMessagesWorkflow¶
- Kind: internal — started by an observer, dispatcher or another workflow
MessageCommand.FlushQueuedGroupMessages - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/FlushQueuedGroupMessagesWorkflow.kt - Lock:
groupSendLockKey(command.groupId) - Uses:
GroupMessageRepository,FindGroupMessagesToFlushUseCase,FindUndeliveredGroupRecipientsUseCase,EncryptGroupMessageUseCase,SaveQueuedGroupRecipientsUseCase,EnqueueGroupPacketsUseCase
FindRecipients -> FindQueuedMessages
-> (FindMissingRecipients -> EncryptMessage -> [SaveRecipientStates] -> EnqueuePackets)* .
The persisted queue survives process death and is replayed whenever membership activates a
recipient. A damaged or temporarily undeliverable message stays queued and never blocks the
following ones.
stateDiagram-v2
[*] --> FindRecipients
FindRecipients --> FindQueuedMessages : RecipientsFound
FindRecipients --> [*] : RecipientsFound
FindQueuedMessages --> FindMissingRecipients : QueuedMessagesFound
FindQueuedMessages --> [*] : QueuedMessagesFound
FindMissingRecipients --> FindMissingRecipients : MessageStaysQueued
FindMissingRecipients --> [*] : MessageStaysQueued
FindMissingRecipients --> EncryptMessage : MissingRecipientsFound
FindMissingRecipients --> FindMissingRecipients : MissingRecipientsFound
FindMissingRecipients --> [*] : MissingRecipientsFound
EncryptMessage --> EnqueuePackets : MessageEncrypted
EncryptMessage --> SaveRecipientStates : MessageEncrypted
EncryptMessage --> FindMissingRecipients : MessageStaysQueued
EncryptMessage --> [*] : MessageStaysQueued
SaveRecipientStates --> FindMissingRecipients : MessageStaysQueued
SaveRecipientStates --> [*] : MessageStaysQueued
SaveRecipientStates --> EnqueuePackets : RecipientStatesSaved
EnqueuePackets --> FindMissingRecipients : MessageFlushed
EnqueuePackets --> [*] : MessageFlushed
EnqueuePackets --> FindMissingRecipients : MessageStaysQueued
EnqueuePackets --> [*] : MessageStaysQueued
MarkGroupConversationReadWorkflow¶
- Kind: public — Chats submits
GroupMessageCommand.MarkConversationRead - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/MarkGroupConversationReadWorkflow.kt - Lock: none
- Uses:
ConversationUnseenCountRepository,GroupMessageRepository,RequireGroupConversationUseCase,AcknowledgeIncomingMessageUseCase
ClearUnseenCount -> FindUnreadMessages -> (AcknowledgeMessage)* .
Each sender gets its own receipt; one failing receipt does not hold back the others.
stateDiagram-v2
[*] --> ClearUnseenCount
ClearUnseenCount --> FindUnreadMessages : UnseenCountCleared
FindUnreadMessages --> AcknowledgeMessage : UnreadMessagesFound
FindUnreadMessages --> Rejected : UnreadMessagesFound
FindUnreadMessages --> [*] : UnreadMessagesFound
AcknowledgeMessage --> AcknowledgeMessage : MessageAcknowledged
AcknowledgeMessage --> Rejected : MessageAcknowledged
AcknowledgeMessage --> [*] : MessageAcknowledged
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject
RetryGroupMessageWorkflow¶
- Kind: public — Chats submits
GroupMessageCommand.RetryMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/RetryGroupMessageWorkflow.kt - Lock: none
- Uses:
FindRetryableGroupRecipientsUseCase,ProtocolOutbox,RecordRetryRequestedUseCase
FindFailedRecipients -> (ResendToRecipient)* .
Retrying a group message resends only to the recipients whose delivery failed; it never
creates a new logical message. One failing recipient does not prevent the others' retry.
stateDiagram-v2
[*] --> FindFailedRecipients
FindFailedRecipients --> ResendToRecipient : FailedRecipientsFound
ResendToRecipient --> Rejected : RecipientAttempted
ResendToRecipient --> ResendToRecipient : RecipientAttempted
ResendToRecipient --> [*] : RecipientAttempted
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject
SendGroupIndicatorWorkflow¶
- Kind: public — Chats submits
GroupMessageCommand.SendIndicator - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/SendGroupIndicatorWorkflow.kt - Lock: none
- Uses:
SendConversationIndicatorUseCase
stateDiagram-v2
[*] --> SendIndicator
SendIndicator --> [*] : IndicatorSent
SendGroupMessageWorkflow¶
- Kind: public — Chats submits
GroupMessageCommand.SendMessage - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/SendGroupMessageWorkflow.kt - Lock:
groupSendLockKey(command.groupId) - Uses:
WorkflowEngine,GroupMessageRepository,CheckGroupMessageAccessUseCase,StoreOutgoingGroupMessageUseCase,DiscardGroupMessagesUseCase,EncryptGroupMessageUseCase,SaveQueuedGroupRecipientsUseCase,EnqueueGroupPacketsUseCase
ValidateContent -> CheckMembership -> FindRecipients -> [FlushQueuedMessages] -> StoreMessage
-> [EncryptMessage -> SaveRecipientStates -> EnqueuePackets].
Without an active recipient the message stays queued and is flushed once a member activates.
Older queued messages are flushed first so recipients receive them in order. A message whose attachment could
not go out yet ([UnsentMessagePolicy]) also stays queued and is flushed again later; any other failure to
encrypt discards it.
stateDiagram-v2
[*] --> ValidateContent
ValidateContent --> CheckMembership : ContentValidated
CheckMembership --> FindRecipients : MembershipActive
CheckMembership --> Rejected : MembershipInactive
FindRecipients --> FlushQueuedMessages : RecipientsFound
FindRecipients --> StoreMessage : RecipientsFound
FlushQueuedMessages --> StoreMessage : QueueFlushed
StoreMessage --> EncryptMessage : MessageStored
StoreMessage --> [*] : MessageStored
EncryptMessage --> DiscardMessage : EncryptionFailed
EncryptMessage --> Rejected : EncryptionFailed
EncryptMessage --> SaveRecipientStates : MessageEncrypted
DiscardMessage --> Rejected : MessageDiscarded
SaveRecipientStates --> EnqueuePackets : RecipientStatesSaved
EnqueuePackets --> [*] : PacketsEnqueued
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject
ToggleGroupReactionWorkflow¶
- Kind: public — Chats submits
GroupMessageCommand.ToggleReaction - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/ToggleGroupReactionWorkflow.kt - Lock: none
- Uses:
ToggleLocalReactionUseCase,CheckGroupMessageAccessUseCase,FindGroupMessageUseCase,FindGroupRecipientsUseCase,EncryptGroupOperationUseCase,EnqueueGroupPacketsUseCase
CheckMembership -> FindMessage -> FindRecipients -> ToggleReaction -> EncryptReaction -> EnqueueReaction.
stateDiagram-v2
[*] --> CheckMembership
CheckMembership --> FindMessage : MembershipActive
CheckMembership --> Rejected : MembershipInactive
FindMessage --> FindRecipients : MessageFound
FindRecipients --> ToggleReaction : RecipientsFound
ToggleReaction --> EncryptReaction : ReactionChanged
EncryptReaction --> EnqueueReaction : ReactionEncrypted
EnqueueReaction --> [*] : ReactionEnqueued
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject
VoteGroupPollWorkflow¶
- Kind: public — Chats submits
GroupMessageCommand.VotePoll - Source:
feature/conversationorchestration/message/src/commonMain/kotlin/com/cbgm/sparrow/feature/conversationorchestration/message/domain/workflow/group/VoteGroupPollWorkflow.kt - Lock: none
- Uses:
CheckGroupMessageAccessUseCase,FindGroupPollHolderUseCase,FindGroupRecipientsUseCase,FindGroupPollUseCase,SaveGroupPollUseCase,EncryptGroupOperationUseCase,EnqueueGroupPacketsUseCase
CheckMembership -> FindPollHolder -> FindRecipients -> FindPoll -> SaveVote -> EncryptVote -> EnqueueVote.
A member who joined after the poll was pinned has the poll only in the pin ([PollHolder.Pin]): the vote is saved
there and sent like any other vote, so members with the message apply it to theirs.
stateDiagram-v2
[*] --> CheckMembership
CheckMembership --> FindPollHolder : MembershipActive
CheckMembership --> Rejected : MembershipInactive
FindPollHolder --> FindRecipients : PollHolderFound
FindRecipients --> FindPoll : RecipientsFound
FindPoll --> SaveVote : PollFound
SaveVote --> EncryptVote : VoteSaved
EncryptVote --> EnqueueVote : VoteEncrypted
EnqueueVote --> [*] : VoteEnqueued
Rejected --> [*]
classDef reject fill:#f8d7da,stroke:#b02a37,color:#58151c
class Rejected reject