Fixing up the muting as you can't add more than the max int....

This commit is contained in:
ThomasSession 2024-09-10 10:33:14 +10:00
parent e6c224bec4
commit c68dc4f12f
3 changed files with 11 additions and 12 deletions

View File

@ -26,14 +26,7 @@ fun showMuteDialog(
context.getSubbedString(entry.stringRes, TIME_LARGE_KEY to largeTimeUnitString)
}
}.toTypedArray()) {
// Note: We add the current timestamp to the mute duration to get the un-mute timestamp
// that gets stored in the database via ConversationMenuHelper.mute().
// Also: This is a kludge, but we ADD one second to the mute duration because otherwise by
// the time the view for how long the conversation is muted for gets set then it's actually
// less than the entire duration - so 1 hour becomes 59 minutes, 1 day becomes 23 hours etc.
// As we really want to see the actual set time (1 hour / 1 day etc.) then we'll bump it by
// 1 second which is neither here nor there in the grand scheme of things.
onMuteDuration(Option.entries[it].getTime() + System.currentTimeMillis() + 1.seconds.inWholeMilliseconds)
onMuteDuration(Option.entries[it].getTime())
}
}
@ -44,5 +37,12 @@ private enum class Option(@StringRes val stringRes: Int, val getTime: () -> Long
SEVEN_DAYS(R.string.notificationsMuteFor, duration = TimeUnit.DAYS.toMillis(7)),
FOREVER(R.string.notificationsMute, getTime = { Long.MAX_VALUE } );
constructor(@StringRes stringRes: Int, duration: Long): this(stringRes, { duration } )
// Note: We add the current timestamp to the mute duration to get the un-mute timestamp
// that gets stored in the database via ConversationMenuHelper.mute().
// Also: This is a kludge, but we ADD one second to the mute duration because otherwise by
// the time the view for how long the conversation is muted for gets set then it's actually
// less than the entire duration - so 1 hour becomes 59 minutes, 1 day becomes 23 hours etc.
// As we really want to see the actual set time (1 hour / 1 day etc.) then we'll bump it by
// 1 second which is neither here nor there in the grand scheme of things.
constructor(@StringRes stringRes: Int, duration: Long): this(stringRes, { duration + System.currentTimeMillis() + 1.seconds.inWholeMilliseconds } )
}

View File

@ -125,9 +125,7 @@ class ConversationActionBarView @JvmOverloads constructor(
settings += ConversationSetting(
recipient.mutedUntil.takeUnless { it == Long.MAX_VALUE }
?.let {
val mutedDuration = (it - System.currentTimeMillis()).milliseconds
val durationString = LocalisedTimeUtil.getDurationWithSingleLargestTimeUnit(context, mutedDuration)
context.getSubbedString(R.string.notificationsMuteFor, TIME_LARGE_KEY to durationString)
context.getString(R.string.notificationsHeaderMute)
}
?: context.getString(R.string.notificationsMuted),
ConversationSettingType.NOTIFICATION,

View File

@ -547,6 +547,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
} else {
showMuteDialog(this) { until ->
lifecycleScope.launch(Dispatchers.IO) {
Log.d("", "**** until: $until")
recipientDatabase.setMuted(thread.recipient, until)
withContext(Dispatchers.Main) {
binding.recyclerView.adapter!!.notifyDataSetChanged()