mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-30 06:56:08 +02:00
![twitter-team](/assets/img/avatar_default.png)
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.
55 lines
2.2 KiB
Scala
55 lines
2.2 KiB
Scala
package com.twitter.home_mixer.marshaller.request
|
|
|
|
import com.twitter.home_mixer.model.request.FollowingProductContext
|
|
import com.twitter.home_mixer.model.request.ForYouProductContext
|
|
import com.twitter.home_mixer.model.request.ListRecommendedUsersProductContext
|
|
import com.twitter.home_mixer.model.request.ListTweetsProductContext
|
|
import com.twitter.home_mixer.model.request.ScoredTweetsProductContext
|
|
import com.twitter.home_mixer.{thriftscala => t}
|
|
import com.twitter.product_mixer.core.model.marshalling.request.ProductContext
|
|
|
|
import javax.inject.Inject
|
|
import javax.inject.Singleton
|
|
|
|
@Singleton
|
|
class HomeMixerProductContextUnmarshaller @Inject() (
|
|
deviceContextUnmarshaller: DeviceContextUnmarshaller) {
|
|
|
|
def apply(productContext: t.ProductContext): ProductContext = productContext match {
|
|
case t.ProductContext.Following(p) =>
|
|
FollowingProductContext(
|
|
deviceContext = p.deviceContext.map(deviceContextUnmarshaller(_)),
|
|
seenTweetIds = p.seenTweetIds,
|
|
dspClientContext = p.dspClientContext
|
|
)
|
|
case t.ProductContext.ForYou(p) =>
|
|
ForYouProductContext(
|
|
deviceContext = p.deviceContext.map(deviceContextUnmarshaller(_)),
|
|
seenTweetIds = p.seenTweetIds,
|
|
dspClientContext = p.dspClientContext
|
|
)
|
|
case t.ProductContext.Realtime(p) =>
|
|
throw new UnsupportedOperationException(s"This product is no longer used")
|
|
case t.ProductContext.ScoredTweets(p) =>
|
|
ScoredTweetsProductContext(
|
|
deviceContext = p.deviceContext.map(deviceContextUnmarshaller(_)),
|
|
seenTweetIds = p.seenTweetIds,
|
|
servedTweetIds = p.servedTweetIds
|
|
)
|
|
case t.ProductContext.ListTweets(p) =>
|
|
ListTweetsProductContext(
|
|
listId = p.listId,
|
|
deviceContext = p.deviceContext.map(deviceContextUnmarshaller(_)),
|
|
dspClientContext = p.dspClientContext
|
|
)
|
|
case t.ProductContext.ListRecommendedUsers(p) =>
|
|
ListRecommendedUsersProductContext(
|
|
listId = p.listId,
|
|
selectedUserIds = p.selectedUserIds,
|
|
excludedUserIds = p.excludedUserIds
|
|
)
|
|
case t.ProductContext.UnknownUnionField(field) =>
|
|
throw new UnsupportedOperationException(s"Unknown display context: ${field.field.name}")
|
|
}
|
|
}
|