2018-03-17 17:25:40 +01:00
|
|
|
import { Component, OnInit, OnDestroy } from "@angular/core";
|
2019-02-12 05:41:21 +01:00
|
|
|
import { HttpErrorResponse } from "@angular/common/http";
|
2019-02-11 05:03:05 +01:00
|
|
|
import { Subscription, Observable } from "rxjs";
|
2018-09-09 07:29:23 +02:00
|
|
|
import { Store } from "@ngxs/store";
|
2019-02-11 05:03:05 +01:00
|
|
|
import { faCommentAlt } from "@fortawesome/free-regular-svg-icons";
|
2018-03-17 17:25:40 +01:00
|
|
|
|
2018-09-09 07:29:23 +02:00
|
|
|
import { Account } from "../../services/models/mastodon.interfaces";
|
2018-03-16 04:48:30 +01:00
|
|
|
import { AccountWrapper } from "../../models/account.models";
|
2019-02-11 05:03:05 +01:00
|
|
|
import { AccountInfo, SelectAccount } from "../../states/accounts.state";
|
2018-09-22 06:22:51 +02:00
|
|
|
import { NavigationService, LeftPanelType } from "../../services/navigation.service";
|
2018-09-16 04:25:20 +02:00
|
|
|
import { MastodonService } from "../../services/mastodon.service";
|
2019-02-12 05:41:21 +01:00
|
|
|
import { NotificationService } from "../../services/notification.service";
|
2019-03-25 06:09:53 +01:00
|
|
|
import { UserNotificationService, UserNotification } from '../../services/user-notification.service';
|
2018-03-16 01:43:53 +01:00
|
|
|
|
|
|
|
@Component({
|
2018-09-22 06:22:51 +02:00
|
|
|
selector: "app-left-side-bar",
|
|
|
|
templateUrl: "./left-side-bar.component.html",
|
|
|
|
styleUrls: ["./left-side-bar.component.scss"]
|
2018-03-16 01:43:53 +01:00
|
|
|
})
|
2018-03-17 17:25:40 +01:00
|
|
|
export class LeftSideBarComponent implements OnInit, OnDestroy {
|
2019-02-11 05:03:05 +01:00
|
|
|
faCommentAlt = faCommentAlt;
|
|
|
|
|
2019-03-24 22:52:34 +01:00
|
|
|
accounts: AccountWithNotificationWrapper[] = [];
|
2019-02-11 04:23:10 +01:00
|
|
|
hasAccounts: boolean;
|
2018-09-26 01:29:49 +02:00
|
|
|
private accounts$: Observable<AccountInfo[]>;
|
2018-03-16 01:43:53 +01:00
|
|
|
|
2019-03-24 22:52:34 +01:00
|
|
|
private accountSub: Subscription;
|
|
|
|
private notificationSub: Subscription;
|
2018-03-16 03:43:41 +01:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
constructor(
|
2019-03-25 06:09:53 +01:00
|
|
|
private readonly userNotificationServiceService: UserNotificationService,
|
2019-02-12 05:41:21 +01:00
|
|
|
private readonly notificationService: NotificationService,
|
2018-09-22 06:22:51 +02:00
|
|
|
private readonly navigationService: NavigationService,
|
|
|
|
private readonly mastodonService: MastodonService,
|
|
|
|
private readonly store: Store) {
|
2018-03-17 17:25:40 +01:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
|
|
|
}
|
2018-03-17 17:25:40 +01:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
private currentLoading: number;
|
|
|
|
ngOnInit() {
|
2019-03-24 22:52:34 +01:00
|
|
|
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
2018-09-22 06:22:51 +02:00
|
|
|
if (accounts) {
|
2019-01-31 07:01:48 +01:00
|
|
|
//Update and Add
|
2018-09-22 06:22:51 +02:00
|
|
|
for (let acc of accounts) {
|
2018-09-26 01:29:49 +02:00
|
|
|
const previousAcc = this.accounts.find(x => x.info.id === acc.id)
|
|
|
|
if (previousAcc) {
|
|
|
|
previousAcc.info.isSelected = acc.isSelected;
|
|
|
|
} else {
|
2019-03-24 22:52:34 +01:00
|
|
|
const accWrapper = new AccountWithNotificationWrapper();
|
2018-09-26 01:29:49 +02:00
|
|
|
accWrapper.info = acc;
|
2019-03-24 22:52:34 +01:00
|
|
|
|
2018-09-26 01:29:49 +02:00
|
|
|
this.accounts.push(accWrapper);
|
|
|
|
|
|
|
|
this.mastodonService.retrieveAccountDetails(acc)
|
|
|
|
.then((result: Account) => {
|
|
|
|
accWrapper.avatar = result.avatar;
|
2019-02-12 05:41:21 +01:00
|
|
|
})
|
|
|
|
.catch((err: HttpErrorResponse) => {
|
|
|
|
this.notificationService.notifyHttpError(err);
|
2018-09-26 01:29:49 +02:00
|
|
|
});
|
|
|
|
}
|
2019-01-31 07:01:48 +01:00
|
|
|
}
|
2018-09-26 01:29:49 +02:00
|
|
|
|
2019-01-31 07:01:48 +01:00
|
|
|
//Delete
|
|
|
|
const deletedAccounts = this.accounts.filter(x => accounts.findIndex(y => y.id === x.info.id) === -1);
|
2019-03-24 22:52:34 +01:00
|
|
|
for (let delAcc of deletedAccounts) {
|
2019-01-31 07:01:48 +01:00
|
|
|
this.accounts = this.accounts.filter(x => x.info.id !== delAcc.info.id);
|
2018-09-22 06:22:51 +02:00
|
|
|
}
|
2019-02-11 04:23:10 +01:00
|
|
|
|
|
|
|
this.hasAccounts = this.accounts.length > 0;
|
2018-09-22 06:22:51 +02:00
|
|
|
}
|
|
|
|
});
|
2019-03-24 22:52:34 +01:00
|
|
|
|
|
|
|
this.notificationSub = this.userNotificationServiceService.userNotifications.subscribe((notifications: UserNotification[]) => {
|
|
|
|
notifications.forEach((notification: UserNotification) => {
|
|
|
|
const acc = this.accounts.find(x => x.info.id === notification.account.id);
|
|
|
|
if(acc){
|
|
|
|
acc.hasActivityNotifications = notification.hasNewMentions || notification.hasNewNotifications;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2018-09-22 06:22:51 +02:00
|
|
|
}
|
2018-03-16 03:43:41 +01:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
ngOnDestroy(): void {
|
2019-03-24 22:52:34 +01:00
|
|
|
this.accountSub.unsubscribe();
|
|
|
|
this.notificationSub.unsubscribe();
|
2018-09-22 06:22:51 +02:00
|
|
|
}
|
2018-09-10 02:12:32 +02:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
onToogleAccountNotify(acc: AccountWrapper) {
|
2018-09-26 01:29:49 +02:00
|
|
|
this.store.dispatch([new SelectAccount(acc.info)]);
|
2018-09-22 06:22:51 +02:00
|
|
|
}
|
2018-03-16 03:43:41 +01:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
onOpenMenuNotify(acc: AccountWrapper) {
|
|
|
|
this.navigationService.openColumnEditor(acc);
|
|
|
|
}
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
createNewStatus(): boolean {
|
|
|
|
this.navigationService.openPanel(LeftPanelType.CreateNewStatus);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
openSearch(): boolean {
|
|
|
|
this.navigationService.openPanel(LeftPanelType.Search);
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-26 01:29:49 +02:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
addNewAccount(): boolean {
|
|
|
|
this.navigationService.openPanel(LeftPanelType.AddNewAccount);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
openSettings(): boolean {
|
|
|
|
this.navigationService.openPanel(LeftPanelType.Settings);
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-16 01:43:53 +01:00
|
|
|
}
|
2019-03-24 22:52:34 +01:00
|
|
|
|
|
|
|
export class AccountWithNotificationWrapper extends AccountWrapper {
|
|
|
|
// constructor(accountWrapper: AccountWrapper) {
|
|
|
|
// super();
|
|
|
|
|
|
|
|
// this.avatar = accountWrapper.avatar;
|
|
|
|
// this.info = accountWrapper.info;
|
|
|
|
// }
|
|
|
|
|
|
|
|
hasActivityNotifications: boolean;
|
|
|
|
}
|