2018-03-17 17:25:40 +01:00
|
|
|
import { Component, OnInit, OnDestroy } from "@angular/core";
|
2023-08-20 06:36:52 +02:00
|
|
|
import { CdkDragDrop, moveItemInArray } from "@angular/cdk/drag-drop";
|
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";
|
2023-08-20 07:16:41 +02:00
|
|
|
import { faPlus, faCog, faSearch, faArrowsAltV } from "@fortawesome/free-solid-svg-icons";
|
2019-08-25 07:43:47 +02:00
|
|
|
import { faCommentAlt, faCalendarAlt } from "@fortawesome/free-regular-svg-icons";
|
2019-09-30 01:21:43 +02:00
|
|
|
import { HotkeysService, Hotkey } from 'angular2-hotkeys';
|
2018-03-17 17:25:40 +01:00
|
|
|
|
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";
|
2019-03-25 06:09:53 +01:00
|
|
|
import { UserNotificationService, UserNotification } from '../../services/user-notification.service';
|
2019-09-06 07:18:41 +02:00
|
|
|
import { ToolsService } from '../../services/tools.service';
|
2019-09-07 22:31:37 +02:00
|
|
|
import { ScheduledStatusService, ScheduledStatusNotification } from '../../services/scheduled-status.service';
|
2021-02-28 08:38:42 +01:00
|
|
|
import { SettingsService } from '../../services/settings.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-06-01 20:22:12 +02:00
|
|
|
faSearch = faSearch;
|
2019-09-07 22:31:37 +02:00
|
|
|
faPlus = faPlus;
|
2019-06-01 20:22:12 +02:00
|
|
|
faCog = faCog;
|
2019-08-25 07:43:47 +02:00
|
|
|
faCalendarAlt = faCalendarAlt;
|
2023-08-20 07:16:41 +02:00
|
|
|
faArrowsAltV = faArrowsAltV;
|
2019-02-11 05:03:05 +01:00
|
|
|
|
2019-03-24 22:52:34 +01:00
|
|
|
accounts: AccountWithNotificationWrapper[] = [];
|
2019-02-11 04:23:10 +01:00
|
|
|
hasAccounts: boolean;
|
2019-09-07 22:31:37 +02:00
|
|
|
hasScheduledStatuses: 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;
|
2019-09-07 22:31:37 +02:00
|
|
|
private scheduledSub: Subscription;
|
2019-03-24 22:52:34 +01:00
|
|
|
private notificationSub: Subscription;
|
2018-03-16 03:43:41 +01:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
constructor(
|
2021-02-28 08:38:42 +01:00
|
|
|
private readonly settingsService: SettingsService,
|
2019-09-30 01:21:43 +02:00
|
|
|
private readonly hotkeysService: HotkeysService,
|
2019-09-07 22:31:37 +02:00
|
|
|
private readonly scheduledStatusService: ScheduledStatusService,
|
2019-09-06 07:18:41 +02:00
|
|
|
private readonly toolsService: ToolsService,
|
2019-03-25 06:09:53 +01:00
|
|
|
private readonly userNotificationServiceService: UserNotificationService,
|
2018-09-22 06:22:51 +02:00
|
|
|
private readonly navigationService: NavigationService,
|
|
|
|
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);
|
2019-09-30 01:21:43 +02:00
|
|
|
|
|
|
|
this.hotkeysService.add(new Hotkey('n', (event: KeyboardEvent): boolean => {
|
|
|
|
this.createNewStatus();
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.hotkeysService.add(new Hotkey('s', (event: KeyboardEvent): boolean => {
|
|
|
|
this.openSearch();
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.hotkeysService.add(new Hotkey('a', (event: KeyboardEvent): boolean => {
|
|
|
|
this.addNewAccount();
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.hotkeysService.add(new Hotkey('c', (event: KeyboardEvent): boolean => {
|
|
|
|
this.navigationService.openPanel(LeftPanelType.Closed);
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.hotkeysService.add(new Hotkey('escape', (event: KeyboardEvent): boolean => {
|
|
|
|
this.navigationService.openPanel(LeftPanelType.Closed);
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.hotkeysService.add(new Hotkey('ctrl+up', (event: KeyboardEvent): boolean => {
|
|
|
|
this.selectPreviousAccount();
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.hotkeysService.add(new Hotkey('ctrl+down', (event: KeyboardEvent): boolean => {
|
|
|
|
this.selectNextAccount();
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2019-11-16 23:40:49 +01:00
|
|
|
private selectPreviousAccount() {
|
2019-09-30 01:21:43 +02:00
|
|
|
let accounts = <AccountInfo[]>this.store.snapshot().registeredaccounts.accounts;
|
|
|
|
let selectedAccount = accounts.find(x => x.isSelected);
|
|
|
|
let selectedIndex = accounts.indexOf(selectedAccount);
|
|
|
|
|
2019-11-16 23:40:49 +01:00
|
|
|
if (selectedIndex > 0) {
|
2019-09-30 01:21:43 +02:00
|
|
|
let previousAccount = accounts[selectedIndex - 1];
|
|
|
|
this.store.dispatch([new SelectAccount(previousAccount)]);
|
2019-11-16 23:40:49 +01:00
|
|
|
}
|
2019-09-30 01:21:43 +02:00
|
|
|
}
|
|
|
|
|
2019-11-16 23:40:49 +01:00
|
|
|
private selectNextAccount() {
|
2019-09-30 01:21:43 +02:00
|
|
|
let accounts = <AccountInfo[]>this.store.snapshot().registeredaccounts.accounts;
|
|
|
|
let selectedAccount = accounts.find(x => x.isSelected);
|
|
|
|
let selectedIndex = accounts.indexOf(selectedAccount);
|
|
|
|
|
2019-11-16 23:40:49 +01:00
|
|
|
if (selectedIndex < accounts.length - 1) {
|
2019-09-30 01:21:43 +02:00
|
|
|
let nextAccount = accounts[selectedIndex + 1];
|
|
|
|
this.store.dispatch([new SelectAccount(nextAccount)]);
|
|
|
|
}
|
2018-09-22 06:22:51 +02:00
|
|
|
}
|
2018-03-17 17:25:40 +01:00
|
|
|
|
2018-09-22 06:22:51 +02:00
|
|
|
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);
|
2019-09-07 22:31:37 +02:00
|
|
|
|
2019-09-06 07:18:41 +02:00
|
|
|
this.toolsService.getAvatar(acc)
|
|
|
|
.then((avatar: string) => {
|
|
|
|
accWrapper.avatar = avatar;
|
2019-09-07 22:31:37 +02:00
|
|
|
});
|
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[]) => {
|
2021-02-28 08:38:42 +01:00
|
|
|
const settings = this.settingsService.getSettings();
|
2019-03-24 22:52:34 +01:00
|
|
|
notifications.forEach((notification: UserNotification) => {
|
|
|
|
const acc = this.accounts.find(x => x.info.id === notification.account.id);
|
2019-11-16 23:40:49 +01:00
|
|
|
|
2019-09-07 22:31:37 +02:00
|
|
|
if (acc) {
|
2019-11-16 23:40:49 +01:00
|
|
|
const accSettings = settings.accountSettings.find(x => x.accountId === acc.info.id);
|
|
|
|
if (!settings.disableAvatarNotifications && !accSettings.disableAvatarNotifications) {
|
|
|
|
acc.hasActivityNotifications = notification.hasNewMentions || notification.hasNewNotifications;
|
|
|
|
}
|
2019-03-24 22:52:34 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-09-07 22:31:37 +02:00
|
|
|
|
|
|
|
this.scheduledSub = this.scheduledStatusService.scheduledStatuses.subscribe((notifications: ScheduledStatusNotification[]) => {
|
|
|
|
let statuses = [];
|
|
|
|
notifications.forEach(n => {
|
|
|
|
n.statuses.forEach(x => {
|
|
|
|
statuses.push(x);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
this.hasScheduledStatuses = statuses.length > 0;
|
|
|
|
});
|
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();
|
2019-09-30 01:21:43 +02:00
|
|
|
this.scheduledSub.unsubscribe();
|
2018-09-22 06:22:51 +02:00
|
|
|
}
|
2018-09-10 02:12:32 +02:00
|
|
|
|
2023-08-20 06:36:52 +02:00
|
|
|
onDrop(event: CdkDragDrop<AccountWithNotificationWrapper[]>) {
|
|
|
|
console.warn(event);
|
|
|
|
|
|
|
|
if (event.previousContainer === event.container) {
|
|
|
|
moveItemInArray(event.container.data,
|
|
|
|
event.previousIndex,
|
|
|
|
event.currentIndex);
|
|
|
|
|
|
|
|
console.warn(this.accounts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2019-08-25 07:43:47 +02:00
|
|
|
|
|
|
|
openScheduledStatuses(): boolean {
|
|
|
|
this.navigationService.openPanel(LeftPanelType.ScheduledStatuses);
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-16 01:43:53 +01:00
|
|
|
}
|
2019-03-24 22:52:34 +01:00
|
|
|
|
|
|
|
export class AccountWithNotificationWrapper extends AccountWrapper {
|
|
|
|
hasActivityNotifications: boolean;
|
|
|
|
}
|