Skip to content

Commit 0e0f904

Browse files
committed
Add message info option to message menu
1 parent 0e4f258 commit 0e0f904

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/component/DeleteMessageForMeComponentFactory.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ import io.getstream.chat.android.ui.common.utils.canDeleteMessage
4545
/**
4646
* Factory for creating components related to deleting messages for the current user.
4747
*/
48-
class DeleteMessageForMeComponentFactory : ChatComponentFactory {
48+
class DeleteMessageForMeComponentFactory(
49+
private val delegate: ChatComponentFactory = MessageInfoComponentFactory(),
50+
) : ChatComponentFactory by delegate {
4951

5052
/**
5153
* Creates a message menu with option for deleting messages for the current user.
@@ -117,7 +119,7 @@ class DeleteMessageForMeComponentFactory : ChatComponentFactory {
117119
)
118120
}
119121

120-
super.MessageMenu(
122+
delegate.MessageMenu(
121123
modifier = modifier,
122124
message = message,
123125
messageOptions = allOptions,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.chat.android.compose.sample.ui.component
18+
19+
import androidx.compose.material.icons.Icons
20+
import androidx.compose.material.icons.outlined.Info
21+
import androidx.compose.material3.ExperimentalMaterial3Api
22+
import androidx.compose.material3.ModalBottomSheet
23+
import androidx.compose.runtime.Composable
24+
import androidx.compose.runtime.getValue
25+
import androidx.compose.runtime.mutableStateOf
26+
import androidx.compose.runtime.remember
27+
import androidx.compose.runtime.setValue
28+
import androidx.compose.ui.Modifier
29+
import androidx.compose.ui.graphics.vector.rememberVectorPainter
30+
import io.getstream.chat.android.compose.sample.R
31+
import io.getstream.chat.android.compose.state.messageoptions.MessageOptionItemState
32+
import io.getstream.chat.android.compose.ui.theme.ChatComponentFactory
33+
import io.getstream.chat.android.compose.ui.theme.ChatTheme
34+
import io.getstream.chat.android.models.Message
35+
import io.getstream.chat.android.ui.common.state.messages.CustomAction
36+
import io.getstream.chat.android.ui.common.state.messages.MessageAction
37+
38+
/**
39+
* Factory for creating components related to message info.
40+
*/
41+
class MessageInfoComponentFactory : ChatComponentFactory {
42+
43+
/**
44+
* Creates a message menu with option for message info.
45+
*/
46+
@OptIn(ExperimentalMaterial3Api::class)
47+
@Suppress("LongMethod")
48+
@Composable
49+
override fun MessageMenu(
50+
modifier: Modifier,
51+
message: Message,
52+
messageOptions: List<MessageOptionItemState>,
53+
ownCapabilities: Set<String>,
54+
onMessageAction: (MessageAction) -> Unit,
55+
onShowMore: () -> Unit,
56+
onDismiss: () -> Unit,
57+
) {
58+
var showMessageInfoDialog by remember { mutableStateOf(false) }
59+
60+
val allOptions = listOf(
61+
MessageOptionItemState(
62+
title = R.string.message_option_message_info,
63+
titleColor = ChatTheme.colors.textHighEmphasis,
64+
iconPainter = rememberVectorPainter(Icons.Outlined.Info),
65+
iconColor = ChatTheme.colors.textLowEmphasis,
66+
action = CustomAction(message, mapOf("message_info" to true)),
67+
)
68+
) + messageOptions
69+
70+
val extendedOnMessageAction: (MessageAction) -> Unit = { action ->
71+
when {
72+
action is CustomAction && action.extraProperties.contains("message_info") ->
73+
showMessageInfoDialog = true
74+
75+
else -> onMessageAction(action)
76+
}
77+
}
78+
79+
var dismissed by remember { mutableStateOf(false) }
80+
81+
if (showMessageInfoDialog) {
82+
ModalBottomSheet(
83+
onDismissRequest = {
84+
showMessageInfoDialog = false
85+
onDismiss()
86+
dismissed = true // Mark as dismissed to avoid animating the menu again
87+
},
88+
containerColor = ChatTheme.colors.appBackground,
89+
) {
90+
// TODO Replace with a proper Message Info Screen
91+
}
92+
} else if (!dismissed) {
93+
super.MessageMenu(
94+
modifier = modifier,
95+
message = message,
96+
messageOptions = allOptions,
97+
ownCapabilities = ownCapabilities,
98+
onMessageAction = extendedOnMessageAction,
99+
onShowMore = onShowMore,
100+
onDismiss = onDismiss,
101+
)
102+
}
103+
}
104+
}

stream-chat-android-compose-sample/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
</plurals>
123123

124124
<string name="message_option_delete_for_me">Delete Message For Me</string>
125+
<string name="message_option_message_info">Message Info</string>
125126

126127
<!-- Channel Attachments -->
127128
<string name="channel_attachments_media_loading_more_error">Failed to load more media attachments</string>

0 commit comments

Comments
 (0)