listen for merge highlight js action

This commit is contained in:
Satindar Dhillon 2022-11-29 14:22:01 -08:00
parent cc4001161e
commit e3ccdc4b41
3 changed files with 48 additions and 3 deletions

View file

@ -29,6 +29,39 @@ data class CreateHighlightParams(
)
}
//2022-11-29 13:41:56.273 13373-14177/app.omnivore.omnivore D/wv: received actionID from Android:
// mergeHighlight, {
// "prefix":"In what may be its final public hearing, the committee intends to present new theevidence about the former presidents state of mind and central role in the plan to overturn ",
// "suffix":"2020 election.",
// "quote":"",
// "id":"646a3b52-a134-469e-8ea3-26aad47f74c3",
// "shortId":"IK35C_Hp","patch":"@@ -307,32 +307,73 @@\n to overturn the\n+%3Comnivore_highlight%3E%3C/omnivore_highlight%3E\n 2020 election.P\n",
// "articleId":"14bb47ff-af23-461b-8ce3-1afe6b8bdc5b",
// "overlapHighlightIdList":[""]}
data class MergeHighlightsParams(
val shortId: String?,
val highlightID: String?,
val quote: String?,
val patch: String?,
val articleId: String?,
val prefix: String?,
val suffix: String?,
val overlapHighlightIdList: List<String>?,
val `annotation`: String?
) {
fun asMergeHighlightInput() = MergeHighlightInput(
annotation = Optional.presentIfNotNull(`annotation`),
prefix = Optional.presentIfNotNull(prefix),
articleId = articleId ?: "",
id = highlightID ?: "",
patch = patch ?: "",
quote = quote ?: "",
shortId = shortId ?: "",
overlapHighlightIdList = overlapHighlightIdList ?: listOf()
)
}
suspend fun Networker.deleteHighlights(highlightIDs: List<String>): Boolean {
val statuses: MutableList<Boolean> = mutableListOf()
for (highlightID in highlightIDs) {
@ -40,6 +73,11 @@ suspend fun Networker.deleteHighlights(highlightIDs: List<String>): Boolean {
return !hasFailure
}
suspend fun Networker.mergeWebHighlights(jsonString: String): Boolean {
val input = Gson().fromJson(jsonString, MergeHighlightsParams::class.java).asMergeHighlightInput()
return mergeHighlights(input)
}
suspend fun Networker.mergeHighlights(input: MergeHighlightInput): Boolean {
val result = authenticatedApolloClient().mutation(MergeHighlightMutation(input)).execute()
Log.d("Network", "highlight merge result: $result")

View file

@ -231,9 +231,10 @@ class OmnivoreWebView(context: Context) : WebView(context) {
}
R.id.highlight -> {
val script = "var event = new Event('highlight');document.dispatchEvent(event);"
evaluateJavascript(script, null)
clearFocus()
mode.finish()
evaluateJavascript(script) {
clearFocus()
mode.finish()
}
true
}
R.id.delete -> {

View file

@ -90,6 +90,12 @@ class WebReaderViewModel @Inject constructor(
"shareHighlight" -> {
// unimplemented
}
"mergeHighlight" -> {
viewModelScope.launch {
val isHighlightSynced = networker.mergeWebHighlights(jsonString)
Log.d("Network", "isMergedHighlightSynced = $isHighlightSynced")
}
}
else -> {
Log.d("Loggo", "receive unrecognized action of $actionID with json: $jsonString")
}