added resilience in account retrieval

This commit is contained in:
Nicolas Constant 2020-03-11 20:54:32 -04:00
parent 59944b68f2
commit 8ae2edf164
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
4 changed files with 50 additions and 18 deletions

View File

@ -1,6 +1,6 @@
<div class="outer-profile">
<div class="profile flexcroll" #statusstream (scroll)="onScroll()">
<div *ngIf="!isLoading" class="profile__floating-header"
<div *ngIf="!isLoading && displayedAccount" class="profile__floating-header"
[ngStyle]="{'background-image':'url('+displayedAccount.header+')'}"
[class.profile__floating-header__activated]="showFloatingHeader">
<div class="profile__floating-header__inner">
@ -41,6 +41,10 @@
<app-waiting-animation *ngIf="isLoading" class="waiting-icon"></app-waiting-animation>
<div *ngIf="!isLoading && !displayedAccount" class="profile__not-found">
account couldn't be found.
</div>
<div class="profile__moved" *ngIf="displayedAccount && displayedAccount.moved">
<span innerHTML="{{displayedAccount | accountEmoji }}"></span> has moved to <br /><a href
(click)="openMigratedAccount(displayedAccount.moved)" class="profile__moved--link"
@ -97,7 +101,7 @@
</app-status-user-context-menu>
</div>
<div class="profile-sub-header">
<div *ngIf="displayedAccount" class="profile-sub-header">
<div *ngIf="displayedAccount">
<div class="profile-name">

View File

@ -21,6 +21,11 @@ $floating-header-height: 60px;
// width: $stream-column-width;
overflow: auto;
&__not-found {
padding-top: 15px;
text-align: center;
}
&__floating-header {
transition: all .2s;
transition-timing-function: ease-in;

View File

@ -153,6 +153,12 @@ export class UserProfileComponent implements OnInit {
this.currentlyUsedAccount = this.toolsService.getSelectedAccounts()[0];
return this.toolsService.findAccount(this.currentlyUsedAccount, this.lastAccountName)
// .then((account: Account) => {
// if(account != null) return account;
// let fullName = `https://${this.lastAccountName.split('@')[2]}/@${this.lastAccountName.split('@')[1]}`;
// return this.toolsService.findAccount(this.currentlyUsedAccount, fullName);
// })
.then((account: Account) => {
this.isLoading = false;
this.statusLoading = true;
@ -170,7 +176,7 @@ export class UserProfileComponent implements OnInit {
return Promise.all([getFollowStatusPromise, getStatusesPromise, getPinnedStatusesPromise]);
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err, this.currentlyUsedAccount);
//this.notificationService.notifyHttpError(err, this.currentlyUsedAccount);
})
.then(() => {
this.isLoading = false;

View File

@ -11,7 +11,7 @@ import { AppInfo, RegisteredAppsStateModel } from '../states/registered-apps.sta
@Injectable({
providedIn: 'root'
})
export class ToolsService {
export class ToolsService {
private accountAvatar: { [id: string]: string; } = {};
private instanceInfos: { [id: string]: InstanceInfo } = {};
@ -99,31 +99,48 @@ export class ToolsService {
return settings;
}
saveSettings(settings: GlobalSettings){
saveSettings(settings: GlobalSettings) {
this.store.dispatch([
new SaveSettings(settings)
]);
}
findAccount(account: AccountInfo, accountName: string): Promise<Account> {
let findAccountFunc = (result: Results) => {
if (accountName[0] === '@') accountName = accountName.substr(1);
const foundAccount = result.accounts.find(
x => (x.acct.toLowerCase() === accountName.toLowerCase()
||
(x.acct.toLowerCase().split('@')[0] === accountName.toLowerCase().split('@')[0])
&& x.url.replace('https://', '').split('/')[0] === accountName.toLowerCase().split('@')[1])
);
return foundAccount;
};
let searchVersion: 'v1' | 'v2' = 'v1';
return this.getInstanceInfo(account)
.then(instance => {
let version: 'v1' | 'v2' = 'v1';
if (instance.major >= 3) version = 'v2';
return this.mastodonService.search(account, accountName, version, true);
//let version: 'v1' | 'v2' = 'v1';
if (instance.major >= 3) searchVersion = 'v2';
return this.mastodonService.search(account, accountName, searchVersion, true);
})
.then((result: Results) => {
if (accountName[0] === '@') accountName = accountName.substr(1);
.then((results: Results) => {
return findAccountFunc(results);
})
.then((foundAccount: Account) => {
console.warn(accountName);
const foundAccount = result.accounts.find(
x => (x.acct.toLowerCase() === accountName.toLowerCase()
||
(x.acct.toLowerCase().split('@')[0] === accountName.toLowerCase().split('@')[0])
&& x.url.replace('https://', '').split('/')[0] === accountName.toLowerCase().split('@')[1])
);
return foundAccount;
if (foundAccount != null) return Promise.resolve(foundAccount);
console.error('tada');
let fullName = `https://${accountName.split('@')[1]}/@${accountName.split('@')[0]}`;
return this.mastodonService.search(account, fullName, searchVersion, true)
.then((results: Results) => {
return findAccountFunc(results);
});
});
}
}
getStatusUsableByAccount(account: AccountInfo, originalStatus: StatusWrapper): Promise<Status> {
const isProvider = originalStatus.provider.id === account.id;