Show number of unread notifications in inactive accounts.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2020-05-19 15:58:23 +02:00
Родитель df03a4edd5
Коммит 7209fb5ff3
5 изменённых файлов: 62 добавлений и 1 удалений

Просмотреть файл

@ -22,6 +22,8 @@ NS_ASSUME_NONNULL_BEGIN
@property NSString *deviceIdentifier;
@property NSString *deviceSignature;
@property NSString *userPublicKey;
@property NSInteger unreadBadgeNumber;
@property BOOL unreadNotification;
@property BOOL active;
@end
@ -60,6 +62,10 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)accountIdForUser:(NSString *)user inServer:(NSString *)server;
- (void)createAccountForUser:(NSString *)user inServer:(NSString *)server;
- (void)removeAccountWithAccountId:(NSString *)accountId;
- (void)increaseUnreadBadgeNumberForAccountId:(NSString *)accountId;
- (void)resetUnreadBadgeNumberForAccountId:(NSString *)accountId;
- (BOOL)shouldShowUnreadNotificationForInactiveAccounts;
- (void)removeUnreadNotificationForInactiveAccounts;
- (ServerCapabilities *)serverCapabilitiesForAccountId:(NSString *)accountId;
- (void)setServerCapabilities:(NSDictionary *)serverCapabilities forAccountId:(NSString *)accountId;

Просмотреть файл

@ -54,7 +54,7 @@
RLMRealmConfiguration *configuration = [RLMRealmConfiguration defaultConfiguration];
NSURL *databaseURL = [[NSURL fileURLWithPath:path] URLByAppendingPathComponent:k_TalkDatabaseFileName];
configuration.fileURL = databaseURL;
configuration.schemaVersion = 1;
configuration.schemaVersion = 2;
[RLMRealmConfiguration setDefaultConfiguration:configuration];
#ifdef DEBUG
@ -154,6 +154,47 @@
[realm commitWriteTransaction];
}
- (void)increaseUnreadBadgeNumberForAccountId:(NSString *)accountId
{
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
NSPredicate *query = [NSPredicate predicateWithFormat:@"accountId = %@", accountId];
TalkAccount *account = [TalkAccount objectsWithPredicate:query].firstObject;
account.unreadBadgeNumber += 1;
account.unreadNotification = YES;
[realm commitWriteTransaction];
}
- (void)resetUnreadBadgeNumberForAccountId:(NSString *)accountId
{
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
NSPredicate *query = [NSPredicate predicateWithFormat:@"accountId = %@", accountId];
TalkAccount *account = [TalkAccount objectsWithPredicate:query].firstObject;
account.unreadBadgeNumber = 0;
account.unreadNotification = NO;
[realm commitWriteTransaction];
}
- (BOOL)shouldShowUnreadNotificationForInactiveAccounts
{
TalkAccount *accountToBeNotified = [TalkAccount objectsWhere:(@"unreadNotification = true")].firstObject;
if (accountToBeNotified) {
return YES;
}
return NO;
}
- (void)removeUnreadNotificationForInactiveAccounts
{
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
for (TalkAccount *account in [TalkAccount allObjects]) {
account.unreadNotification = NO;
}
[realm commitWriteTransaction];
}
#pragma mark - Server capabilities
- (ServerCapabilities *)serverCapabilitiesForAccountId:(NSString *)accountId

Просмотреть файл

@ -106,6 +106,11 @@ NSString * const NCLocalNotificationJoinChatNotification = @"NCLocalN
[self updateAppIconBadgeNumber:1];
NSString *activeAccountId = [[[NCDatabaseManager sharedInstance] activeAccount] accountId];
if (![activeAccountId isEqualToString:pushNotification.accountId]) {
[[NCDatabaseManager sharedInstance] increaseUnreadBadgeNumberForAccountId:pushNotification.accountId];
}
[[NSNotificationCenter defaultCenter] postNotificationName:NCNotificationControllerWillPresentNotification object:self userInfo:nil];
}

Просмотреть файл

@ -170,6 +170,7 @@ NSString * const NCUserProfileImageUpdatedNotification = @"NCUserProfileImageUpd
{
[[NCUserInterfaceController sharedInstance] presentConversationsList];
[[NCDatabaseManager sharedInstance] setActiveAccountWithAccountId:accountId];
[[NCDatabaseManager sharedInstance] resetUnreadBadgeNumberForAccountId:accountId];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] removeCookiesSinceDate:[NSDate dateWithTimeIntervalSince1970:0]];
[[NCConnectionController sharedInstance] checkAppState];
}

Просмотреть файл

@ -21,6 +21,7 @@
#import "UIImageView+AFNetworking.h"
#import "UIImageView+Letters.h"
#import "CCBKPasscode.h"
#import "RoundedNumberView.h"
#import <SafariServices/SafariServices.h>
typedef enum SettingsSection {
@ -400,6 +401,13 @@ typedef enum AboutSection {
NSString *accountServer = [account.server stringByReplacingOccurrencesOfString:[[NSURL URLWithString:account.server] scheme] withString:@""];
cell.accountServerLabel.text = [accountServer stringByReplacingOccurrencesOfString:@"://" withString:@""];
[cell.accountImageView setImage:[[NCAPIController sharedInstance] userProfileImageForAccount:account withSize:CGSizeMake(90, 90)]];
cell.accessoryView = nil;
if (account.unreadBadgeNumber > 0) {
RoundedNumberView *badgeView = [[RoundedNumberView alloc] init];
badgeView.important = YES;
badgeView.number = account.unreadBadgeNumber;
cell.accessoryView = badgeView;
}
return cell;
} else {
cell = [tableView dequeueReusableCellWithIdentifier:addAccountCellIdentifier];