Commit 1523bf33 authored by Eugene Shapovalov's avatar Eugene Shapovalov 💬

Add share operator for issue/mergerequest request in repository.

parent d29d3c3d
......@@ -29,6 +29,7 @@ class IssueRepository @Inject constructor(
private val markDownUrlResolver: MarkDownUrlResolver
) {
private val defaultPageSize = defaultPageSizeWrapper.value
private var issueSharedSingle: Single<Issue>? = null
fun getMyIssues(
scope: IssueScope? = null,
......@@ -129,18 +130,27 @@ class IssueRepository @Inject constructor(
projectId: Long,
issueId: Long
) = Single
.zip(
api.getProject(projectId),
api.getIssue(projectId, issueId),
BiFunction<Project, Issue, Issue> { project, issue ->
val resolved = markDownUrlResolver.resolve(issue.description, project)
if (resolved != issue.description) {
issue.copy(description = resolved)
} else {
issue
}
.defer {
if (issueSharedSingle == null) {
issueSharedSingle = Single
.zip(
api.getProject(projectId),
api.getIssue(projectId, issueId),
BiFunction<Project, Issue, Issue> { project, issue ->
val resolved = markDownUrlResolver.resolve(issue.description, project)
if (resolved != issue.description) {
issue.copy(description = resolved)
} else {
issue
}
}
)
.toObservable()
.share()
.singleOrError()
}
)
issueSharedSingle
}
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
......
......@@ -26,6 +26,7 @@ class MergeRequestRepository @Inject constructor(
private val markDownUrlResolver: MarkDownUrlResolver
) {
private val defaultPageSize = defaultPageSizeWrapper.value
private var mergeRequestSharedSingle: Single<MergeRequest>? = null
fun getMyMergeRequests(
state: MergeRequestState? = null,
......@@ -140,18 +141,27 @@ class MergeRequestRepository @Inject constructor(
projectId: Long,
mergeRequestId: Long
) = Single
.zip(
api.getProject(projectId),
api.getMergeRequest(projectId, mergeRequestId),
BiFunction<Project, MergeRequest, MergeRequest> { project, mr ->
val resolved = markDownUrlResolver.resolve(mr.description, project)
if (resolved != mr.description) {
mr.copy(description = resolved)
} else {
mr
}
.defer {
if (mergeRequestSharedSingle == null) {
mergeRequestSharedSingle = Single
.zip(
api.getProject(projectId),
api.getMergeRequest(projectId, mergeRequestId),
BiFunction<Project, MergeRequest, MergeRequest> { project, mr ->
val resolved = markDownUrlResolver.resolve(mr.description, project)
if (resolved != mr.description) {
mr.copy(description = resolved)
} else {
mr
}
}
)
.toObservable()
.share()
.singleOrError()
}
)
mergeRequestSharedSingle
}
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
......
......@@ -7,8 +7,8 @@ import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.di.ProjectId
import ru.terrakok.gitlabclient.entity.app.target.TargetAction
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.model.repository.issue.IssueRepository
import ru.terrakok.gitlabclient.ui.global.FlowFragment
import ru.terrakok.gitlabclient.ui.mergerequest.MergeRequestFlowFragment
import toothpick.Scope
import toothpick.config.Module
......@@ -31,6 +31,8 @@ class IssueFlowFragment : FlowFragment() {
.toInstance(PrimitiveWrapper(issueId))
bind(TargetAction::class.java)
.toInstance(targetAction)
bind(IssueRepository::class.java)
.singletonInScope()
}
}
)
......
......@@ -7,6 +7,7 @@ import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.di.ProjectId
import ru.terrakok.gitlabclient.entity.app.target.TargetAction
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.model.repository.mergerequest.MergeRequestRepository
import ru.terrakok.gitlabclient.ui.global.FlowFragment
import toothpick.Scope
import toothpick.config.Module
......@@ -30,6 +31,8 @@ class MergeRequestFlowFragment : FlowFragment() {
.toInstance(PrimitiveWrapper(mrId))
bind(TargetAction::class.java)
.toInstance(targetAction)
bind(MergeRequestRepository::class.java)
.singletonInScope()
}
}
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment