mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Fix inactivity status when last seen timestamp is null
This commit is contained in:
parent
87928b4e12
commit
01429b352a
@ -142,7 +142,7 @@ class DevicesViewModel @AssistedInject constructor(
|
||||
.map { deviceInfo ->
|
||||
val cryptoDeviceInfo = cryptoList.firstOrNull { it.deviceId == deviceInfo.deviceId }
|
||||
val trustLevelForShield = getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoDeviceInfo)
|
||||
val isInactive = checkIfSessionIsInactiveUseCase.execute(deviceInfo.lastSeenTs ?: 0)
|
||||
val isInactive = checkIfSessionIsInactiveUseCase.execute(deviceInfo.lastSeenTs)
|
||||
DeviceFullInfo(deviceInfo, cryptoDeviceInfo, trustLevelForShield, isInactive)
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ class GetDeviceFullInfoListUseCase @Inject constructor(
|
||||
.map { deviceInfo ->
|
||||
val cryptoDeviceInfo = cryptoList.firstOrNull { it.deviceId == deviceInfo.deviceId }
|
||||
val roomEncryptionTrustLevel = getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoDeviceInfo)
|
||||
val isInactive = checkIfSessionIsInactiveUseCase.execute(deviceInfo.lastSeenTs ?: 0)
|
||||
val isInactive = checkIfSessionIsInactiveUseCase.execute(deviceInfo.lastSeenTs)
|
||||
val isCurrentDevice = currentSessionCrossSigningInfo.deviceId == cryptoDeviceInfo?.deviceId
|
||||
val deviceExtendedInfo = parseDeviceUserAgentUseCase.execute(deviceInfo.getBestLastSeenUserAgent())
|
||||
val matrixClientInfo = deviceInfo.deviceId
|
||||
|
@ -24,11 +24,13 @@ class CheckIfSessionIsInactiveUseCase @Inject constructor(
|
||||
private val clock: Clock,
|
||||
) {
|
||||
|
||||
fun execute(lastSeenTs: Long): Boolean {
|
||||
// In case of the server doesn't send the last seen date.
|
||||
if (lastSeenTs == 0L) return true
|
||||
|
||||
val diffMilliseconds = clock.epochMillis() - lastSeenTs
|
||||
return diffMilliseconds >= TimeUnit.DAYS.toMillis(SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS.toLong())
|
||||
fun execute(lastSeenTsMillis: Long?): Boolean {
|
||||
return if (lastSeenTsMillis == null || lastSeenTsMillis <= 0) {
|
||||
// in these situations we cannot say anything about the inactivity of the session
|
||||
false
|
||||
} else {
|
||||
val diffMilliseconds = clock.epochMillis() - lastSeenTsMillis
|
||||
diffMilliseconds >= TimeUnit.DAYS.toMillis(SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class GetDeviceFullInfoUseCase @Inject constructor(
|
||||
val cryptoInfo = cryptoDeviceInfo.getOrNull()
|
||||
val fullInfo = if (info != null && cryptoInfo != null) {
|
||||
val roomEncryptionTrustLevel = getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoInfo)
|
||||
val isInactive = checkIfSessionIsInactiveUseCase.execute(info.lastSeenTs ?: 0)
|
||||
val isInactive = checkIfSessionIsInactiveUseCase.execute(info.lastSeenTs)
|
||||
val isCurrentDevice = currentSessionCrossSigningInfo.deviceId == cryptoInfo.deviceId
|
||||
val deviceUserAgent = parseDeviceUserAgentUseCase.execute(info.getBestLastSeenUserAgent())
|
||||
val matrixClientInfo = info.deviceId
|
||||
|
@ -17,43 +17,69 @@
|
||||
package im.vector.app.features.settings.devices.v2.list
|
||||
|
||||
import im.vector.app.test.fakes.FakeClock
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
import org.amshove.kluent.shouldBeFalse
|
||||
import org.amshove.kluent.shouldBeTrue
|
||||
import org.junit.Test
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
private const val A_TIMESTAMP = 1654689143L
|
||||
private const val A_TIMESTAMP_MILLIS = 1654689143000L
|
||||
|
||||
class CheckIfSessionIsInactiveUseCaseTest {
|
||||
|
||||
private val clock = FakeClock().apply { givenEpoch(A_TIMESTAMP) }
|
||||
private val clock = FakeClock().apply { givenEpoch(A_TIMESTAMP_MILLIS) }
|
||||
private val checkIfSessionIsInactiveUseCase = CheckIfSessionIsInactiveUseCase(clock)
|
||||
|
||||
@Test
|
||||
fun `given an old last seen date then session is inactive`() {
|
||||
val lastSeenDate = A_TIMESTAMP - TimeUnit.DAYS.toMillis(SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS.toLong()) - 1
|
||||
val lastSeenDate = A_TIMESTAMP_MILLIS - TimeUnit.DAYS.toMillis(SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS.toLong()) - 1
|
||||
|
||||
checkIfSessionIsInactiveUseCase.execute(lastSeenDate) shouldBeEqualTo true
|
||||
val result = checkIfSessionIsInactiveUseCase.execute(lastSeenDate)
|
||||
|
||||
result.shouldBeTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given a last seen date equal to the threshold then session is inactive`() {
|
||||
val lastSeenDate = A_TIMESTAMP - TimeUnit.DAYS.toMillis(SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS.toLong())
|
||||
val lastSeenDate = A_TIMESTAMP_MILLIS - TimeUnit.DAYS.toMillis(SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS.toLong())
|
||||
|
||||
checkIfSessionIsInactiveUseCase.execute(lastSeenDate) shouldBeEqualTo true
|
||||
val result = checkIfSessionIsInactiveUseCase.execute(lastSeenDate)
|
||||
|
||||
result.shouldBeTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given a recent last seen date then session is active`() {
|
||||
val lastSeenDate = A_TIMESTAMP - TimeUnit.DAYS.toMillis(SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS.toLong()) + 1
|
||||
val lastSeenDate = A_TIMESTAMP_MILLIS - TimeUnit.DAYS.toMillis(SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS.toLong()) + 1
|
||||
|
||||
checkIfSessionIsInactiveUseCase.execute(lastSeenDate) shouldBeEqualTo false
|
||||
val result = checkIfSessionIsInactiveUseCase.execute(lastSeenDate)
|
||||
|
||||
result.shouldBeFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given a last seen date as zero then session is inactive`() {
|
||||
// In case of the server doesn't send the last seen date.
|
||||
fun `given a last seen date as zero then session is not inactive`() {
|
||||
val lastSeenDate = 0L
|
||||
|
||||
checkIfSessionIsInactiveUseCase.execute(lastSeenDate) shouldBeEqualTo true
|
||||
val result = checkIfSessionIsInactiveUseCase.execute(lastSeenDate)
|
||||
|
||||
result.shouldBeFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given a last seen date as null then session is not inactive`() {
|
||||
val lastSeenDate = null
|
||||
|
||||
val result = checkIfSessionIsInactiveUseCase.execute(lastSeenDate)
|
||||
|
||||
result.shouldBeFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given a last seen date as negative then session is not inactive`() {
|
||||
val lastSeenDate = -3L
|
||||
|
||||
val result = checkIfSessionIsInactiveUseCase.execute(lastSeenDate)
|
||||
|
||||
result.shouldBeFalse()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user