-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement MessageContentFactory (#5498)
- Loading branch information
Showing
7 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...io/getstream/chat/android/compose/ui/components/messages/factory/MessageContentFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
* | ||
* Licensed under the Stream License; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.getstream.chat.android.compose.ui.components.messages.factory | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import io.getstream.chat.android.compose.ui.components.messages.DefaultMessageDeletedContent | ||
import io.getstream.chat.android.compose.ui.components.messages.DefaultMessageGiphyContent | ||
import io.getstream.chat.android.compose.ui.components.messages.MessageText | ||
import io.getstream.chat.android.compose.ui.components.messages.QuotedMessage | ||
import io.getstream.chat.android.models.Message | ||
import io.getstream.chat.android.models.User | ||
import io.getstream.chat.android.ui.common.state.messages.list.GiphyAction | ||
|
||
/** | ||
* Factory for creating message contents that are used to represent the chat message items. | ||
*/ | ||
@Stable | ||
public open class MessageContentFactory { | ||
|
||
/** | ||
* Represents the default Giphy message content. | ||
*/ | ||
@Composable | ||
public open fun MessageGiphyContent( | ||
message: Message, | ||
onGiphyActionClick: (GiphyAction) -> Unit, | ||
) { | ||
DefaultMessageGiphyContent( | ||
message = message, | ||
onGiphyActionClick = onGiphyActionClick, | ||
) | ||
} | ||
|
||
/** | ||
* Represents the default content of a deleted message. | ||
*/ | ||
@Composable | ||
public open fun MessageDeletedContent( | ||
modifier: Modifier, | ||
) { | ||
DefaultMessageDeletedContent(modifier = modifier) | ||
} | ||
|
||
/** | ||
* Represents the default regular message content. | ||
*/ | ||
@Composable | ||
public open fun MessageTextContent( | ||
message: Message, | ||
currentUser: User?, | ||
onLongItemClick: (Message) -> Unit, | ||
onLinkClick: ((Message, String) -> Unit)?, | ||
onUserMentionClick: (User) -> Unit, | ||
) { | ||
MessageText( | ||
message = message, | ||
currentUser = currentUser, | ||
onLongItemClick = onLongItemClick, | ||
onLinkClick = onLinkClick, | ||
) | ||
} | ||
|
||
/** | ||
* Represents the default quoted message content. | ||
*/ | ||
@Composable | ||
public open fun QuotedMessageContent( | ||
message: Message, | ||
currentUser: User?, | ||
onLongItemClick: (Message) -> Unit, | ||
onQuotedMessageClick: (Message) -> Unit, | ||
) { | ||
val quotedMessage = message.replyTo | ||
if (quotedMessage != null) { | ||
QuotedMessage( | ||
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), | ||
message = quotedMessage, | ||
currentUser = currentUser, | ||
replyMessage = message, | ||
onLongItemClick = { onLongItemClick(message) }, | ||
onQuotedMessageClick = onQuotedMessageClick, | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.