Set alias and avatar to accounts.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2022-12-20 16:05:19 +01:00
Родитель 582fabd5a1
Коммит 2c73b37266
1 изменённых файлов: 31 добавлений и 11 удалений

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

@ -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