fix: community link opening (#488)

* fix: match name and host while searching communities

* feat: open community from chat
This commit is contained in:
Diego Beraldin 2024-01-26 13:35:33 +01:00 committed by GitHub
parent 1b1facbdfe
commit f56b72b174
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 5 deletions

View File

@ -282,6 +282,7 @@ flowchart LR
:unit:chat --> :core:appearance :unit:chat --> :core:appearance
:unit:chat --> :core:architecture :unit:chat --> :core:architecture
:unit:chat --> :core:commonui:components :unit:chat --> :core:commonui:components
:unit:chat --> :core:commonui:detailOpenerApi
:unit:chat --> :core:commonui:lemmyui :unit:chat --> :core:commonui:lemmyui
:unit:chat --> :core:commonui:modals :unit:chat --> :core:commonui:modals
:unit:chat --> :core:navigation :unit:chat --> :core:navigation
@ -292,6 +293,7 @@ flowchart LR
:unit:chat --> :domain:lemmy:data :unit:chat --> :domain:lemmy:data
:unit:chat --> :domain:lemmy:repository :unit:chat --> :domain:lemmy:repository
:unit:chat --> :unit:rawcontent :unit:chat --> :unit:rawcontent
:unit:chat --> :unit:web
:unit:chat --> :unit:zoomableimage :unit:chat --> :unit:zoomableimage
:unit:chat --> :resources :unit:chat --> :resources
``` ```

View File

@ -35,7 +35,7 @@ class DefaultDetailOpener(
override fun openCommunityDetail(community: CommunityModel, otherInstance: String) { override fun openCommunityDetail(community: CommunityModel, otherInstance: String) {
scope.launch { scope.launch {
val (actualCommunity, actualInstance) = withContext(Dispatchers.IO) { val (actualCommunity, actualInstance) = withContext(Dispatchers.IO) {
val found = searchCommunity(community.name) val found = searchCommunity(name = community.name, host = otherInstance)
if (found != null) { if (found != null) {
found to "" found to ""
} else { } 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 val auth = identityRepository.authToken.value
tailrec suspend fun searchRec(page: Int = 0): CommunityModel? { tailrec suspend fun searchRec(page: Int = 0): CommunityModel? {
@ -143,10 +143,10 @@ class DefaultDetailOpener(
)?.filterIsInstance<SearchResult.Community>().orEmpty() )?.filterIsInstance<SearchResult.Community>().orEmpty()
val found = results.firstOrNull { val found = results.firstOrNull {
it.model.name == name it.model.name == name && it.model.host == host
}?.model }?.model
// iterates for no more than 20 pages before giving up // iterates for no more than 10 pages before giving up
if (found != null || page >= 20) { if (found != null || page >= 10) {
return found return found
} }

View File

@ -47,11 +47,13 @@ kotlin {
implementation(projects.core.commonui.components) implementation(projects.core.commonui.components)
implementation(projects.core.commonui.lemmyui) implementation(projects.core.commonui.lemmyui)
implementation(projects.core.commonui.modals) implementation(projects.core.commonui.modals)
implementation(projects.core.commonui.detailopenerApi)
implementation(projects.core.navigation) implementation(projects.core.navigation)
implementation(projects.core.persistence) implementation(projects.core.persistence)
implementation(projects.core.notifications) implementation(projects.core.notifications)
implementation(projects.unit.zoomableimage) implementation(projects.unit.zoomableimage)
implementation(projects.unit.rawcontent) implementation(projects.unit.rawcontent)
implementation(projects.unit.web)
implementation(projects.domain.identity) implementation(projects.domain.identity)
implementation(projects.domain.lemmy.data) implementation(projects.domain.lemmy.data)

View File

@ -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.appearance.theme.toTypography
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomImage 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.Option
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.OptionId import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.OptionId
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.TextFormattingBar 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.MessageCard
import com.github.diegoberaldin.raccoonforlemmy.unit.chat.components.MessageCardPlaceholder import com.github.diegoberaldin.raccoonforlemmy.unit.chat.components.MessageCardPlaceholder
import com.github.diegoberaldin.raccoonforlemmy.unit.rawcontent.RawContentDialog 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 com.github.diegoberaldin.raccoonforlemmy.unit.zoomableimage.ZoomableImageScreen
import dev.icerock.moko.resources.compose.stringResource import dev.icerock.moko.resources.compose.stringResource
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
@ -98,6 +100,7 @@ class InboxChatScreen(
val typography = contentFontFamily.toTypography() val typography = contentFontFamily.toTypography()
var rawContent by remember { mutableStateOf<Any?>(null) } var rawContent by remember { mutableStateOf<Any?>(null) }
val lazyListState = rememberLazyListState() val lazyListState = rememberLazyListState()
val detailOpener = remember { getDetailOpener() }
LaunchedEffect(model) { LaunchedEffect(model) {
model.effects.onEach { effect -> model.effects.onEach { effect ->
@ -250,6 +253,26 @@ class InboxChatScreen(
onOpenImage = rememberCallbackArgs { url -> onOpenImage = rememberCallbackArgs { url ->
navigationCoordinator.pushScreen(ZoomableImageScreen(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 { options = buildList {
this += Option( this += Option(
OptionId.SeeRaw, OptionId.SeeRaw,

View File

@ -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.compose.rememberCallback
import com.github.diegoberaldin.raccoonforlemmy.core.utils.datetime.prettifyDate import com.github.diegoberaldin.raccoonforlemmy.core.utils.datetime.prettifyDate
import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalDp 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 @Composable
internal fun MessageCard( internal fun MessageCard(
isMyMessage: Boolean = false, isMyMessage: Boolean = false,
content: String = "", content: String = "",
date: 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, onOpenImage: ((String) -> Unit)? = null,
options: List<Option> = emptyList(), options: List<Option> = emptyList(),
onOptionSelected: ((OptionId) -> Unit)? = null, onOptionSelected: ((OptionId) -> Unit)? = null,
@ -112,6 +119,10 @@ internal fun MessageCard(
PostCardBody( PostCardBody(
text = content, text = content,
onOpenImage = onOpenImage, onOpenImage = onOpenImage,
onOpenCommunity = onOpenCommunity,
onOpenUser = onOpenUser,
onOpenPost = onOpenPost,
onOpenWeb = onOpenWeb,
) )
Box { Box {
Row( Row(