IDEA-338866 Set time scope for feedback collection for tips of the day

(cherry picked from commit 8826a4cc3a5484b07c5223eb5693ef8da93af481)

IJ-CR-121256

GitOrigin-RevId: 966b6fb35426abf42415ec0d1ec6d5b36bfeac74
This commit is contained in:
Dmitry Pogrebnoy
2023-12-11 11:54:08 +00:00
committed by intellij-monorepo-bot
parent 7e4b6b7aed
commit 9106b0a3c8
2 changed files with 13 additions and 0 deletions
@@ -40,6 +40,7 @@
<orderEntry type="library" name="kotlinx-coroutines-core" level="project" />
<orderEntry type="library" name="kotlinx-serialization-core" level="project" />
<orderEntry type="library" name="kotlinx-serialization-json" level="project" />
<orderEntry type="library" name="kotlinx-datetime-jvm" level="project" />
<orderEntry type="module" module-name="intellij.platform.feedback" />
</component>
</module>
@@ -9,12 +9,18 @@ import com.intellij.platform.feedback.impl.FeedbackRequestData
import com.intellij.platform.feedback.impl.FeedbackRequestType
import com.intellij.platform.feedback.impl.submitFeedback
import com.intellij.util.xmlb.annotations.XMap
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.periodUntil
import kotlinx.datetime.toKotlinInstant
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
@Service
@State(name = "TipsFeedback", storages = [Storage(value = "tips-feedback.xml", roamingType = RoamingType.DISABLED)])
class TipsFeedback : SimplePersistentStateComponent<TipsFeedback.State>(State()) {
private val timeScopeForResultCollectionInDays = 120
fun getLikenessState(tipId: String): Boolean? {
return state.tipToLikeness[tipId]
}
@@ -35,6 +41,12 @@ class TipsFeedback : SimplePersistentStateComponent<TipsFeedback.State>(State())
}
fun scheduleFeedbackSending(tipId: String, likenessState: Boolean) {
val buildDate = ApplicationInfo.getInstance().buildDate
val buildToCurrentPeriod = buildDate.toInstant().toKotlinInstant().periodUntil(Clock.System.now(), TimeZone.currentSystemDefault())
if (buildToCurrentPeriod.days > timeScopeForResultCollectionInDays) {
return
}
val dataJsonObject = buildJsonObject {
put("format_version", FEEDBACK_FORMAT_VERSION)
put("tip_id", tipId)