display avatar on scheduled statuses

This commit is contained in:
Nicolas Constant 2019-09-06 01:18:41 -04:00
parent 9a0af9f246
commit 8299137b56
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
5 changed files with 55 additions and 9 deletions

View File

@ -1,5 +1,6 @@
<div class="scheduled-status">
<div class="scheduled-status__avatar">
<img class="scheduled-status__avatar--image" src="{{avatar}}" />
</div>
<div class="scheduled-status__content">

View File

@ -0,0 +1,16 @@
.scheduled-status {
padding: 5px 5px 0 5px;
outline: 1px solid greenyellow;
&__avatar {
&--image {
width: 40px;
}
}
&__content {
}
}

View File

@ -2,6 +2,7 @@ import { Component, OnInit, Input } from '@angular/core';
import { AccountInfo } from '../../../../states/accounts.state';
import { ScheduledStatus } from '../../../../services/models/mastodon.interfaces';
import { ToolsService } from '../../../../services/tools.service';
@Component({
selector: 'app-scheduled-status',
@ -10,12 +11,16 @@ import { ScheduledStatus } from '../../../../services/models/mastodon.interfaces
})
export class ScheduledStatusComponent implements OnInit {
avatar: string;
@Input() account: AccountInfo;
@Input() status: ScheduledStatus;
constructor() { }
constructor(private readonly toolsService: ToolsService) { }
ngOnInit() {
this.toolsService.getAvatar(this.account)
.then((avatar: string) => {
this.avatar = avatar;
});
}
}

View File

@ -12,6 +12,7 @@ import { NavigationService, LeftPanelType } from "../../services/navigation.serv
import { MastodonService } from "../../services/mastodon.service";
import { NotificationService } from "../../services/notification.service";
import { UserNotificationService, UserNotification } from '../../services/user-notification.service';
import { ToolsService } from '../../services/tools.service';
@Component({
selector: "app-left-side-bar",
@ -33,6 +34,7 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
private notificationSub: Subscription;
constructor(
private readonly toolsService: ToolsService,
private readonly userNotificationServiceService: UserNotificationService,
private readonly notificationService: NotificationService,
private readonly navigationService: NavigationService,
@ -56,14 +58,19 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
accWrapper.info = acc;
this.accounts.push(accWrapper);
this.toolsService.getAvatar(acc)
.then((avatar: string) => {
accWrapper.avatar = avatar;
});
this.mastodonService.retrieveAccountDetails(acc)
.then((result: Account) => {
accWrapper.avatar = result.avatar;
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err);
});
// this.mastodonService.retrieveAccountDetails(acc)
// .then((result: Account) => {
// accWrapper.avatar = result.avatar;
// })
// .catch((err: HttpErrorResponse) => {
// this.notificationService.notifyHttpError(err);
// });
}
}

View File

@ -11,11 +11,28 @@ import { AccountSettings, SaveAccountSettings } from '../states/settings.state';
providedIn: 'root'
})
export class ToolsService {
private accountAvatar: { [id: string]: string; } = {};
constructor(
private readonly mastodonService: MastodonService,
private readonly store: Store) { }
getAvatar(acc: AccountInfo): Promise<string> {
if (this.accountAvatar[acc.id]) {
return Promise.resolve(this.accountAvatar[acc.id]);
} else {
return this.mastodonService.retrieveAccountDetails(acc)
.then((result: Account) => {
this.accountAvatar[acc.id] = result.avatar;
return result.avatar;
})
.catch((err) => {
return "";
});
}
}
getSelectedAccounts(): AccountInfo[] {
var regAccounts = <AccountInfo[]>this.store.snapshot().registeredaccounts.accounts;
return regAccounts.filter(x => x.isSelected);