Add text formatting support to release notes channel.

This commit is contained in:
Cody Henthorne
2023-06-14 16:36:57 -04:00
parent 08c661bb14
commit ec6b1a44de

View File

@@ -187,10 +187,31 @@ class RetrieveRemoteAnnouncementsJob private constructor(private val force: Bool
resolvedNotes resolvedNotes
.filterNotNull() .filterNotNull()
.forEach { note -> .forEach { note ->
val body = "${note.translation.title}\n\n${note.translation.body}" val title = "${note.translation.title}\n\n"
val body = "$title${note.translation.body}"
val bodyRangeList = BodyRangeList.newBuilder() val bodyRangeList = BodyRangeList.newBuilder()
.addStyle(BodyRangeList.BodyRange.Style.BOLD, 0, note.translation.title.length) .addStyle(BodyRangeList.BodyRange.Style.BOLD, 0, note.translation.title.length)
if (note.translation.bodyRanges?.isNotEmpty() == true) {
note.translation.bodyRanges
.filter { it.style != null && it.start != null && it.length != null }
.map { it.copy(start = it.start!! + title.length) }
.forEach {
val style = when (it.style!!) {
"bold" -> BodyRangeList.BodyRange.Style.BOLD
"italic" -> BodyRangeList.BodyRange.Style.ITALIC
"strikethrough" -> BodyRangeList.BodyRange.Style.STRIKETHROUGH
"spoiler" -> BodyRangeList.BodyRange.Style.SPOILER
"mono" -> BodyRangeList.BodyRange.Style.MONOSPACE
else -> null
}
if (style != null && it.start!! in body.indices && (it.start + it.length!! - 1) in body.indices) {
bodyRangeList.addStyle(style, it.start, it.length)
}
}
}
if (note.releaseNote.link?.isNotEmpty() == true && note.translation.linkText?.isNotEmpty() == true) { if (note.releaseNote.link?.isNotEmpty() == true && note.translation.linkText?.isNotEmpty() == true) {
val linkIndex = body.indexOf(note.translation.linkText) val linkIndex = body.indexOf(note.translation.linkText)
if (linkIndex != -1 && linkIndex + note.translation.linkText.length < body.length) { if (linkIndex != -1 && linkIndex + note.translation.linkText.length < body.length) {
@@ -405,7 +426,14 @@ class RetrieveRemoteAnnouncementsJob private constructor(private val force: Bool
@JsonProperty val linkText: String?, @JsonProperty val linkText: String?,
@JsonProperty val title: String, @JsonProperty val title: String,
@JsonProperty val body: String, @JsonProperty val body: String,
@JsonProperty val callToActionText: String? @JsonProperty val callToActionText: String?,
@JsonProperty val bodyRanges: List<ReleaseNoteBodyRange>?
)
data class ReleaseNoteBodyRange(
@JsonProperty val style: String?,
@JsonProperty val start: Int?,
@JsonProperty val length: Int?
) )
data class TranslatedRemoteMegaphone( data class TranslatedRemoteMegaphone(