Skip to content

Commit

Permalink
DROID-3140 Space-level chat | Fix | Opening bookmark objects in brows…
Browse files Browse the repository at this point in the history
…er (#2100)
  • Loading branch information
uburoiubu authored Feb 14, 2025
1 parent 73cd7ab commit 7fe3f6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/src/main/java/com/anytypeio/anytype/ui/chats/ChatFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ class ChatFragment : BaseComposeFragment() {
Timber.e(it, "Error while opening space member card")
}
}
is ChatViewModel.ViewModelCommand.Browse -> {
runCatching {
proceedWithAction(
SystemAction.OpenUrl(
command.url
)
)
}.onFailure {
Timber.e(it, "Error while opening bookmark from chat")
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.Command
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.chats.Chat
import com.anytypeio.anytype.core_models.primitives.Space
import com.anytypeio.anytype.core_models.primitives.SpaceId
Expand Down Expand Up @@ -622,7 +623,18 @@ class ChatViewModel @Inject constructor(
is ChatView.Message.Attachment.Link -> {
val wrapper = attachment.wrapper
if (wrapper != null) {
navigation.emit(wrapper.navigation())
if (wrapper.layout == ObjectType.Layout.BOOKMARK) {
val bookmark = ObjectWrapper.Bookmark(wrapper.map)
val url = bookmark.source
if (!url.isNullOrEmpty()) {
commands.emit(ViewModelCommand.Browse(url))
} else {
// If url not found, open bookmark object instead of browsing.
navigation.emit(wrapper.navigation())
}
} else {
navigation.emit(wrapper.navigation())
}
} else {
Timber.w("Wrapper is not found in attachment")
}
Expand Down Expand Up @@ -761,6 +773,7 @@ class ChatViewModel @Inject constructor(
data object Exit : ViewModelCommand()
data object OpenWidgets : ViewModelCommand()
data class MediaPreview(val url: String) : ViewModelCommand()
data class Browse(val url: String) : ViewModelCommand()
data class SelectChatReaction(val msg: Id) : ViewModelCommand()
data class ViewChatReaction(val msg: Id, val emoji: String) : ViewModelCommand()
data class ViewMemberCard(val member: Id, val space: SpaceId) : ViewModelCommand()
Expand Down

0 comments on commit 7fe3f6d

Please sign in to comment.