зеркало из https://github.com/nextcloud/talk-ios.git
Show number of unread notifications in inactive accounts.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
df03a4edd5
Коммит
7209fb5ff3
|
@ -22,6 +22,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
@property NSString *deviceIdentifier;
|
@property NSString *deviceIdentifier;
|
||||||
@property NSString *deviceSignature;
|
@property NSString *deviceSignature;
|
||||||
@property NSString *userPublicKey;
|
@property NSString *userPublicKey;
|
||||||
|
@property NSInteger unreadBadgeNumber;
|
||||||
|
@property BOOL unreadNotification;
|
||||||
@property BOOL active;
|
@property BOOL active;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -60,6 +62,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
- (NSString *)accountIdForUser:(NSString *)user inServer:(NSString *)server;
|
- (NSString *)accountIdForUser:(NSString *)user inServer:(NSString *)server;
|
||||||
- (void)createAccountForUser:(NSString *)user inServer:(NSString *)server;
|
- (void)createAccountForUser:(NSString *)user inServer:(NSString *)server;
|
||||||
- (void)removeAccountWithAccountId:(NSString *)accountId;
|
- (void)removeAccountWithAccountId:(NSString *)accountId;
|
||||||
|
- (void)increaseUnreadBadgeNumberForAccountId:(NSString *)accountId;
|
||||||
|
- (void)resetUnreadBadgeNumberForAccountId:(NSString *)accountId;
|
||||||
|
- (BOOL)shouldShowUnreadNotificationForInactiveAccounts;
|
||||||
|
- (void)removeUnreadNotificationForInactiveAccounts;
|
||||||
|
|
||||||
- (ServerCapabilities *)serverCapabilitiesForAccountId:(NSString *)accountId;
|
- (ServerCapabilities *)serverCapabilitiesForAccountId:(NSString *)accountId;
|
||||||
- (void)setServerCapabilities:(NSDictionary *)serverCapabilities forAccountId:(NSString *)accountId;
|
- (void)setServerCapabilities:(NSDictionary *)serverCapabilities forAccountId:(NSString *)accountId;
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
RLMRealmConfiguration *configuration = [RLMRealmConfiguration defaultConfiguration];
|
RLMRealmConfiguration *configuration = [RLMRealmConfiguration defaultConfiguration];
|
||||||
NSURL *databaseURL = [[NSURL fileURLWithPath:path] URLByAppendingPathComponent:k_TalkDatabaseFileName];
|
NSURL *databaseURL = [[NSURL fileURLWithPath:path] URLByAppendingPathComponent:k_TalkDatabaseFileName];
|
||||||
configuration.fileURL = databaseURL;
|
configuration.fileURL = databaseURL;
|
||||||
configuration.schemaVersion = 1;
|
configuration.schemaVersion = 2;
|
||||||
[RLMRealmConfiguration setDefaultConfiguration:configuration];
|
[RLMRealmConfiguration setDefaultConfiguration:configuration];
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -154,6 +154,47 @@
|
||||||
[realm commitWriteTransaction];
|
[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
|
#pragma mark - Server capabilities
|
||||||
|
|
||||||
- (ServerCapabilities *)serverCapabilitiesForAccountId:(NSString *)accountId
|
- (ServerCapabilities *)serverCapabilitiesForAccountId:(NSString *)accountId
|
||||||
|
|
|
@ -106,6 +106,11 @@ NSString * const NCLocalNotificationJoinChatNotification = @"NCLocalN
|
||||||
|
|
||||||
[self updateAppIconBadgeNumber:1];
|
[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];
|
[[NSNotificationCenter defaultCenter] postNotificationName:NCNotificationControllerWillPresentNotification object:self userInfo:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,6 +170,7 @@ NSString * const NCUserProfileImageUpdatedNotification = @"NCUserProfileImageUpd
|
||||||
{
|
{
|
||||||
[[NCUserInterfaceController sharedInstance] presentConversationsList];
|
[[NCUserInterfaceController sharedInstance] presentConversationsList];
|
||||||
[[NCDatabaseManager sharedInstance] setActiveAccountWithAccountId:accountId];
|
[[NCDatabaseManager sharedInstance] setActiveAccountWithAccountId:accountId];
|
||||||
|
[[NCDatabaseManager sharedInstance] resetUnreadBadgeNumberForAccountId:accountId];
|
||||||
[[NSHTTPCookieStorage sharedHTTPCookieStorage] removeCookiesSinceDate:[NSDate dateWithTimeIntervalSince1970:0]];
|
[[NSHTTPCookieStorage sharedHTTPCookieStorage] removeCookiesSinceDate:[NSDate dateWithTimeIntervalSince1970:0]];
|
||||||
[[NCConnectionController sharedInstance] checkAppState];
|
[[NCConnectionController sharedInstance] checkAppState];
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#import "UIImageView+AFNetworking.h"
|
#import "UIImageView+AFNetworking.h"
|
||||||
#import "UIImageView+Letters.h"
|
#import "UIImageView+Letters.h"
|
||||||
#import "CCBKPasscode.h"
|
#import "CCBKPasscode.h"
|
||||||
|
#import "RoundedNumberView.h"
|
||||||
#import <SafariServices/SafariServices.h>
|
#import <SafariServices/SafariServices.h>
|
||||||
|
|
||||||
typedef enum SettingsSection {
|
typedef enum SettingsSection {
|
||||||
|
@ -400,6 +401,13 @@ typedef enum AboutSection {
|
||||||
NSString *accountServer = [account.server stringByReplacingOccurrencesOfString:[[NSURL URLWithString:account.server] scheme] withString:@""];
|
NSString *accountServer = [account.server stringByReplacingOccurrencesOfString:[[NSURL URLWithString:account.server] scheme] withString:@""];
|
||||||
cell.accountServerLabel.text = [accountServer stringByReplacingOccurrencesOfString:@"://" withString:@""];
|
cell.accountServerLabel.text = [accountServer stringByReplacingOccurrencesOfString:@"://" withString:@""];
|
||||||
[cell.accountImageView setImage:[[NCAPIController sharedInstance] userProfileImageForAccount:account withSize:CGSizeMake(90, 90)]];
|
[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;
|
return cell;
|
||||||
} else {
|
} else {
|
||||||
cell = [tableView dequeueReusableCellWithIdentifier:addAccountCellIdentifier];
|
cell = [tableView dequeueReusableCellWithIdentifier:addAccountCellIdentifier];
|
||||||
|
|
Загрузка…
Ссылка в новой задаче