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

Added transient info storage dictionary on MXKAccount. #858

Merged
merged 2 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 21 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,16 @@ - (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 +1851,9 @@ - (void)onBackgroundSyncDone:(NSError*)error
backgroundSyncTimer = nil;
}

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

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

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

// End background task
if (self.backgroundSyncBgTask.isRunning)
Expand Down Expand Up @@ -1874,7 +1890,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