From a2c4d6fb464eeddc2c851b525bd38ba009280de7 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Tue, 10 Sep 2024 16:32:40 +1000 Subject: [PATCH] Fixing mute --- .../org/thoughtcrime/securesms/MuteDialog.kt | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt index 2c03fe2511..d5e551d02a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt @@ -22,27 +22,31 @@ fun showMuteDialog( if (entry.stringRes == R.string.notificationsMute) { context.getString(R.string.notificationsMute) } else { - val largeTimeUnitString = LocalisedTimeUtil.getDurationWithSingleLargestTimeUnit(context, Option.entries[index].getTime().milliseconds) + val largeTimeUnitString = LocalisedTimeUtil.getDurationWithSingleLargestTimeUnit( + context, + Option.entries[index].duration.milliseconds + ) context.getSubbedString(entry.stringRes, TIME_LARGE_KEY to largeTimeUnitString) } }.toTypedArray()) { - onMuteDuration(Option.entries[it].getTime()) + // 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. + val muteTime = Option.entries[it].duration + val muteTimeFromNow = if (muteTime == Long.MAX_VALUE) muteTime + else muteTime + System.currentTimeMillis() + 1.seconds.inWholeMilliseconds + onMuteDuration(muteTimeFromNow) } } -private enum class Option(@StringRes val stringRes: Int, val getTime: () -> Long) { - ONE_HOUR(R.string.notificationsMuteFor, duration = TimeUnit.HOURS.toMillis(1)), - TWO_HOURS(R.string.notificationsMuteFor, duration = TimeUnit.HOURS.toMillis(2)), - ONE_DAY(R.string.notificationsMuteFor, duration = TimeUnit.DAYS.toMillis(1)), +private enum class Option(@StringRes val stringRes: Int, val duration: Long) { + ONE_HOUR(R.string.notificationsMuteFor, duration = TimeUnit.HOURS.toMillis(1)), + TWO_HOURS(R.string.notificationsMuteFor, duration = TimeUnit.HOURS.toMillis(2)), + ONE_DAY(R.string.notificationsMuteFor, duration = TimeUnit.DAYS.toMillis(1)), SEVEN_DAYS(R.string.notificationsMuteFor, duration = TimeUnit.DAYS.toMillis(7)), - FOREVER(R.string.notificationsMute, getTime = { Long.MAX_VALUE } ); - - // 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 } ) + FOREVER(R.string.notificationsMute, duration = Long.MAX_VALUE ); } \ No newline at end of file