зеркало из https://github.com/nextcloud/talk-ios.git
Set alias and avatar to accounts.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
582fabd5a1
Коммит
2c73b37266
|
@ -167,16 +167,6 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
||||||
|
|
||||||
- (void)createAccountsFile
|
- (void)createAccountsFile
|
||||||
{
|
{
|
||||||
NSMutableArray *accounts = [NSMutableArray new];
|
|
||||||
for (TalkAccount *account in [[NCDatabaseManager sharedInstance] allAccounts]) {
|
|
||||||
NKDataAccountFile *accountFileData = [[NKDataAccountFile alloc] initWithUrl:account.server user:account.user alias:nil avatar:nil];
|
|
||||||
[accounts addObject:accountFileData];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!accounts.count) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Talk directory in apps group container
|
// Create Talk directory in apps group container
|
||||||
NSString *path = [[[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appsGroupIdentifier] URLByAppendingPathComponent:kTalkDatabaseFolder] path];
|
NSString *path = [[[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appsGroupIdentifier] URLByAppendingPathComponent:kTalkDatabaseFolder] path];
|
||||||
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
|
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
|
||||||
|
@ -184,9 +174,39 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
|
||||||
}
|
}
|
||||||
NSURL *accountsFileURL = [[NSURL fileURLWithPath:path] URLByAppendingPathComponent:kTalkAccountsFileName];
|
NSURL *accountsFileURL = [[NSURL fileURLWithPath:path] URLByAppendingPathComponent:kTalkAccountsFileName];
|
||||||
|
|
||||||
|
// Create accounts data
|
||||||
|
NSMutableArray *accounts = [NSMutableArray new];
|
||||||
|
for (TalkAccount *account in [[NCDatabaseManager sharedInstance] allAccounts]) {
|
||||||
|
NSString *avatarPath = [self copyUserAvatarInPath:path forAccount:account];
|
||||||
|
NKDataAccountFile *accountFileData = [[NKDataAccountFile alloc] initWithUrl:account.server user:account.user alias:account.userDisplayName avatar:avatarPath];
|
||||||
|
[accounts addObject:accountFileData];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!accounts.count) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
[[NKCommon shared] createDataAccountFileAt:accountsFileURL accounts:accounts];
|
[[NKCommon shared] createDataAccountFileAt:accountsFileURL accounts:accounts];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)copyUserAvatarInPath:(NSString *)path forAccount:(TalkAccount *)account
|
||||||
|
{
|
||||||
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
|
NSString *documentsPath = [[fileManager containerURLForSecurityApplicationGroupIdentifier:groupIdentifier] path];
|
||||||
|
NSString *fileName = [NSString stringWithFormat:@"%@-%@.png", account.userId, [[NSURL URLWithString:account.server] host]];
|
||||||
|
NSString *filePath = [documentsPath stringByAppendingPathComponent:fileName];
|
||||||
|
NSString *copyPath = [path stringByAppendingPathComponent:fileName];
|
||||||
|
|
||||||
|
NSError *error = nil;
|
||||||
|
if ([fileManager fileExistsAtPath:copyPath]) {
|
||||||
|
[fileManager removeItemAtPath:copyPath error:&error];
|
||||||
|
}
|
||||||
|
[fileManager copyItemAtPath:filePath toPath:copyPath error:&error];
|
||||||
|
NSLog(@"Copied profile picture. Error: %@", error);
|
||||||
|
|
||||||
|
return error ? nil : copyPath;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Notifications
|
#pragma mark - Notifications
|
||||||
|
|
||||||
- (void)tokenRevokedResponseReceived:(NSNotification *)notification
|
- (void)tokenRevokedResponseReceived:(NSNotification *)notification
|
||||||
|
|
Загрузка…
Ссылка в новой задаче