Use System.currentTimeMillis

This commit is contained in:
AsamK 2021-05-29 10:08:16 +02:00
parent a70dfdc8b8
commit 1ce1ae91be
3 changed files with 6 additions and 8 deletions

View file

@ -333,7 +333,7 @@ public class Manager implements Closeable {
if (account.getLastReceiveTimestamp() == 0) { if (account.getLastReceiveTimestamp() == 0) {
logger.warn("The Signal protocol expects that incoming messages are regularly received."); logger.warn("The Signal protocol expects that incoming messages are regularly received.");
} else { } else {
var diffInMilliseconds = new Date().getTime() - account.getLastReceiveTimestamp(); var diffInMilliseconds = System.currentTimeMillis() - account.getLastReceiveTimestamp();
long days = TimeUnit.DAYS.convert(diffInMilliseconds, TimeUnit.MILLISECONDS); long days = TimeUnit.DAYS.convert(diffInMilliseconds, TimeUnit.MILLISECONDS);
if (days > 7) { if (days > 7) {
logger.warn( logger.warn(
@ -585,7 +585,7 @@ public class Manager implements Closeable {
) { ) {
var profile = account.getProfileStore().getProfile(recipientId); var profile = account.getProfileStore().getProfile(recipientId);
var now = new Date().getTime(); var now = System.currentTimeMillis();
// Profiles are cached for 24h before retrieving them again, unless forced // Profiles are cached for 24h before retrieving them again, unless forced
if (!force && profile != null && now - profile.getLastUpdateTimestamp() < 24 * 60 * 60 * 1000) { if (!force && profile != null && now - profile.getLastUpdateTimestamp() < 24 * 60 * 60 * 1000) {
return profile; return profile;
@ -611,7 +611,7 @@ public class Manager implements Closeable {
var profileKey = account.getProfileStore().getProfileKey(recipientId); var profileKey = account.getProfileStore().getProfileKey(recipientId);
if (profileKey == null) { if (profileKey == null) {
profile = new Profile(new Date().getTime(), profile = new Profile(System.currentTimeMillis(),
null, null,
null, null,
null, null,
@ -1993,7 +1993,7 @@ public class Manager implements Closeable {
SignalServiceContent content = null; SignalServiceContent content = null;
Exception exception = null; Exception exception = null;
final CachedMessage[] cachedMessage = {null}; final CachedMessage[] cachedMessage = {null};
account.setLastReceiveTimestamp(new Date().getTime()); account.setLastReceiveTimestamp(System.currentTimeMillis());
try { try {
var result = messagePipe.readOrEmpty(timeout, unit, envelope1 -> { var result = messagePipe.readOrEmpty(timeout, unit, envelope1 -> {
final var recipientId = envelope1.hasSource() final var recipientId = envelope1.hasSource()

View file

@ -12,7 +12,6 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -51,7 +50,7 @@ public class MessageCache {
} }
public CachedMessage cacheMessage(SignalServiceEnvelope envelope, RecipientId recipientId) { public CachedMessage cacheMessage(SignalServiceEnvelope envelope, RecipientId recipientId) {
final var now = new Date().getTime(); final var now = System.currentTimeMillis();
try { try {
var cacheFile = getMessageCacheFile(recipientId, now, envelope.getTimestamp()); var cacheFile = getMessageCacheFile(recipientId, now, envelope.getTimestamp());

View file

@ -8,7 +8,6 @@ import org.whispersystems.signalservice.api.crypto.ProfileCipher;
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile; import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
import java.util.Base64; import java.util.Base64;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
public class ProfileUtils { public class ProfileUtils {
@ -23,7 +22,7 @@ public class ProfileUtils {
var aboutEmoji = decrypt(encryptedProfile.getAboutEmoji(), profileCipher); var aboutEmoji = decrypt(encryptedProfile.getAboutEmoji(), profileCipher);
final var nameParts = splitName(name); final var nameParts = splitName(name);
return new Profile(new Date().getTime(), return new Profile(System.currentTimeMillis(),
nameParts.first(), nameParts.first(),
nameParts.second(), nameParts.second(),
about, about,