This commit is contained in:
Niels Andriesse 2020-02-21 10:07:28 +07:00
parent 1b3a1b55cc
commit a74dbf9a16
2 changed files with 3 additions and 3 deletions

View File

@ -782,12 +782,12 @@ static NSTimeInterval launchStartedAt;
NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults; NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults;
NSDate *now = [NSDate new]; NSDate *now = [NSDate new];
NSDate *lastProfilePictureUpload = (NSDate *)[userDefaults objectForKey:@"lastProfilePictureUpload"]; NSDate *lastProfilePictureUpload = (NSDate *)[userDefaults objectForKey:@"lastProfilePictureUpload"];
if ([now timeIntervalSinceDate:lastProfilePictureUpload] > 14 * 24 * 60 * 60) { if (lastProfilePictureUpload != nil && [now timeIntervalSinceDate:lastProfilePictureUpload] > 14 * 24 * 60 * 60) {
OWSProfileManager *profileManager = OWSProfileManager.sharedManager; OWSProfileManager *profileManager = OWSProfileManager.sharedManager;
NSString *displayName = [profileManager profileNameForRecipientId:userHexEncodedPublicKey]; NSString *displayName = [profileManager profileNameForRecipientId:userHexEncodedPublicKey];
UIImage *profilePicture = [profileManager profileAvatarForRecipientId:userHexEncodedPublicKey]; UIImage *profilePicture = [profileManager profileAvatarForRecipientId:userHexEncodedPublicKey];
[profileManager updateLocalProfileName:displayName avatarImage:profilePicture success:^{ [profileManager updateLocalProfileName:displayName avatarImage:profilePicture success:^{
[userDefaults setObject:now forKey:@"lastProfilePictureUpload"]; // Do nothing; the user defaults flag is updated in LokiFileServerAPI
} failure:^(NSError *error) { } failure:^(NSError *error) {
// Do nothing // Do nothing
} requiresSync:YES]; } requiresSync:YES];

View File

@ -156,7 +156,7 @@ public final class LokiFileServerAPI : LokiDotNetAPI {
print("[Loki] Couldn't parse profile picture from: \(responseObject).") print("[Loki] Couldn't parse profile picture from: \(responseObject).")
throw LokiDotNetAPIError.parsingFailed throw LokiDotNetAPIError.parsingFailed
} }
UserDefaults.standard[.lastProfilePictureUpload] = Date().timeIntervalSince1970 UserDefaults.standard[.lastProfilePictureUpload] = Date()
return downloadURL return downloadURL
} }
} }