ensure account returned is matching acct fix #23

This commit is contained in:
Nicolas Constant 2018-11-02 21:35:33 -04:00
parent 2d4768e2b0
commit 6428ee927e
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 23 additions and 5 deletions

View File

@ -76,11 +76,10 @@ export class UserProfileComponent implements OnInit {
}
this.isLoading = true;
return this.mastodonService.search(selectedAccounts[0], accountName, true)
.then((result: Results) => {
console.warn(result);
return this.toolsService.findAccount(selectedAccounts[0], accountName)
.then((result) => {
this.isLoading = false;
return result.accounts[0];
return result;
});
}

View File

@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { AccountInfo } from '../states/accounts.state';
import { MastodonService } from './mastodon.service';
import { Account, Results } from "./models/mastodon.interfaces";
@Injectable({
@ -9,7 +11,9 @@ import { AccountInfo } from '../states/accounts.state';
})
export class ToolsService {
constructor( private readonly store: Store) { }
constructor(
private readonly mastodonService: MastodonService,
private readonly store: Store) { }
getSelectedAccounts(): AccountInfo[] {
@ -17,4 +21,19 @@ export class ToolsService {
return regAccounts.filter(x => x.isSelected);
}
findAccount(account: AccountInfo, accountName: string): Promise<Account> {
return this.mastodonService.search(account, accountName, true)
.then((result: Results) => {
console.warn('findAccount');
console.warn(`accountName ${accountName}`);
console.warn(result);
const foundAccount = result.accounts.filter(
x => x.acct.toLowerCase() === accountName.toLowerCase()
|| x.acct.toLowerCase() === accountName.toLowerCase().split('@')[0]
)[0];
return foundAccount;
});
}
}