Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
element-hq/element-ios/issues/4578 - Added generic others storage d…
Browse files Browse the repository at this point in the history
…ictionary on MXKAccount.
  • Loading branch information
stefanceriu committed Jul 20, 2021
1 parent 6f6dbae commit 60120c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changes to be released in next version
*

🙌 Improvements
*
* MXKAccount: added generic `others` storage dictionary (vector-im/element-ios/issues/4578)

🐛 Bugfix
*
Expand Down
5 changes: 5 additions & 0 deletions MatrixKit/Models/Account/MXKAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
*/
@property (nonatomic, readonly) BOOL pushNotificationServiceIsActive;

/**
Transient information storage.
*/
@property (nonatomic, strong, readonly) NSMutableDictionary<NSString *, id<NSCoding>> *others;

/**
Enable Push notification based on Apple Push Notification Service (APNS).
Expand Down
25 changes: 20 additions & 5 deletions MatrixKit/Models/Account/MXKAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ @interface MXKAccount ()

// Background sync management
MXOnBackgroundSyncDone backgroundSyncDone;
MXOnBackgroundSyncFail backgroundSyncfails;
MXOnBackgroundSyncFail backgroundSyncFails;
NSTimer* backgroundSyncTimer;

// Observe UIApplicationSignificantTimeChangeNotification to refresh MXRoomSummaries on time formatting change.
Expand All @@ -89,6 +89,8 @@ @interface MXKAccount ()
@property (nonatomic, strong) id<MXBackgroundTask> backgroundTask;
@property (nonatomic, strong) id<MXBackgroundTask> backgroundSyncBgTask;

@property (nonatomic, strong) NSMutableDictionary<NSString *, id<NSCoding>> *others;

@end

@implementation MXKAccount
Expand Down Expand Up @@ -225,6 +227,8 @@ - (id)initWithCoder:(NSCoder *)coder

_showDecryptedContentInNotifications = [coder decodeBoolForKey:@"showDecryptedContentInNotifications"];

_others = [coder decodeObjectForKey:@"others"];

// Refresh device information
[self loadDeviceInformation:nil failure:nil];
}
Expand Down Expand Up @@ -284,6 +288,8 @@ - (void)encodeWithCoder:(NSCoder *)coder
[coder encodeBool:_warnedAboutEncryption forKey:@"warnedAboutEncryption"];

[coder encodeBool:_showDecryptedContentInNotifications forKey:@"showDecryptedContentInNotifications"];

[coder encodeObject:_others forKey:@"others"];
}

#pragma mark - Properties
Expand Down Expand Up @@ -614,6 +620,15 @@ - (void)setShowDecryptedContentInNotifications:(BOOL)showDecryptedContentInNotif
[[MXKAccountManager sharedManager] saveAccounts];
}

- (NSMutableDictionary<NSString *, id<NSCoding>> *)others
{
if(_others == nil) {
_others = [NSMutableDictionary dictionary];
}

return _others;
}

#pragma mark - Matrix user's profile

- (void)setUserDisplayName:(NSString*)displayname success:(void (^)(void))success failure:(void (^)(NSError *error))failure
Expand Down Expand Up @@ -1835,9 +1850,9 @@ - (void)onBackgroundSyncDone:(NSError*)error
backgroundSyncTimer = nil;
}

if (backgroundSyncfails && error)
if (backgroundSyncFails && error)
{
backgroundSyncfails(error);
backgroundSyncFails(error);
}

if (backgroundSyncDone && !error)
Expand All @@ -1846,7 +1861,7 @@ - (void)onBackgroundSyncDone:(NSError*)error
}

backgroundSyncDone = nil;
backgroundSyncfails = nil;
backgroundSyncFails = nil;

// End background task
if (self.backgroundSyncBgTask.isRunning)
Expand Down Expand Up @@ -1874,7 +1889,7 @@ - (void)backgroundSync:(unsigned int)timeout success:(void (^)(void))success fai
MXLogDebug(@"[MXKAccount] starts a background Sync");

backgroundSyncDone = success;
backgroundSyncfails = failure;
backgroundSyncFails = failure;

MXWeakify(self);

Expand Down

0 comments on commit 60120c2

Please sign in to comment.