Fix #3468 - Timed Mute (#3544)

This commit is contained in:
Dane Evans 2025-10-30 16:48:06 +11:00 committed by GitHub
parent c482bd0aaf
commit 54104b00ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 77 additions and 4 deletions

View file

@ -230,8 +230,18 @@ interface PacketDao {
suspend fun setMuteUntil(contacts: List<String>, until: Long) {
val contactList =
contacts.map { contact ->
getContactSettings(contact)?.copy(muteUntil = until)
?: ContactSettings(contact_key = contact, muteUntil = until)
// Always mute
val absoluteMuteUntil =
if (until == Long.MAX_VALUE) {
Long.MAX_VALUE
} else if (until == 0L) { // unmute
0L
} else {
System.currentTimeMillis() + until
}
getContactSettings(contact)?.copy(muteUntil = absoluteMuteUntil)
?: ContactSettings(contact_key = contact, muteUntil = absoluteMuteUntil)
}
upsertContactSettings(contactList)
}

View file

@ -21,6 +21,8 @@ import java.text.DateFormat
import java.util.Date
import java.util.concurrent.TimeUnit
private const val ONLINE_WINDOW_HOURS = 2
// return time if within 24 hours, otherwise date
fun getShortDate(time: Long): String? {
val date = if (time != 0L) Date(time) else return null
@ -62,5 +64,21 @@ private fun formatUptime(seconds: Long): String {
.joinToString(" ")
}
@Suppress("MagicNumber")
fun onlineTimeThreshold() = (System.currentTimeMillis() / 1000 - 2 * 60 * 60).toInt()
fun onlineTimeThreshold(): Int {
val currentSeconds = System.currentTimeMillis() / TimeUnit.SECONDS.toMillis(1)
return (currentSeconds - TimeUnit.HOURS.toSeconds(ONLINE_WINDOW_HOURS.toLong())).toInt()
}
/**
* Calculates the remaining mute time in days and hours.
*
* @param remainingMillis The remaining time in milliseconds
* @return Pair of (days, hours), where days is Int and hours is Double
*/
fun formatMuteRemainingTime(remainingMillis: Long): Pair<Int, Double> {
if (remainingMillis <= 0) return Pair(0, 0.0)
val totalHours = remainingMillis.toDouble() / TimeUnit.HOURS.toMillis(1)
val days = (totalHours / TimeUnit.DAYS.toHours(1)).toInt()
val hours = totalHours % TimeUnit.DAYS.toHours(1)
return Pair(days, hours)
}

View file

@ -337,6 +337,11 @@
<string name="mute_8_hours">8 hours</string>
<string name="mute_1_week">1 week</string>
<string name="mute_always">Always</string>
<string name="currently">Currently:</string>
<string name="mute_status_always">Always muted</string>
<string name="mute_status_unmuted">Not muted</string>
<string name="mute_status_muted_for_days">Muted for %1d days, %.1f hours</string>
<string name="mute_status_muted_for_hours">Muted for %.1f hours</string>
<string name="replace">Replace</string>
<string name="wifi_qr_code_scan">Scan WiFi QR code</string>
<string name="wifi_qr_code_error">Invalid WiFi Credential QR code format</string>