Skip to content

Commit 71a6c52

Browse files
committed
refactor message and input UI components for improved state management and performance
- introduce `MessageAppearanceConfig`, `MessageRowBehaviorConfig`, and `MessageRowUiFlags` to centralize message rendering and interaction logic - refactor `ChatInputBar` to use structured state objects (`ChatInputBarCapabilities`, `ComposerRowState`, `ComposerBotState`) for cleaner prop drilling - implement `derivedStateOf` and `rememberUpdatedState` in `InputTextField` to optimize composition and avoid unnecessary rebuilds during text transformation - decompose `VideoMessageBubble` into specialized sub-components (e.g., `VideoMuteToggle`, `VideoPlaybackBadge`, `VideoInteractionOverlay`) for better maintainability - extract message bubble layout tracking into `MessageBubbleLayoutTracker` to standardize position reporting for context menus and replies - modularize `ChatInputBarComposerSection` into `ComposerMainRow`, `ComposerInputSlot`, and `ComposerActionsSlot` - consolidate sender grouping logic into a unified `buildSenderGrouping` utility - update `MessageBubbleContainer` and `AlbumMessageBubbleContainer` to utilize the new configuration contracts for UI flags and behavior - simplify `InputBarSendButton` by passing a single `InputBarSendButtonState` object - refine `InputTextFieldContainer` logic to use `InputTextFieldUiState` for reactive visibility and action states
1 parent 48f83c6 commit 71a6c52

15 files changed

Lines changed: 1951 additions & 1293 deletions

presentation/src/main/java/org/monogram/presentation/features/chats/conversation/ui/AlbumMessageBubbleContainer.kt

Lines changed: 74 additions & 109 deletions
Large diffs are not rendered by default.

presentation/src/main/java/org/monogram/presentation/features/chats/conversation/ui/ChatInputBar.kt

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ import org.monogram.domain.models.StickerModel
5151
import org.monogram.domain.repository.StickerRepository
5252
import org.monogram.presentation.core.util.AppPreferences
5353
import org.monogram.presentation.features.camera.CameraScreen
54-
import org.monogram.presentation.features.chats.conversation.ui.message.getEmojiFontFamily
5554
import org.monogram.presentation.features.chats.conversation.ui.inputbar.ChatInputBarActions
55+
import org.monogram.presentation.features.chats.conversation.ui.inputbar.ChatInputBarCapabilities
5656
import org.monogram.presentation.features.chats.conversation.ui.inputbar.ChatInputBarComposerSection
5757
import org.monogram.presentation.features.chats.conversation.ui.inputbar.ChatInputBarState
5858
import org.monogram.presentation.features.chats.conversation.ui.inputbar.ClosedTopicBar
59+
import org.monogram.presentation.features.chats.conversation.ui.inputbar.ComposerAttachmentState
60+
import org.monogram.presentation.features.chats.conversation.ui.inputbar.ComposerBotState
61+
import org.monogram.presentation.features.chats.conversation.ui.inputbar.ComposerRowState
62+
import org.monogram.presentation.features.chats.conversation.ui.inputbar.ComposerSuggestionState
5963
import org.monogram.presentation.features.chats.conversation.ui.inputbar.FullScreenEditorSheet
6064
import org.monogram.presentation.features.chats.conversation.ui.inputbar.InputBarMode
6165
import org.monogram.presentation.features.chats.conversation.ui.inputbar.RestrictedInputBar
@@ -74,6 +78,7 @@ import org.monogram.presentation.features.chats.conversation.ui.inputbar.hasAllP
7478
import org.monogram.presentation.features.chats.conversation.ui.inputbar.isInlineBotPrefillText
7579
import org.monogram.presentation.features.chats.conversation.ui.inputbar.parseInlineQueryInput
7680
import org.monogram.presentation.features.chats.conversation.ui.inputbar.rememberVoiceRecorder
81+
import org.monogram.presentation.features.chats.conversation.ui.message.getEmojiFontFamily
7782
import org.monogram.presentation.features.gallery.GalleryScreen
7883
import org.monogram.presentation.features.gallery.components.PollComposerSheet
7984
import java.util.Calendar
@@ -150,6 +155,31 @@ fun ChatInputBar(
150155
canWriteText || canOpenAttachSheet || canSendStickers || canSendVoice || canSendVideoNotes || canSendPolls
151156
}
152157
}
158+
val capabilities = remember(
159+
canWriteText,
160+
canSendPhotos,
161+
canSendVideos,
162+
canSendDocuments,
163+
canSendAudios,
164+
canOpenAttachSheet,
165+
canSendStickers,
166+
canSendVoice,
167+
canSendVideoNotes,
168+
canSendAnything
169+
) {
170+
ChatInputBarCapabilities(
171+
canWriteText = canWriteText,
172+
canSendPhotos = canSendPhotos,
173+
canSendVideos = canSendVideos,
174+
canSendDocuments = canSendDocuments,
175+
canSendAudios = canSendAudios,
176+
canOpenAttachSheet = canOpenAttachSheet,
177+
canSendStickers = canSendStickers,
178+
canSendVoice = canSendVoice,
179+
canSendVideoNotes = canSendVideoNotes,
180+
canSendAnything = canSendAnything
181+
)
182+
}
153183

154184
val context = LocalContext.current
155185
val emojiStyle by appPreferences.emojiStyle.collectAsState()
@@ -648,45 +678,49 @@ fun ChatInputBar(
648678
InputBarMode.Composer -> ChatInputBarComposerSection(
649679
editingMessage = state.editingMessage,
650680
replyMessage = state.replyMessage,
651-
pendingMediaPaths = state.pendingMediaPaths,
652-
pendingDocumentPaths = state.pendingDocumentPaths,
653-
mentionSuggestions = state.mentionSuggestions,
654-
filteredCommands = filteredCommands,
655-
currentInlineBotUsername = state.currentInlineBotUsername.takeIf { canSendStickers },
656-
isInlineBotLoading = canSendStickers && state.isInlineBotLoading,
657-
inlineBotResults = state.inlineBotResults.takeIf { canSendStickers },
658-
isBot = state.isBot,
659-
botMenuButton = state.botMenuButton,
660-
botCommands = state.botCommands,
661-
scheduledMessagesCount = state.scheduledMessages.size,
662-
textValue = textValue,
681+
attachments = ComposerAttachmentState(
682+
pendingMediaPaths = state.pendingMediaPaths,
683+
pendingDocumentPaths = state.pendingDocumentPaths,
684+
scheduledMessagesCount = state.scheduledMessages.size
685+
),
686+
suggestions = ComposerSuggestionState(
687+
mentionSuggestions = state.mentionSuggestions,
688+
filteredCommands = filteredCommands,
689+
currentInlineBotUsername = state.currentInlineBotUsername.takeIf { canSendStickers },
690+
isInlineBotLoading = canSendStickers && state.isInlineBotLoading,
691+
inlineBotResults = state.inlineBotResults.takeIf { canSendStickers },
692+
replyMarkup = state.replyMarkup,
693+
isGifSearchFocused = isGifSearchFocused
694+
),
695+
botState = ComposerBotState(
696+
isBot = state.isBot,
697+
botMenuButton = state.botMenuButton,
698+
botCommands = state.botCommands
699+
),
700+
rowState = ComposerRowState(
701+
textValue = textValue,
702+
editingMessage = state.editingMessage,
703+
isStickerMenuVisible = isStickerMenuVisible,
704+
closeStickerMenuWithoutSlide = closeStickerMenuWithoutSlide,
705+
isKeyboardVisible = isKeyboardVisible,
706+
stickerMenuHeight = stickerMenuHeight,
707+
showFullScreenEditor = showFullScreenEditor,
708+
currentMessageLength = currentMessageLength,
709+
maxMessageLength = maxMessageLength,
710+
isOverMessageLimit = isOverMessageLimit,
711+
showSendOptionsSheet = showSendOptionsSheet,
712+
isVideoMessageMode = isVideoMessageMode,
713+
isSlowModeActive = isSlowModeActive,
714+
slowModeRemainingSeconds = slowModeRemainingSeconds
715+
),
663716
onTextValueChange = { textValue = it },
664717
knownCustomEmojis = knownCustomEmojis,
665718
emojiFontFamily = emojiFontFamily,
666719
focusRequester = focusRequester,
667-
canWriteText = canWriteText,
668-
canOpenAttachSheet = canOpenAttachSheet,
720+
capabilities = capabilities,
669721
canSendAttachments = canSendPendingAttachments,
670-
canShowBotActions = canWriteText,
671722
canPasteMediaFromClipboard = canUseMediaPicker && state.editingMessage == null,
672-
canSendStickers = canSendStickers,
673-
canSendVoice = canSendVoice,
674-
canSendVideoNotes = canSendVideoNotes,
675-
isStickerMenuVisible = isStickerMenuVisible,
676-
closeStickerMenuWithoutSlide = closeStickerMenuWithoutSlide,
677-
isKeyboardVisible = isKeyboardVisible,
678-
stickerMenuHeight = stickerMenuHeight,
679723
voiceRecorder = voiceRecorder,
680-
isGifSearchFocused = isGifSearchFocused,
681-
showFullScreenEditor = showFullScreenEditor,
682-
currentMessageLength = currentMessageLength,
683-
maxMessageLength = maxMessageLength,
684-
isOverMessageLimit = isOverMessageLimit,
685-
isVideoMessageMode = isVideoMessageMode,
686-
isSlowModeActive = isSlowModeActive,
687-
slowModeRemainingSeconds = slowModeRemainingSeconds,
688-
replyMarkup = state.replyMarkup,
689-
showSendOptionsSheet = showSendOptionsSheet,
690724
stickerRepository = stickerRepository,
691725
onCancelEdit = actions.onCancelEdit,
692726
onCancelReply = actions.onCancelReply,

0 commit comments

Comments
 (0)