Ensure a Callback and only one is provided in the Plugin. Also reduce boilerplate code in Nodes.

This commit is contained in:
Benoit Marty
2025-10-30 09:14:41 +01:00
committed by Benoit Marty
parent 596b7f00fc
commit 5197154f54
76 changed files with 374 additions and 741 deletions

View File

@@ -22,6 +22,7 @@ import dev.zacsweers.metro.AssistedInject
import io.element.android.annotations.ContributesNode
import io.element.android.features.forward.api.ForwardEntryPoint
import io.element.android.libraries.architecture.NodeInputs
import io.element.android.libraries.architecture.callback
import io.element.android.libraries.architecture.inputs
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.matrix.api.core.EventId
@@ -55,8 +56,8 @@ class ForwardMessagesNode(
) : NodeInputs
private val inputs = inputs<Inputs>()
private val callback: ForwardEntryPoint.Callback = callback()
private val presenter = presenterFactory.create(inputs.eventId.value, inputs.timelineProvider)
private val callbacks = plugins.filterIsInstance<ForwardEntryPoint.Callback>()
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
val callback = object : RoomSelectEntryPoint.Callback {
@@ -65,7 +66,7 @@ class ForwardMessagesNode(
}
override fun onCancel() {
onForwardDone(emptyList())
callback.onDone(emptyList())
}
}
@@ -86,12 +87,8 @@ class ForwardMessagesNode(
val state = presenter.present()
ForwardMessagesView(
state = state,
onForwardSuccess = ::onForwardDone,
onForwardSuccess = callback::onDone,
)
}
}
private fun onForwardDone(roomIds: List<RoomId>) {
callbacks.forEach { it.onDone(roomIds) }
}
}