2018-10-03 06:37:41 +02:00
|
|
|
import { Component, OnInit, OnDestroy, Input } from '@angular/core';
|
2018-10-02 06:19:11 +02:00
|
|
|
import { Store } from '@ngxs/store';
|
|
|
|
|
2018-10-02 05:46:12 +02:00
|
|
|
import { StatusWrapper } from '../../stream.component';
|
2018-10-02 06:19:11 +02:00
|
|
|
import { MastodonService } from '../../../../services/mastodon.service';
|
|
|
|
import { AccountInfo } from '../../../../states/accounts.state';
|
2018-10-03 06:37:41 +02:00
|
|
|
import { Observable, Subscription } from 'rxjs';
|
|
|
|
// import { map } from "rxjs/operators";
|
2018-10-02 05:46:12 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-action-bar',
|
|
|
|
templateUrl: './action-bar.component.html',
|
|
|
|
styleUrls: ['./action-bar.component.scss']
|
|
|
|
})
|
2018-10-03 06:37:41 +02:00
|
|
|
export class ActionBarComponent implements OnInit, OnDestroy {
|
|
|
|
|
2018-10-02 05:46:12 +02:00
|
|
|
@Input() statusWrapper: StatusWrapper;
|
|
|
|
|
|
|
|
isFavorited: boolean;
|
|
|
|
isBoosted: boolean;
|
2018-10-03 06:37:41 +02:00
|
|
|
|
2018-10-02 06:19:11 +02:00
|
|
|
isBoostLocked: boolean;
|
|
|
|
isLocked: boolean;
|
2018-10-02 05:46:12 +02:00
|
|
|
|
2018-10-03 06:37:41 +02:00
|
|
|
private isProviderSelected: boolean;
|
|
|
|
private selectedAccounts: AccountInfo[];
|
|
|
|
|
|
|
|
private accounts$: Observable<AccountInfo[]>;
|
|
|
|
private accountSub: Subscription;
|
|
|
|
|
2018-10-02 06:19:11 +02:00
|
|
|
constructor(
|
|
|
|
private readonly store: Store,
|
2018-10-03 06:37:41 +02:00
|
|
|
private readonly mastodonService: MastodonService) {
|
|
|
|
|
|
|
|
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
// const selectedAccounts = this.getSelectedAccounts();
|
|
|
|
// this.checkStatus(selectedAccounts);
|
|
|
|
|
|
|
|
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
|
|
|
console.warn('selectedAccounts');
|
|
|
|
this.checkStatus(accounts);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.accountSub.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
private checkStatus(accounts: AccountInfo[]): void {
|
|
|
|
const status = this.statusWrapper.status;
|
|
|
|
const provider = this.statusWrapper.provider;
|
|
|
|
this.selectedAccounts = accounts.filter(x => x.isSelected);
|
|
|
|
this.isProviderSelected = this.selectedAccounts.filter(x => x.id === provider.id).length > 0;
|
2018-10-02 05:46:12 +02:00
|
|
|
|
2018-10-03 06:37:41 +02:00
|
|
|
if (status.visibility === 'direct' || status.visibility === 'private') {
|
|
|
|
this.isBoostLocked = true;
|
|
|
|
} else {
|
|
|
|
this.isBoostLocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((status.visibility === 'direct' || status.visibility === 'private') && !this.isProviderSelected) {
|
|
|
|
this.isLocked = true;
|
|
|
|
} else {
|
|
|
|
this.isLocked = false;
|
|
|
|
}
|
2018-10-02 05:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
reply(): boolean {
|
|
|
|
console.warn('reply');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost(): boolean {
|
2018-10-03 06:37:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-02 05:46:12 +02:00
|
|
|
console.warn('boost');
|
|
|
|
this.isBoosted = !this.isBoosted;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
favorite(): boolean {
|
|
|
|
console.warn('favorite');
|
|
|
|
this.isFavorited = !this.isFavorited;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
more(): boolean {
|
|
|
|
console.warn('more');
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-02 06:19:11 +02:00
|
|
|
|
|
|
|
private getSelectedAccounts(): AccountInfo[] {
|
|
|
|
var regAccounts = <AccountInfo[]>this.store.snapshot().registeredaccounts.accounts;
|
2018-10-03 06:37:41 +02:00
|
|
|
return regAccounts;
|
2018-10-02 06:19:11 +02:00
|
|
|
}
|
2018-10-02 05:46:12 +02:00
|
|
|
}
|