From c68dc4f12fe36287241fe0e78fde1564813c0aaa Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Tue, 10 Sep 2024 10:33:14 +1000 Subject: [PATCH] Fixing up the muting as you can't add more than the max int.... --- .../org/thoughtcrime/securesms/MuteDialog.kt | 18 +++++++++--------- .../conversation/ConversationActionBarView.kt | 4 +--- .../securesms/home/HomeActivity.kt | 1 + 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt index b45d1e9f8e..2c03fe2511 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt @@ -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 } ) } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActionBarView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActionBarView.kt index 61d17e44f0..ff7f781ebf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActionBarView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActionBarView.kt @@ -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, diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index dbcc39e7b6..05c2fe658b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -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()