Rename `now` to more explicit `currentTimeMillis`

This commit is contained in:
Benoit Marty 2022-05-04 17:48:36 +02:00
parent 09e628f227
commit 2d98cbd915
15 changed files with 45 additions and 39 deletions

View File

@ -46,8 +46,9 @@ data class IncomingRequestCancellation(
* Factory
*
* @param event the event
* @param currentTimeMillis the current time in milliseconds
*/
fun fromEvent(event: Event, now: Long): IncomingRequestCancellation? {
fun fromEvent(event: Event, currentTimeMillis: Long): IncomingRequestCancellation? {
return event.getClearContent()
.toModel<ShareRequestCancellation>()
?.let {
@ -55,7 +56,7 @@ data class IncomingRequestCancellation(
userId = event.senderId,
deviceId = it.requestingDeviceId,
requestId = it.requestId,
localCreationTimestamp = event.ageLocalTs ?: now
localCreationTimestamp = event.ageLocalTs ?: currentTimeMillis
)
}
}

View File

@ -64,8 +64,9 @@ data class IncomingRoomKeyRequest(
* Factory
*
* @param event the event
* @param currentTimeMillis the current time in milliseconds
*/
fun fromEvent(event: Event, now: Long): IncomingRoomKeyRequest? {
fun fromEvent(event: Event, currentTimeMillis: Long): IncomingRoomKeyRequest? {
return event.getClearContent()
.toModel<RoomKeyShareRequest>()
?.let {
@ -74,7 +75,7 @@ data class IncomingRoomKeyRequest(
deviceId = it.requestingDeviceId,
requestId = it.requestId,
requestBody = it.body ?: RoomKeyRequestBody(),
localCreationTimestamp = event.ageLocalTs ?: now
localCreationTimestamp = event.ageLocalTs ?: currentTimeMillis
)
}
}

View File

@ -64,8 +64,9 @@ data class IncomingSecretShareRequest(
* Factory
*
* @param event the event
* @param currentTimeMillis the current time in milliseconds
*/
fun fromEvent(event: Event, now: Long): IncomingSecretShareRequest? {
fun fromEvent(event: Event, currentTimeMillis: Long): IncomingSecretShareRequest? {
return event.getClearContent()
.toModel<SecretShareRequest>()
?.let {
@ -74,7 +75,7 @@ data class IncomingSecretShareRequest(
deviceId = it.requestingDeviceId,
requestId = it.requestId,
secretName = it.secretName,
localCreationTimestamp = event.ageLocalTs ?: now
localCreationTimestamp = event.ageLocalTs ?: currentTimeMillis
)
}
}

View File

@ -129,10 +129,10 @@ interface VerificationService {
private const val TEN_MINUTES_IN_MILLIS = 10 * 60 * 1000
private const val FIVE_MINUTES_IN_MILLIS = 5 * 60 * 1000
fun isValidRequest(age: Long?, now: Long): Boolean {
fun isValidRequest(age: Long?, currentTimeMillis: Long): Boolean {
if (age == null) return false
val tooInThePast = now - TEN_MINUTES_IN_MILLIS
val tooInTheFuture = now + FIVE_MINUTES_IN_MILLIS
val tooInThePast = currentTimeMillis - TEN_MINUTES_IN_MILLIS
val tooInTheFuture = currentTimeMillis + FIVE_MINUTES_IN_MILLIS
return age in tooInThePast..tooInTheFuture
}
}

View File

@ -34,7 +34,7 @@ internal data class OlmSessionWrapper(
/**
* Notify that a message has been received on this olm session so that it updates `lastReceivedMessageTs`
*/
fun onMessageReceived(now: Long) {
lastReceivedMessageTs = now
fun onMessageReceived(currentTimeMillis: Long) {
lastReceivedMessageTs = currentTimeMillis
}
}

View File

@ -138,7 +138,7 @@ internal fun ThreadSummaryEntity.Companion.createOrUpdate(
roomEntity: RoomEntity,
userId: String,
cryptoService: CryptoService? = null,
now: Long,
currentTimeMillis: Long,
) {
when (threadSummaryType) {
ThreadSummaryUpdateType.REPLACE -> {
@ -154,14 +154,14 @@ internal fun ThreadSummaryEntity.Companion.createOrUpdate(
Timber.i("###THREADS ThreadSummaryHelper REPLACE eventId:${it.rootThreadEventId} ")
}
val rootThreadEventEntity = createEventEntity(realm, roomId, rootThreadEvent, now).also {
val rootThreadEventEntity = createEventEntity(realm, roomId, rootThreadEvent, currentTimeMillis).also {
try {
decryptIfNeeded(cryptoService, it, roomId)
} catch (e: InterruptedException) {
Timber.i("Decryption got interrupted")
}
}
val latestThreadEventEntity = createLatestEventEntity(realm, roomId, rootThreadEvent, roomMemberContentsByUser, now)?.also {
val latestThreadEventEntity = createLatestEventEntity(realm, roomId, rootThreadEvent, roomMemberContentsByUser, currentTimeMillis)?.also {
try {
decryptIfNeeded(cryptoService, it, roomId)
} catch (e: InterruptedException) {
@ -269,8 +269,8 @@ private fun HashMap<String, RoomMemberContent?>.addSenderState(realm: Realm, roo
/**
* Create an EventEntity for the root thread event or get an existing one
*/
private fun createEventEntity(realm: Realm, roomId: String, event: Event, now: Long): EventEntity {
val ageLocalTs = event.unsignedData?.age?.let { now - it }
private fun createEventEntity(realm: Realm, roomId: String, event: Event, currentTimeMillis: Long): EventEntity {
val ageLocalTs = event.unsignedData?.age?.let { currentTimeMillis - it }
return event.toEntity(roomId, SendState.SYNCED, ageLocalTs).copyToRealmOrIgnore(realm, EventInsertType.PAGINATION)
}
@ -283,13 +283,13 @@ private fun createLatestEventEntity(
roomId: String,
rootThreadEvent: Event,
roomMemberContentsByUser: HashMap<String, RoomMemberContent?>,
now: Long,
currentTimeMillis: Long,
): EventEntity? {
return getLatestEvent(rootThreadEvent)?.let {
it.senderId?.let { senderId ->
roomMemberContentsByUser.addSenderState(realm, roomId, senderId)
}
createEventEntity(realm, roomId, it, now)
createEventEntity(realm, roomId, it, currentTimeMillis)
}
}

View File

@ -34,11 +34,11 @@ internal fun ContentScanResultEntity.Companion.get(realm: Realm, attachmentUrl:
internal fun ContentScanResultEntity.Companion.getOrCreate(realm: Realm,
attachmentUrl: String,
contentScannerUrl: String?,
now: Long): ContentScanResultEntity {
currentTimeMillis: Long): ContentScanResultEntity {
return ContentScanResultEntity.get(realm, attachmentUrl, contentScannerUrl)
?: realm.createObject<ContentScanResultEntity>().also {
it.mediaUrl = attachmentUrl
it.scanDateTimestamp = now
it.scanDateTimestamp = currentTimeMillis
it.scannerUrl = contentScannerUrl
}
}

View File

@ -98,7 +98,7 @@ internal class DefaultFetchThreadSummariesTask @Inject constructor(
roomEntity = roomEntity,
userId = userId,
cryptoService = cryptoService,
now = clock.epochMillis(),
currentTimeMillis = clock.epochMillis(),
)
}
}

View File

@ -44,12 +44,14 @@ internal class ReadReceiptHandler @Inject constructor(
companion object {
fun createContent(userId: String, eventId: String, now: Long): ReadReceiptContent {
fun createContent(userId: String,
eventId: String,
currentTimeMillis: Long): ReadReceiptContent {
return mapOf(
eventId to mapOf(
READ_KEY to mapOf(
userId to mapOf(
TIMESTAMP_KEY to now.toDouble()
TIMESTAMP_KEY to currentTimeMillis.toDouble()
)
)
)

View File

@ -445,7 +445,7 @@ internal class RoomSyncHandler @Inject constructor(
roomMemberContentsByUser = roomMemberContentsByUser,
userId = userId,
roomEntity = roomEntity,
now = clock.epochMillis(),
currentTimeMillis = clock.epochMillis(),
)
}
} ?: run {

View File

@ -106,7 +106,7 @@ class VectorSyncService : SyncService() {
syncDelaySeconds = syncDelaySeconds,
isPeriodic = true,
isNetworkBack = false,
now = clock.epochMillis()
currentTimeMillis = clock.epochMillis()
)
}
@ -162,7 +162,7 @@ class VectorSyncService : SyncService() {
syncDelaySeconds = syncDelaySeconds,
isPeriodic = isPeriodic,
isNetworkBack = true,
now = clock.epochMillis()
currentTimeMillis = clock.epochMillis()
)
// Indicate whether the work finished successfully with the Result
return Result.success()
@ -195,7 +195,7 @@ private fun Context.rescheduleSyncService(sessionId: String,
syncDelaySeconds: Int,
isPeriodic: Boolean,
isNetworkBack: Boolean,
now: Long) {
currentTimeMillis: Long) {
Timber.d("## Sync: rescheduleSyncService")
val intent = if (isPeriodic) {
VectorSyncService.newPeriodicIntent(
@ -221,7 +221,7 @@ private fun Context.rescheduleSyncService(sessionId: String,
} else {
PendingIntent.getService(this, 0, intent, PendingIntentCompat.FLAG_IMMUTABLE)
}
val firstMillis = now + syncDelaySeconds * 1000L
val firstMillis = currentTimeMillis + syncDelaySeconds * 1000L
val alarmMgr = getSystemService<AlarmManager>()!!
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmMgr.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, firstMillis, pendingIntent)

View File

@ -256,7 +256,7 @@ suspend fun saveMedia(context: Context,
title: String,
mediaMimeType: String?,
notificationUtils: NotificationUtils,
now: Long) {
currentTimeMillis: Long) {
withContext(Dispatchers.IO) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val filename = appendTimeToFilename(title)
@ -265,8 +265,8 @@ suspend fun saveMedia(context: Context,
put(MediaStore.Images.Media.TITLE, filename)
put(MediaStore.Images.Media.DISPLAY_NAME, filename)
put(MediaStore.Images.Media.MIME_TYPE, mediaMimeType)
put(MediaStore.Images.Media.DATE_ADDED, now)
put(MediaStore.Images.Media.DATE_TAKEN, now)
put(MediaStore.Images.Media.DATE_ADDED, currentTimeMillis)
put(MediaStore.Images.Media.DATE_TAKEN, currentTimeMillis)
}
val externalContentUri = when {
mediaMimeType?.isMimeTypeImage() == true -> MediaStore.Images.Media.EXTERNAL_CONTENT_URI
@ -297,7 +297,7 @@ suspend fun saveMedia(context: Context,
}
}
} else {
saveMediaLegacy(context, mediaMimeType, title, file, now)
saveMediaLegacy(context, mediaMimeType, title, file, currentTimeMillis)
}
}
}
@ -307,7 +307,7 @@ private fun saveMediaLegacy(context: Context,
mediaMimeType: String?,
title: String,
file: File,
now: Long) {
currentTimeMillis: Long) {
val state = Environment.getExternalStorageState()
if (Environment.MEDIA_MOUNTED != state) {
context.toast(context.getString(R.string.error_saving_media_file))
@ -328,7 +328,7 @@ private fun saveMediaLegacy(context: Context,
} else {
title
}
val savedFile = saveFileIntoLegacy(file, downloadDir, outputFilename, now)
val savedFile = saveFileIntoLegacy(file, downloadDir, outputFilename, currentTimeMillis)
if (savedFile != null) {
val downloadManager = context.getSystemService<DownloadManager>()
downloadManager?.addCompletedDownload(
@ -418,10 +418,11 @@ fun selectTxtFileToWrite(
* @param sourceFile the file source path
* @param dstDirPath the dst path
* @param outputFilename optional the output filename
* @param currentTimeMillis the current time in milliseconds
* @return the created file
*/
@Suppress("DEPRECATION")
fun saveFileIntoLegacy(sourceFile: File, dstDirPath: File, outputFilename: String?, now: Long): File? {
fun saveFileIntoLegacy(sourceFile: File, dstDirPath: File, outputFilename: String?, currentTimeMillis: Long): File? {
// defines another name for the external media
var dstFileName: String
@ -433,7 +434,7 @@ fun saveFileIntoLegacy(sourceFile: File, dstDirPath: File, outputFilename: Strin
if (dotPos > 0) {
fileExt = sourceFile.name.substring(dotPos)
}
dstFileName = "vector_$now$fileExt"
dstFileName = "vector_$currentTimeMillis$fileExt"
} else {
dstFileName = outputFilename
}

View File

@ -2187,7 +2187,7 @@ class TimelineFragment @Inject constructor(
title = action.messageContent.body,
mediaMimeType = action.messageContent.mimeType ?: getMimeTypeFromUri(requireContext(), it.toUri()),
notificationUtils = notificationUtils,
now = clock.epochMillis()
currentTimeMillis = clock.epochMillis()
)
}
.onFailure {

View File

@ -43,7 +43,7 @@ class DownloadMediaUseCase @Inject constructor(
title = input.name,
mediaMimeType = getMimeTypeFromUri(appContext, input.toUri()),
notificationUtils = notificationUtils,
now = clock.epochMillis()
currentTimeMillis = clock.epochMillis()
)
}
}

View File

@ -91,7 +91,7 @@ class RoomUploadsFragment @Inject constructor(
title = it.title,
mediaMimeType = getMimeTypeFromUri(requireContext(), it.file.toUri()),
notificationUtils = notificationUtils,
now = clock.epochMillis()
currentTimeMillis = clock.epochMillis()
)
}.onFailure { failure ->
if (!isAdded) return@onFailure