2020-06-14 09:07:44 +02:00
|
|
|
import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
|
2019-03-20 03:07:42 +01:00
|
|
|
import { faAt, faUserPlus } from "@fortawesome/free-solid-svg-icons";
|
2020-03-14 02:06:08 +01:00
|
|
|
import { faBell, faEnvelope, faUser, faStar, faBookmark } from "@fortawesome/free-regular-svg-icons";
|
2019-03-25 02:11:23 +01:00
|
|
|
import { Subscription } from 'rxjs';
|
2019-03-19 05:21:00 +01:00
|
|
|
|
2018-09-11 07:54:23 +02:00
|
|
|
import { AccountWrapper } from '../../../models/account.models';
|
2019-03-25 06:09:53 +01:00
|
|
|
import { UserNotificationService, UserNotification } from '../../../services/user-notification.service';
|
2020-03-14 02:06:08 +01:00
|
|
|
import { OpenThreadEvent, ToolsService, InstanceInfo } from '../../../services/tools.service';
|
2019-10-02 06:14:40 +02:00
|
|
|
import { MastodonWrapperService } from '../../../services/mastodon-wrapper.service';
|
2019-06-15 20:03:29 +02:00
|
|
|
import { Account } from "../../../services/models/mastodon.interfaces";
|
|
|
|
import { NotificationService } from '../../../services/notification.service';
|
|
|
|
import { AccountInfo } from '../../../states/accounts.state';
|
2020-04-30 08:12:01 +02:00
|
|
|
import { BookmarksComponent } from './bookmarks/bookmarks.component';
|
|
|
|
import { NotificationsComponent } from './notifications/notifications.component';
|
|
|
|
import { MentionsComponent } from './mentions/mentions.component';
|
|
|
|
import { DirectMessagesComponent } from './direct-messages/direct-messages.component';
|
|
|
|
import { FavoritesComponent } from './favorites/favorites.component';
|
2020-06-14 09:07:44 +02:00
|
|
|
import { BrowseBase } from '../../common/browse-base';
|
2021-02-28 08:38:42 +01:00
|
|
|
import { SettingsService } from '../../../services/settings.service';
|
2019-03-25 02:11:23 +01:00
|
|
|
|
2018-09-10 03:55:16 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-01-28 06:46:37 +01:00
|
|
|
selector: 'app-manage-account',
|
|
|
|
templateUrl: './manage-account.component.html',
|
|
|
|
styleUrls: ['./manage-account.component.scss']
|
2018-09-10 03:55:16 +02:00
|
|
|
})
|
2020-06-14 09:07:44 +02:00
|
|
|
export class ManageAccountComponent extends BrowseBase {
|
2019-03-19 05:21:00 +01:00
|
|
|
faAt = faAt;
|
|
|
|
faBell = faBell;
|
|
|
|
faEnvelope = faEnvelope;
|
|
|
|
faUser = faUser;
|
2019-03-20 03:07:42 +01:00
|
|
|
faStar = faStar;
|
|
|
|
faUserPlus = faUserPlus;
|
2020-03-14 02:06:08 +01:00
|
|
|
faBookmark = faBookmark;
|
2019-03-19 05:21:00 +01:00
|
|
|
|
2020-03-14 02:06:08 +01:00
|
|
|
subPanel: 'account' | 'notifications' | 'mentions' | 'dm' | 'favorites' | 'bookmarks' = 'account';
|
2019-03-20 03:25:04 +01:00
|
|
|
hasNotifications = false;
|
|
|
|
hasMentions = false;
|
2020-03-14 02:06:08 +01:00
|
|
|
isBookmarksAvailable = false;
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2019-06-15 20:03:29 +02:00
|
|
|
userAccount: Account;
|
|
|
|
|
2019-03-25 02:11:23 +01:00
|
|
|
@Input('account')
|
|
|
|
set account(acc: AccountWrapper) {
|
|
|
|
this._account = acc;
|
2020-03-14 02:06:08 +01:00
|
|
|
this.checkIfBookmarksAreAvailable();
|
2019-03-25 02:11:23 +01:00
|
|
|
this.checkNotifications();
|
2019-06-15 20:03:29 +02:00
|
|
|
this.getUserUrl(acc.info);
|
2019-03-25 02:11:23 +01:00
|
|
|
}
|
|
|
|
get account(): AccountWrapper {
|
|
|
|
return this._account;
|
|
|
|
}
|
|
|
|
|
|
|
|
private userNotificationServiceSub: Subscription;
|
|
|
|
private _account: AccountWrapper;
|
|
|
|
|
|
|
|
constructor(
|
2021-02-28 08:38:42 +01:00
|
|
|
private readonly settingsService: SettingsService,
|
2019-11-17 04:35:20 +01:00
|
|
|
private readonly toolsService: ToolsService,
|
2019-10-02 06:14:40 +02:00
|
|
|
private readonly mastodonService: MastodonWrapperService,
|
2019-06-15 20:03:29 +02:00
|
|
|
private readonly notificationService: NotificationService,
|
2022-11-18 00:08:13 +01:00
|
|
|
private readonly userNotificationService: UserNotificationService) {
|
2020-06-14 09:07:44 +02:00
|
|
|
super();
|
|
|
|
}
|
2019-03-25 02:11:23 +01:00
|
|
|
|
2022-11-18 00:08:13 +01:00
|
|
|
ngOnInit() {
|
2019-03-25 02:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.userNotificationServiceSub.unsubscribe();
|
|
|
|
}
|
2019-01-30 04:33:49 +01:00
|
|
|
|
2020-03-14 02:06:08 +01:00
|
|
|
private checkIfBookmarksAreAvailable() {
|
|
|
|
this.toolsService.getInstanceInfo(this.account.info)
|
|
|
|
.then((instance: InstanceInfo) => {
|
2022-11-18 00:08:13 +01:00
|
|
|
if (instance.major == 3 && instance.minor >= 1 || instance.major > 3) {
|
2020-03-14 02:06:08 +01:00
|
|
|
this.isBookmarksAvailable = true;
|
|
|
|
} else {
|
|
|
|
this.isBookmarksAvailable = false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
this.isBookmarksAvailable = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-17 04:35:20 +01:00
|
|
|
private getUserUrl(account: AccountInfo) {
|
2019-06-15 20:03:29 +02:00
|
|
|
this.mastodonService.retrieveAccountDetails(this.account.info)
|
|
|
|
.then((acc: Account) => {
|
|
|
|
this.userAccount = acc;
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2019-09-07 23:52:07 +02:00
|
|
|
this.notificationService.notifyHttpError(err, this.account.info);
|
2019-06-15 20:03:29 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-17 04:35:20 +01:00
|
|
|
private checkNotifications() {
|
|
|
|
if (this.userNotificationServiceSub) {
|
2019-03-25 05:52:30 +01:00
|
|
|
this.userNotificationServiceSub.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2019-03-25 02:11:23 +01:00
|
|
|
this.userNotificationServiceSub = this.userNotificationService.userNotifications.subscribe((userNotifications: UserNotification[]) => {
|
|
|
|
const userNotification = userNotifications.find(x => x.account.id === this.account.info.id);
|
2019-11-17 04:35:20 +01:00
|
|
|
if (userNotification) {
|
2021-02-28 08:38:42 +01:00
|
|
|
let settings = this.settingsService.getSettings();
|
|
|
|
let accSettings = this.settingsService.getAccountSettings(this.account.info);
|
2019-11-17 04:35:20 +01:00
|
|
|
|
|
|
|
if (!settings.disableAvatarNotifications && !accSettings.disableAvatarNotifications) {
|
|
|
|
this.hasNotifications = userNotification.hasNewNotifications;
|
|
|
|
this.hasMentions = userNotification.hasNewMentions;
|
|
|
|
}
|
2019-03-25 02:11:23 +01:00
|
|
|
}
|
|
|
|
});
|
2019-11-17 04:35:20 +01:00
|
|
|
|
|
|
|
let current = this.userNotificationService.userNotifications.value;
|
|
|
|
const userNotification = current.find(x => x.account.id === this.account.info.id);
|
|
|
|
if (userNotification) {
|
2021-02-28 08:38:42 +01:00
|
|
|
let settings = this.settingsService.getSettings();
|
|
|
|
let accSettings = this.settingsService.getAccountSettings(this.account.info);
|
2019-11-17 04:35:20 +01:00
|
|
|
|
|
|
|
if (!settings.disableAutofocus && !settings.disableAvatarNotifications && !accSettings.disableAvatarNotifications) {
|
|
|
|
if (userNotification.hasNewNotifications) {
|
|
|
|
this.loadSubPanel('notifications');
|
|
|
|
} else if (userNotification.hasNewMentions) {
|
|
|
|
this.loadSubPanel('mentions');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-30 04:33:49 +01:00
|
|
|
}
|
2019-03-20 03:25:04 +01:00
|
|
|
|
2020-04-30 08:12:01 +02:00
|
|
|
@ViewChild('bookmarks') bookmarksComp:BookmarksComponent;
|
|
|
|
@ViewChild('notifications') notificationsComp:NotificationsComponent;
|
|
|
|
@ViewChild('mentions') mentionsComp:MentionsComponent;
|
|
|
|
@ViewChild('dm') dmComp:DirectMessagesComponent;
|
|
|
|
@ViewChild('favorites') favoritesComp:FavoritesComponent;
|
|
|
|
|
|
|
|
loadSubPanel(subpanel: 'account' | 'notifications' | 'mentions' | 'dm' | 'favorites' | 'bookmarks'): boolean {
|
|
|
|
if(this.subPanel === subpanel){
|
|
|
|
switch(subpanel){
|
2022-11-18 00:08:13 +01:00
|
|
|
case 'bookmarks':
|
2020-04-30 08:12:01 +02:00
|
|
|
this.bookmarksComp.applyGoToTop();
|
|
|
|
break;
|
|
|
|
case 'notifications':
|
|
|
|
this.notificationsComp.applyGoToTop();
|
|
|
|
break;
|
|
|
|
case 'mentions':
|
|
|
|
this.mentionsComp.applyGoToTop();
|
|
|
|
break;
|
|
|
|
case 'dm':
|
|
|
|
this.dmComp.applyGoToTop();
|
|
|
|
break;
|
|
|
|
case 'favorites':
|
|
|
|
this.favoritesComp.applyGoToTop();
|
2022-11-18 00:08:13 +01:00
|
|
|
break;
|
2020-04-30 08:12:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-20 03:25:04 +01:00
|
|
|
this.subPanel = subpanel;
|
2022-11-18 00:08:13 +01:00
|
|
|
|
2019-03-20 03:25:04 +01:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-01 02:24:07 +02:00
|
|
|
|
2019-06-23 21:33:45 +02:00
|
|
|
browseLocalAccount(): boolean {
|
|
|
|
var accountName = `@${this.account.info.username}@${this.account.info.instance}`;
|
|
|
|
this.browseAccountEvent.next(accountName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
openLocalAccount(): boolean {
|
|
|
|
window.open(this.userAccount.url, '_blank');
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-10 03:55:16 +02:00
|
|
|
}
|