mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-13 22:58:54 +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.
40 lines
1.7 KiB
Scala
40 lines
1.7 KiB
Scala
package com.twitter.visibility.builder.tweets
|
|
|
|
import com.twitter.spam.rtf.thriftscala.SafetyLabelType
|
|
import com.twitter.spam.rtf.thriftscala.SafetyLabelType.ExperimentalNudge
|
|
import com.twitter.spam.rtf.thriftscala.SafetyLabelType.SemanticCoreMisinformation
|
|
import com.twitter.spam.rtf.thriftscala.SafetyLabelType.UnsafeUrl
|
|
import com.twitter.visibility.common.LocalizedNudgeSource
|
|
import com.twitter.visibility.common.actions.TweetVisibilityNudgeReason
|
|
import com.twitter.visibility.common.actions.TweetVisibilityNudgeReason.ExperimentalNudgeSafetyLabelReason
|
|
import com.twitter.visibility.common.actions.TweetVisibilityNudgeReason.SemanticCoreMisinformationLabelReason
|
|
import com.twitter.visibility.common.actions.TweetVisibilityNudgeReason.UnsafeURLLabelReason
|
|
import com.twitter.visibility.rules.LocalizedNudge
|
|
|
|
class TweetVisibilityNudgeSourceWrapper(localizedNudgeSource: LocalizedNudgeSource) {
|
|
|
|
def getLocalizedNudge(
|
|
reason: TweetVisibilityNudgeReason,
|
|
languageCode: String,
|
|
countryCode: Option[String]
|
|
): Option[LocalizedNudge] =
|
|
reason match {
|
|
case ExperimentalNudgeSafetyLabelReason =>
|
|
fetchNudge(ExperimentalNudge, languageCode, countryCode)
|
|
case SemanticCoreMisinformationLabelReason =>
|
|
fetchNudge(SemanticCoreMisinformation, languageCode, countryCode)
|
|
case UnsafeURLLabelReason =>
|
|
fetchNudge(UnsafeUrl, languageCode, countryCode)
|
|
}
|
|
|
|
private def fetchNudge(
|
|
safetyLabel: SafetyLabelType,
|
|
languageCode: String,
|
|
countryCode: Option[String]
|
|
): Option[LocalizedNudge] = {
|
|
localizedNudgeSource
|
|
.fetch(safetyLabel, languageCode, countryCode)
|
|
.map(LocalizedNudge.fromStratoThrift)
|
|
}
|
|
}
|