diff --git a/MODULE_DIAGRAMS.md b/MODULE_DIAGRAMS.md index a9348695e..b10fb9122 100644 --- a/MODULE_DIAGRAMS.md +++ b/MODULE_DIAGRAMS.md @@ -282,6 +282,7 @@ flowchart LR :unit:chat --> :core:appearance :unit:chat --> :core:architecture :unit:chat --> :core:commonui:components + :unit:chat --> :core:commonui:detailOpenerApi :unit:chat --> :core:commonui:lemmyui :unit:chat --> :core:commonui:modals :unit:chat --> :core:navigation @@ -292,6 +293,7 @@ flowchart LR :unit:chat --> :domain:lemmy:data :unit:chat --> :domain:lemmy:repository :unit:chat --> :unit:rawcontent + :unit:chat --> :unit:web :unit:chat --> :unit:zoomableimage :unit:chat --> :resources ``` diff --git a/core/commonui/detailopener-impl/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/detailopener/impl/DefaultDetailOpener.kt b/core/commonui/detailopener-impl/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/detailopener/impl/DefaultDetailOpener.kt index c419b207b..622d5518a 100644 --- a/core/commonui/detailopener-impl/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/detailopener/impl/DefaultDetailOpener.kt +++ b/core/commonui/detailopener-impl/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/detailopener/impl/DefaultDetailOpener.kt @@ -35,7 +35,7 @@ class DefaultDetailOpener( override fun openCommunityDetail(community: CommunityModel, otherInstance: String) { scope.launch { val (actualCommunity, actualInstance) = withContext(Dispatchers.IO) { - val found = searchCommunity(community.name) + val found = searchCommunity(name = community.name, host = otherInstance) if (found != null) { found to "" } else { @@ -130,7 +130,7 @@ class DefaultDetailOpener( } } - private suspend fun searchCommunity(name: String): CommunityModel? { + private suspend fun searchCommunity(name: String, host: String): CommunityModel? { val auth = identityRepository.authToken.value tailrec suspend fun searchRec(page: Int = 0): CommunityModel? { @@ -143,10 +143,10 @@ class DefaultDetailOpener( )?.filterIsInstance().orEmpty() val found = results.firstOrNull { - it.model.name == name + it.model.name == name && it.model.host == host }?.model - // iterates for no more than 20 pages before giving up - if (found != null || page >= 20) { + // iterates for no more than 10 pages before giving up + if (found != null || page >= 10) { return found } diff --git a/unit/chat/build.gradle.kts b/unit/chat/build.gradle.kts index 8e823570a..6a7a53745 100644 --- a/unit/chat/build.gradle.kts +++ b/unit/chat/build.gradle.kts @@ -47,11 +47,13 @@ kotlin { implementation(projects.core.commonui.components) implementation(projects.core.commonui.lemmyui) implementation(projects.core.commonui.modals) + implementation(projects.core.commonui.detailopenerApi) implementation(projects.core.navigation) implementation(projects.core.persistence) implementation(projects.core.notifications) implementation(projects.unit.zoomableimage) implementation(projects.unit.rawcontent) + implementation(projects.unit.web) implementation(projects.domain.identity) implementation(projects.domain.lemmy.data) diff --git a/unit/chat/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/chat/InboxChatScreen.kt b/unit/chat/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/chat/InboxChatScreen.kt index e7b6c3378..467a79f99 100644 --- a/unit/chat/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/chat/InboxChatScreen.kt +++ b/unit/chat/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/chat/InboxChatScreen.kt @@ -57,6 +57,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.toTypography import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomImage +import com.github.diegoberaldin.raccoonforlemmy.core.commonui.detailopener.api.getDetailOpener import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.Option import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.OptionId import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.TextFormattingBar @@ -70,6 +71,7 @@ import com.github.diegoberaldin.raccoonforlemmy.resources.MR import com.github.diegoberaldin.raccoonforlemmy.unit.chat.components.MessageCard import com.github.diegoberaldin.raccoonforlemmy.unit.chat.components.MessageCardPlaceholder import com.github.diegoberaldin.raccoonforlemmy.unit.rawcontent.RawContentDialog +import com.github.diegoberaldin.raccoonforlemmy.unit.web.WebViewScreen import com.github.diegoberaldin.raccoonforlemmy.unit.zoomableimage.ZoomableImageScreen import dev.icerock.moko.resources.compose.stringResource import kotlinx.coroutines.flow.launchIn @@ -98,6 +100,7 @@ class InboxChatScreen( val typography = contentFontFamily.toTypography() var rawContent by remember { mutableStateOf(null) } val lazyListState = rememberLazyListState() + val detailOpener = remember { getDetailOpener() } LaunchedEffect(model) { model.effects.onEach { effect -> @@ -250,6 +253,26 @@ class InboxChatScreen( onOpenImage = rememberCallbackArgs { url -> navigationCoordinator.pushScreen(ZoomableImageScreen(url)) }, + onOpenCommunity = rememberCallbackArgs { community, instance -> + detailOpener.openCommunityDetail( + community, + instance + ) + }, + onOpenUser = rememberCallbackArgs { user, instance -> + detailOpener.openUserDetail(user, instance) + }, + onOpenPost = rememberCallbackArgs { post, instance -> + detailOpener.openPostDetail( + post = post, + otherInstance = instance, + ) + }, + onOpenWeb = rememberCallbackArgs { url -> + navigationCoordinator.pushScreen( + WebViewScreen(url) + ) + }, options = buildList { this += Option( OptionId.SeeRaw, diff --git a/unit/chat/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/chat/components/MessageCard.kt b/unit/chat/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/chat/components/MessageCard.kt index 464e4ef1a..a8f2266d9 100644 --- a/unit/chat/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/chat/components/MessageCard.kt +++ b/unit/chat/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/chat/components/MessageCard.kt @@ -42,12 +42,19 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.onClick import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallback import com.github.diegoberaldin.raccoonforlemmy.core.utils.datetime.prettifyDate import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalDp +import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel +import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel +import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel @Composable internal fun MessageCard( isMyMessage: Boolean = false, content: String = "", date: String = "", + onOpenCommunity: ((CommunityModel, String) -> Unit)? = null, + onOpenUser: ((UserModel, String) -> Unit)? = null, + onOpenPost: ((PostModel, String) -> Unit)? = null, + onOpenWeb: ((String) -> Unit)? = null, onOpenImage: ((String) -> Unit)? = null, options: List