Completed OTS Support
This commit is contained in:
@@ -741,10 +741,10 @@ object LocalCache {
|
|||||||
// Already processed this event.
|
// Already processed this event.
|
||||||
if (version.event?.id() == event.id()) return
|
if (version.event?.id() == event.id()) return
|
||||||
|
|
||||||
if (version.event == null) {
|
// makes sure the OTS has a valid certificate
|
||||||
// makes sure the OTS has a valid certificate
|
if (event.cacheVerify() == null) return // no valid OTS
|
||||||
if (event.cacheVerify() == null) return // no valid OTS
|
|
||||||
|
|
||||||
|
if (version.event == null) {
|
||||||
version.loadEvent(event, author, emptyList())
|
version.loadEvent(event, author, emptyList())
|
||||||
|
|
||||||
version.liveSet?.innerOts?.invalidateData()
|
version.liveSet?.innerOts?.invalidateData()
|
||||||
|
|||||||
@@ -241,6 +241,8 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@@ -2560,15 +2562,27 @@ fun DisplayOts(
|
|||||||
LoadOts(
|
LoadOts(
|
||||||
note,
|
note,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
whenConfirmed = {
|
whenConfirmed = { unixtimestamp ->
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val timeStr by remember(note) { mutableStateOf(timeAgo(it, context = context)) }
|
val timeStr by remember(unixtimestamp) { mutableStateOf(timeAgoNoDot(unixtimestamp, context = context)) }
|
||||||
|
|
||||||
Text(
|
ClickableText(
|
||||||
stringResource(id = R.string.existed_since, timeStr),
|
text = buildAnnotatedString { append(stringResource(id = R.string.existed_since, timeStr)) },
|
||||||
color = MaterialTheme.colorScheme.lessImportantLink,
|
onClick = {
|
||||||
fontSize = Font14SP,
|
val fullDateTime =
|
||||||
fontWeight = FontWeight.Bold,
|
SimpleDateFormat.getDateTimeInstance().format(Date(unixtimestamp * 1000))
|
||||||
|
|
||||||
|
accountViewModel.toast(
|
||||||
|
context.getString(R.string.ots_info_title),
|
||||||
|
context.getString(R.string.ots_info_description, fullDateTime),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
style =
|
||||||
|
LocalTextStyle.current.copy(
|
||||||
|
color = MaterialTheme.colorScheme.lessImportantLink,
|
||||||
|
fontSize = Font14SP,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -2688,11 +2702,12 @@ fun LoadOts(
|
|||||||
|
|
||||||
LaunchedEffect(key1 = noteStatus) {
|
LaunchedEffect(key1 = noteStatus) {
|
||||||
accountViewModel.findOtsEventsForNote(noteStatus?.note ?: note) { newOts ->
|
accountViewModel.findOtsEventsForNote(noteStatus?.note ?: note) { newOts ->
|
||||||
if (newOts == null) {
|
earliestDate =
|
||||||
earliestDate = GenericLoadable.Empty()
|
if (newOts == null) {
|
||||||
} else {
|
GenericLoadable.Empty()
|
||||||
earliestDate = GenericLoadable.Loaded(newOts)
|
} else {
|
||||||
}
|
GenericLoadable.Loaded(newOts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,46 @@ fun timeAgo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun timeAgoNoDot(
|
||||||
|
time: Long?,
|
||||||
|
context: Context,
|
||||||
|
): String {
|
||||||
|
if (time == null) return " "
|
||||||
|
if (time == 0L) return " ${context.getString(R.string.never)}"
|
||||||
|
|
||||||
|
val timeDifference = TimeUtils.now() - time
|
||||||
|
|
||||||
|
return if (timeDifference > TimeUtils.ONE_YEAR) {
|
||||||
|
// Dec 12, 2022
|
||||||
|
|
||||||
|
if (locale != Locale.getDefault()) {
|
||||||
|
locale = Locale.getDefault()
|
||||||
|
yearFormatter = SimpleDateFormat("MMM dd, yyyy", locale)
|
||||||
|
monthFormatter = SimpleDateFormat("MMM dd", locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
yearFormatter.format(time * 1000)
|
||||||
|
} else if (timeDifference > TimeUtils.ONE_MONTH) {
|
||||||
|
// Dec 12
|
||||||
|
if (locale != Locale.getDefault()) {
|
||||||
|
locale = Locale.getDefault()
|
||||||
|
yearFormatter = SimpleDateFormat("MMM dd, yyyy", locale)
|
||||||
|
monthFormatter = SimpleDateFormat("MMM dd", locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
monthFormatter.format(time * 1000)
|
||||||
|
} else if (timeDifference > TimeUtils.ONE_DAY) {
|
||||||
|
// 2 days
|
||||||
|
(timeDifference / TimeUtils.ONE_DAY).toString() + context.getString(R.string.d)
|
||||||
|
} else if (timeDifference > TimeUtils.ONE_HOUR) {
|
||||||
|
(timeDifference / TimeUtils.ONE_HOUR).toString() + context.getString(R.string.h)
|
||||||
|
} else if (timeDifference > TimeUtils.ONE_MINUTE) {
|
||||||
|
(timeDifference / TimeUtils.ONE_MINUTE).toString() + context.getString(R.string.m)
|
||||||
|
} else {
|
||||||
|
context.getString(R.string.now)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun timeAgoShort(
|
fun timeAgoShort(
|
||||||
mills: Long?,
|
mills: Long?,
|
||||||
stringForNow: String,
|
stringForNow: String,
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ import com.vitorpamplona.amethyst.ui.note.BlankNote
|
|||||||
import com.vitorpamplona.amethyst.ui.note.CreateImageHeader
|
import com.vitorpamplona.amethyst.ui.note.CreateImageHeader
|
||||||
import com.vitorpamplona.amethyst.ui.note.DisplayHighlight
|
import com.vitorpamplona.amethyst.ui.note.DisplayHighlight
|
||||||
import com.vitorpamplona.amethyst.ui.note.DisplayLocation
|
import com.vitorpamplona.amethyst.ui.note.DisplayLocation
|
||||||
|
import com.vitorpamplona.amethyst.ui.note.DisplayOts
|
||||||
import com.vitorpamplona.amethyst.ui.note.DisplayPeopleList
|
import com.vitorpamplona.amethyst.ui.note.DisplayPeopleList
|
||||||
import com.vitorpamplona.amethyst.ui.note.DisplayRelaySet
|
import com.vitorpamplona.amethyst.ui.note.DisplayRelaySet
|
||||||
import com.vitorpamplona.amethyst.ui.note.FileHeaderDisplay
|
import com.vitorpamplona.amethyst.ui.note.FileHeaderDisplay
|
||||||
@@ -449,6 +450,8 @@ fun NoteMaster(
|
|||||||
if (pow > 20) {
|
if (pow > 20) {
|
||||||
DisplayPoW(pow)
|
DisplayPoW(pow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DisplayOts(note, accountViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -787,4 +787,7 @@
|
|||||||
<string name="git_web_address">Web:</string>
|
<string name="git_web_address">Web:</string>
|
||||||
<string name="git_clone_address">Clone:</string>
|
<string name="git_clone_address">Clone:</string>
|
||||||
<string name="existed_since">OTS: %1$s</string>
|
<string name="existed_since">OTS: %1$s</string>
|
||||||
|
|
||||||
|
<string name="ots_info_title">Timestamp Proof</string>
|
||||||
|
<string name="ots_info_description">There\'s proof this post was signed sometime before %1$s. The proof was stamped in the Bitcoin blockchain at that date and time.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user