mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Fix inactivity status when last seen timestamp is null
This commit is contained in:
parent
87928b4e12
commit
01429b352a
5 changed files with 49 additions and 21 deletions
|
@ -142,7 +142,7 @@ class DevicesViewModel @AssistedInject constructor(
|
||||||
.map { deviceInfo ->
|
.map { deviceInfo ->
|
||||||
val cryptoDeviceInfo = cryptoList.firstOrNull { it.deviceId == deviceInfo.deviceId }
|
val cryptoDeviceInfo = cryptoList.firstOrNull { it.deviceId == deviceInfo.deviceId }
|
||||||
val trustLevelForShield = getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoDeviceInfo)
|
val trustLevelForShield = getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoDeviceInfo)
|
||||||
val isInactive = checkIfSessionIsInactiveUseCase.execute(deviceInfo.lastSeenTs ?: 0)
|
val isInactive = checkIfSessionIsInactiveUseCase.execute(deviceInfo.lastSeenTs)
|
||||||
DeviceFullInfo(deviceInfo, cryptoDeviceInfo, trustLevelForShield, isInactive)
|
DeviceFullInfo(deviceInfo, cryptoDeviceInfo, trustLevelForShield, isInactive)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ class GetDeviceFullInfoListUseCase @Inject constructor(
|
||||||
.map { deviceInfo ->
|
.map { deviceInfo ->
|
||||||
val cryptoDeviceInfo = cryptoList.firstOrNull { it.deviceId == deviceInfo.deviceId }
|
val cryptoDeviceInfo = cryptoList.firstOrNull { it.deviceId == deviceInfo.deviceId }
|
||||||
val roomEncryptionTrustLevel = getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoDeviceInfo)
|
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 isCurrentDevice = currentSessionCrossSigningInfo.deviceId == cryptoDeviceInfo?.deviceId
|
||||||
val deviceExtendedInfo = parseDeviceUserAgentUseCase.execute(deviceInfo.getBestLastSeenUserAgent())
|
val deviceExtendedInfo = parseDeviceUserAgentUseCase.execute(deviceInfo.getBestLastSeenUserAgent())
|
||||||
val matrixClientInfo = deviceInfo.deviceId
|
val matrixClientInfo = deviceInfo.deviceId
|
||||||
|
|
|
@ -24,11 +24,13 @@ class CheckIfSessionIsInactiveUseCase @Inject constructor(
|
||||||
private val clock: Clock,
|
private val clock: Clock,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun execute(lastSeenTs: Long): Boolean {
|
fun execute(lastSeenTsMillis: Long?): Boolean {
|
||||||
// In case of the server doesn't send the last seen date.
|
return if (lastSeenTsMillis == null || lastSeenTsMillis <= 0) {
|
||||||
if (lastSeenTs == 0L) return true
|
// in these situations we cannot say anything about the inactivity of the session
|
||||||
|
false
|
||||||
val diffMilliseconds = clock.epochMillis() - lastSeenTs
|
} else {
|
||||||
return diffMilliseconds >= TimeUnit.DAYS.toMillis(SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS.toLong())
|
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 cryptoInfo = cryptoDeviceInfo.getOrNull()
|
||||||
val fullInfo = if (info != null && cryptoInfo != null) {
|
val fullInfo = if (info != null && cryptoInfo != null) {
|
||||||
val roomEncryptionTrustLevel = getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoInfo)
|
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 isCurrentDevice = currentSessionCrossSigningInfo.deviceId == cryptoInfo.deviceId
|
||||||
val deviceUserAgent = parseDeviceUserAgentUseCase.execute(info.getBestLastSeenUserAgent())
|
val deviceUserAgent = parseDeviceUserAgentUseCase.execute(info.getBestLastSeenUserAgent())
|
||||||
val matrixClientInfo = info.deviceId
|
val matrixClientInfo = info.deviceId
|
||||||
|
|
|
@ -17,43 +17,69 @@
|
||||||
package im.vector.app.features.settings.devices.v2.list
|
package im.vector.app.features.settings.devices.v2.list
|
||||||
|
|
||||||
import im.vector.app.test.fakes.FakeClock
|
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 org.junit.Test
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
private const val A_TIMESTAMP = 1654689143L
|
private const val A_TIMESTAMP_MILLIS = 1654689143000L
|
||||||
|
|
||||||
class CheckIfSessionIsInactiveUseCaseTest {
|
class CheckIfSessionIsInactiveUseCaseTest {
|
||||||
|
|
||||||
private val clock = FakeClock().apply { givenEpoch(A_TIMESTAMP) }
|
private val clock = FakeClock().apply { givenEpoch(A_TIMESTAMP_MILLIS) }
|
||||||
private val checkIfSessionIsInactiveUseCase = CheckIfSessionIsInactiveUseCase(clock)
|
private val checkIfSessionIsInactiveUseCase = CheckIfSessionIsInactiveUseCase(clock)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given an old last seen date then session is inactive`() {
|
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
|
@Test
|
||||||
fun `given a last seen date equal to the threshold then session is inactive`() {
|
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
|
@Test
|
||||||
fun `given a recent last seen date then session is active`() {
|
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
|
@Test
|
||||||
fun `given a last seen date as zero then session is inactive`() {
|
fun `given a last seen date as zero then session is not inactive`() {
|
||||||
// In case of the server doesn't send the last seen date.
|
|
||||||
val lastSeenDate = 0L
|
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 a new issue