mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-01 08:48:46 +02:00
ef4c5eb65e
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
29 lines
1.0 KiB
Scala
29 lines
1.0 KiB
Scala
package com.twitter.product_mixer.component_library.candidate_source.timeline_ranker
|
|
|
|
import com.twitter.product_mixer.core.functional_component.candidate_source.CandidateSource
|
|
import com.twitter.product_mixer.core.model.common.identifier.CandidateSourceIdentifier
|
|
import com.twitter.stitch.Stitch
|
|
import com.twitter.timelineranker.{thriftscala => t}
|
|
|
|
import javax.inject.Inject
|
|
import javax.inject.Singleton
|
|
|
|
@Singleton
|
|
class TimelineRankerRecapCandidateSource @Inject() (
|
|
timelineRankerClient: t.TimelineRanker.MethodPerEndpoint)
|
|
extends CandidateSource[t.RecapQuery, t.CandidateTweet] {
|
|
|
|
override val identifier: CandidateSourceIdentifier =
|
|
CandidateSourceIdentifier("TimelineRankerRecap")
|
|
|
|
override def apply(
|
|
request: t.RecapQuery
|
|
): Stitch[Seq[t.CandidateTweet]] = {
|
|
Stitch
|
|
.callFuture(timelineRankerClient.getRecapCandidatesFromAuthors(Seq(request)))
|
|
.map { response: Seq[t.GetCandidateTweetsResponse] =>
|
|
response.headOption.flatMap(_.candidates).getOrElse(Seq.empty).filter(_.tweet.nonEmpty)
|
|
}
|
|
}
|
|
}
|