fix settings state
This commit is contained in:
parent
f792f227f8
commit
b096ced237
|
@ -55,6 +55,7 @@ import { FavoritesComponent } from './components/floating-column/manage-account/
|
|||
import { DirectMessagesComponent } from './components/floating-column/manage-account/direct-messages/direct-messages.component';
|
||||
import { MentionsComponent } from './components/floating-column/manage-account/mentions/mentions.component';
|
||||
import { NotificationsComponent } from './components/floating-column/manage-account/notifications/notifications.component';
|
||||
import { SettingsState } from './states/settings.state';
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: "", redirectTo: "home", pathMatch: "full" },
|
||||
|
@ -112,7 +113,8 @@ const routes: Routes = [
|
|||
NgxsModule.forRoot([
|
||||
RegisteredAppsState,
|
||||
AccountsState,
|
||||
StreamsState
|
||||
StreamsState,
|
||||
SettingsState
|
||||
]),
|
||||
NgxsStoragePluginModule.forRoot()
|
||||
],
|
||||
|
|
|
@ -129,7 +129,6 @@ describe('CreateStatusComponent', () => {
|
|||
expect(result[1].length).toBeLessThanOrEqual(527);
|
||||
expect(result[0]).toContain('@Lorem@ipsum.com ');
|
||||
expect(result[1]).toContain('@Lorem@ipsum.com ');
|
||||
console.warn(result);
|
||||
});
|
||||
|
||||
});
|
|
@ -30,7 +30,6 @@ export class FavoritesComponent implements OnInit {
|
|||
|
||||
@Input('account')
|
||||
set account(acc: AccountWrapper) {
|
||||
console.warn('account');
|
||||
this._account = acc;
|
||||
this.getFavorites();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Component, OnInit, OnDestroy, Input, ViewChild, ElementRef } from '@angular/core';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { Store } from '@ngxs/store';
|
||||
|
||||
import { AccountWrapper } from '../../../../models/account.models';
|
||||
import { UserNotificationService, UserNotification } from '../../../../services/user-notification.service';
|
||||
|
@ -7,6 +8,8 @@ import { StatusWrapper } from '../../../../models/common.model';
|
|||
import { Status, Notification } from '../../../../services/models/mastodon.interfaces';
|
||||
import { MastodonService } from '../../../../services/mastodon.service';
|
||||
import { NotificationService } from '../../../../services/notification.service';
|
||||
import { AccountSettings, SettingsState } from '../../../../states/settings.state';
|
||||
import { ToolsService } from '../../../../services/tools.service';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -26,6 +29,9 @@ export class MentionsComponent implements OnInit, OnDestroy {
|
|||
console.warn('account');
|
||||
this._account = acc;
|
||||
this.loadMentions();
|
||||
|
||||
const accountSettings = this.toolsService.getAccountSettings(acc.info);
|
||||
console.warn(accountSettings);
|
||||
}
|
||||
get account(): AccountWrapper {
|
||||
return this._account;
|
||||
|
@ -39,9 +45,13 @@ export class MentionsComponent implements OnInit, OnDestroy {
|
|||
private lastId: string;
|
||||
|
||||
constructor(
|
||||
private readonly toolsService: ToolsService,
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly userNotificationService: UserNotificationService,
|
||||
private readonly mastodonService: MastodonService) { }
|
||||
private readonly mastodonService: MastodonService,
|
||||
private readonly store: Store) {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ export class NotificationsComponent implements OnInit, OnDestroy {
|
|||
|
||||
@Input('account')
|
||||
set account(acc: AccountWrapper) {
|
||||
console.warn('account');
|
||||
this._account = acc;
|
||||
this.loadNotifications();
|
||||
}
|
||||
|
@ -92,13 +91,8 @@ export class NotificationsComponent implements OnInit, OnDestroy {
|
|||
|
||||
this.isLoading = true;
|
||||
|
||||
console.warn(`this.lastId ${this.lastId}`);
|
||||
|
||||
this.mastodonService.getNotifications(this.account.info, ['mention'], this.lastId)
|
||||
.then((notifications: Notification[]) => {
|
||||
console.warn(notifications);
|
||||
|
||||
// const statuses = result.map(x => x.status);
|
||||
if (notifications.length === 0) {
|
||||
this.maxReached = true;
|
||||
return;
|
||||
|
|
|
@ -90,9 +90,6 @@ export class UserProfileComponent implements OnInit {
|
|||
|
||||
return this.toolsService.findAccount(this.currentlyUsedAccount, this.lastAccountName)
|
||||
.then((account: Account) => {
|
||||
|
||||
console.warn(account);
|
||||
|
||||
this.isLoading = false;
|
||||
this.statusLoading = true;
|
||||
|
||||
|
|
|
@ -5,12 +5,13 @@ import { AccountInfo } from '../states/accounts.state';
|
|||
import { MastodonService } from './mastodon.service';
|
||||
import { Account, Results, Status } from "./models/mastodon.interfaces";
|
||||
import { StatusWrapper } from '../models/common.model';
|
||||
import { AccountSettings, SaveAccountSettings } from '../states/settings.state';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ToolsService {
|
||||
|
||||
|
||||
constructor(
|
||||
private readonly mastodonService: MastodonService,
|
||||
private readonly store: Store) { }
|
||||
|
@ -20,6 +21,23 @@ export class ToolsService {
|
|||
var regAccounts = <AccountInfo[]>this.store.snapshot().registeredaccounts.accounts;
|
||||
return regAccounts.filter(x => x.isSelected);
|
||||
}
|
||||
|
||||
getAccountSettings(account: AccountInfo): AccountSettings {
|
||||
var accountsSettings = <AccountSettings[]>this.store.snapshot().globalsettings.settings.accountSettings;
|
||||
let accountSettings = accountsSettings.find(x => x.accountId === account.id);
|
||||
if(!accountSettings){
|
||||
accountSettings = new AccountSettings();
|
||||
accountSettings.accountId = account.id;
|
||||
this.saveAccountSettings(accountSettings);
|
||||
}
|
||||
return accountSettings;
|
||||
}
|
||||
|
||||
saveAccountSettings(accountSettings: AccountSettings){
|
||||
this.store.dispatch([
|
||||
new SaveAccountSettings(accountSettings)
|
||||
])
|
||||
}
|
||||
|
||||
findAccount(account: AccountInfo, accountName: string): Promise<Account> {
|
||||
return this.mastodonService.search(account, accountName, true)
|
||||
|
@ -51,6 +69,7 @@ export class ToolsService {
|
|||
|
||||
return statusPromise;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class OpenThreadEvent {
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
import { State, Action, StateContext } from '@ngxs/store';
|
||||
import { State, Action, StateContext, Selector, createSelector } from '@ngxs/store';
|
||||
|
||||
export class RemoveUserSettings {
|
||||
static readonly type = '[Settings] Remove UserSettings';
|
||||
export class RemoveAccountSettings {
|
||||
static readonly type = '[Settings] Remove AccountSettings';
|
||||
constructor(public accountId: string) {}
|
||||
}
|
||||
|
||||
export class SaveUserSettings {
|
||||
static readonly type = '[Settings] Update UserSettings';
|
||||
constructor(public userSettings: UserSettings) {}
|
||||
export class SaveAccountSettings {
|
||||
static readonly type = '[Settings] Save AccountSettings';
|
||||
constructor(public accountSettings: AccountSettings) {}
|
||||
}
|
||||
|
||||
export class SaveSettings {
|
||||
static readonly type = '[Settings] Update UserSettings';
|
||||
static readonly type = '[Settings] Save Settings';
|
||||
constructor(public settings: GlobalSettings) {}
|
||||
}
|
||||
|
||||
export class UserSettings {
|
||||
export class AccountSettings {
|
||||
accountId: string;
|
||||
displayMention: boolean = true;
|
||||
displayNotifications: boolean = true;
|
||||
|
@ -25,7 +25,7 @@ export class UserSettings {
|
|||
|
||||
export class GlobalSettings {
|
||||
disableAllNotifications = false;
|
||||
userSettings: UserSettings[] = [];
|
||||
accountSettings: AccountSettings[] = [];
|
||||
}
|
||||
|
||||
export interface SettingsStateModel {
|
||||
|
@ -38,27 +38,35 @@ export interface SettingsStateModel {
|
|||
settings: new GlobalSettings()
|
||||
}
|
||||
})
|
||||
export class SettingsState {
|
||||
@Action(RemoveUserSettings)
|
||||
RemoveUserSettings(ctx: StateContext<SettingsStateModel>, action: RemoveUserSettings){
|
||||
export class SettingsState {
|
||||
|
||||
accountSettings(accountId: string){
|
||||
return createSelector([SettingsState], (state: GlobalSettings) => {
|
||||
return state.accountSettings.find(x => x.accountId === accountId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Action(RemoveAccountSettings)
|
||||
RemoveAccountSettings(ctx: StateContext<SettingsStateModel>, action: RemoveAccountSettings){
|
||||
const state = ctx.getState();
|
||||
const newSettings = new GlobalSettings();
|
||||
|
||||
newSettings.disableAllNotifications = state.settings.disableAllNotifications;
|
||||
newSettings.userSettings = [...state.settings.userSettings.filter(x => x.accountId !== action.accountId)];
|
||||
newSettings.accountSettings = [...state.settings.accountSettings.filter(x => x.accountId !== action.accountId)];
|
||||
|
||||
ctx.patchState({
|
||||
settings: newSettings
|
||||
});
|
||||
}
|
||||
|
||||
@Action(SaveUserSettings)
|
||||
SaveUserSettings(ctx: StateContext<SettingsStateModel>, action: SaveUserSettings){
|
||||
@Action(SaveAccountSettings)
|
||||
SaveAccountSettings(ctx: StateContext<SettingsStateModel>, action: SaveAccountSettings){
|
||||
const state = ctx.getState();
|
||||
const newSettings = new GlobalSettings();
|
||||
|
||||
newSettings.disableAllNotifications = state.settings.disableAllNotifications;
|
||||
newSettings.userSettings = [...state.settings.userSettings.filter(x => x.accountId !== action.userSettings.accountId), action.userSettings];
|
||||
newSettings.accountSettings = [...state.settings.accountSettings.filter(x => x.accountId !== action.accountSettings.accountId), action.accountSettings];
|
||||
|
||||
ctx.patchState({
|
||||
settings: newSettings
|
||||
|
@ -71,7 +79,7 @@ export class SettingsState {
|
|||
const newSettings = new GlobalSettings();
|
||||
|
||||
newSettings.disableAllNotifications = action.settings.disableAllNotifications;
|
||||
newSettings.userSettings = [...state.settings.userSettings];
|
||||
newSettings.accountSettings = [...state.settings.accountSettings];
|
||||
|
||||
ctx.patchState({
|
||||
settings: newSettings
|
||||
|
|
Loading…
Reference in New Issue