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 * Factory
* *
* @param event the event * @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() return event.getClearContent()
.toModel<ShareRequestCancellation>() .toModel<ShareRequestCancellation>()
?.let { ?.let {
@ -55,7 +56,7 @@ data class IncomingRequestCancellation(
userId = event.senderId, userId = event.senderId,
deviceId = it.requestingDeviceId, deviceId = it.requestingDeviceId,
requestId = it.requestId, requestId = it.requestId,
localCreationTimestamp = event.ageLocalTs ?: now localCreationTimestamp = event.ageLocalTs ?: currentTimeMillis
) )
} }
} }

View File

@ -64,8 +64,9 @@ data class IncomingRoomKeyRequest(
* Factory * Factory
* *
* @param event the event * @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() return event.getClearContent()
.toModel<RoomKeyShareRequest>() .toModel<RoomKeyShareRequest>()
?.let { ?.let {
@ -74,7 +75,7 @@ data class IncomingRoomKeyRequest(
deviceId = it.requestingDeviceId, deviceId = it.requestingDeviceId,
requestId = it.requestId, requestId = it.requestId,
requestBody = it.body ?: RoomKeyRequestBody(), requestBody = it.body ?: RoomKeyRequestBody(),
localCreationTimestamp = event.ageLocalTs ?: now localCreationTimestamp = event.ageLocalTs ?: currentTimeMillis
) )
} }
} }

View File

@ -64,8 +64,9 @@ data class IncomingSecretShareRequest(
* Factory * Factory
* *
* @param event the event * @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() return event.getClearContent()
.toModel<SecretShareRequest>() .toModel<SecretShareRequest>()
?.let { ?.let {
@ -74,7 +75,7 @@ data class IncomingSecretShareRequest(
deviceId = it.requestingDeviceId, deviceId = it.requestingDeviceId,
requestId = it.requestId, requestId = it.requestId,
secretName = it.secretName, 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 TEN_MINUTES_IN_MILLIS = 10 * 60 * 1000
private const val FIVE_MINUTES_IN_MILLIS = 5 * 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 if (age == null) return false
val tooInThePast = now - TEN_MINUTES_IN_MILLIS val tooInThePast = currentTimeMillis - TEN_MINUTES_IN_MILLIS
val tooInTheFuture = now + FIVE_MINUTES_IN_MILLIS val tooInTheFuture = currentTimeMillis + FIVE_MINUTES_IN_MILLIS
return age in tooInThePast..tooInTheFuture 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` * Notify that a message has been received on this olm session so that it updates `lastReceivedMessageTs`
*/ */
fun onMessageReceived(now: Long) { fun onMessageReceived(currentTimeMillis: Long) {
lastReceivedMessageTs = now lastReceivedMessageTs = currentTimeMillis
} }
} }

View File

@ -138,7 +138,7 @@ internal fun ThreadSummaryEntity.Companion.createOrUpdate(
roomEntity: RoomEntity, roomEntity: RoomEntity,
userId: String, userId: String,
cryptoService: CryptoService? = null, cryptoService: CryptoService? = null,
now: Long, currentTimeMillis: Long,
) { ) {
when (threadSummaryType) { when (threadSummaryType) {
ThreadSummaryUpdateType.REPLACE -> { ThreadSummaryUpdateType.REPLACE -> {
@ -154,14 +154,14 @@ internal fun ThreadSummaryEntity.Companion.createOrUpdate(
Timber.i("###THREADS ThreadSummaryHelper REPLACE eventId:${it.rootThreadEventId} ") 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 { try {
decryptIfNeeded(cryptoService, it, roomId) decryptIfNeeded(cryptoService, it, roomId)
} catch (e: InterruptedException) { } catch (e: InterruptedException) {
Timber.i("Decryption got interrupted") Timber.i("Decryption got interrupted")
} }
} }
val latestThreadEventEntity = createLatestEventEntity(realm, roomId, rootThreadEvent, roomMemberContentsByUser, now)?.also { val latestThreadEventEntity = createLatestEventEntity(realm, roomId, rootThreadEvent, roomMemberContentsByUser, currentTimeMillis)?.also {
try { try {
decryptIfNeeded(cryptoService, it, roomId) decryptIfNeeded(cryptoService, it, roomId)
} catch (e: InterruptedException) { } 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 * 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 { private fun createEventEntity(realm: Realm, roomId: String, event: Event, currentTimeMillis: Long): EventEntity {
val ageLocalTs = event.unsignedData?.age?.let { now - it } val ageLocalTs = event.unsignedData?.age?.let { currentTimeMillis - it }
return event.toEntity(roomId, SendState.SYNCED, ageLocalTs).copyToRealmOrIgnore(realm, EventInsertType.PAGINATION) return event.toEntity(roomId, SendState.SYNCED, ageLocalTs).copyToRealmOrIgnore(realm, EventInsertType.PAGINATION)
} }
@ -283,13 +283,13 @@ private fun createLatestEventEntity(
roomId: String, roomId: String,
rootThreadEvent: Event, rootThreadEvent: Event,
roomMemberContentsByUser: HashMap<String, RoomMemberContent?>, roomMemberContentsByUser: HashMap<String, RoomMemberContent?>,
now: Long, currentTimeMillis: Long,
): EventEntity? { ): EventEntity? {
return getLatestEvent(rootThreadEvent)?.let { return getLatestEvent(rootThreadEvent)?.let {
it.senderId?.let { senderId -> it.senderId?.let { senderId ->
roomMemberContentsByUser.addSenderState(realm, roomId, 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, internal fun ContentScanResultEntity.Companion.getOrCreate(realm: Realm,
attachmentUrl: String, attachmentUrl: String,
contentScannerUrl: String?, contentScannerUrl: String?,
now: Long): ContentScanResultEntity { currentTimeMillis: Long): ContentScanResultEntity {
return ContentScanResultEntity.get(realm, attachmentUrl, contentScannerUrl) return ContentScanResultEntity.get(realm, attachmentUrl, contentScannerUrl)
?: realm.createObject<ContentScanResultEntity>().also { ?: realm.createObject<ContentScanResultEntity>().also {
it.mediaUrl = attachmentUrl it.mediaUrl = attachmentUrl
it.scanDateTimestamp = now it.scanDateTimestamp = currentTimeMillis
it.scannerUrl = contentScannerUrl it.scannerUrl = contentScannerUrl
} }
} }

View File

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

View File

@ -44,12 +44,14 @@ internal class ReadReceiptHandler @Inject constructor(
companion object { companion object {
fun createContent(userId: String, eventId: String, now: Long): ReadReceiptContent { fun createContent(userId: String,
eventId: String,
currentTimeMillis: Long): ReadReceiptContent {
return mapOf( return mapOf(
eventId to mapOf( eventId to mapOf(
READ_KEY to mapOf( READ_KEY to mapOf(
userId 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, roomMemberContentsByUser = roomMemberContentsByUser,
userId = userId, userId = userId,
roomEntity = roomEntity, roomEntity = roomEntity,
now = clock.epochMillis(), currentTimeMillis = clock.epochMillis(),
) )
} }
} ?: run { } ?: run {

View File

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

View File

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

View File

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

View File

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

View File

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